Example #1
0
class YearIndices:
    def __init__(self, start_index, start_date):
        self.start_date = date(start_date.year, 01, 01)
        self.last_date = date(start_date.year, 12, 31)

        self.year = start_date.year
        self.months = Bindings()
        self.indices = []

        self.add(start_index, start_date)

    def __getitem__(self, month):
        return self.months[month]

    def __str__(self):
        return ("Year %s: Start at %d (%s observations)\n  " %
                (self.year, self.indices[0], len(self.indices)) +
                "\n  ".join([str(m) for m in self.months.itervalues()]))

    def __iter__(self):
        return self.months.iteritems()

    def add(self, index, date):
        self.indices.append(index)

        try:
            self.months[date.month].add(index, date)
        except (KeyError, ValueError), err:
            self.months[date.month] = MonthIndices(index, date)
Example #2
0
class YearIndices:
    def __init__( self, start_index, start_date ):        
        self.start_date = date( start_date.year, 01, 01 )
        self.last_date  = date( start_date.year, 12, 31 )
        
        self.year       = start_date.year
        self.months     = Bindings()
        self.indices    = []

        self.add( start_index, start_date )

    def __getitem__( self, month ):
        return self.months[ month ]

    def __str__( self ):
        return ( "Year %s: Start at %d (%s observations)\n  " % (self.year, self.indices[0], len(self.indices))
                 + "\n  ".join([ str(m) for m in self.months.itervalues() ])
                 )

    def __iter__( self ):
        return self.months.iteritems()

    def add( self, index, date ):
        self.indices.append( index )

        try:
            self.months[ date.month ].add( index, date )
        except ( KeyError, ValueError ), err:
            self.months[ date.month ] = MonthIndices( index, date )
Example #3
0
    def __init__(self, start_index, start_date):
        self.start_date = date(start_date.year, 01, 01)
        self.last_date = date(start_date.year, 12, 31)

        self.year = start_date.year
        self.months = Bindings()
        self.indices = []

        self.add(start_index, start_date)
Example #4
0
 def __init__(self, dates):
     self.dates = dates
     self.years = Bindings()
     for index, date in enumerate(dates):
         try:
             self.years[date.year].add(index, date)
         except (KeyError, ValueError), err:
             self.years[date.year] = YearIndices(index, date)
Example #5
0
    def __init__( self, start_index, start_date ):        
        self.start_date = date( start_date.year, 01, 01 )
        self.last_date  = date( start_date.year, 12, 31 )
        
        self.year       = start_date.year
        self.months     = Bindings()
        self.indices    = []

        self.add( start_index, start_date )
Example #6
0
    def __init__(self, start_index, start_date):
        self.start_date = date(start_date.year, start_date.month, 01)
        if start_date.month == 12:
            self.last_date = date(start_date.year, 12, 31)
        else:
            self.last_date = date(start_date.year, start_date.month + 1,
                                  01) - timedelta(1)

        self.month = start_date.month
        self.months = Bindings()
        self.indices = []

        self.add(start_index, date)
Example #7
0
    def __init__(self, keysrc=[]):
        expkey = []
        if isinstance(keysrc, str):  # Handle single string
            keysrc = [keysrc]
        assert isinstance(keysrc, list)

        # List of tuples
        if keysrc and isinstance(keysrc[0], tuple):
            expkey = keysrc

        # List of strings
        elif keysrc and isinstance(keysrc[0], str):
            for key in keysrc:
                lhs_rhs = key.split('=', 1)
                if len(lhs_rhs) == 1:
                    expkey.append((lhs_rhs[0].strip(), None))
                else:
                    expkey.append((lhs_rhs[0].strip(), lhs_rhs[1].strip()))

        # Create the dict
        Bindings.__init__(self, expkey)
        for neg in self._neglected:
            if neg in self:
                del self[neg]
Example #8
0
    def __init__(self, keysrc=[]):
        expkey = []
        if isinstance(keysrc, str): # Handle single string
            keysrc = [ keysrc ]
        assert isinstance(keysrc, list)
        
        # List of tuples
        if keysrc and isinstance(keysrc[0], tuple):
            expkey = keysrc

        # List of strings
        elif keysrc and isinstance(keysrc[0], str):
            for key in keysrc:
                lhs_rhs = key.split('=',1)
                if len(lhs_rhs)==1:
                    expkey.append( (lhs_rhs[0].strip(), None) )
                else:
                    expkey.append( (lhs_rhs[0].strip(), lhs_rhs[1].strip()) )

        # Create the dict
        Bindings.__init__(self, expkey)
        for neg in self._neglected:
            if neg in self:
                del self[neg]
Example #9
0
    def getContextBindings():
        """Returns a L{Bindings} instance of plopt name-to-value pairs.

        The bindings could thereafter be used to re-create the current
        context from a command-line::

            bindings = plargs.getContextBindings()
            cmdline = [ "%s=%s"%(opt, bindings['opt']) for opt in bindings ]
            actual_command_line = " ".join(cmdline)
        """
        context = actualContext(plargs)
        bindings = Bindings()

        for binder in plargs.getBinders():
            for opt in plopt.iterator(binder):
                bindings[opt.getName()] = opt.get()

        for namespace in plargs.getNamespaces():
            for opt in plopt.iterator(namespace):
                key = "%s.%s" % (namespace.__name__, opt.getName())
                bindings[key] = opt.get()

        return bindings
Example #10
0
 def __getitem__( self, key ):
     ref = self.references[ key ]
     if ref.expanded:
         return ref.plrepr 
     return ref.expand( Bindings.__getitem__( self, key ) )
Example #11
0
    def __setitem__( self, key, value ):
        assert key not in self.ordered_keys, "Representations can not be updated."
        Bindings.__setitem__( self, key, value )

        #raw_input((len(self.ordered_keys), key, value ))
        self.references[ key ] = PRef( len(self.ordered_keys) )
Example #12
0
 def __init__( self ):
     Bindings.__init__( self )
     self.references = {}