Contact: fumanchu@aminus.org

Log in as guest/dejavu to create tickets

I think I've seen this ORM somewhere before...

Changeset 69

Show
Ignore:
Timestamp:
04/04/05 22:14:45
Author:
fumanchu
Message:

1. Fixed bug in db.SQLDecompiler.visit_CALL_FUNCTION, affecting Expressions with kwargs inside function calls.
2. db stack sentinels now have repr's to help debugging.
3. Changed Adapter.pickle to .do_pickle to help avoid shadowing the pickle module.
4. Put a conn timeout in sockets.SocketClient?.query.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/storage/db.py

    r68 r69  
    248248    coerce_decimal_Decimal = tostr 
    249249     
    250     def pickle(self, value): 
     250    def do_pickle(self, value): 
    251251        return self.coerce_str(pickle.dumps(value)) 
    252252     
    253     coerce_dict = pickle 
     253    coerce_dict = do_pickle 
    254254     
    255255    coerce_fixedpoint_FixedPoint = tostr 
     
    257257    coerce_int = tostr 
    258258     
    259     coerce_list = pickle 
     259    coerce_list = do_pickle 
    260260     
    261261    coerce_long = tostr 
     
    266266        return "'" + value + "'" 
    267267     
    268     coerce_tuple = pickle 
     268    coerce_tuple = do_pickle 
    269269     
    270270    coerce_unicode = coerce_str 
     
    309309        unit._properties[key] = value 
    310310     
    311     def pickle(self, value, coltype): 
     311    def do_pickle(self, value, coltype): 
    312312        # Coerce to str for pickle.loads restriction. 
    313313        value = str(value) 
     
    340340        return decimal.Decimal(str(value)) 
    341341     
    342     coerce_dict = pickle 
     342    coerce_dict = do_pickle 
    343343     
    344344    def coerce_fixedpoint_FixedPoint(self, value, coltype): 
     
    351351        return int(value) 
    352352     
    353     coerce_list = pickle 
     353    coerce_list = do_pickle 
    354354     
    355355    def coerce_long(self, value, coltype): 
     
    359359        return str(value) 
    360360     
    361     coerce_tuple = pickle 
     361    coerce_tuple = do_pickle 
    362362     
    363363    def coerce_unicode(self, value, coltype): 
     
    391391 
    392392# Stack sentinels 
    393 table_arg = object() 
    394 kw_arg = object() 
     393class Sentinel(object): 
     394     
     395    def __init__(self, name): 
     396        self.name = name 
     397     
     398    def __repr__(self): 
     399        return 'Stack Sentinel: %s' % self.name 
     400 
     401table_arg = Sentinel('Table Arg') 
     402kw_arg = Sentinel('Keyword Arg') 
    395403# cannot_represent exists so that a portion of an Expression can be 
    396404# labeled imperfect. For example, the function dejavu.iscurrentweek 
     
    398406# the Expression) will be recalled; they can then be compared in 
    399407# expr.evaluate(unit). 
    400 cannot_represent = object(
     408cannot_represent = Sentinel('Cannot Repr'
    401409 
    402410 
     
    505513    def visit_CALL_FUNCTION(self, lo, hi): 
    506514        kwargs = {} 
    507         for i in range(hi): 
     515        for i in xrange(hi): 
    508516            val = self.stack.pop() 
    509517            key = self.stack.pop() 
     
    512520         
    513521        args = [] 
    514         for i in range(lo): 
     522        for i in xrange(lo): 
    515523            arg = self.stack.pop() 
    516524            args.append(arg) 
     
    539547                return 
    540548         
    541         if self.stack: 
    542             self.stack[-1] = cannot_represent 
    543         else: 
    544             self.stack = [cannot_represent] 
     549        self.stack.append(cannot_represent) 
    545550        self.imperfect = True 
    546551     
     
    870875    def execute(self, query, conn=None): 
    871876        """execute(query, conn=None) -> result set.""" 
    872 ##        try: 
    873877        if conn is None: 
    874878            conn = self.connection() 
    875879        return conn.query(query.encode('utf8')) 
    876 ##        except Exception, x: 
    877 ##            x.args += (query,) 
    878 ##            # Dereference the connection so that release() is called back. 
    879 ##            conn = None 
    880 ##            raise x 
    881880     
    882881    def fetch(self, query, conn=None): 
  • trunk/storage/sockets.py

    r68 r69  
    8787        """ 
    8888        conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 
    89 ##        conn.settimeout(self.timeout) 
     89        # Not sure if we should have a timeout or not-- 
     90        # some users getting "Address already in use" errors..? 
     91        conn.settimeout(self.timeout) 
    9092##        conn.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 
    9193        conn.connect((self.host, self.port)) 
  • trunk/storage/storeado.py

    r68 r69  
    181181                / 86400.0) 
    182182     
    183     def pickle(self, value): 
     183    def do_pickle(self, value): 
    184184        # We must not use a pickle format other than 0, because binary 
    185185        # strings are not safe for all DB string fields. 
    186186        return pickle.dumps(value) 
    187187     
    188     coerce_dict = pickle 
     188    coerce_dict = do_pickle 
    189189     
    190190    def coerce_fixedpoint_FixedPoint(self, value): 
     
    196196    coerce_int = noop 
    197197     
    198     coerce_list = pickle 
     198    coerce_list = do_pickle 
    199199     
    200200    coerce_long = noop 
    201201    coerce_str = noop 
    202202     
    203     coerce_tuple = pickle 
     203    coerce_tuple = do_pickle 
    204204     
    205205    coerce_unicode = noop 
  • trunk/storage/zoo_fixture.py

    r68 r69  
    241241        self.assertEqual(matches(lambda x: 'p' in x.Name 
    242242                                 and x.Name.count('e') > 1), 3) 
    243      
     243         
    244244        # Test wildcards in LIKE. 
    245245        box.flush_all() 
    246246        units = box.recall(zoo.Zoo, logic.Expression(lambda x: "_" in x.Name)) 
     247        self.assertEqual(len([x for x in units]), 1) 
     248         
     249        # This broke in MSAccess (storeado) in April 2005, due to a bug in 
     250        # db.SQLDecompiler.visit_CALL_FUNCTION (append TOS, not replace!). 
     251        box.flush_all() 
     252        e = logic.Expression(lambda x, **kw: x.LastEscape != None 
     253                             and x.LastEscape >= datetime.date(kw['Year'], 12, 1) 
     254                             and x.LastEscape < datetime.date(kw['Year'], 12, 31) 
     255                             ) 
     256        e.bind_args(Year=2004) 
     257        units = box.recall(zoo.Animal, e) 
    247258        self.assertEqual(len([x for x in units]), 1) 
    248259