<s> INV_URL = "<STR_LIT>" <EOL> import pdb <EOL> import re <EOL> INFO = <NUM_LIT:0> <EOL> WARNING = <NUM_LIT:1> <EOL> ERROR = <NUM_LIT:2> <EOL> DEBUG = <NUM_LIT:3> <EOL> BUILD = <NUM_LIT:4> <EOL> def log ( msg , level = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> do_info = True <EOL> do_warning = True <EOL> do_error = True <EOL> do_debug = True <EOL> do_build = True <EOL> if do_info and level == <NUM_LIT:0> : <EOL> print "<STR_LIT>" . format ( msg ) , <EOL> return <EOL> elif do_warning and level == <NUM_LIT:1> : <EOL> print "<STR_LIT>" . format ( msg ) , <EOL> return <EOL> elif do_error and level == <NUM_LIT:2> : <EOL> print "<STR_LIT>" . format ( msg ) , <EOL> return <EOL> elif do_debug and level == <NUM_LIT:3> : <EOL> print "<STR_LIT>" . format ( msg ) , <EOL> return <EOL> elif do_build and level == <NUM_LIT:4> : <EOL> print "<STR_LIT>" . format ( msg ) , <EOL> return <EOL> def print_system ( system ) : <EOL> return "<STR_LIT>" . format ( system , INV_URL , system . pk ) <EOL> """<STR_LIT>""" <EOL> def _ip_to_domain_name ( ip , lowercase = False ) : <EOL> """<STR_LIT>""" <EOL> octets = ip . split ( '<STR_LIT:.>' ) <EOL> name = '<STR_LIT>' <EOL> if lowercase : <EOL> name = name . lowercase <EOL> name = '<STR_LIT:.>' . join ( list ( reversed ( octets ) ) ) + name <EOL> return name <EOL> def dns2ip_form ( dnsip ) : <EOL> dnsip = dnsip . upper ( ) <EOL> dnsip = dnsip . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return '<STR_LIT:.>' . join ( list ( reversed ( dnsip . split ( '<STR_LIT:.>' ) ) ) ) <EOL> def ensure_include ( file_ , file_type , include_file ) : <EOL> """<STR_LIT>""" <EOL> fd = open ( file_ , '<STR_LIT>' ) <EOL> try : <EOL> new_content = _ensure_include ( fd , file_type , include_file ) <EOL> fd . close ( ) <EOL> fd = open ( file_ , '<STR_LIT>' ) <EOL> fd . write ( new_content ) <EOL> except Exception , e : <EOL> raise Exception <EOL> finally : <EOL> fd . close ( ) <EOL> def _ensure_include ( text , file_type , include_file ) : <EOL> """<STR_LIT>""" <EOL> if _has_include ( text , include_file ) : <EOL> text . seek ( <NUM_LIT:0> ) <EOL> return text . read ( ) <EOL> text . seek ( <NUM_LIT:0> ) <EOL> done = False <EOL> return_text = "<STR_LIT>" <EOL> comment = "<STR_LIT>" <EOL> if file_type == '<STR_LIT>' : <EOL> matches = [ re . compile ( "<STR_LIT>" ) , <EOL> re . compile ( "<STR_LIT>" ) ] <EOL> else : <EOL> matches = [ re . compile ( "<STR_LIT>" ) ] <EOL> for raw_line in text . readlines ( ) : <EOL> if done == True : <EOL> return_text += raw_line <EOL> continue <EOL> line = raw_line . strip ( ) <EOL> for regex in matches : <EOL> if regex . match ( line ) : <EOL> log ( "<STR_LIT>" <EOL> "<STR_LIT>" . format ( include_file ) , INFO ) <EOL> return_text += "<STR_LIT:\n>" <EOL> return_text += "<STR_LIT>" . format ( include_file , comment ) <EOL> return_text += "<STR_LIT:\n>" <EOL> done = True <EOL> return_text += raw_line <EOL> return return_text <EOL> def _has_include ( text , include_file = None ) : <EOL> """<STR_LIT>""" <EOL> is_file_include = re . compile ( "<STR_LIT>" ) <EOL> done = False <EOL> for raw_line in text . readlines ( ) : <EOL> file_include = is_file_include . match ( raw_line ) <EOL> if file_include : <EOL> include_str = file_include . groups ( <NUM_LIT:0> ) [ <NUM_LIT:0> ] <EOL> include_str = include_str . strip ( "<STR_LIT:'>" ) . strip ( '<STR_LIT:">' ) <EOL> if include_str == include_file : <EOL> log ( "<STR_LIT>" . format ( include_str ) , DEBUG ) <EOL> return True <EOL> return False <EOL> def get_serial ( file_ ) : <EOL> """<STR_LIT>""" <EOL> with open ( file_ , '<STR_LIT:r>' ) as fd : <EOL> return _str_get_soa ( fd ) <EOL> def _str_get_serial ( text ) : <EOL> """<STR_LIT>""" <EOL> isSOA = False <EOL> done = False <EOL> for raw_line in text . readlines ( ) : <EOL> if done : <EOL> break <EOL> line = raw_line . strip ( ) <EOL> ll = LexLine ( line ) <EOL> if isSOA : <EOL> serial = _lex_word ( ll ) <EOL> if serial . isdigit ( ) : <EOL> return serial <EOL> else : <EOL> return None <EOL> if not line or line [ <NUM_LIT:0> ] == '<STR_LIT:$>' or line [ <NUM_LIT:0> ] == '<STR_LIT:;>' : <EOL> continue <EOL> _lex_word ( ll ) <EOL> _lex_ws ( ll ) <EOL> c = ll . pop ( ) <EOL> if c . isdigit ( ) : <EOL> _lex_word ( ll ) <EOL> _lex_ws ( ll ) <EOL> else : <EOL> ll . unpop ( ) <EOL> _lex_word ( ll ) <EOL> _lex_ws ( ll ) <EOL> rr = _lex_word ( ll ) <EOL> if rr . upper ( ) != '<STR_LIT>' : <EOL> continue <EOL> isSOA = True <EOL> _lex_ws ( ll ) <EOL> _lex_word ( ll ) <EOL> _lex_ws ( ll ) <EOL> email = _lex_word ( ll ) <EOL> if email [ - <NUM_LIT:1> : ] == '<STR_LIT:(>' : <EOL> _lex_ws ( ll ) <EOL> else : <EOL> _lex_ws ( ll ) <EOL> next = ll . peek ( ) <EOL> if next == '<STR_LIT:(>' : <EOL> ll . pop ( ) <EOL> _lex_ws ( ll ) <EOL> serial = _lex_word ( ll ) <EOL> if not serial : <EOL> continue <EOL> if serial . isdigit ( ) : <EOL> return serial <EOL> else : <EOL> return None <EOL> def _lex_word ( ll ) : <EOL> word = '<STR_LIT>' <EOL> while True : <EOL> c = ll . pop ( ) <EOL> if c is None : <EOL> if word : <EOL> return word <EOL> else : <EOL> return None <EOL> if re . match ( '<STR_LIT>' , c ) : <EOL> ll . unpop ( ) <EOL> break <EOL> else : <EOL> word = word + c <EOL> return word <EOL> def _lex_ws ( ll ) : <EOL> while True : <EOL> c = ll . pop ( ) <EOL> if c is None : <EOL> return <EOL> if re . match ( '<STR_LIT>' , c ) : <EOL> continue <EOL> else : <EOL> ll . unpop ( ) <EOL> break <EOL> return <EOL> class LexLine ( object ) : <EOL> def __init__ ( self , line ) : <EOL> self . line = line <EOL> self . length = len ( line ) <EOL> self . pos = <NUM_LIT:0> <EOL> def pop ( self ) : <EOL> if self . pos == self . length : <EOL> return None <EOL> else : <EOL> c = self . line [ self . pos ] <EOL> self . pos += <NUM_LIT:1> <EOL> return c <EOL> def unpop ( self ) : <EOL> if self . pos > <NUM_LIT:0> : <EOL> self . pos -= <NUM_LIT:1> <EOL> def peek ( self ) : <EOL> return self . line [ self . pos ] </s>
