Changeset 177

Show
Ignore:
Timestamp:
Tue Dec 20 13:59:38 2005
Author:
drew
Message:

bump

Files:

Legend:

Unmodified
Added
Removed
Modified
  • branches/utils/tests/doctests/txt/xix-utils-timetool-setDayOfWeek-startsun.txt

    r159 r177  
    4 4 >>> from time import strptime, strftime, mktime, tzset  
    5 5 >>> from datetime import datetime  
    6   >>> t = strptime('2005-12-02', '%Y-%m-%d')  
      6 >>> t = strptime('2005-11-29', '%Y-%m-%d')  
    6 6 >>> dt = datetime.fromtimestamp(mktime(t))  
    7 7 >>> dt2 = setDayOfWeek(dt, SUNDAY, startsun=True)  
  • branches/utils/utiltests.py

    r166 r177  
    4 4 import xix.utils.python  
    5 5 import xix.utils.timetool  
      6 import xix.utils.diff  
    6 7 from tests import doctests  
    7 8  
     
    12 13     xix.utils.python,  
    13 14     xix.utils.timetool,  
      15     xix.utils.diff,  
    14 16     doctests.utils.config,  
    15 17     doctests.utils.python  
  • branches/utils/xix/utils/timetool.py

    r175 r177  
    90 90         def getweekday(dt):  
    91 91             return dt.weekday()  
    92       step = (1, -1)[wday < dtime.weekday()]  
      92     if not dtime.weekday(): # Monday is special case  
      93         step = (1, -1)[wday <= dtime.weekday()]  
      94     else:  
      95         step = (1, -1)[wday < dtime.weekday()]  
    93 96     newtime = dtime  
    94 97     while getweekday(newtime) != wday:  
  • branches/utils/xix/utils/decor.py

    r159 r177  
    54 54             self._nargs = nargs  
    55 55             if posonly or pargs:  
    56                   self._curried = pargs  
      56                 self._curried = pargs or []  
    56 56                 self._posonly = True  
    57 57             else:  
    58                   self._curried = kwargs  
      58                 self._curried = kwargs or {}  
    58 58                 self._posonly = False  
    59 59             if self._nargs is None:  
     
    102 102     return wrapper  
    103 103  
    104   __all__ = allexcept('time', 'inspect', 'allexcept')  
      104 #__all__ = allexcept('time', 'inspect', 'allexcept')  
    104 104  
  • branches/utils/xix/utils/console.py

    r159 r177  
    1   '''  
      1 """  
    1 1 console.py  
    2 2  
     
    7 7 See LICENSE for details.  
    8 8  
    9   '''  
      9 """  
    9 9  
    10 10 # $Id$  
     
    77 77     globs['BG' + k] = v  
    78 78  
    79   def format(message, *codes):  
    80       '''  
    81       Format meessage give list of codes defined as globals in this module.  
    82    
    83       Example usage:  
    84        
    85       >>> s = format('console test', FGBROWN, BGBLUE, BOLD)  
    86       >>> s  
    87       '\\x1b[33;44;1mconsole test\\x1b[0m'  
    88        
    89       '''  
    90       code_string = ';'.join([str(code) for code in codes])  
    91       return '\033[%sm%s\033[%sm' % (code_string, message, RESET)  
      79 class Format:  
      80  
      81     format_on = True  
      82  
      83     def __call__(self, message, *codes):  
      84         return self.format(message, *codes)  
      85  
      86     def format(self, message, *codes):  
      87         """Format meessage give list of codes defined as globals in this module.  
      88          
      89         Example usage:  
      90            
      91         >>> from xix.utils.console import format  
      92         >>> s = format('console test', FGBROWN, BGBLUE, BOLD)  
      93         >>> s  
      94         '\\x1b[33;44;1mconsole test\\x1b[0m'  
      95          
      96         Supressing format in application:  
      97              
      98         >>> format.format_on = False  
      99         >>> s = format('console test')  
      100         >>> s  
      101         'console test'  
      102          
      103         """  
      104         if not self.format_on:  
      105             return message     
      106         code_string = ';'.join([str(code) for code in codes])  
      107         return '\033[%sm%s\033[%sm' % (code_string, message, RESET)  
      108  
      109 format = Format()  
    92 110      
    93 111 __all__ = setAll([], locals(), 'setAll', 'k', 'v')  
  • branches/utils/xix/utils/string.py

    r159 r177  
    10 10 #write = getlogger()  
    11 11  
      12 import math  
      13  
      14 # Allignment  
      15  
      16 def lalign(text, cols=20):  
      17     """example usage:  
      18  
      19     >>> txt = lalign('a test') + '||'  
      20     >>> print txt  
      21     a test              ||  
      22     """  
      23     padding = (0, cols-len(text))[cols > len(text)]  
      24     return text + (' ' * padding)  
      25  
      26 def center(text, cols=20):  
      27     """example usage:  
      28  
      29     >>> txt = center('a test') + '||'  
      30     >>> print txt  
      31            a test       ||  
      32     """  
      33     delta = cols - len(text)  
      34     pleft = int(math.floor(delta / 2.))  
      35     pright = int(math.ceil(delta / 2.))  
      36     return (' ' * pleft) + text + (' ' * pright)  
      37  
      38 def ralign(text, cols=20):  
      39     """example usage:  
      40  
      41     >>> txt = ralign('a test') + '||'  
      42     >>> print txt  
      43                   a test||  
      44     """  
      45     padding = (0, cols-len(text))[cols > len(text)]  
      46     return (' ' * padding) + text  
    12 47  
    13 48 class IndentPrint:  
  • branches/utils/xix/utils/interfaces.py

    r159 r177  
    9 9  
    10 10 class IDataStoreNode(Interface):  
    11       '''This interface is for (potential) future use. Currently it  
      11     """This interface is for (potential) future use. Currently it  
    11 11     is not used in xix.utils.  
    12       '''  
      12     """  
    12 12  
    13       name = Attribute('''  
    14               Relative name of this node''')  
      13     name = Attribute("""  
      14             Relative name of this node""")  
    15 15  
    16       children = Attribute('''  
    17               List of children or None if this is a leaf''')  
      16     children = Attribute("""  
      17             List of children or None if this is a leaf""")  
    18 18  
    19       data = Attribute('''  
    20               Data pertaining to node or None is this is _not_ a leaf''')  
      19     data = Attribute("""  
      20             Data pertaining to node or None is this is _not_ a leaf""")  
    21 21          
    22 22 class IDataStore(Interface):  
    23       '''DataStore interface  
    24       '''  
      23     """DataStore interface  
      24     """  
    25 25     def addNode(node=None, parent=None, path=None, recurse=True):  
    26           '''Add DataStoreNode descibed by path, or as child to parent to  
      26         """Add DataStoreNode descibed by path, or as child to parent to  
    26 26         this dataStore.  
    27 27          
     
    42 42         @raises DataStoreException: on error  
    43 43         @raises TypeError: if arguments supplied incorrectly  
    44           '''  
      44         """  
    44 44     def load(path):  
    45           '''Lookup node given path.  path argumented may also be interpretted  
      45         """Lookup node given path.  path argumented may also be interpretted  
    45 45         as a key for lookup.  
    46 46  
     
    51 51         @return a DataStoreNode  
    52 52         @rtype IDataStoreNode  
    53           '''  
      53         """  
    53 53          
    54 54  
     
    59 59          
    60 60 class IConfig(Interface):  
    61       '''Application configuration container  
    62       '''  
      61     """Application configuration container  
      62     """  
    63 63     def __getattr__(configKey):  
    64           '''Return value of configifuration key.  
      64         """Return value of configifuration key.  
    64 64         Example: config.verboseLogging -> True  
    65 65  
     
    69 69         @return a configuration value  
    70 70         @rtype  object  
    71           '''  
      71         """  
    71 71  
    72 72 class IConfigParser(Interface):  
    73       '''A Config parser.  
    74       '''  
      73     """A Config parser.  
      74     """  
    75 75     def parse(s):  
    76           '''Parse a string s, returning a Config instance.  
      76         """Parse a string s, returning a Config instance.  
    76 76  
    77 77         @param s: string to parse  
     
    81 81         @return: IConfig provider  
    82 82         @rtype: IConfig  
    83           '''  
      83         """  
    83 83  
    84 84 class IConfigLoader(Interface):  
    85       '''ConfigLoader loads a configuration from a datasource.  
    86       '''  
      85     """ConfigLoader loads a configuration from a datasource.  
      86     """  
    87 87     def load(src):  
    88           '''load configuration from datasource src. Returns a Config instance.  
      88         """load configuration from datasource src. Returns a Config instance.  
    88 88  
    89 89         @param src: datasource where configuration resides  
     
    93 93         @return: IConfig provider  
    94 94         @rtype: IConfig  
    95           '''  
      95         """  
    95 95  
    96 96 class IConfigFactory(Interface):  
    97       '''Configuration Factory for loading application configuration containers  
    98       '''  
      97     """Configuration Factory for loading application configuration containers  
      98     """  
    99 99     def getConfig(name):  
    100           '''Return configuration with name name or default configuration  
      100         """Return configuration with name name or default configuration  
    100 100  
    101 101         @param name: name of configuration  
     
    105 105         @return: IConfig provider  
    106 106         @rtype: IConfig  
    107           '''  
      107         """  
    107 107     def addResource(name, url):  
    108           '''Add a resource used by loader with name and url.  
      108         """Add a resource used by loader with name and url.  
    108 108  
    109 109         @param name: symbolic name of resource  
     
    113 113         @param  url: url of the resource  
    114 114         @type   url: string  
    115           '''  
      115         """  
    115 115  
    116 116 ##########################################################################  
     
    120 120          
    121 121 class IModuleWrapper(Interface):  
    122       '''ModuleWrapper contains a string reference to a python module, such as  
      122     """ModuleWrapper contains a string reference to a python module, such as  
    122 122     xix.utils.string and methods for loading components of the module into the  
    123 123     caller's global namespace.  
    124       '''  
      124     """  
    124 124      
    125       moduleName = Attribute('''  
    126               The name of wrapped module (ex. xix.utils.string)''')  
      125     moduleName = Attribute("""  
      126             The name of wrapped module (ex. xix.utils.string)""")  
    127 127      
    128 128     def importModule():  
    129           '''Import the module into the caller's global namespace.  
    130           '''  
      129         """Import the module into the caller's global namespace.  
      130         """  
    131 131     def importNames(*names):  
    132           '''Import all names from module given by positional arguments into caller's  
      132         """Import all names from module given by positional arguments into caller's  
    132 132         global namespace.  
    133           '''  
      133         """  
    133 133     def importAll():  
    134           '''Import all visible names from module into caller's global namespace.  
    135           '''  
      134         """Import all visible names from module into caller's global namespace.  
      135         """  
    136 136  
    137 137 ##########################################################################  
     
    144 144  
    145 145 class IRule(Interface):  
    146       '''Rule interface.  A rule is closure which performs validation based  
      146     """Rule interface.  A rule is closure which performs validation based  
    146 146     on arguments supplied.  A rule may be statefule.  
    147       '''  
      147     """  
    147 147  
    148 148     def __call__(*pargs, **kwargs):  
    149           ''' Rules return True if validation based on arguments/state passes, False otherwise.  
      149         """ Rules return True if validation based on arguments/state passes, False otherwise.  
    149 149          
    150 150         @param pargs positional arguments for validation  
    151 151         @param kwargs keyword arguments for validation  
    152 152         @return True if all rules pass, False otherwise  
    153           '''  
      153         """  
    153 153 class IRuleChain(Interface):  
    154       '''RuleChain interface.  A rule chain acts as an aggregation of several rules.  
      154     """RuleChain interface.  A rule chain acts as an aggregation of several rules.  
    154 154     RuleChains pass only if all rules in the chain pass.  
    155       '''  
      155     """  
    155 155  
    156       rules = Attribute('''Chain of rules.''')  
      156     rules = Attribute("""Chain of rules.""")  
    156 156  
    157 157     def __call__(*pargs, **kwargs):  
    158           '''Validate rules.  Return True if all rules pass, false otherwise.  
      158         """Validate rules.  Return True if all rules pass, false otherwise.  
    158 158  
    159 159         @param pargs positional arguments for validation  
    160 160         @param kwargs keyword arguments for validation  
    161 161         @return True if all rules pass, False otherwise  
    162           '''  
    163            
      162         """  
      163        
      164 ##########################################################################  
      165 # Diff interfaces  
      166 ##########################################################################  
      167  
      168 class IDiff(Interface):  
      169     """A diff represents differences between a source and target sequence of objects.  
      170     It is up to the application using this library to compute the diff object -  
      171     or object that adapts this interface  
      172  
      173     same: tuple of objects that are same between the source and target sequences  
      174     missing: tuple of objects that are in source sequence but not in target sequence  
      175     added: tuple of objects that are in target sequence but not in source sequence  
      176     """  
      177      
      178     missing = Attribute("""Tuple of objects in target sequence but not in  
      179             source sequence""")  
      180  
      181     added = Attribute("""Tuple of objects in source sequence but not in  
      182             target sequence""")  
      183  
      184     same = Attribute("""Tuple of objects in both source and target  
      185             sequences""")  
      186  
      187  
  • branches/utils/runtests.py

    r174 r177  
    23 23  
    24 24 docfiles = glob('tests/doctests/txt/*.txt')  
      25 docfiles.sort()  
    25 26          
    26 27 def main():