<s> import random <EOL> import string <EOL> __author__ = '<STR_LIT>' <EOL> def generate_random_token ( size ) : <EOL> return '<STR_LIT>' . join ( random . choice ( string . ascii_letters ) for _ in range ( size ) ) <EOL> def parse_blockwise ( value ) : <EOL> """<STR_LIT>""" <EOL> length = byte_len ( value ) <EOL> if length == <NUM_LIT:1> : <EOL> num = value & <NUM_LIT> <EOL> num >>= <NUM_LIT:4> <EOL> m = value & <NUM_LIT> <EOL> m >>= <NUM_LIT:3> <EOL> size = value & <NUM_LIT> <EOL> elif length == <NUM_LIT:2> : <EOL> num = value & <NUM_LIT> <EOL> num >>= <NUM_LIT:4> <EOL> m = value & <NUM_LIT> <EOL> m >>= <NUM_LIT:3> <EOL> size = value & <NUM_LIT> <EOL> else : <EOL> num = value & <NUM_LIT> <EOL> num >>= <NUM_LIT:4> <EOL> m = value & <NUM_LIT> <EOL> m >>= <NUM_LIT:3> <EOL> size = value & <NUM_LIT> <EOL> return num , int ( m ) , pow ( <NUM_LIT:2> , ( size + <NUM_LIT:4> ) ) <EOL> def byte_len ( int_type ) : <EOL> """<STR_LIT>""" <EOL> length = <NUM_LIT:0> <EOL> while int_type : <EOL> int_type >>= <NUM_LIT:1> <EOL> length += <NUM_LIT:1> <EOL> if length > <NUM_LIT:0> : <EOL> if length % <NUM_LIT:8> != <NUM_LIT:0> : <EOL> length = int ( length / <NUM_LIT:8> ) + <NUM_LIT:1> <EOL> else : <EOL> length = int ( length / <NUM_LIT:8> ) <EOL> return length <EOL> def parse_uri ( uri ) : <EOL> t = uri . split ( "<STR_LIT>" ) <EOL> tmp = t [ <NUM_LIT:1> ] <EOL> t = tmp . split ( "<STR_LIT:/>" , <NUM_LIT:1> ) <EOL> tmp = t [ <NUM_LIT:0> ] <EOL> path = t [ <NUM_LIT:1> ] <EOL> t = tmp . split ( "<STR_LIT::>" , <NUM_LIT:1> ) <EOL> try : <EOL> host = t [ <NUM_LIT:0> ] <EOL> port = int ( t [ <NUM_LIT:1> ] ) <EOL> except IndexError : <EOL> host = tmp <EOL> port = <NUM_LIT> <EOL> return str ( host ) , port , path <EOL> def create_logging ( ) : <EOL> with open ( "<STR_LIT>" , "<STR_LIT:w>" ) as f : <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> f . writelines ( "<STR_LIT>" ) <EOL> class Tree ( object ) : <EOL> def __init__ ( self ) : <EOL> self . tree = { } <EOL> def dump ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . tree . keys ( ) <EOL> def with_prefix ( self , path ) : <EOL> ret = [ ] <EOL> for key in self . tree . keys ( ) : <EOL> if path . startswith ( key ) : <EOL> ret . append ( key ) <EOL> if len ( ret ) > <NUM_LIT:0> : <EOL> return ret <EOL> raise KeyError <EOL> def with_prefix_resource ( self , path ) : <EOL> ret = [ ] <EOL> for key , value in self . tree . iteritems ( ) : <EOL> if path . startswith ( key ) : <EOL> ret . append ( value ) <EOL> if len ( ret ) > <NUM_LIT:0> : <EOL> return ret <EOL> raise KeyError <EOL> def __getitem__ ( self , item ) : <EOL> return self . tree [ item ] <EOL> def __setitem__ ( self , key , value ) : <EOL> self . tree [ key ] = value <EOL> def __delitem__ ( self , key ) : <EOL> del self . tree [ key ] </s>
