Revision: 6982
Author:   nicdumz
Date:     2009-06-22 15:00:31 +0000 (Mon, 22 Jun 2009)

Log Message:
-----------
cosmetic/coding style changes: adding spaces around operators, mostly

Modified Paths:
--------------
    branches/rewrite/pywikibot/bot.py
    branches/rewrite/pywikibot/config2.py
    branches/rewrite/pywikibot/date.py

Modified: branches/rewrite/pywikibot/bot.py
===================================================================
--- branches/rewrite/pywikibot/bot.py   2009-06-21 14:22:19 UTC (rev 6981)
+++ branches/rewrite/pywikibot/bot.py   2009-06-22 15:00:31 UTC (rev 6982)
@@ -282,7 +282,7 @@
     return os.path.basename(called)
 
 def _decodeArg(arg):
-    if sys.platform=='win32':
+    if sys.platform == 'win32':
         if config.console_encoding in ("cp437", 'cp850'):
             # Western Windows versions give parameters encoded as windows-1252
             # even though the console encoding is cp850 or cp437.
@@ -399,7 +399,7 @@
         except NameError:
             modname = "no_module"
 
-    globalHelp =u'''\
+    globalHelp = u'''\
 Global arguments available for all bots:
 
 -dir:PATH         Read the bot's configuration data from directory given by

Modified: branches/rewrite/pywikibot/config2.py
===================================================================
--- branches/rewrite/pywikibot/config2.py       2009-06-21 14:22:19 UTC (rev 
6981)
+++ branches/rewrite/pywikibot/config2.py       2009-06-22 15:00:31 UTC (rev 
6982)
@@ -199,7 +199,7 @@
 # The command for the editor you want to use. If set to None, a simple Tkinter
 # editor will be used.
 # On Windows systems, this script tries to determine the default text editor.
-if __sys.platform=='win32':
+if __sys.platform == 'win32':
     try:
         import _winreg
         _key1 = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, 
'Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.txt\OpenWithProgids')
@@ -211,6 +211,7 @@
         if editor.lower().endswith('notepad.exe'):
             editor = None
     except:
+        # XXX what are we catching here?
         #raise
         editor = None
 else:
@@ -476,25 +477,25 @@
 # ============================
 # System-level and User-level changes.
 # Store current variables and their types.
-_glv={}
+_glv = {}
 _glv.update(globals())
-_gl=_glv.keys()
-_tp={}
+_gl = _glv.keys()
+_tp = {}
 for _key in _gl:
-    if _key[0]!='_':
-        _tp[_key]=type(globals()[_key])
+    if _key[0]! = '_':
+        _tp[_key] = type(globals()[_key])
 
 # Get the user files
-_thislevel=0
-_fns=[os.path.join(_base_dir, "user-config.py")]
+_thislevel = 0
+_fns = [os.path.join(_base_dir, "user-config.py")]
 for _filename in _fns:
     _thislevel += 1
     if os.path.exists(_filename):
-        _filestatus=os.stat(_filename)
-        _filemode=_filestatus[0]
-        _fileuid=_filestatus[4]
-        if (__sys.platform=='win32' or _fileuid==os.getuid() or _fileuid==0):
-            if __sys.platform=='win32' or _filemode&002==0:
+        _filestatus = os.stat(_filename)
+        _filemode = _filestatus[0]
+        _fileuid = _filestatus[4]
+        if __sys.platform == 'win32' or _fileuid in [os.getuid(), 0]:
+            if __sys.platform == 'win32' or _filemode & 002 == 0:
                 execfile(_filename)
             else:
                 print "WARNING: Skipped '%(fn)s': writeable by others."\
@@ -520,7 +521,7 @@
             print "WARNING: Type of '%(_key)s' changed" % locals()
             print "         %(was)s: %(old)s" % {'was': "Was", 'old': ot}
             print "         %(was)s: %(new)s" % {'now': "Now", 'new': nt}
-        del nt,ot
+        del nt, ot
     else:
         print \
             "Configuration variable %(_key)r is defined but unknown."\
@@ -528,7 +529,7 @@
 
 # Fix up default console_encoding
 if console_encoding == None:
-    if __sys.platform=='win32':
+    if __sys.platform == 'win32':
         console_encoding = 'cp850'
     else:
         console_encoding = 'iso-8859-1'
