idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
251,800 | def _normalize_json_search_response ( self , json ) : result = { } if 'facet_counts' in json : result [ 'facet_counts' ] = json [ u'facet_counts' ] if 'grouped' in json : result [ 'grouped' ] = json [ u'grouped' ] if 'stats' in json : result [ 'stats' ] = json [ u'stats' ] if u'response' in json : result [ 'num_found' ] = json [ u'response' ] [ u'numFound' ] result [ 'max_score' ] = float ( json [ u'response' ] [ u'maxScore' ] ) docs = [ ] for doc in json [ u'response' ] [ u'docs' ] : resdoc = { } if u'_yz_rk' in doc : resdoc = doc else : resdoc [ u'id' ] = doc [ u'id' ] if u'fields' in doc : for k , v in six . iteritems ( doc [ u'fields' ] ) : resdoc [ k ] = v docs . append ( resdoc ) result [ 'docs' ] = docs return result | Normalizes a JSON search response so that PB and HTTP have the same return value |
251,801 | def _normalize_xml_search_response ( self , xml ) : target = XMLSearchResult ( ) parser = ElementTree . XMLParser ( target = target ) parser . feed ( xml ) return parser . close ( ) | Normalizes an XML search response so that PB and HTTP have the same return value |
251,802 | def connect ( self ) : HTTPConnection . connect ( self ) self . sock . setsockopt ( socket . IPPROTO_TCP , socket . TCP_NODELAY , 1 ) | Set TCP_NODELAY on socket |
251,803 | 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 : raise e . args [ 0 ] finally : first_try = False | Performs the passed function with retries against the given pool . |
251,804 | 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 : raise RuntimeError ( "Client is closed." ) return pool | Selects a connection pool according to the default protocol and the passed one . |
251,805 | 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 . |
251,806 | 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 . |
251,807 | 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 . |
251,808 | 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 ) self . server_version | Use the appropriate connection class ; optionally with security . |
251,809 | 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 |
251,810 | def query ( self , query , interpolations = None ) : return self . _client . ts_query ( self , query , interpolations ) | Queries a timeseries table . |
251,811 | 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 |
251,812 | def setConfigKey ( key , value ) : configFile = ConfigurationManager . _configFile ( ) return JsonDataManager ( configFile ) . setKey ( key , value ) | Sets the config data value for the specified dictionary key |
251,813 | def clearCache ( ) : if os . path . exists ( CachedDataManager . _cacheDir ( ) ) == True : shutil . rmtree ( CachedDataManager . _cacheDir ( ) ) | Clears any cached data we have stored about specific engine versions |
251,814 | 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 |
251,815 | 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 |
251,816 | def writeFile ( filename , data ) : with open ( filename , 'wb' ) as f : f . write ( data . encode ( 'utf-8' ) ) | Writes data to a file |
251,817 | def patchFile ( filename , replacements ) : patched = Utility . readFile ( filename ) for key in replacements : patched = patched . replace ( key , replacements [ key ] ) Utility . writeFile ( filename , patched ) | Applies the supplied list of replacements to a file |
251,818 | 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 |
251,819 | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.