idx
int64
0
251k
question
stringlengths
53
3.53k
target
stringlengths
5
1.23k
len_question
int64
20
893
len_target
int64
3
238
250,100
def update_snapshot_schedule ( cls , cluster_id_label , s3_location = None , frequency_unit = None , frequency_num = None , status = None ) : conn = Qubole . agent ( version = Cluster . api_version ) data = { } if s3_location is not None : data [ "s3_location" ] = s3_location if frequency_unit is not None : data [ "fre...
Update for snapshot schedule
168
4
250,101
def set_spot_instance_settings ( self , maximum_bid_price_percentage = None , timeout_for_request = None , maximum_spot_instance_percentage = None ) : self . hadoop_settings [ 'spot_instance_settings' ] = { 'maximum_bid_price_percentage' : maximum_bid_price_percentage , 'timeout_for_request' : timeout_for_request , 'ma...
Purchase options for spot instances . Valid only when slave_request_type is hybrid or spot .
113
19
250,102
def set_stable_spot_instance_settings ( self , maximum_bid_price_percentage = None , timeout_for_request = None , allow_fallback = True ) : self . hadoop_settings [ 'stable_spot_instance_settings' ] = { 'maximum_bid_price_percentage' : maximum_bid_price_percentage , 'timeout_for_request' : timeout_for_request , 'allow_...
Purchase options for stable spot instances .
105
7
250,103
def minimal_payload ( self ) : payload_dict = self . __dict__ payload_dict . pop ( "api_version" , None ) return util . _make_minimal ( payload_dict )
This method can be used to create the payload which is sent while creating or updating a cluster .
45
19
250,104
def _handle_error ( response ) : code = response . status_code if 200 <= code < 400 : return if code == 400 : sys . stderr . write ( response . text + "\n" ) raise BadRequest ( response ) elif code == 401 : sys . stderr . write ( response . text + "\n" ) raise UnauthorizedAccess ( response ) elif code == 403 : sys . st...
Raise exceptions in response to any http errors
332
9
250,105
def createTemplate ( data ) : conn = Qubole . agent ( ) return conn . post ( Template . rest_entity_path , data )
Create a new template .
31
5
250,106
def editTemplate ( id , data ) : conn = Qubole . agent ( ) return conn . put ( Template . element_path ( id ) , data )
Edit an existing template .
34
5
250,107
def viewTemplate ( id ) : conn = Qubole . agent ( ) return conn . get ( Template . element_path ( id ) )
View an existing Template details .
30
6
250,108
def submitTemplate ( id , data = { } ) : conn = Qubole . agent ( ) path = str ( id ) + "/run" return conn . post ( Template . element_path ( path ) , data )
Submit an existing Template .
47
5
250,109
def runTemplate ( id , data = { } ) : conn = Qubole . agent ( ) path = str ( id ) + "/run" res = conn . post ( Template . element_path ( path ) , data ) cmdType = res [ 'command_type' ] cmdId = res [ 'id' ] cmdClass = eval ( cmdType ) cmd = cmdClass . find ( cmdId ) while not Command . is_done ( cmd . status ) : time ....
Run an existing Template and waits for the Result . Prints result to stdout .
134
17
250,110
def listTemplates ( data = { } ) : conn = Qubole . agent ( ) url_path = Template . rest_entity_path page_attr = [ ] if "page" in data and data [ "page" ] is not None : page_attr . append ( "page=%s" % data [ "page" ] ) if "per_page" in data and data [ "per_page" ] is not None : page_attr . append ( "per_page=%s" % data...
Fetch existing Templates details .
160
7
250,111
def edit ( args ) : tap = DbTap . find ( args . id ) options = { } if not args . name is None : options [ "db_name" ] = args . name if args . host is not None : options [ "db_host" ] = args . host if args . user is not None : options [ "db_user" ] = args . user if args . password is not None : options [ "db_passwd" ] =...
Carefully setup a dict
190
5
250,112
def create ( cls , name , config = None , kind = "spark" ) : conn = Qubole . agent ( ) return conn . post ( cls . rest_entity_path , data = { 'name' : name , 'config' : config , 'kind' : kind } )
Create a new app .
65
5
250,113
def configure ( cls , api_token , api_url = "https://api.qubole.com/api/" , version = "v1.2" , poll_interval = 5 , skip_ssl_cert_check = False , cloud_name = "AWS" ) : cls . _auth = QuboleAuth ( api_token ) cls . api_token = api_token cls . version = version cls . baseurl = api_url if poll_interval < Qubole . MIN_POLL_...
Set parameters governing interaction with QDS
246
7
250,114
def get_cluster_request_parameters ( cluster_info , cloud_config , engine_config ) : cluster_request = { } cloud_config = util . _make_minimal ( cloud_config . __dict__ ) if bool ( cloud_config ) : cluster_request [ 'cloud_config' ] = cloud_config engine_config = util . _make_minimal ( engine_config . __dict__ ) if boo...
Use this to return final minimal request from cluster_info cloud_config or engine_config objects Alternatively call util . _make_minimal if only one object needs to be implemented
141
36
250,115
def create ( cls , cluster_info ) : conn = Qubole . agent ( version = "v2" ) return conn . post ( cls . rest_entity_path , data = cluster_info )
Create a new cluster using information provided in cluster_info .
46
12
250,116
def _download_to_local ( boto_conn , s3_path , fp , num_result_dir , delim = None ) : #Progress bar to display download progress def _callback ( downloaded , total ) : ''' Call function for upload. `downloaded`: File size already downloaded (int) `total`: Total file size to be downloaded (int) ''' if ( total is 0 ) or ...
Downloads the contents of all objects in s3_path into fp
665
15
250,117
def cancel_id ( cls , id ) : conn = Qubole . agent ( ) data = { "status" : "kill" } return conn . put ( cls . element_path ( id ) , data )
Cancels command denoted by this id
48
9
250,118
def get_log_id ( cls , id ) : conn = Qubole . agent ( ) r = conn . get_raw ( cls . element_path ( id ) + "/logs" ) return r . text
Fetches log for the command represented by this id
49
11
250,119
def get_log ( self ) : log_path = self . meta_data [ 'logs_resource' ] conn = Qubole . agent ( ) r = conn . get_raw ( log_path ) return r . text
Fetches log for the command represented by this object
50
11
250,120
def get_results ( self , fp = sys . stdout , inline = True , delim = None , fetch = True , qlog = None , arguments = [ ] ) : result_path = self . meta_data [ 'results_resource' ] conn = Qubole . agent ( ) include_header = "false" if len ( arguments ) == 1 : include_header = arguments . pop ( 0 ) if include_header not i...
Fetches the result for the command represented by this object
758
12
250,121
def pluralize ( singular ) : if singular in UNCOUNTABLES : return singular for i in IRREGULAR : if i [ 0 ] == singular : return i [ 1 ] for i in PLURALIZE_PATTERNS : if re . search ( i [ 0 ] , singular ) : return re . sub ( i [ 0 ] , i [ 1 ] , singular )
Convert singular word to its plural form .
81
9
250,122
def singularize ( plural ) : if plural in UNCOUNTABLES : return plural for i in IRREGULAR : if i [ 1 ] == plural : return i [ 0 ] for i in SINGULARIZE_PATTERNS : if re . search ( i [ 0 ] , plural ) : return re . sub ( i [ 0 ] , i [ 1 ] , plural ) return plural
Convert plural word to its singular form .
83
9
250,123
def camelize ( word ) : return '' . join ( w [ 0 ] . upper ( ) + w [ 1 : ] for w in re . sub ( '[^A-Z^a-z^0-9^:]+' , ' ' , word ) . split ( ' ' ) )
Convert a word from lower_with_underscores to CamelCase .
63
16
250,124
def _make_minimal ( dictionary ) : new_dict = { } for key , value in dictionary . items ( ) : if value is not None : if isinstance ( value , dict ) : new_value = _make_minimal ( value ) if new_value : new_dict [ key ] = new_value else : new_dict [ key ] = value return new_dict
This function removes all the keys whose value is either None or an empty dictionary .
83
16
250,125
def upload_profiler_report ( url , filename , config ) : try : logger . debug ( "Uploading profiler report to IOpipe" ) with open ( filename , "rb" ) as data : response = requests . put ( url , data = data , timeout = config [ "network_timeout" ] ) response . raise_for_status ( ) except Exception as e : logger . debug ...
Uploads a profiler report to IOpipe
154
10
250,126
def read_pid_stat ( pid ) : return { "utime" : random . randint ( 0 , 999999999 ) , "stime" : random . randint ( 0 , 999999999 ) , "cutime" : random . randint ( 0 , 999999999 ) , "cstime" : random . randint ( 0 , 999999999 ) , }
Mocks read_pid_stat as this is a Linux - specific operation .
82
16
250,127
def read_stat ( ) : return [ { "times" : { "user" : random . randint ( 0 , 999999999 ) , "nice" : random . randint ( 0 , 999999999 ) , "sys" : random . randint ( 0 , 999999999 ) , "idle" : random . randint ( 0 , 999999999 ) , "irq" : random . randint ( 0 , 999999999 ) , } } ]
Mocks read_stat as this is a Linux - specific operation .
100
14
250,128
def load_plugins ( self , plugins ) : def instantiate ( plugin ) : return plugin ( ) if inspect . isclass ( plugin ) else plugin loaded_plugins = [ ] plugins_seen = [ ] # Iterate over plugins in reverse to permit users to override default # plugin config for plugin in reversed ( plugins ) : if not is_plugin ( plugin ) ...
Loads plugins that match the Plugin interface and are instantiated .
124
13
250,129
def run_hooks ( self , name , event = None , context = None ) : hooks = { "pre:setup" : lambda p : p . pre_setup ( self ) , "post:setup" : lambda p : p . post_setup ( self ) , "pre:invoke" : lambda p : p . pre_invoke ( event , context ) , "post:invoke" : lambda p : p . post_invoke ( event , context ) , "pre:report" : l...
Runs plugin hooks for each registered plugin .
200
9
250,130
def wait_for_futures ( self ) : [ future for future in futures . as_completed ( self . futures ) ] self . futures = [ ]
Wait for all futures to complete . This should be done at the end of an an invocation .
35
19
250,131
def validate_context ( self , context ) : return all ( [ hasattr ( context , attr ) for attr in [ "aws_request_id" , "function_name" , "function_version" , "get_remaining_time_in_millis" , "invoked_function_arn" , "log_group_name" , "log_stream_name" , "memory_limit_in_mb" , ] ] ) and callable ( context . get_remaining...
Checks to see if we re working with a valid lambda context object .
117
15
250,132
def patch_session_send ( context , http_filter ) : if Session is None : return def send ( self , * args , * * kwargs ) : id = ensure_utf8 ( str ( uuid . uuid4 ( ) ) ) with context . iopipe . mark ( id ) : response = original_session_send ( self , * args , * * kwargs ) trace = context . iopipe . mark . measure ( id ) co...
Monkey patches requests Session class if available . Overloads the send method to add tracing and metrics collection .
137
21
250,133
def patch_botocore_session_send ( context , http_filter ) : if BotocoreSession is None : return def send ( self , * args , * * kwargs ) : id = str ( uuid . uuid4 ( ) ) with context . iopipe . mark ( id ) : response = original_botocore_session_send ( self , * args , * * kwargs ) trace = context . iopipe . mark . measure...
Monkey patches botocore s vendored requests if available . Overloads the Session class send method to add tracing and metric collection .
145
27
250,134
def collect_metrics_for_response ( http_response , context , trace , http_filter ) : http_response = copy . deepcopy ( http_response ) if http_filter is not None and callable ( http_filter ) : http_response = http_filter ( http_response ) if http_response is False : return request = None if hasattr ( http_response , "r...
Collects relevant metrics from a requests Response object and adds them to the IOpipe context .
571
19
250,135
def get_plugin_meta ( plugins ) : return [ { "name" : p . name , "version" : p . version , "homepage" : p . homepage , "enabled" : p . enabled , } for p in plugins if is_plugin ( p ) ]
Returns meta data about plugins .
59
6
250,136
def is_plugin ( plugin ) : try : return isinstance ( plugin , Plugin ) or issubclass ( plugin , Plugin ) except TypeError : return False
Returns true if the plugin implements the Plugin interface .
33
10
250,137
def with_metaclass ( meta , * bases ) : class metaclass ( meta ) : def __new__ ( cls , name , this_bases , d ) : return meta ( name , bases , d ) return type . __new__ ( metaclass , "temporary_class" , ( ) , { } )
Python 2 and 3 compatible way to do meta classes
72
10
250,138
def extract_context_data ( self ) : data = { } for k , v in { # camel case names in the report to align with AWS standards "functionName" : "function_name" , "functionVersion" : "function_version" , "memoryLimitInMB" : "memory_limit_in_mb" , "invokedFunctionArn" : "invoked_function_arn" , "awsRequestId" : "aws_request_...
Returns the contents of a AWS Lambda context .
342
10
250,139
def retain_error ( self , error , frame = None ) : if frame is None : stack = traceback . format_exc ( ) self . labels . add ( "@iopipe/error" ) else : stack = "\n" . join ( traceback . format_stack ( frame ) ) self . labels . add ( "@iopipe/timeout" ) details = { "name" : type ( error ) . __name__ , "message" : "{}" ....
Adds details of an error to the report .
120
9
250,140
def prepare ( self , error = None , frame = None ) : if error : self . retain_error ( error , frame ) self . report [ "environment" ] [ "host" ] [ "boot_id" ] = system . read_bootid ( ) # convert labels to list for sending self . report [ "labels" ] = list ( self . labels ) meminfo = system . read_meminfo ( ) self . re...
Prepare the report to be sent to IOpipe .
351
12
250,141
def send ( self ) : if self . sent is True : return self . sent = True logger . debug ( "Sending report to IOpipe:" ) logger . debug ( json . dumps ( self . report , indent = 2 , sort_keys = True ) ) self . client . submit_future ( send_report , copy . deepcopy ( self . report ) , self . config )
Sends the report to IOpipe .
82
9
250,142
def send_report ( report , config ) : headers = { "Authorization" : "Bearer {}" . format ( config [ "token" ] ) } url = "https://{host}{path}" . format ( * * config ) try : response = session . post ( url , json = report , headers = headers , timeout = config [ "network_timeout" ] ) response . raise_for_status ( ) exce...
Sends the report to IOpipe s collector .
129
11
250,143
def upload_log_data ( url , stream_or_file , config ) : try : logger . debug ( "Uploading log data to IOpipe" ) if isinstance ( stream_or_file , StringIO ) : stream_or_file . seek ( 0 ) response = requests . put ( url , data = stream_or_file , timeout = config [ "network_timeout" ] ) else : with open ( stream_or_file ,...
Uploads log data to IOpipe .
248
9
250,144
def get_signer_hostname ( ) : region = os . getenv ( "AWS_REGION" , "" ) region = region if region and region in SUPPORTED_REGIONS else "us-west-2" return "signer.{region}.iopipe.com" . format ( region = region )
Returns the IOpipe signer hostname for a region
69
12
250,145
def get_signed_request ( config , context , extension ) : url = "https://{hostname}/" . format ( hostname = get_signer_hostname ( ) ) try : logger . debug ( "Requesting signed request URL from %s" , url ) response = requests . post ( url , json = { "arn" : context . invoked_function_arn , "requestId" : context . aws_re...
Returns a signed request URL from IOpipe
234
9
250,146
def handler ( event , context ) : try : ip = requests . get ( "http://checkip.amazonaws.com/" ) except requests . RequestException as e : # Send some context about this error to Lambda Logs print ( e ) raise e return { "statusCode" : 200 , "body" : json . dumps ( { "message" : "hello world" , "location" : ip . text . r...
Sample pure Lambda function
101
5
250,147
def read_meminfo ( ) : data = { } with open ( "/proc/meminfo" , "rb" ) as meminfo_file : for row in meminfo_file : fields = row . split ( ) # Example content: # MemTotal: 3801016 kB # MemFree: 1840972 kB # MemAvailable: 3287752 kB # HugePages_Total: 0 data [ fields [ 0 ] . decode ( "ascii" ) [ : - 1 ] ] = int ( fields ...
Returns system memory usage information .
118
6
250,148
def read_pid_stat ( pid = "self" ) : with open ( "/proc/%s/stat" % ( pid , ) , "rb" ) as f : stat = f . readline ( ) . split ( ) return { "utime" : int ( stat [ 13 ] ) , "stime" : int ( stat [ 14 ] ) , "cutime" : int ( stat [ 15 ] ) , "cstime" : int ( stat [ 16 ] ) , }
Returns system process stat information .
106
6
250,149
def read_pid_status ( pid = "self" ) : data = { } with open ( "/proc/%s/status" % ( pid , ) , "rb" ) as status_file : for row in status_file : fields = row . split ( ) if fields and fields [ 0 ] in [ b"VmRSS:" , b"Threads:" , b"FDSize:" ] : try : data [ fields [ 0 ] . decode ( "ascii" ) [ : - 1 ] ] = int ( fields [ 1 ]...
Returns the system process sstatus .
161
7
250,150
def read_stat ( ) : data = [ ] with open ( "/proc/stat" , "rb" ) as stat_file : for line in stat_file : cpu_stat = line . split ( ) if cpu_stat [ 0 ] [ : 3 ] != b"cpu" : break # First cpu line is aggregation of following lines, skip it if len ( cpu_stat [ 0 ] ) == 3 : continue data . append ( { "times" : { "user" : int...
Returns the system stat information .
176
6
250,151
def set_config ( * * config ) : config . setdefault ( "debug" , bool ( strtobool ( os . getenv ( "IOPIPE_DEBUG" , "false" ) ) ) ) config . setdefault ( "enabled" , bool ( strtobool ( os . getenv ( "IOPIPE_ENABLED" , "true" ) ) ) ) config . setdefault ( "host" , get_hostname ( ) ) config . setdefault ( "install_method" ...
Returns IOpipe configuration options setting defaults as necessary .
556
11
250,152
def b ( s ) : return s if isinstance ( s , bytes ) else s . encode ( locale . getpreferredencoding ( ) )
Encodes Unicode strings to byte strings if necessary .
31
10
250,153
def LogMsg ( msg ) : global headerlogged if headerlogged == 0 : print ( "{0:<8} {1:<90} {2}" . format ( "Time" , "MainThread" , "UpdateSNMPObjsThread" ) ) print ( "{0:-^120}" . format ( "-" ) ) headerlogged = 1 threadname = threading . currentThread ( ) . name funcname = sys . _getframe ( 1 ) . f_code . co_name if func...
Writes a formatted log message with a timestamp to stdout .
287
13
250,154
def UpdateSNMPObjs ( ) : global threadingString LogMsg ( "Beginning data update." ) data = "" # Obtain the data by calling an external command. We don't use # subprocess.check_output() here for compatibility with Python versions # older than 2.7. LogMsg ( "Calling external command \"sleep 5; date\"." ) proc = subproces...
Function that does the actual data update .
229
8
250,155
def getRegistered ( self , context = "" ) : myobjs = { } try : # Python 2.x objs_iterator = self . _objs [ context ] . iteritems ( ) except AttributeError : # Python 3.x objs_iterator = self . _objs [ context ] . items ( ) for oidstr , snmpobj in objs_iterator : myobjs [ oidstr ] = { "type" : type ( snmpobj ) . __name_...
Returns a dictionary with the currently registered SNMP objects .
127
11
250,156
def start ( self ) : if self . _status != netsnmpAgentStatus . CONNECTED and self . _status != netsnmpAgentStatus . RECONNECTING : self . _status = netsnmpAgentStatus . FIRSTCONNECT libnsa . init_snmp ( b ( self . AgentName ) ) if self . _status == netsnmpAgentStatus . CONNECTFAILED : msg = "Error connecting to snmpd i...
Starts the agent . Among other things this means connecting to the master agent if configured that way .
139
20
250,157
def _adjust_trim_top ( self , canv , size ) : action = self . _scroll_action self . _scroll_action = None maxcol , maxrow = size trim_top = self . _trim_top canv_rows = canv . rows ( ) if trim_top < 0 : # Negative trim_top values use bottom of canvas as reference trim_top = canv_rows - maxrow + trim_top + 1 if canv_row...
Adjust self . _trim_top according to self . _scroll_action
512
16
250,158
def rows_max ( self , size = None , focus = False ) : if size is not None : ow = self . _original_widget ow_size = self . _get_original_widget_size ( size ) sizing = ow . sizing ( ) if FIXED in sizing : self . _rows_max_cached = ow . pack ( ow_size , focus ) [ 1 ] elif FLOW in sizing : self . _rows_max_cached = ow . ro...
Return the number of rows for size
145
7
250,159
def scrolling_base_widget ( self ) : def orig_iter ( w ) : while hasattr ( w , 'original_widget' ) : w = w . original_widget yield w yield w def is_scrolling_widget ( w ) : return hasattr ( w , 'get_scrollpos' ) and hasattr ( w , 'rows_max' ) for w in orig_iter ( self ) : if is_scrolling_widget ( w ) : return w raise V...
Nearest original_widget that is compatible with the scrolling API
121
12
250,160
def ignore_after ( seconds , coro = None , * args , timeout_result = None ) : if coro : return _ignore_after_func ( seconds , False , coro , args , timeout_result ) return TimeoutAfter ( seconds , ignore = True )
Execute the specified coroutine and return its result . Issue a cancellation request after seconds have elapsed . When a timeout occurs no exception is raised . Instead timeout_result is returned .
58
36
250,161
def _add_task ( self , task ) : if hasattr ( task , '_task_group' ) : raise RuntimeError ( 'task is already part of a group' ) if self . _closed : raise RuntimeError ( 'task group is closed' ) task . _task_group = self if task . done ( ) : self . _done . append ( task ) else : self . _pending . add ( task ) task . add_...
Add an already existing task to the task group .
107
10
250,162
async def next_done ( self ) : if not self . _done and self . _pending : self . _done_event . clear ( ) await self . _done_event . wait ( ) if self . _done : return self . _done . popleft ( ) return None
Returns the next completed task . Returns None if no more tasks remain . A TaskGroup may also be used as an asynchronous iterator .
63
26
250,163
async def join ( self ) : def errored ( task ) : return not task . cancelled ( ) and task . exception ( ) try : if self . _wait in ( all , object ) : while True : task = await self . next_done ( ) if task is None : return if errored ( task ) : break if self . _wait is object : if task . cancelled ( ) or task . result (...
Wait for tasks in the group to terminate according to the wait policy for the group .
145
17
250,164
async def cancel_remaining ( self ) : self . _closed = True task_list = list ( self . _pending ) for task in task_list : task . cancel ( ) for task in task_list : with suppress ( CancelledError ) : await task
Cancel all remaining tasks .
58
6
250,165
async def _connect_one ( self , remote_address ) : loop = asyncio . get_event_loop ( ) for info in await loop . getaddrinfo ( str ( self . address . host ) , self . address . port , type = socket . SOCK_STREAM ) : # This object has state so is only good for one connection client = self . protocol ( remote_address , sel...
Connect to the proxy and perform a handshake requesting a connection .
220
12
250,166
async def _connect ( self , remote_addresses ) : assert remote_addresses exceptions = [ ] for remote_address in remote_addresses : sock = await self . _connect_one ( remote_address ) if isinstance ( sock , socket . socket ) : return sock , remote_address exceptions . append ( sock ) strings = set ( f'{exc!r}' for exc i...
Connect to the proxy and perform a handshake requesting a connection to each address in addresses .
122
17
250,167
async def _detect_proxy ( self ) : if self . protocol is SOCKS4a : remote_address = NetAddress ( 'www.apple.com' , 80 ) else : remote_address = NetAddress ( '8.8.8.8' , 53 ) sock = await self . _connect_one ( remote_address ) if isinstance ( sock , socket . socket ) : sock . close ( ) return True # SOCKSFailure indicat...
Return True if it appears we can connect to a SOCKS proxy otherwise False .
125
17
250,168
async def auto_detect_at_host ( cls , host , ports , auth ) : for port in ports : proxy = await cls . auto_detect_at_address ( NetAddress ( host , port ) , auth ) if proxy : return proxy return None
Try to detect a SOCKS proxy on a host on one of the ports .
59
17
250,169
async def create_connection ( self ) : connector = self . proxy or self . loop return await connector . create_connection ( self . session_factory , self . host , self . port , * * self . kwargs )
Initiate a connection .
50
6
250,170
def data_received ( self , framed_message ) : if self . verbosity >= 4 : self . logger . debug ( f'Received framed message {framed_message}' ) self . recv_size += len ( framed_message ) self . bump_cost ( len ( framed_message ) * self . bw_cost_per_byte ) self . framer . received_bytes ( framed_message )
Called by asyncio when a message comes in .
90
11
250,171
def pause_writing ( self ) : if not self . is_closing ( ) : self . _can_send . clear ( ) self . transport . pause_reading ( )
Transport calls when the send buffer is full .
38
10
250,172
def resume_writing ( self ) : if not self . _can_send . is_set ( ) : self . _can_send . set ( ) self . transport . resume_reading ( )
Transport calls when the send buffer has room .
42
10
250,173
def connection_made ( self , transport ) : self . transport = transport # If the Socks proxy was used then _proxy and _remote_address are already set if self . _proxy is None : # This would throw if called on a closed SSL transport. Fixed in asyncio in # Python 3.6.1 and 3.5.4 peername = transport . get_extra_info ( 'p...
Called by asyncio when a connection is established .
135
11
250,174
def connection_lost ( self , exc ) : # Work around uvloop bug; see https://github.com/MagicStack/uvloop/issues/246 if self . transport : self . transport = None self . closed_event . set ( ) # Release waiting tasks self . _can_send . set ( ) # Cancelling directly leads to self-cancellation problems for member # functio...
Called by asyncio when the connection closes .
106
10
250,175
def recalc_concurrency ( self ) : # Refund resource usage proportionally to elapsed time; the bump passed is negative now = time . time ( ) self . cost = max ( 0 , self . cost - ( now - self . _cost_time ) * self . cost_decay_per_sec ) self . _cost_time = now self . _cost_last = self . cost # Setting cost_hard_limit <=...
Call to recalculate sleeps and concurrency for the session . Called automatically if cost has drifted significantly . Otherwise can be called at regular intervals if desired .
269
31
250,176
async def close ( self , * , force_after = 30 ) : if self . transport : self . transport . close ( ) try : async with timeout_after ( force_after ) : await self . closed_event . wait ( ) except TaskTimeout : self . abort ( ) await self . closed_event . wait ( )
Close the connection and return when closed .
70
8
250,177
async def send_request ( self , method , args = ( ) ) : message , event = self . connection . send_request ( Request ( method , args ) ) return await self . _send_concurrent ( message , event , 1 )
Send an RPC request over the network .
52
8
250,178
async def send_notification ( self , method , args = ( ) ) : message = self . connection . send_notification ( Notification ( method , args ) ) await self . _send_message ( message )
Send an RPC notification over the network .
46
8
250,179
async def close ( self ) : if self . server : self . server . close ( ) await self . server . wait_closed ( ) self . server = None
Close the listening socket . This does not close any ServerSession objects created to handle incoming connections .
35
19
250,180
def _message_to_payload ( cls , message ) : try : return json . loads ( message . decode ( ) ) except UnicodeDecodeError : message = 'messages must be encoded in UTF-8' except json . JSONDecodeError : message = 'invalid JSON' raise cls . _error ( cls . PARSE_ERROR , message , True , None )
Returns a Python object or a ProtocolError .
83
9
250,181
def batch_message ( cls , batch , request_ids ) : assert isinstance ( batch , Batch ) if not cls . allow_batches : raise ProtocolError . invalid_request ( 'protocol does not permit batches' ) id_iter = iter ( request_ids ) rm = cls . request_message nm = cls . notification_message parts = ( rm ( request , next ( id_ite...
Convert a request Batch to a message .
123
10
250,182
def batch_message_from_parts ( cls , messages ) : # Comma-separate the messages and wrap the lot in square brackets middle = b', ' . join ( messages ) if not middle : raise ProtocolError . empty_batch ( ) return b'' . join ( [ b'[' , middle , b']' ] )
Convert messages one per batch item into a batch message . At least one message must be passed .
71
20
250,183
def encode_payload ( cls , payload ) : try : return json . dumps ( payload ) . encode ( ) except TypeError : msg = f'JSON payload encoding error: {payload}' raise ProtocolError ( cls . INTERNAL_ERROR , msg ) from None
Encode a Python object as JSON and convert it to bytes .
60
13
250,184
def detect_protocol ( cls , message ) : main = cls . _message_to_payload ( message ) def protocol_for_payload ( payload ) : if not isinstance ( payload , dict ) : return JSONRPCLoose # Will error # Obey an explicit "jsonrpc" version = payload . get ( 'jsonrpc' ) if version == '2.0' : return JSONRPCv2 if version == '1.0...
Attempt to detect the protocol from the message .
276
9
250,185
def receive_message ( self , message ) : if self . _protocol is JSONRPCAutoDetect : self . _protocol = JSONRPCAutoDetect . detect_protocol ( message ) try : item , request_id = self . _protocol . message_to_item ( message ) except ProtocolError as e : if e . response_msg_id is not id : return self . _receive_response (...
Call with an unframed message received from the network .
239
12
250,186
def cancel_pending_requests ( self ) : exception = CancelledError ( ) for _request , event in self . _requests . values ( ) : event . result = exception event . set ( ) self . _requests . clear ( )
Cancel all pending requests .
54
6
250,187
def is_valid_hostname ( hostname ) : if not isinstance ( hostname , str ) : raise TypeError ( 'hostname must be a string' ) # strip exactly one dot from the right, if present if hostname and hostname [ - 1 ] == "." : hostname = hostname [ : - 1 ] if not hostname or len ( hostname ) > 253 : return False labels = hostnam...
Return True if hostname is valid otherwise False .
147
10
250,188
def classify_host ( host ) : if isinstance ( host , ( IPv4Address , IPv6Address ) ) : return host if is_valid_hostname ( host ) : return host return ip_address ( host )
Host is an IPv4Address IPv6Address or a string .
47
13
250,189
def validate_port ( port ) : if not isinstance ( port , ( str , int ) ) : raise TypeError ( f'port must be an integer or string: {port}' ) if isinstance ( port , str ) and port . isdigit ( ) : port = int ( port ) if isinstance ( port , int ) and 0 < port <= 65535 : return port raise ValueError ( f'invalid port: {port}'...
Validate port and return it as an integer .
96
10
250,190
def validate_protocol ( protocol ) : if not re . match ( PROTOCOL_REGEX , protocol ) : raise ValueError ( f'invalid protocol: {protocol}' ) return protocol . lower ( )
Validate a protocol a string and return it .
47
10
250,191
def is_async_call ( func ) : while isinstance ( func , partial ) : func = func . func return inspect . iscoroutinefunction ( func )
inspect . iscoroutinefunction that looks through partials .
35
13
250,192
def from_string ( cls , string , * , default_func = None ) : if not isinstance ( string , str ) : raise TypeError ( f'service must be a string: {string}' ) parts = string . split ( '://' , 1 ) if len ( parts ) == 2 : protocol , address = parts else : item , = parts protocol = None if default_func : if default_func ( it...
Construct a Service from a string .
209
7
250,193
def scrub ( self ) : LOG . info ( "Scrubbing out the nasty characters that break our parser." ) myfile = '/' . join ( ( self . rawdir , self . files [ 'data' ] [ 'file' ] ) ) tmpfile = '/' . join ( ( self . rawdir , self . files [ 'data' ] [ 'file' ] + '.tmp.gz' ) ) tmp = gzip . open ( tmpfile , 'wb' ) du = DipperUtil ...
The XML file seems to have mixed - encoding ; we scrub out the control characters from the file for processing .
272
22
250,194
def process_associations ( self , limit ) : myfile = '/' . join ( ( self . rawdir , self . files [ 'data' ] [ 'file' ] ) ) f = gzip . open ( myfile , 'rb' ) filereader = io . TextIOWrapper ( f , newline = "" ) filereader . readline ( ) # remove the xml declaration line for event , elem in ET . iterparse ( filereader ) ...
Loop through the xml file and process the article - breed article - phene breed - phene phene - gene associations and the external links to LIDA .
308
32
250,195
def _process_article_phene_row ( self , row ) : # article_id, phene_id, added_by # look up the article in the hashmap phenotype_id = self . id_hash [ 'phene' ] . get ( row [ 'phene_id' ] ) article_id = self . id_hash [ 'article' ] . get ( row [ 'article_id' ] ) omia_id = self . _get_omia_id_from_phene_id ( phenotype_id...
Linking articles to species - specific phenes .
198
10
250,196
def filter_keep_phenotype_entry_ids ( self , entry ) : omim_id = str ( entry [ 'mimNumber' ] ) otype = self . globaltt [ 'obsolete' ] if omim_id in self . omim_type : otype = self . omim_type [ omim_id ] if otype == self . globaltt [ 'obsolete' ] and omim_id in self . omim_replaced : omim_id = self . omim_replaced [ om...
doubt this should be kept
186
6
250,197
def make_spo ( sub , prd , obj ) : # To establish string as a curie and expand, # we use a global curie_map(.yaml) # sub are allways uri (unless a bnode) # prd are allways uri (unless prd is 'a') # should fail loudly if curie does not exist if prd == 'a' : prd = 'rdf:type' try : ( subcuri , subid ) = re . split ( r':' ...
Decorates the three given strings as a line of ntriples
643
14
250,198
def write_spo ( sub , prd , obj ) : rcvtriples . append ( make_spo ( sub , prd , obj ) )
write triples to a buffer incase we decide to drop them
34
13
250,199
def make_allele_by_consequence ( self , consequence , gene_id , gene_symbol ) : allele_id = None # Loss of function : Nonsense, frame-shifting indel, # essential splice site mutation, whole gene deletion or any other # mutation where functional analysis demonstrates clear reduction # or loss of function # All missense/...
Given a consequence label that describes a variation type create an anonymous variant of the specified gene as an instance of that consequence type .
432
25