@@ -549,13 +550,11 @@
     from [email protected] 2002/03/18
 
     """
-    from os import makedirs
-    from os.path import normpath, dirname, exists, abspath
+    dpath = os.path.normpath(os.path.dirname(path))
+    if not os.path.exists(dpath): 
+        os.makedirs(dpath)
+    return os.path.normpath(os.path.abspath(path))
 
-    dpath = normpath(dirname(path))
-    if not exists(dpath): makedirs(dpath)
-    return normpath(abspath(path))
-
 def datafilepath(*filename):
     """Return an absolute path to a data file in a standard location.
 
@@ -564,12 +563,10 @@
     directories in the path that do not already exist are created.
 
     """
-    import os
     return makepath(os.path.join(base_dir, *filename))
 
 def shortpath(path):
     """Return a file path relative to config.base_dir."""
-    import os
     if path.startswith(base_dir):
         return path[len(base_dir) + len(os.path.sep) : ]
     return path
@@ -577,21 +574,21 @@
 #
 # When called as main program, list all configuration variables
 #
-if __name__=="__main__":
+if __name__ == "__main__":
     import types
-    _all=1
+    _all = 1
     for _arg in __sys.argv[1:]:
-        if _arg=="modified":
-            _all=0
+        if _arg == "modified":
+            _all = 0
         else:
             print "Unknown arg %(_arg)s ignored" % locals()
-    _k=globals().keys()
+    _k = globals().keys()
     _k.sort()
     for _name in _k:
-        if _name[0]!='_':
+        if _name[0] != '_':
             if not type(globals()[_name]) in [types.FunctionType, 
types.ModuleType]:
-                if _all or _glv[_name]!=globals()[_name]:
-                    print _name,"=",repr(globals()[_name])
+                if _all or _glv[_name] != globals()[_name]:
+                    print _name, "=", repr(globals()[_name])
 
 # cleanup all locally-defined variables
 

Modified: branches/rewrite/pywikibot/date.py
===================================================================
--- branches/rewrite/pywikibot/date.py  2009-06-21 14:22:19 UTC (rev 6981)
+++ branches/rewrite/pywikibot/date.py  2009-06-22 15:00:31 UTC (rev 6982)
@@ -12,7 +12,7 @@
 #
 # Distributed under the terms of the MIT license.
 #
-__version__='$Id$'
+__version__ = '$Id$'
 
 # used for date recognition
 import types
@@ -197,34 +197,34 @@
        to accept all other values"""
     return True
 
-def monthName(lang,ind):
+def monthName(lang, ind):
     return formats['MonthName'][lang](ind)
 
 
 # Helper for KN: digits representation
-_knDigits=u'೦೧೨೩೪೫೬೭೮೯'
-_knDigitsToLocal=dict([(ord(unicode(i)), _knDigits[i]) for i in range(10)])
-_knLocalToDigits=dict([(ord(_knDigits[i]), unicode(i)) for i in range(10)])
+_knDigits = u'೦೧೨೩೪೫೬೭೮೯'
+_knDigitsToLocal = dict([(ord(unicode(i)), _knDigits[i]) for i in range(10)])
+_knLocalToDigits = dict([(ord(_knDigits[i]), unicode(i)) for i in range(10)])
 
 # Helper for Urdu/Persian languages
-_faDigits=u'۰۱۲۳۴۵۶۷۸۹'
-_faDigitsToLocal=dict([(ord(unicode(i)), _faDigits[i]) for i in range(10)])
-_faLocalToDigits=dict([(ord(_faDigits[i]), unicode(i)) for i in range(10)])
+_faDigits = u'۰۱۲۳۴۵۶۷۸۹'
+_faDigitsToLocal = dict([(ord(unicode(i)), _faDigits[i]) for i in range(10)])
+_faLocalToDigits = dict([(ord(_faDigits[i]), unicode(i)) for i in range(10)])
 
 # Helper for HI:, MR:
-_hiDigits=u'०१२३४५६७८९'
-_hiDigitsToLocal=dict([(ord(unicode(i)), _hiDigits[i]) for i in range(10)])
-_hiLocalToDigits=dict([(ord(_hiDigits[i]), unicode(i)) for i in range(10)])
+_hiDigits = u'०१२३४५६७८९'
+_hiDigitsToLocal = dict([(ord(unicode(i)), _hiDigits[i]) for i in range(10)])
+_hiLocalToDigits = dict([(ord(_hiDigits[i]), unicode(i)) for i in range(10)])
 
 # Helper for BN:
