<s> import logging <EOL> import re <EOL> import sys <EOL> import time <EOL> sys . path . append ( '<STR_LIT>' ) <EOL> logger = logging . getLogger ( ) <EOL> logger . setLevel ( logging . DEBUG ) <EOL> log_format = "<STR_LIT>" <EOL> log_stream = logging . StreamHandler ( ) <EOL> log_stream . setFormatter ( logging . Formatter ( "<STR_LIT>" + log_format ) ) <EOL> log_stream . setLevel ( logging . WARNING ) <EOL> logger . addHandler ( log_stream ) <EOL> import nipap . backend <EOL> class bonk : <EOL> def __init__ ( self ) : <EOL> self . n = nipap . backend . Nipap ( ) <EOL> def clear_db ( self ) : <EOL> """<STR_LIT>""" <EOL> self . n . _execute ( "<STR_LIT>" ) <EOL> def init_db ( self ) : <EOL> """<STR_LIT>""" <EOL> def find_prefix ( self , argp ) : <EOL> """<STR_LIT:U+0020>""" <EOL> arg_prefix = argp . split ( "<STR_LIT:/>" ) [ <NUM_LIT:0> ] <EOL> arg_pl = argp . split ( "<STR_LIT:/>" ) [ <NUM_LIT:1> ] <EOL> if self . n . _is_ipv4 ( arg_prefix ) : <EOL> m = re . match ( "<STR_LIT>" , arg_prefix ) <EOL> os1 = int ( m . group ( <NUM_LIT:1> ) ) <EOL> os2 = int ( m . group ( <NUM_LIT:2> ) ) <EOL> os3 = int ( m . group ( <NUM_LIT:3> ) ) <EOL> os4 = int ( m . group ( <NUM_LIT:4> ) ) <EOL> count = <NUM_LIT:2> ** ( <NUM_LIT:32> - int ( arg_pl ) ) <EOL> i = <NUM_LIT:0> <EOL> t0 = time . time ( ) <EOL> try : <EOL> for o1 in xrange ( os1 , <NUM_LIT:255> ) : <EOL> for o2 in xrange ( os2 , <NUM_LIT:255> ) : <EOL> for o3 in xrange ( os3 , <NUM_LIT:255> ) : <EOL> t2 = time . time ( ) <EOL> for o4 in xrange ( os4 , <NUM_LIT:255> ) : <EOL> prefix = "<STR_LIT>" % ( o1 , o2 , o3 , o4 ) <EOL> self . n . list_prefix ( { '<STR_LIT:name>' : '<STR_LIT>' } , { '<STR_LIT>' : prefix } ) <EOL> i += <NUM_LIT:1> <EOL> if i >= count : <EOL> raise StopIteration ( ) <EOL> t3 = time . time ( ) <EOL> print o3 , ( t3 - t2 ) / <NUM_LIT> <EOL> except StopIteration : <EOL> pass <EOL> t1 = time . time ( ) <EOL> print count , "<STR_LIT>" , t1 - t0 <EOL> elif self . n . _is_ipv6 ( argp ) : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> def fill_prefix ( self , argp ) : <EOL> """<STR_LIT>""" <EOL> arg_prefix = argp . split ( "<STR_LIT:/>" ) [ <NUM_LIT:0> ] <EOL> arg_pl = argp . split ( "<STR_LIT:/>" ) [ <NUM_LIT:1> ] <EOL> netcount = <NUM_LIT:0> <EOL> if self . n . _is_ipv4 ( arg_prefix ) : <EOL> m = re . match ( "<STR_LIT>" , arg_prefix ) <EOL> os1 = int ( m . group ( <NUM_LIT:1> ) ) <EOL> os2 = int ( m . group ( <NUM_LIT:2> ) ) <EOL> os3 = int ( m . group ( <NUM_LIT:3> ) ) <EOL> os4 = int ( m . group ( <NUM_LIT:4> ) ) <EOL> count = <NUM_LIT:2> ** ( <NUM_LIT:32> - int ( arg_pl ) ) <EOL> i = <NUM_LIT:0> <EOL> t0 = time . time ( ) <EOL> try : <EOL> for o1 in xrange ( os1 , <NUM_LIT:255> ) : <EOL> for o2 in xrange ( os2 , <NUM_LIT:255> ) : <EOL> for o3 in xrange ( os3 , <NUM_LIT:255> ) : <EOL> t2 = time . time ( ) <EOL> for o4 in xrange ( os4 , <NUM_LIT:255> ) : <EOL> prefix = "<STR_LIT>" % ( o1 , o2 , o3 , o4 ) <EOL> self . n . add_prefix ( { '<STR_LIT:name>' : '<STR_LIT>' } , { '<STR_LIT>' : prefix , '<STR_LIT:description>' : '<STR_LIT:test>' } ) <EOL> i += <NUM_LIT:1> <EOL> if i >= count : <EOL> raise StopIteration ( ) <EOL> t3 = time . time ( ) <EOL> print netcount , ( t3 - t2 ) / <NUM_LIT> <EOL> netcount += <NUM_LIT:1> <EOL> except StopIteration : <EOL> pass <EOL> t1 = time . time ( ) <EOL> print count , "<STR_LIT>" , t1 - t0 <EOL> elif self . n . _is_ipv6 ( argp ) : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> def find_free_prefix ( self , argp ) : <EOL> t0 = time . time ( ) <EOL> prefix = self . n . find_free_prefix ( { '<STR_LIT:name>' : '<STR_LIT>' } , { '<STR_LIT>' : [ argp ] , '<STR_LIT>' : <NUM_LIT:32> } ) <EOL> t1 = time . time ( ) <EOL> d1 = t1 - t0 <EOL> print "<STR_LIT>" , prefix , "<STR_LIT>" , d1 , "<STR_LIT>" <EOL> def add_prefix ( self , argp ) : <EOL> t0 = time . time ( ) <EOL> prefix = self . n . add_prefix ( { '<STR_LIT:name>' : '<STR_LIT>' } , { '<STR_LIT>' : argp , '<STR_LIT:description>' : '<STR_LIT:test>' } ) <EOL> t1 = time . time ( ) <EOL> d1 = t1 - t0 <EOL> print "<STR_LIT>" , argp , "<STR_LIT>" , d1 , "<STR_LIT>" <EOL> def remove_prefix ( self , argp ) : <EOL> t0 = time . time ( ) <EOL> prefix = self . n . remove_prefix ( { '<STR_LIT:name>' : '<STR_LIT>' } , { '<STR_LIT>' : argp } ) <EOL> t1 = time . time ( ) <EOL> d1 = t1 - t0 <EOL> print "<STR_LIT>" , argp , "<STR_LIT>" , d1 , "<STR_LIT>" <EOL> def prefix_insert ( self , argp ) : <EOL> pass <EOL> def test1 ( self ) : <EOL> t0 = time . time ( ) <EOL> res = self . n . find_free_prefix ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ '<STR_LIT>' ] } , <NUM_LIT:32> , <NUM_LIT:1> ) <EOL> t1 = time . time ( ) <EOL> res = self . n . find_free_prefix ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ '<STR_LIT>' ] } , <NUM_LIT:32> , <NUM_LIT> ) <EOL> t2 = time . time ( ) <EOL> for prefix in res : <EOL> self . n . add_prefix ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : prefix , '<STR_LIT:description>' : '<STR_LIT:test>' } ) <EOL> t3 = time . time ( ) <EOL> res = self . n . find_free_prefix ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ '<STR_LIT>' ] } , <NUM_LIT:32> , <NUM_LIT:1> ) <EOL> t4 = time . time ( ) <EOL> d1 = t1 - t0 <EOL> d2 = t2 - t1 <EOL> d3 = t3 - t2 <EOL> d4 = t4 - t3 <EOL> d5 = d4 - d1 <EOL> print "<STR_LIT>" , d1 <EOL> print "<STR_LIT>" , d2 <EOL> print "<STR_LIT>" , d3 <EOL> print "<STR_LIT>" , d4 <EOL> print "<STR_LIT>" , d5 <EOL> def test2 ( self ) : <EOL> t0 = time . time ( ) <EOL> res = self . n . find_free_prefix ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ '<STR_LIT>' ] } , <NUM_LIT:32> , <NUM_LIT:1> ) <EOL> t1 = time . time ( ) <EOL> d1 = t1 - t0 <EOL> print "<STR_LIT>" , d1 <EOL> def test3 ( self ) : <EOL> self . n . find_free_prefix ( { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : [ '<STR_LIT>' ] } , <NUM_LIT:32> , <NUM_LIT:1> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import optparse <EOL> parser = optparse . OptionParser ( ) <EOL> parser . add_option ( '<STR_LIT>' , metavar = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , metavar = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , metavar = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_option ( '<STR_LIT>' , metavar = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> b = bonk ( ) <EOL> options , args = parser . parse_args ( ) <EOL> if options . fill_prefix is not None : <EOL> if not b . n . _get_afi ( options . fill_prefix ) : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> b . fill_prefix ( options . fill_prefix ) <EOL> if options . find_free_prefix is not None : <EOL> b . find_free_prefix ( options . find_free_prefix ) <EOL> if options . add_prefix is not None : <EOL> b . add_prefix ( options . add_prefix ) <EOL> if options . remove_prefix is not None : <EOL> b . remove_prefix ( options . remove_prefix ) </s>
