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,800
def connect ( self ) : HTTPConnection . connect ( self ) self . sock . setsockopt ( socket . IPPROTO_TCP , socket . TCP_NODELAY , 1 )
Set TCP_NODELAY on socket
41
9
250,801
def _with_retries ( self , pool , fn ) : skip_nodes = [ ] def _skip_bad_nodes ( transport ) : return transport . _node not in skip_nodes retry_count = self . retries - 1 first_try = True current_try = 0 while True : try : with pool . transaction ( _filter = _skip_bad_nodes , yield_resource = True ) as resource : transport = resource . object try : return fn ( transport ) except ( IOError , HTTPException , ConnectionClosed ) as e : resource . errored = True if _is_retryable ( e ) : transport . _node . error_rate . incr ( 1 ) skip_nodes . append ( transport . _node ) if first_try : continue else : raise BadResource ( e ) else : raise except BadResource as e : if current_try < retry_count : resource . errored = True current_try += 1 continue else : # Re-raise the inner exception raise e . args [ 0 ] finally : first_try = False
Performs the passed function with retries against the given pool .
233
13
250,802
def _choose_pool ( self , protocol = None ) : if not protocol : protocol = self . protocol if protocol == 'http' : pool = self . _http_pool elif protocol == 'tcp' or protocol == 'pbc' : pool = self . _tcp_pool else : raise ValueError ( "invalid protocol %s" % protocol ) if pool is None or self . _closed : # NB: GH-500, this can happen if client is closed raise RuntimeError ( "Client is closed." ) return pool
Selects a connection pool according to the default protocol and the passed one .
115
15
250,803
def default_encoder ( obj ) : if isinstance ( obj , bytes ) : return json . dumps ( bytes_to_str ( obj ) , ensure_ascii = False ) . encode ( "utf-8" ) else : return json . dumps ( obj , ensure_ascii = False ) . encode ( "utf-8" )
Default encoder for JSON datatypes which returns UTF - 8 encoded json instead of the default bloated backslash u XXXX escaped ASCII strings .
75
30
250,804
def close ( self ) : if not self . _closed : self . _closed = True self . _stop_multi_pools ( ) if self . _http_pool is not None : self . _http_pool . clear ( ) self . _http_pool = None if self . _tcp_pool is not None : self . _tcp_pool . clear ( ) self . _tcp_pool = None
Iterate through all of the connections and close each one .
91
12
250,805
def _create_credentials ( self , n ) : if not n : return n elif isinstance ( n , SecurityCreds ) : return n elif isinstance ( n , dict ) : return SecurityCreds ( * * n ) else : raise TypeError ( "%s is not a valid security configuration" % repr ( n ) )
Create security credentials if necessary .
75
6
250,806
def _connect ( self ) : timeout = None if self . _options is not None and 'timeout' in self . _options : timeout = self . _options [ 'timeout' ] if self . _client . _credentials : self . _connection = self . _connection_class ( host = self . _node . host , port = self . _node . http_port , credentials = self . _client . _credentials , timeout = timeout ) else : self . _connection = self . _connection_class ( host = self . _node . host , port = self . _node . http_port , timeout = timeout ) # Forces the population of stats and resources before any # other requests are made. self . server_version
Use the appropriate connection class ; optionally with security .
157
10
250,807
def _security_auth_headers ( self , username , password , headers ) : userColonPassword = username + ":" + password b64UserColonPassword = base64 . b64encode ( str_to_bytes ( userColonPassword ) ) . decode ( "ascii" ) headers [ 'Authorization' ] = 'Basic %s' % b64UserColonPassword
Add in the requisite HTTP Authentication Headers
84
8
250,808
def query ( self , query , interpolations = None ) : return self . _client . ts_query ( self , query , interpolations )
Queries a timeseries table .
30
7
250,809
def getConfigDirectory ( ) : if platform . system ( ) == 'Windows' : return os . path . join ( os . environ [ 'APPDATA' ] , 'ue4cli' ) else : return os . path . join ( os . environ [ 'HOME' ] , '.config' , 'ue4cli' )
Determines the platform - specific config directory location for ue4cli
72
15
250,810
def setConfigKey ( key , value ) : configFile = ConfigurationManager . _configFile ( ) return JsonDataManager ( configFile ) . setKey ( key , value )
Sets the config data value for the specified dictionary key
38
11
250,811
def clearCache ( ) : if os . path . exists ( CachedDataManager . _cacheDir ( ) ) == True : shutil . rmtree ( CachedDataManager . _cacheDir ( ) )
Clears any cached data we have stored about specific engine versions
45
12
250,812
def getCachedDataKey ( engineVersionHash , key ) : cacheFile = CachedDataManager . _cacheFileForHash ( engineVersionHash ) return JsonDataManager ( cacheFile ) . getKey ( key )
Retrieves the cached data value for the specified engine version hash and dictionary key
47
16
250,813
def setCachedDataKey ( engineVersionHash , key , value ) : cacheFile = CachedDataManager . _cacheFileForHash ( engineVersionHash ) return JsonDataManager ( cacheFile ) . setKey ( key , value )
Sets the cached data value for the specified engine version hash and dictionary key
51
15
250,814
def writeFile ( filename , data ) : with open ( filename , 'wb' ) as f : f . write ( data . encode ( 'utf-8' ) )
Writes data to a file
36
6
250,815
def patchFile ( filename , replacements ) : patched = Utility . readFile ( filename ) # Perform each of the replacements in the supplied dictionary for key in replacements : patched = patched . replace ( key , replacements [ key ] ) Utility . writeFile ( filename , patched )
Applies the supplied list of replacements to a file
55
10
250,816
def escapePathForShell ( path ) : if platform . system ( ) == 'Windows' : return '"{}"' . format ( path . replace ( '"' , '""' ) ) else : return shellescape . quote ( path )
Escapes a filesystem path for use as a command - line argument
51
13
250,817
def join ( delim , items , quotes = False ) : transform = lambda s : s if quotes == True : transform = lambda s : s if ' ' not in s else '"{}"' . format ( s ) stripped = list ( [ transform ( i ) for i in items if len ( i ) > 0 ] ) if len ( stripped ) > 0 : return delim . join ( stripped ) return ''
Joins the supplied list of strings after removing any empty strings from the list
85
15