[Mailman-checkins] [Branch ~mailman-coders/mailman/3.0]

2007-09-19 Thread noreply

revno: 6554
committer: Barry Warsaw [EMAIL PROTECTED]
branch nick: 3.0
timestamp: Wed 2007-09-19 07:28:58 -0400
message:
  Implement a context manager for Python 2.5's with statement, which is
  used where we used to do a try/except to temporarily change the global
  translation language.  This makes the code shorter and cleaner.  E.g.
  
  with i18n.using_language(another_language):
  # do something
modified:
  Mailman/Archiver/HyperArch.py
  Mailman/Cgi/subscribe.py
  Mailman/Deliverer.py
  Mailman/Handlers/Hold.py
  Mailman/Handlers/ToDigest.py
  Mailman/MailList.py
  Mailman/Queue/Runner.py
  Mailman/app/membership.py
  Mailman/app/moderator.py
  Mailman/bin/add_members.py
  Mailman/bin/change_pw.py
  Mailman/bin/newlist.py
  Mailman/i18n.py
  TODO.txt

=== modified file 'Mailman/Archiver/HyperArch.py'
--- a/Mailman/Archiver/HyperArch.py 2007-07-15 01:23:28 +
+++ b/Mailman/Archiver/HyperArch.py 2007-09-19 11:28:58 +
@@ -26,6 +26,8 @@
(probably in the 'update_dirty_archives' method).
 
 
+from __future__ import with_statement
+
 import os
 import re
 import sys
@@ -114,13 +116,8 @@
 if e.errno  errno.ENOENT: raise
 return _('size not available')
 if size  1000:
-# Avoid i18n side-effects
-otrans = i18n.get_translation()
-try:
-i18n.set_language(lang)
+with i18n.using_language(lang):
 out = _(' %(size)i bytes ')
-finally:
-i18n.set_translation(otrans)
 return out
 elif size  100:
 return ' %d KB ' % (size / 1000)
@@ -269,17 +266,12 @@
 # article (for this list) could be different from the site-wide
 # preferred language, so we need to ensure no side-effects will
 # occur.  Think what happens when executing bin/arch.
-otrans = i18n.get_translation()
-try:
-i18n.set_language(lang)
+with i18n.using_language(lang):
 if self.author == self.email:
 self.author = self.email = re.sub('@', _(' at '),
   self.email)
 else:
 self.email = re.sub('@', _(' at '), self.email)
-finally:
-i18n.set_translation(otrans)
-
 # Snag the content-* headers.  RFC 1521 states that their values are
 # case insensitive.
 ctype = message.get('Content-Type', 'text/plain')
@@ -401,14 +393,10 @@
 self.decoded['email'] = email
 if subject:
 if config.ARCHIVER_OBSCURES_EMAILADDRS:
-otrans = i18n.get_translation()
-try:
-i18n.set_language(self._lang)
+with i18n.using_language(self._lang):
 atmark = unicode(_(' at '), Utils.GetCharSet(self._lang))
 subject = re.sub(r'([-+,.\w]+)@([-+.\w]+)',
   '\g1' + atmark + '\g2', subject)
-finally:
-i18n.set_translation(otrans)
 self.decoded['subject'] = subject
 self.decoded['stripped'] = self.strip_subject(subject or self.subject)
 
@@ -443,9 +431,7 @@
 def as_html(self):
 d = self.__dict__.copy()
 # avoid i18n side-effects
-otrans = i18n.get_translation()
-i18n.set_language(self._lang)
-try:
+with i18n.using_language(self._lang):
 d[prev], d[prev_wsubj] = self._get_prev()
 d[next], d[next_wsubj] = self._get_next()
 
@@ -468,9 +454,6 @@
 d['listurl'] = self._mlist.GetScriptURL('listinfo', absolute=1)
 d['listname'] = self._mlist.real_name
 d['encoding'] = ''
-finally:
-i18n.set_translation(otrans)
-
 charset = Utils.GetCharSet(self._lang)
 d[encoding] = html_charset % charset
 
@@ -562,14 +545,10 @@
 if not isinstance(body, unicode):
 body = unicode(body, cset, 'replace')
 if config.ARCHIVER_OBSCURES_EMAILADDRS:
-otrans = i18n.get_translation()
-try:
+with i18n.using_language(self._lang):
 atmark = unicode(_(' at '), cset)
-i18n.set_language(self._lang)
 body = re.sub(r'([-+,.\w]+)@([-+.\w]+)',
   '\g1' + atmark + '\g2', body)
-finally:
-i18n.set_translation(otrans)
 # Return body to character set of article.
 body = body.encode(cset, 'replace')
 return NL.join(headers) % d + '\n\n' + body + '\n'
@@ -668,12 +647,10 @@
 def html_foot(self):
 # avoid i18n side-effects
 mlist = self.maillist