-_bnDigits=u'০১২৩৪৫৬৭৮৯'
-_bnDigitsToLocal=dict([(ord(unicode(i)), _bnDigits[i]) for i in range(10)])
-_bnLocalToDigits=dict([(ord(_bnDigits[i]), unicode(i)) for i in range(10)])
+_bnDigits = u'০১২৩৪৫৬৭৮৯'
+_bnDigitsToLocal = dict([(ord(unicode(i)), _bnDigits[i]) for i in range(10)])
+_bnLocalToDigits = dict([(ord(_bnDigits[i]), unicode(i)) for i in range(10)])
 
 # Helper for GU:
-_guDigits=u'૦૧૨૩૪૫૬૭૮૯'
-_guDigitsToLocal=dict([(ord(unicode(i)), _guDigits[i]) for i in range(10)])
-_guLocalToDigits=dict([(ord(_guDigits[i]), unicode(i)) for i in range(10)])
+_guDigits = u'૦૧૨૩૪૫૬૭૮૯'
+_guDigitsToLocal = dict([(ord(unicode(i)), _guDigits[i]) for i in range(10)])
+_guLocalToDigits = dict([(ord(_guDigits[i]), unicode(i)) for i in range(10)])
 
 def intToLocalDigitsStr( value, digitsToLocalDict ):
     # Encode an integer value into a textual form.
@@ -284,8 +284,8 @@
 _escPtrnCache2 = {}
 
 # Allow both unicode and single-byte strings
