<s> import random <EOL> import threading <EOL> import time <EOL> import urllib <EOL> import weakref <EOL> import re <EOL> import traceback <EOL> from dbconstants import * <EOL> ZOO_ACL_OPEN = [ { "<STR_LIT>" : <NUM_LIT> , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:id>" : "<STR_LIT>" } ] <EOL> LOCK_TIMEOUT = <NUM_LIT:30> <EOL> TX_TIMEOUT = <NUM_LIT:30> <EOL> GC_INTERVAL = <NUM_LIT:30> <EOL> ID_BLOCK = <NUM_LIT:1000> <EOL> DEFAULT_HOST = "<STR_LIT>" <EOL> GLOBAL_LOCK_KEY = "<STR_LIT>" <EOL> GLOBAL_ID_KEY = "<STR_LIT>" <EOL> PATH_SEPARATOR = "<STR_LIT:/>" <EOL> APPS_PATH = "<STR_LIT>" <EOL> APP_TX_PATH = "<STR_LIT>" <EOL> APP_LOCK_PATH = "<STR_LIT>" <EOL> APP_ID_PATH = "<STR_LIT>" <EOL> APP_TX_PREFIX = "<STR_LIT>" <EOL> APP_LOCK_PREFIX = "<STR_LIT>" <EOL> APP_ID_PREFIX = "<STR_LIT:id>" <EOL> TX_LOCK_PATH = "<STR_LIT>" <EOL> TX_BLACKLIST_PATH = "<STR_LIT>" <EOL> TX_VALIDLIST_PATH = "<STR_LIT>" <EOL> TX_UPDATEDKEY_PREFIX = "<STR_LIT>" <EOL> GC_LOCK_PATH = "<STR_LIT>" <EOL> GC_TIME_PATH = "<STR_LIT>" <EOL> class ZKTransactionException ( Exception ) : <EOL> TYPE_UNKNOWN = <NUM_LIT:0> <EOL> TYPE_NO_CONNECTION = <NUM_LIT:1> <EOL> TYPE_INVALID = <NUM_LIT:2> <EOL> TYPE_EXPIRED = <NUM_LIT:3> <EOL> TYPE_DIFFERENT_ROOTKEY = <NUM_LIT:4> <EOL> def __init__ ( self , type , message ) : <EOL> Exception . __init__ ( self , message ) <EOL> self . type = type <EOL> def getType ( self ) : <EOL> return self . type <EOL> class ZKTransaction : <EOL> STATE_REGISTERED = <NUM_LIT:0> <EOL> STATE_MODIFIED = <NUM_LIT:1> <EOL> STATE_FAILED = <NUM_LIT:2> <EOL> STATE_DONE = <NUM_LIT:3> <EOL> def __init__ ( self , host = DEFAULT_HOST , startgc = True ) : <EOL> self . connectcv = threading . Condition ( ) <EOL> self . connected = False <EOL> self . gcrunning = False <EOL> self . gccv = threading . Condition ( ) <EOL> self . __rollbackFunc = None <EOL> def getTransactionID ( self , app_id ) : <EOL> """<STR_LIT>""" <EOL> return random . randint ( <NUM_LIT:0> , <NUM_LIT> ) <EOL> def checkTransaction ( self , app_id , txid ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def acquireLock ( self , app_id , txid , entity_key = GLOBAL_LOCK_KEY ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def getUpdatedKeyList ( self , app_id , txid ) : <EOL> """<STR_LIT>""" <EOL> return [ ] <EOL> def releaseLock ( self , app_id , txid , key = None ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> def isBlacklisted ( self , app_id , txid , entity_key = None ) : <EOL> """<STR_LIT>""" <EOL> return False <EOL> def getValidTransactionID ( self , app_id , target_txid , entity_key ) : <EOL> """<STR_LIT>""" <EOL> return long ( target_txid ) <EOL> def registUpdatedKey ( self , app_id , current_txid , target_txid , entity_key ) : <EOL> """<STR_LIT>""" <EOL> return <EOL> def notifyFailedTransaction ( self , app_id , txid ) : <EOL> """<STR_LIT>""" <EOL> return <EOL> def setRollbackFunction ( self , func ) : <EOL> """<STR_LIT>""" <EOL> self . __rollbackFunc = func <EOL> def generateIDBlock ( self , app_id , entity_key = GLOBAL_ID_KEY ) : <EOL> """<STR_LIT>""" <EOL> return ( random . randint ( <NUM_LIT:0> , <NUM_LIT> ) , ID_BLOCK ) </s>