-otrans = i18n.get_translation()
-i18n.set_language(mlist.preferred_language)
 # Convenience
 def quotetime(s):
 return 

[Mailman-checkins] [Branch ~mailman-coders/mailman/3.0]

2007-09-19 Thread noreply

revno: 6555
committer: Barry Warsaw [EMAIL PROTECTED]
branch nick: 3.0
timestamp: Wed 2007-09-19 22:35:37 -0400
message:
  InitTempVars() is completely eradicated.  The only bit I think we
  still need temporarily is the _gui component initialization, so this
  has been moved into MailList.__init__().
  
  Fixed the __getattr__() super call to properly dispatch up.
  
  Removed the _memberadaptor instance variable initialization.  The
  whole MemberAdaptor stuff is next on the chopping block.
  
  Essentially MailList locking is gone too now, although it's not  yet
  completely eradicated.  However, the __repr__() no longer states the
  lock status.
  
  The full_path property is now just an attribute on the underlying
  MailingList database object.
modified:
  Mailman/MailList.py
  Mailman/database/model/mailinglist.py
  Mailman/docs/hold.txt
  Mailman/docs/membership.txt
  Mailman/docs/requests.txt
  TODO.txt

=== modified file 'Mailman/MailList.py'
--- a/Mailman/MailList.py   2007-09-19 11:28:58 +
+++ b/Mailman/MailList.py   2007-09-20 02:35:37 +
@@ -97,12 +97,16 @@
 
 def __init__(self, data):
 self._data = data
-# Only one level of mixin inheritance allowed
+# Only one level of mixin inheritance allowed.
 for baseclass in self.__class__.__bases__:
 if hasattr(baseclass, '__init__'):
 baseclass.__init__(self)
-# Initialize volatile attributes
-self.InitTempVars()
+# Initialize the web u/i components.
+self._gui = []
+for component in dir(Gui):
+if component.startswith('_'):
+continue
+self._gui.append(getattr(Gui, component)())
 # Give the extension mechanism a chance to process this list.
 try:
 from Mailman.ext import init_mlist
@@ -114,15 +118,11 @@
 def __getattr__(self, name):
 missing = object()
 if name.startswith('_'):
-return super(MailList, self).__getattr__(name)
+return getattr(super(MailList, self), name)
 # Delegate to the database model object if it has the attribute.
 obj = getattr(self._data, name, missing)
 if obj is not missing:
 return obj
-# Delegate to the member adapter next.
-obj = getattr(self._memberadaptor, name, missing)
-if obj is not missing:
-return obj
 # Finally, delegate to one of the gui components.
 for guicomponent in self._gui:
 obj = getattr(guicomponent, name, missing)
@@ -132,12 +132,7 @@
 raise AttributeError(name)
 
 def __repr__(self):
-if self.Locked():
-status = '(locked)'
-else:
-status = '(unlocked)'
-return 'mailing list %s %s at %x' % (
-self.fqdn_listname, status, id(self))
+return 'mailing list %s at %x' % (self.fqdn_listname, id(self))
 
 
 #
@@ -170,15 +165,6 @@
 
 
 
-#
-# Useful accessors
-#
-@property
-def full_path(self):
-return self._full_path
-
-
-
 # IMailingListAddresses
 
 @property
@@ -278,42 +264,6 @@
 
 
 #
-# Instance and subcomponent initialization
-#
-def InitTempVars(self):
-Set transient variables of this and inherited classes.
-# Because of the semantics of the database layer, it's possible that
-# this method gets called more than once on an existing object.  For
-# example, if the MailList object is expunged from the current db
-# session, then this may get called again when the object's persistent
-# attributes are re-read from the database.  This can have nasty
-# consequences, so ensure that we're only called once.
-if hasattr(self, '_lock'):
-return
-# Attach a membership adaptor instance.
-parts = config.MEMBER_ADAPTOR_CLASS.split(DOT)
-adaptor_class = parts.pop()
-adaptor_module = DOT.join(parts)
-__import__(adaptor_module)
-mod = sys.modules[adaptor_module]
-self._memberadaptor = getattr(mod, adaptor_class)(self)
-self._make_lock(self.fqdn_listname)
-# Create the list's data directory.
-self._full_path = os.path.join(config.LIST_DATA_DIR, 
self.fqdn_listname)
-Utils.makedirs(self._full_path)
-# Only one level of mixin inheritance allowed
-for baseclass in self.__class__.__bases__:
-if hasattr(baseclass, 'InitTempVars'):
-baseclass.InitTempVars(self)
-# Now, initialize our gui components
-self._gui = []
-for component in dir(Gui):
-if component.startswith('_'):
-continue
-self._gui.append(getattr(Gui, component)())
-
-
-#
 # Web API support via administrative categories
 #
 def GetConfigCategories(self):

===