<s> from urllib . request import Request , urlopen , URLError <EOL> from random import choice <EOL> import os <EOL> import pickle <EOL> def admin ( * args ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( func ) : <EOL> path = os . path . dirname ( os . path . abspath ( __file__ ) ) + '<STR_LIT>' <EOL> try : <EOL> with open ( path , '<STR_LIT:rb>' ) as pickle_file : <EOL> commands = pickle . load ( pickle_file ) <EOL> except ( OSError , IOError ) : <EOL> commands = dict ( ) <EOL> command_name = func . __module__ + '<STR_LIT:.>' + func . __name__ <EOL> if args : <EOL> for name in args : <EOL> commands [ name ] = ( command_name , True ) <EOL> commands [ func . __name__ ] = ( command_name , False ) <EOL> with open ( path , '<STR_LIT:wb>' ) as pickle_file : <EOL> pickle . dump ( commands , pickle_file ) <EOL> return func <EOL> return decorator <EOL> def command ( * args ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( func ) : <EOL> path = os . path . dirname ( os . path . abspath ( __file__ ) ) + '<STR_LIT>' <EOL> try : <EOL> with open ( path , '<STR_LIT:rb>' ) as pickle_file : <EOL> commands = pickle . load ( pickle_file ) <EOL> except ( OSError , IOError ) : <EOL> commands = dict ( ) <EOL> command_name = func . __module__ + '<STR_LIT:.>' + func . __name__ <EOL> if args : <EOL> for name in args : <EOL> commands [ name ] = ( command_name , True ) <EOL> commands [ func . __name__ ] = ( command_name , False ) <EOL> with open ( path , '<STR_LIT:wb>' ) as pickle_file : <EOL> pickle . dump ( commands , pickle_file ) <EOL> return func <EOL> return decorator <EOL> def get_line ( m , file ) : <EOL> """<STR_LIT>""" <EOL> with open ( m . bot . base_path + '<STR_LIT>' + file , '<STR_LIT:r>' ) as resps : <EOL> lines = resps . read ( ) . splitlines ( ) <EOL> l = choice ( lines ) <EOL> return l <EOL> def get_url ( m , url , title = False ) : <EOL> """<STR_LIT>""" <EOL> request = Request ( url , headers = m . bot . header ) <EOL> try : <EOL> html = urlopen ( request ) <EOL> except URLError as e : <EOL> m . bot . logger . info ( "<STR_LIT>" . format ( url , e . reason ) ) <EOL> return None <EOL> else : <EOL> try : <EOL> bytes = html . read ( <NUM_LIT> if title else - <NUM_LIT:1> ) . decode ( '<STR_LIT:utf-8>' ) <EOL> except UnicodeDecodeError as e : <EOL> m . bot . logger . info ( "<STR_LIT>" . format ( url , e . reason ) ) <EOL> return None <EOL> else : <EOL> return bytes <EOL> def humanize_list ( l ) : <EOL> """<STR_LIT>""" <EOL> if len ( l ) == <NUM_LIT:1> : <EOL> return l [ <NUM_LIT:0> ] <EOL> elif len ( l ) == <NUM_LIT:2> : <EOL> return "<STR_LIT>" . format ( l [ <NUM_LIT:0> ] , l [ <NUM_LIT:1> ] ) <EOL> else : <EOL> return "<STR_LIT:U+002CU+0020>" . join ( l [ : - <NUM_LIT:1> ] ) + "<STR_LIT>" + l [ - <NUM_LIT:1> ] </s>
