<s> import sys <EOL> if sys . version_info . major < <NUM_LIT:3> : <EOL> print ( "<STR_LIT>" ) <EOL> exit ( ) <EOL> import json <EOL> import datetime <EOL> import lzma <EOL> import edce . error <EOL> class edict ( dict ) : <EOL> __setattr__ = dict . __setitem__ <EOL> __delattr__ = dict . __delitem__ <EOL> def __init__ ( self , data ) : <EOL> if type ( data ) == str : <EOL> data = json . loads ( data ) <EOL> for name , value in data . items ( ) : <EOL> setattr ( self , name , self . _wrap ( value ) ) <EOL> def __getattr__ ( self , attr ) : <EOL> return self . get ( attr , None ) <EOL> def _wrap ( self , value ) : <EOL> if isinstance ( value , ( tuple , list , set , frozenset ) ) : <EOL> return type ( value ) ( [ self . _wrap ( v ) for v in value ] ) <EOL> else : <EOL> if isinstance ( value , dict ) : <EOL> return edict ( value ) <EOL> else : <EOL> return value <EOL> def convertUTF8 ( str ) : <EOL> if edce . globals . debug : <EOL> print ( "<STR_LIT>" ) <EOL> try : <EOL> str . decode ( '<STR_LIT:utf-8>' ) <EOL> return str <EOL> except AttributeError : <EOL> return str <EOL> except UnicodeError : <EOL> return str . encode ( '<STR_LIT:utf-8>' ) <EOL> except UnicodeEncodeError : <EOL> return str . encode ( '<STR_LIT:utf-8>' ) <EOL> def writeUTF8 ( filename , data , compress = False ) : <EOL> if edce . globals . debug : <EOL> print ( "<STR_LIT>" + filename ) <EOL> try : <EOL> utf8filename = convertUTF8 ( filename ) <EOL> utf8data = convertUTF8 ( data ) <EOL> if compress : <EOL> with lzma . open ( utf8filename , "<STR_LIT:wb>" ) as f : <EOL> f . write ( utf8data ) <EOL> f . close ( ) <EOL> else : <EOL> with open ( utf8filename , "<STR_LIT:w>" , encoding = '<STR_LIT:utf8>' ) as f : <EOL> f . write ( bytes ( data , "<STR_LIT:utf-8>" ) . decode ( "<STR_LIT>" ) ) <EOL> f . close ( ) <EOL> except : <EOL> errstr = "<STR_LIT>" <EOL> raise edce . error . ErrorLog ( errstr ) <EOL> def writeJSONLog ( name , system , data ) : <EOL> if edce . globals . debug : <EOL> print ( "<STR_LIT>" ) <EOL> try : <EOL> logfile = "<STR_LIT>" . format ( n = name , s = system , d = datetime . datetime . utcnow ( ) ) <EOL> writeUTF8 ( logfile , json . dumps ( data , ensure_ascii = False ) . encode ( '<STR_LIT:utf8>' ) , True ) <EOL> except : <EOL> errstr = "<STR_LIT>" <EOL> raise edce . error . ErrorLog ( errstr ) </s>
