@@ -181,11 +181,13 @@ def run(self, query, parameters=None, mode=None, bookmarks=None,
181181 extra ["tx_metadata" ] = dict (metadata )
182182 except TypeError :
183183 raise TypeError ("Metadata must be coercible to a dict" )
184- if timeout :
184+ if timeout is not None :
185185 try :
186- extra ["tx_timeout" ] = int (1000 * timeout )
186+ extra ["tx_timeout" ] = int (1000 * float ( timeout ) )
187187 except TypeError :
188188 raise TypeError ("Timeout must be specified as a number of seconds" )
189+ if extra ["tx_timeout" ] < 0 :
190+ raise ValueError ("Timeout must be a positive number or 0." )
189191 fields = (query , parameters , extra )
190192 log .debug ("[#%04X] C: RUN %s" , self .local_port , " " .join (map (repr , fields )))
191193 if query .upper () == u"COMMIT" :
@@ -232,11 +234,13 @@ def begin(self, mode=None, bookmarks=None, metadata=None, timeout=None,
232234 extra ["tx_metadata" ] = dict (metadata )
233235 except TypeError :
234236 raise TypeError ("Metadata must be coercible to a dict" )
235- if timeout :
237+ if timeout is not None :
236238 try :
237- extra ["tx_timeout" ] = int (1000 * timeout )
239+ extra ["tx_timeout" ] = int (1000 * float ( timeout ) )
238240 except TypeError :
239241 raise TypeError ("Timeout must be specified as a number of seconds" )
242+ if extra ["tx_timeout" ] < 0 :
243+ raise ValueError ("Timeout must be a positive number or 0." )
240244 log .debug ("[#%04X] C: BEGIN %r" , self .local_port , extra )
241245 self ._append (b"\x11 " , (extra ,), Response (self , "begin" , ** handlers ))
242246
@@ -492,12 +496,13 @@ def run(self, query, parameters=None, mode=None, bookmarks=None,
492496 extra ["tx_metadata" ] = dict (metadata )
493497 except TypeError :
494498 raise TypeError ("Metadata must be coercible to a dict" )
495- if timeout :
499+ if timeout is not None :
496500 try :
497- extra ["tx_timeout" ] = int (1000 * timeout )
501+ extra ["tx_timeout" ] = int (1000 * float ( timeout ) )
498502 except TypeError :
499- raise TypeError ("Timeout must be specified as a number of "
500- "seconds" )
503+ raise TypeError ("Timeout must be specified as a number of seconds" )
504+ if extra ["tx_timeout" ] < 0 :
505+ raise ValueError ("Timeout must be a positive number or 0." )
501506 fields = (query , parameters , extra )
502507 log .debug ("[#%04X] C: RUN %s" , self .local_port ,
503508 " " .join (map (repr , fields )))
@@ -527,11 +532,12 @@ def begin(self, mode=None, bookmarks=None, metadata=None, timeout=None,
527532 extra ["tx_metadata" ] = dict (metadata )
528533 except TypeError :
529534 raise TypeError ("Metadata must be coercible to a dict" )
530- if timeout :
535+ if timeout is not None :
531536 try :
532- extra ["tx_timeout" ] = int (1000 * timeout )
537+ extra ["tx_timeout" ] = int (1000 * float ( timeout ) )
533538 except TypeError :
534- raise TypeError ("Timeout must be specified as a number of "
535- "seconds" )
539+ raise TypeError ("Timeout must be specified as a number of seconds" )
540+ if extra ["tx_timeout" ] < 0 :
541+ raise ValueError ("Timeout must be a positive number or 0." )
536542 log .debug ("[#%04X] C: BEGIN %r" , self .local_port , extra )
537543 self ._append (b"\x11 " , (extra ,), Response (self , "begin" , ** handlers ))
0 commit comments