<s> """<STR_LIT>""" <EOL> import datetime <EOL> from twisted . enterprise import adbapi <EOL> from psycopg2 . extensions import adapt , register_adapter , AsIs <EOL> from psycopg2 . extras import CompositeCaster , register_composite <EOL> from twistar . registry import Registry <EOL> from twistar . dbobject import DBObject <EOL> from opennsa import nsa <EOL> from opennsa . ext . iso8601 import iso8601 <EOL> LOG_SYSTEM = '<STR_LIT>' <EOL> def adaptLabel ( label ) : <EOL> return AsIs ( "<STR_LIT>" % ( adapt ( label . type_ ) , adapt ( label . labelValue ( ) ) ) ) <EOL> def adaptSecuritAttribute ( label ) : <EOL> return AsIs ( "<STR_LIT>" % ( adapt ( label . type_ ) , adapt ( label . value ) ) ) <EOL> def adaptDatetime ( dt ) : <EOL> return AsIs ( "<STR_LIT:%s>" % adapt ( dt . isoformat ( ) ) ) <EOL> register_adapter ( nsa . Label , adaptLabel ) <EOL> register_adapter ( nsa . SecurityAttribute , adaptSecuritAttribute ) <EOL> register_adapter ( datetime . datetime , adaptDatetime ) <EOL> class LabelComposite ( CompositeCaster ) : <EOL> def make ( self , values ) : <EOL> return nsa . Label ( * values ) <EOL> class SecuritAttributeComposite ( CompositeCaster ) : <EOL> def make ( self , values ) : <EOL> return nsa . SecurityAttribute ( * values ) <EOL> def castDatetime ( value , cur ) : <EOL> return iso8601 . parse ( value ) <EOL> def setupDatabase ( database , user , password = None ) : <EOL> import psycopg2 <EOL> conn = psycopg2 . connect ( user = user , password = password , database = database ) <EOL> cur = conn . cursor ( ) <EOL> register_composite ( '<STR_LIT:label>' , cur , globally = True , factory = LabelComposite ) <EOL> register_composite ( '<STR_LIT>' , cur , globally = True , factory = SecuritAttributeComposite ) <EOL> cur . execute ( "<STR_LIT>" ) <EOL> timestamptz_oid = cur . fetchone ( ) [ <NUM_LIT:0> ] <EOL> DT = psycopg2 . extensions . new_type ( ( timestamptz_oid , ) , "<STR_LIT>" , castDatetime ) <EOL> psycopg2 . extensions . register_type ( DT ) <EOL> conn . close ( ) <EOL> Registry . DBPOOL = adbapi . ConnectionPool ( '<STR_LIT>' , user = user , password = password , database = database ) <EOL> class ServiceConnection ( DBObject ) : <EOL> HASMANY = [ '<STR_LIT>' ] <EOL> class SubConnection ( DBObject ) : <EOL> BELONGSTO = [ '<STR_LIT>' ] <EOL> Registry . register ( ServiceConnection , SubConnection ) </s>
