<s> import sys <EOL> import os <EOL> def test_already_running ( pid_path , proc_name ) : <EOL> try : <EOL> with open ( pid_path ) as f : <EOL> pid = int ( f . read ( ) ) <EOL> with open ( '<STR_LIT>' . format ( pid ) ) as f : <EOL> if proc_name in f . read ( ) : <EOL> assert pid != <NUM_LIT:0> <EOL> return pid <EOL> except Exception : <EOL> pass <EOL> return False <EOL> def get_error_code ( status_code ) : <EOL> return status_code >> <NUM_LIT> <EOL> def get_sync_code ( status_code ) : <EOL> return status_code & <NUM_LIT> <EOL> def tail ( f , window = <NUM_LIT:20> ) : <EOL> """<STR_LIT>""" <EOL> if window == <NUM_LIT:0> : <EOL> return [ ] <EOL> BUFSIZ = <NUM_LIT> <EOL> f . seek ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> bytes = f . tell ( ) <EOL> size = window + <NUM_LIT:1> <EOL> block = - <NUM_LIT:1> <EOL> data = [ ] <EOL> while size > <NUM_LIT:0> and bytes > <NUM_LIT:0> : <EOL> if bytes - BUFSIZ > <NUM_LIT:0> : <EOL> f . seek ( block * BUFSIZ , <NUM_LIT:2> ) <EOL> data . insert ( <NUM_LIT:0> , f . read ( BUFSIZ ) ) <EOL> else : <EOL> f . seek ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> data . insert ( <NUM_LIT:0> , f . read ( bytes ) ) <EOL> linesFound = data [ <NUM_LIT:0> ] . count ( '<STR_LIT:\n>' ) <EOL> size -= linesFound <EOL> bytes -= BUFSIZ <EOL> block -= <NUM_LIT:1> <EOL> return '<STR_LIT>' . join ( data ) . splitlines ( ) [ - window : ] <EOL> def dict_from_slots_obj ( obj ) : <EOL> slots = obj . __slots__ <EOL> attr_dict = { } <EOL> for slot in slots : <EOL> attr_dict [ slot ] = getattr ( obj , slot ) <EOL> return attr_dict <EOL> def get_own_dir ( own_filename ) : <EOL> if getattr ( sys , "<STR_LIT>" , False ) : <EOL> own_path = sys . executable <EOL> else : <EOL> own_path = os . path . join ( os . getcwd ( ) , own_filename ) <EOL> return os . path . dirname ( own_path ) <EOL> def get_proxy ( ui_config ) : <EOL> proxy_url = ui_config . get ( '<STR_LIT>' ) <EOL> if proxy_url is None : <EOL> proxy_url = os . getenv ( '<STR_LIT>' ) or os . getenv ( '<STR_LIT>' ) <EOL> return proxy_url <EOL> def set_proxy ( ui_config , proxy_url ) : <EOL> set_config_value ( ui_config , '<STR_LIT>' , proxy_url ) <EOL> def get_ratelimits ( ui_config ) : <EOL> download_limit = ui_config . get ( '<STR_LIT>' ) or <NUM_LIT:0> <EOL> upload_limit = ui_config . get ( '<STR_LIT>' ) or <NUM_LIT:0> <EOL> return download_limit , upload_limit <EOL> def set_ratelimits ( ui_config , download_limit , upload_limit ) : <EOL> set_config_value ( ui_config , '<STR_LIT>' , download_limit ) <EOL> set_config_value ( ui_config , '<STR_LIT>' , upload_limit ) <EOL> def set_config_value ( ui_config , key , value ) : <EOL> if value is None : <EOL> ui_config . unset ( key ) <EOL> else : <EOL> ui_config . set ( key , value ) </s>