-_stringTypes = [type(u''), type('')]
-_listTypes = [type([]),type(())]
+_stringTypes = [unicode, str]
+_listTypes = [list, tuple]
 
 def escapePattern2( pattern ):
     """Converts a string pattern into a regex expression and cache.
@@ -299,7 +299,7 @@
         for s in _reParameters.split(pattern):
             if s is None:
                 pass
-            elif len(s) in [2,3] and s[0]=='%' and s[-1] in _digitDecoders and 
(len(s)==2 or s[1] in _decimalDigits):
+            elif len(s) in [2, 3] and s[0] == '%' and s[-1] in _digitDecoders 
and (len(s) == 2 or s[1] in _decimalDigits):
                 # Must match a "%2d" or "%d" style
                 dec = _digitDecoders[s[-1]]
                 if type(dec) in _stringTypes:
@@ -1433,21 +1433,21 @@
 # In addition, tuple contains start, end, and step values that will be used to 
test the formats table for internal consistency.
 #
 formatLimits = {
-    'MonthName'                        : (lambda v: 1<=v and v<13,             
    1,13),
-    'Number'                   : (lambda v: 0<=v and v<1000000,            
0,1001),
+    'MonthName'                        : (lambda v: 1 <=v and v < 13,          
       1, 13),
+    'Number'                   : (lambda v: 0 <=v and v < 1000000,            
0, 1001),
 
-    'YearAD'                   : (lambda v: 0<=v and v<2501,               
0,2501),
-    'YearBC'                   : (lambda v: 0<=v and v<4001,               
0,501),   # zh: has years as old as 前1700年
-    'DecadeAD'                 : (lambda v: 0<=v and v<2501,               
0,2501),  # At some point need to re-add  "and v%10==0" to the limitation
-    'DecadeBC'                 : (lambda v: 0<=v and v<4001,               
0,501),   # zh: has decades as old as 前1700年代
-    'CenturyAD'                        : (lambda v: 1<=v and v<41,             
    1,23),    # Some centuries use Roman numerals or a given list - do not 
exceed them in testing
-    'CenturyBC'                        : (lambda v: 1<=v and v<91,             
    1,23),    # Some centuries use Roman numerals or a given list - do not 
exceed them in testing
-    'MillenniumAD'             : (lambda v: 1<=v and v<6,                  
1,4),     # For milleniums, only test first 3 AD Milleniums,
-    'MillenniumBC'             : (lambda v: 1<=v and v<20,                 
1,2),     # And only 1 BC Millenium
-    'CenturyAD_Cat'     : (lambda v: 1<=v and v<41,                 1,23),    
# Some centuries use Roman numerals or a given list - do not exceed them in 
testing
-    'CenturyBC_Cat'     : (lambda v: 1<=v and v<41,                 1,23),    
# Some centuries use Roman numerals or a given list - do not exceed them in 
testing
-    'Cat_Year_MusicAlbums'     : (lambda v: 1950<=v and v<2021,        
1950,2021),
-    'CurrEvents'                       : (lambda v: 0<=v and v<1,              
0,1),
+    'YearAD'                   : (lambda v: 0 <=v and v < 2501,               
0, 2501),
+    'YearBC'                   : (lambda v: 0 <=v and v < 4001,               
0, 501),   # zh: has years as old as 前1700年
+    'DecadeAD'                 : (lambda v: 0 <=v and v < 2501,               
0, 2501),  # At some point need to re-add  "and v%10==0" to the limitation
+    'DecadeBC'                 : (lambda v: 0 <=v and v < 4001,               
0, 501),   # zh: has decades as old as 前1700年代
+    'CenturyAD'                        : (lambda v: 1 <=v and v < 41,          
       1, 23),    # Some centuries use Roman numerals or a given list - do not 
exceed them in testing
+    'CenturyBC'                        : (lambda v: 1 <=v and v < 91,          
       1, 23),    # Some centuries use Roman numerals or a given list - do not 
exceed them in testing
+    'MillenniumAD'             : (lambda v: 1 <=v and v < 6,                  
1, 4),     # For milleniums, only test first 3 AD Milleniums,
+    'MillenniumBC'             : (lambda v: 1 <=v and v < 20,                 
1, 2),     # And only 1 BC Millenium
+    'CenturyAD_Cat'     : (lambda v: 1 <=v and v < 41,                 1, 23), 
   # Some centuries use Roman numerals or a given list - do not exceed them in 
testing
+    'CenturyBC_Cat'     : (lambda v: 1 <=v and v < 41,                 1, 23), 
   # Some centuries use Roman numerals or a given list - do not exceed them in 
testing
+    'Cat_Year_MusicAlbums'     : (lambda v: 1950 <= v and v < 2021,        
1950, 2021),
+    'CurrEvents'                       : (lambda v:  0<= v and v < 1,          
    0, 1),
 }
 
 # All month of year articles are in the same format
@@ -1459,7 +1459,7 @@
 _formatLimit_DayOfMonth30 = (lambda v: 1 <= v and v < 31,           1, 31)
 _formatLimit_DayOfMonth29 = (lambda v: 1 <= v and v < 30,           1, 30)
 for monthId in range(12):
-    if (monthId+1) in [1,3,5,7,8,10,12]:
+    if (monthId + 1) in [1, 3, 5, 7, 8, 10, 12]:
         formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth31      # 
31 days a month
     elif (monthId+1) == 2: # February
         formatLimits[dayMnthFmts[monthId]] = _formatLimit_DayOfMonth29      # 
29 days a month
@@ -1468,7 +1468,7 @@
 
 def getNumberOfDaysInMonth(month):
     """Returns the number of days in a given month, 1 being January, etc."""
-    return formatLimits[dayMnthFmts[month-1]][2]-1
+    return formatLimits[dayMnthFmts[month - 1]][2] - 1
 
 
 def getAutoFormat( lang, title, ignoreFirstLetterCase = True ):
@@ -1476,7 +1476,7 @@
     for dictName, dict in formats.iteritems():
         try:
             year = dict[ lang ]( title )
-            return (dictName,year)
+            return dictName, year
         except:
             pass
 
@@ -1493,14 +1493,14 @@
         except:
             pass
 
-    return (None,None)
+    return None, None
 
 class FormatDate(object):
     def __init__(self, site):
         self.site = site
 
     def __call__(self, m, d):
-        return formats['Day_' + enMonthNames[m-1]][self.site.code](d)
+        return formats['Day_' + enMonthNames[m - 1]][self.site.code](d)
 
 
 def formatYear(lang, year):
@@ -1536,14 +1536,14 @@
     if formatName in decadeFormats: step = 10
     predicate,start,stop = formatLimits[formatName]
     if value is not None:
-        start, stop = value, value+1
+        start, stop = value, value + 1
     if showAll:
-        print(u"Processing %s with limits from %d to %d and step %d" % 
(formatName, start,stop-1,step))
+        print(u"Processing %s with limits from %d to %d and step %d" % 
(formatName, start, stop - 1, step))
     
     for code, convFunc in formats[formatName].iteritems():
 #        import time
 #        startClock = time.clock()
-        for value in range(start,stop,step):
+        for value in range(start, stop, step):
             try:
                 if not predicate(value):
                     raise AssertionError("     Not a valid value for this 
format.")



_______________________________________________
Pywikipedia-svn mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-svn

Reply via email to