idx int64 0 251k | question stringlengths 53 3.53k | target stringlengths 5 1.23k | len_question int64 20 893 | len_target int64 3 238 |
|---|---|---|---|---|
8,000 | def publish ( self , topic , dct ) : get_logger ( ) . info ( "Publishing message {} on routing key " "{}..." . format ( dct , topic ) ) self . _channel . basic_publish ( exchange = self . exchange , routing_key = topic , body = json . dumps ( dct ) ) | Send a dict with internal routing key to the exchange . | 73 | 11 |
8,001 | def _callback ( self , ch , method , properties , body ) : get_logger ( ) . info ( "Message received! Calling listeners..." ) topic = method . routing_key dct = json . loads ( body . decode ( 'utf-8' ) ) for listener in self . listeners : listener ( self , topic , dct ) | Internal method that will be called when receiving message . | 73 | 10 |
8,002 | def _handle_ping ( client , topic , dct ) : if dct [ 'type' ] == 'request' : resp = { 'type' : 'answer' , 'name' : client . name , 'source' : dct } client . publish ( 'ping' , resp ) | Internal method that will be called when receiving ping message . | 63 | 11 |
8,003 | def _create_argument_value_pairs ( func , * args , * * kwargs ) : # Capture parameters that have been explicitly specified in function call try : arg_dict = signature ( func ) . bind_partial ( * args , * * kwargs ) . arguments except TypeError : return dict ( ) # Capture parameters that have not been explicitly specifi... | Create dictionary with argument names as keys and their passed values as values . | 156 | 14 |
8,004 | def _get_contract_exception_dict ( contract_msg ) : # A pcontract-defined custom exception message is wrapped in a string # that starts with '[START CONTRACT MSG:' and ends with # '[STOP CONTRACT MSG]'. This is done to easily detect if an # exception raised is from a custom contract and thus be able # to easily retriev... | Generate message for exception . | 307 | 6 |
8,005 | def _get_custom_contract ( param_contract ) : if not isinstance ( param_contract , str ) : return None for custom_contract in _CUSTOM_CONTRACTS : if re . search ( r"\b{0}\b" . format ( custom_contract ) , param_contract ) : return custom_contract return None | Return True if parameter contract is a custom contract False otherwise . | 75 | 12 |
8,006 | def _get_replacement_token ( msg ) : return ( None if not re . search ( r"\*\[[\w|\W]+\]\*" , msg ) else re . search ( r"\*\[[\w|\W]+\]\*" , msg ) . group ( ) [ 2 : - 2 ] ) | Extract replacement token from exception message . | 77 | 8 |
8,007 | def _get_type_name ( type_ ) : # type: (type) -> str name = repr ( type_ ) if name . startswith ( "<" ) : name = getattr ( type_ , "__qualname__" , getattr ( type_ , "__name__" , "" ) ) return name . rsplit ( "." , 1 ) [ - 1 ] or repr ( type_ ) | Return a displayable name for the type . | 89 | 9 |
8,008 | def _get_class_frame_source ( class_name ) : # type: (str) -> Optional[str] for frame_info in inspect . stack ( ) : try : with open ( frame_info [ 1 ] ) as fp : src = "" . join ( fp . readlines ( ) [ frame_info [ 2 ] - 1 : ] ) except IOError : continue if re . search ( r"\bclass\b\s+\b{}\b" . format ( class_name ) , sr... | Return the source code for a class by checking the frame stack . | 338 | 13 |
8,009 | def _is_propertyable ( names , # type: List[str] attrs , # type: Dict[str, Any] annotations , # type: Dict[str, type] attr , # Dict[str, Any] ) : # type: (...) -> bool return ( attr in annotations and not attr . startswith ( "_" ) and not attr . isupper ( ) and "__{}" . format ( attr ) not in names and not isinstance (... | Determine if an attribute can be replaced with a property . | 125 | 13 |
8,010 | def _create_typed_object_meta ( get_fset ) : # type: (Callable[[str, str, Type[_T]], Callable[[_T], None]]) -> type def _get_fget ( attr , private_attr , type_ ) : # type: (str, str, Type[_T]) -> Callable[[], Any] """Create a property getter method for an attribute. Args: attr: The name of the attribute that will be re... | Create a metaclass for typed objects . | 886 | 9 |
8,011 | def _tp__get_typed_properties ( self ) : try : return tuple ( getattr ( self , p ) for p in self . _tp__typed_properties ) except AttributeError : raise NotImplementedError | Return a tuple of typed attrs that can be used for comparisons . | 50 | 14 |
8,012 | def run ( cls , routes , * args , * * kwargs ) : # pragma: no cover app = init ( cls , routes , * args , * * kwargs ) HOST = os . getenv ( 'HOST' , '0.0.0.0' ) PORT = int ( os . getenv ( 'PORT' , 8000 ) ) aiohttp . web . run_app ( app , port = PORT , host = HOST ) | Run a web application . | 104 | 5 |
8,013 | def add ( self , vector , InterventionAnophelesParams = None ) : # TODO # 1. If there are GVI interventions, for every GVI, add anophelesParams section. # (gvi_anophelesParams field in AnophelesSnippets models) # 2. If there are ITN interventions, for every ITN, add anophelesParams section # (itn_anophelesParams field ... | Add a vector to entomology section . vector is either ElementTree or xml snippet | 243 | 17 |
8,014 | def _format_msg ( text , width , indent = 0 , prefix = "" ) : text = repr ( text ) . replace ( "`" , "\\`" ) . replace ( "\\n" , " ``\\n`` " ) sindent = " " * indent if not prefix else prefix wrapped_text = textwrap . wrap ( text , width , subsequent_indent = sindent ) # [1:-1] eliminates quotes generated by repr in fi... | r Format exception message . | 125 | 5 |
8,015 | def _validate_fname ( fname , arg_name ) : if fname is not None : msg = "Argument `{0}` is not valid" . format ( arg_name ) if ( not isinstance ( fname , str ) ) or ( isinstance ( fname , str ) and ( "\0" in fname ) ) : raise RuntimeError ( msg ) try : if not os . path . exists ( fname ) : os . access ( fname , os . W_... | Validate that a string is a valid file name . | 131 | 11 |
8,016 | def _build_ex_tree ( self ) : # Load exception data into tree structure sep = self . _exh_obj . callables_separator data = self . _exh_obj . exceptions_db if not data : raise RuntimeError ( "Exceptions database is empty" ) # Add root node to exceptions, needed when tracing done # through test runner which is excluded f... | Construct exception tree from trace . | 379 | 6 |
8,017 | def _build_module_db ( self ) : tdict = collections . defaultdict ( lambda : [ ] ) for callable_name , callable_dict in self . _exh_obj . callables_db . items ( ) : fname , line_no = callable_dict [ "code_id" ] cname = ( "{cls_name}.__init__" . format ( cls_name = callable_name ) if callable_dict [ "type" ] == "class" ... | Build database of module callables sorted by line number . | 190 | 11 |
8,018 | def _process_exlist ( self , exc , raised ) : if ( not raised ) or ( raised and exc . endswith ( "*" ) ) : return exc [ : - 1 ] if exc . endswith ( "*" ) else exc return None | Remove raised info from exception message and create separate list for it . | 57 | 13 |
8,019 | def _set_depth ( self , depth ) : if depth and ( ( not isinstance ( depth , int ) ) or ( isinstance ( depth , int ) and ( depth < 0 ) ) ) : raise RuntimeError ( "Argument `depth` is not valid" ) self . _depth = depth | Depth setter . | 64 | 4 |
8,020 | def _set_exclude ( self , exclude ) : if exclude and ( ( not isinstance ( exclude , list ) ) or ( isinstance ( exclude , list ) and any ( [ not isinstance ( item , str ) for item in exclude ] ) ) ) : raise RuntimeError ( "Argument `exclude` is not valid" ) self . _exclude = exclude | Exclude setter . | 79 | 5 |
8,021 | def get_sphinx_autodoc ( self , depth = None , exclude = None , width = 72 , error = False , raised = False , no_comment = False , ) : # This code is cog-specific: cog code file name is the module # file name, a plus (+), and then the line number where the # cog function is frame = sys . _getframe ( 1 ) index = frame .... | r Return exception list in reStructuredText _ auto - determining callable name . | 316 | 17 |
8,022 | def resize ( self , size ) : if size < len ( self ) : raise ValueError ( "Value is out of bound. Array can't be shrinked" ) current_size = self . __size for i in range ( size - current_size ) : self . __array . append ( WBinArray ( 0 , self . __class__ . byte_size ) ) self . __size = size | Grow this array to specified length . This array can t be shrinked | 85 | 15 |
8,023 | def swipe ( self ) : result = WFixedSizeByteArray ( len ( self ) ) for i in range ( len ( self ) ) : result [ len ( self ) - i - 1 ] = self [ i ] return result | Mirror current array value in reverse . Bytes that had greater index will have lesser index and vice - versa . This method doesn t change this array . It creates a new one and return it as a result . | 48 | 43 |
8,024 | def mime_type ( filename ) : # TODO: write lock-free mime_type function try : __mime_lock . acquire ( ) extension = filename . split ( "." ) extension = extension [ len ( extension ) - 1 ] if extension == "woff2" : return "application/font-woff2" if extension == "css" : return "text/css" m = magic . from_file ( filenam... | Guess mime type for the given file name | 182 | 10 |
8,025 | def _validate_type ( self , item , name ) : if item is None : # don't validate None items, since they'll be caught by the portion # of the validator responsible for handling `required`ness return if not isinstance ( item , self . allowed_types ) : item_class_name = item . __class__ . __name__ raise ArgumentError ( name... | Validate the item against allowed_types . | 112 | 9 |
8,026 | def _validate_required ( self , item , name ) : if self . required is True and item is None : raise ArgumentError ( name , "This argument is required." ) | Validate that the item is present if it s required . | 38 | 12 |
8,027 | def doc_dict ( self ) : doc = { 'type' : self . __class__ . __name__ , 'description' : self . description , 'default' : self . default , 'required' : self . required } if hasattr ( self , 'details' ) : doc [ 'detailed_description' ] = self . details return doc | Returns the documentation dictionary for this argument . | 75 | 8 |
8,028 | def validate_items ( self , input_list ) : output_list = [ ] for item in input_list : valid = self . list_item_type . validate ( item , self . item_name ) output_list . append ( valid ) # this might lead to confusing error messages. tbh, we need to # figure out a better way to do validation and error handling here, # b... | Validates that items in the list are of the type specified . | 103 | 13 |
8,029 | def startserver ( self , hostname = "localhost" , port = 8080 , daemon = False , handle_sigint = True ) : if daemon : print ( "Sorry daemon server not supported just yet." ) # TODO start as daemon similar to bitcoind else : print ( "Starting %s json-rpc service at http://%s:%s" % ( self . __class__ . __name__ , hostnam... | Start json - rpc service . | 198 | 7 |
8,030 | def _get_asym_hel ( self , d ) : # get data 1+ 2+ 1- 2- d0 = d [ 0 ] d1 = d [ 2 ] d2 = d [ 1 ] d3 = d [ 3 ] # pre-calcs denom1 = d0 + d1 denom2 = d2 + d3 # check for div by zero denom1 [ denom1 == 0 ] = np . nan denom2 [ denom2 == 0 ] = np . nan # asymmetries in both helicities asym_hel = [ ( d0 - d1 ) / denom1 , ( d2 ... | Find the asymmetry of each helicity . | 425 | 9 |
8,031 | def _get_asym_comb ( self , d ) : # get data d0 = d [ 0 ] d1 = d [ 2 ] d2 = d [ 1 ] d3 = d [ 3 ] # pre-calcs r_denom = d0 * d3 r_denom [ r_denom == 0 ] = np . nan r = np . sqrt ( ( d1 * d2 / r_denom ) ) r [ r == - 1 ] = np . nan # combined asymmetry asym_comb = ( r - 1 ) / ( r + 1 ) # check for div by zero d0 [ d0 == 0... | Find the combined asymmetry for slr runs . Elegant 4 - counter method . | 291 | 18 |
8,032 | def _get_1f_sum_scans ( self , d , freq ) : # combine scans: values with same frequency unique_freq = np . unique ( freq ) sum_scans = [ [ ] for i in range ( len ( d ) ) ] for f in unique_freq : tag = freq == f for i in range ( len ( d ) ) : sum_scans [ i ] . append ( np . sum ( d [ i ] [ tag ] ) ) return ( np . array ... | Sum counts in each frequency bin over 1f scans . | 129 | 11 |
8,033 | def get_pulse_s ( self ) : try : dwelltime = self . ppg . dwelltime . mean beam_on = self . ppg . beam_on . mean except AttributeError : raise AttributeError ( "Missing logged ppg parameter: dwelltime " + "or beam_on" ) return dwelltime * beam_on / 1000. | Get pulse duration in seconds for pulsed measurements . | 77 | 10 |
8,034 | def extract_endpoints ( api_module ) : if not hasattr ( api_module , 'endpoints' ) : raise ValueError ( ( "pale.extract_endpoints expected the passed in " "api_module to have an `endpoints` attribute, but it didn't!" ) ) endpoints = api_module . endpoints if isinstance ( endpoints , types . ModuleType ) : classes = [ v... | Return the endpoints from an API implementation module . | 287 | 10 |
8,035 | def extract_resources ( api_module ) : endpoints = extract_endpoints ( api_module ) resource_classes = [ e . _returns . __class__ for e in endpoints ] return list ( set ( resource_classes ) ) | Return the resources from an API implementation module . | 52 | 9 |
8,036 | def load_template_source ( self , template_name , template_dirs = None ) : #Get every app's folder log . error ( "Calling zip loader" ) for folder in app_template_dirs : if ".zip/" in folder . replace ( "\\" , "/" ) : lib_file , relative_folder = get_zip_file_and_relative_path ( folder ) log . error ( lib_file , relati... | Template loader that loads templates from zipped modules . | 279 | 10 |
8,037 | def fetch ( self , start = None , stop = None ) : # Set defaults if no explicit indices were provided. if not start : start = 0 if not stop : stop = len ( self . log ) # Sanity check: indices must be valid. if start < 0 : start = 0 if stop > len ( self . log ) : stop = len ( self . log ) # Clear the fetch flag. It will... | Fetch log records and return them as a list . | 127 | 11 |
8,038 | def bind_blueprint ( pale_api_module , flask_blueprint ) : if not isinstance ( flask_blueprint , Blueprint ) : raise TypeError ( ( "pale.flask_adapter.bind_blueprint expected the " "passed in flask_blueprint to be an instance of " "Blueprint, but it was an instance of %s instead." ) % ( type ( flask_blueprint ) , ) ) i... | Binds an implemented pale API module to a Flask Blueprint . | 290 | 12 |
8,039 | def cookie_name_check ( cookie_name ) : cookie_match = WHTTPCookie . cookie_name_non_compliance_re . match ( cookie_name . encode ( 'us-ascii' ) ) return len ( cookie_name ) > 0 and cookie_match is None | Check cookie name for validity . Return True if name is valid | 64 | 12 |
8,040 | def cookie_attr_value_check ( attr_name , attr_value ) : attr_value . encode ( 'us-ascii' ) return WHTTPCookie . cookie_attr_value_compliance [ attr_name ] . match ( attr_value ) is not None | Check cookie attribute value for validity . Return True if value is valid | 66 | 13 |
8,041 | def __attr_name ( self , name ) : if name not in self . cookie_attr_value_compliance . keys ( ) : suggested_name = name . replace ( '_' , '-' ) . lower ( ) if suggested_name not in self . cookie_attr_value_compliance . keys ( ) : raise ValueError ( 'Invalid attribute name is specified' ) name = suggested_name return na... | Return suitable and valid attribute name . This method replaces dash char to underscore . If name is invalid ValueError exception is raised | 87 | 24 |
8,042 | def remove_cookie ( self , cookie_name ) : if self . __ro_flag : raise RuntimeError ( 'Read-only cookie-jar changing attempt' ) if cookie_name in self . __cookies . keys ( ) : self . __cookies . pop ( cookie_name ) | Remove cookie by its name | 62 | 5 |
8,043 | def ro ( self ) : ro_jar = WHTTPCookieJar ( ) for cookie in self . __cookies . values ( ) : ro_jar . add_cookie ( cookie . ro ( ) ) ro_jar . __ro_flag = True return ro_jar | Return read - only copy | 59 | 5 |
8,044 | def import_simple_cookie ( cls , simple_cookie ) : cookie_jar = WHTTPCookieJar ( ) for cookie_name in simple_cookie . keys ( ) : cookie_attrs = { } for attr_name in WHTTPCookie . cookie_attr_value_compliance . keys ( ) : attr_value = simple_cookie [ cookie_name ] [ attr_name ] if attr_value != '' : cookie_attrs [ attr_... | Create cookie jar from SimpleCookie object | 154 | 8 |
8,045 | def is_prime ( n ) : if n % 2 == 0 and n > 2 : return False return all ( n % i for i in range ( 3 , int ( math . sqrt ( n ) ) + 1 , 2 ) ) | Check if n is a prime number | 50 | 7 |
8,046 | def loadFile ( self , fileName ) : # Assign QFile object with the current name. self . file = QtCore . QFile ( fileName ) if self . file . exists ( ) : self . qteText . append ( open ( fileName ) . read ( ) ) else : msg = "File <b>{}</b> does not exist" . format ( self . qteAppletID ( ) ) self . qteLogger . info ( msg ... | Display the file associated with the appletID . | 103 | 10 |
8,047 | def _encode ( self ) : obj = { k : v for k , v in self . __dict__ . items ( ) if not k . startswith ( '_' ) and type ( v ) in SAFE_TYPES } obj . update ( { k : v . _encode ( ) for k , v in self . __dict__ . items ( ) if isinstance ( v , Ent ) } ) return obj | Generate a recursive JSON representation of the ent . | 93 | 10 |
8,048 | def merge ( cls , * args , * * kwargs ) : newkeys = bool ( kwargs . get ( 'newkeys' , False ) ) ignore = kwargs . get ( 'ignore' , list ( ) ) if len ( args ) < 1 : raise ValueError ( 'no ents given to Ent.merge()' ) elif not all ( isinstance ( s , Ent ) for s in args ) : raise ValueError ( 'all positional arguments to ... | Create a new Ent from one or more existing Ents . Keys in the later Ent objects will overwrite the keys of the previous Ents . Later keys of different type than in earlier Ents will be bravely ignored . | 264 | 44 |
8,049 | def diff ( cls , * args , * * kwargs ) : newkeys = bool ( kwargs . get ( 'newkeys' , False ) ) ignore = kwargs . get ( 'ignore' , list ( ) ) if len ( args ) < 2 : raise ValueError ( 'less than two ents given to Ent.diff()' ) elif not all ( isinstance ( s , Ent ) for s in args ) : raise ValueError ( 'all positional argu... | Create a new Ent representing the differences in two or more existing Ents . Keys in the later Ents with values that differ from the earlier Ents will be present in the final Ent with the latest value seen for that key . Later keys of different type than in earlier Ents will be bravely ignored . | 294 | 62 |
8,050 | def subclasses ( cls ) : seen = set ( ) queue = set ( [ cls ] ) while queue : c = queue . pop ( ) seen . add ( c ) sc = c . __subclasses__ ( ) for c in sc : if c not in seen : queue . add ( c ) seen . remove ( cls ) return seen | Return a set of all Ent subclasses recursively . | 74 | 12 |
8,051 | def base_url ( self ) : if self . location in self . known_locations : return self . known_locations [ self . location ] elif '.' in self . location or self . location == 'localhost' : return 'https://' + self . location else : return 'https://' + self . location + API_HOST_SUFFIX | Protocol + hostname | 78 | 5 |
8,052 | def _build_exclusion_list ( exclude ) : mod_files = [ ] if exclude : for mod in exclude : mdir = None mod_file = None for token in mod . split ( "." ) : try : mfile , mdir , _ = imp . find_module ( token , mdir and [ mdir ] ) if mfile : mod_file = mfile . name mfile . close ( ) except ImportError : msg = "Source for mo... | Build file names list of modules to exclude from exception handling . | 156 | 12 |
8,053 | def _invalid_frame ( fobj ) : fin = fobj . f_code . co_filename invalid_module = any ( [ fin . endswith ( item ) for item in _INVALID_MODULES_LIST ] ) return invalid_module or ( not os . path . isfile ( fin ) ) | Select valid stack frame to process . | 70 | 7 |
8,054 | def _sorted_keys_items ( dobj ) : keys = sorted ( dobj . keys ( ) ) for key in keys : yield key , dobj [ key ] | Return dictionary items sorted by key . | 37 | 7 |
8,055 | def addex ( extype , exmsg , condition = None , edata = None ) : return _ExObj ( extype , exmsg , condition , edata ) . craise | r Add an exception in the global exception handler . | 39 | 10 |
8,056 | def addai ( argname , condition = None ) : # pylint: disable=C0123 if not isinstance ( argname , str ) : raise RuntimeError ( "Argument `argname` is not valid" ) if ( condition is not None ) and ( type ( condition ) != bool ) : raise RuntimeError ( "Argument `condition` is not valid" ) obj = _ExObj ( RuntimeError , "Ar... | r Add an AI exception in the global exception handler . | 116 | 11 |
8,057 | def get_or_create_exh_obj ( full_cname = False , exclude = None , callables_fname = None ) : if not hasattr ( __builtin__ , "_EXH" ) : set_exh_obj ( ExHandle ( full_cname = full_cname , exclude = exclude , callables_fname = callables_fname ) ) return get_exh_obj ( ) | r Return global exception handler if set otherwise create a new one and return it . | 94 | 16 |
8,058 | def _flatten_ex_dict ( self ) : odict = { } for _ , fdict in self . _ex_dict . items ( ) : for ( extype , exmsg ) , value in fdict . items ( ) : key = value [ "name" ] odict [ key ] = copy . deepcopy ( value ) del odict [ key ] [ "name" ] odict [ key ] [ "type" ] = extype odict [ key ] [ "msg" ] = exmsg return odict | Flatten structure of exceptions dictionary . | 113 | 7 |
8,059 | def _format_msg ( self , msg , edata ) : edata = edata if isinstance ( edata , list ) else [ edata ] for fdict in edata : if "*[{token}]*" . format ( token = fdict [ "field" ] ) not in msg : raise RuntimeError ( "Field {token} not in exception message" . format ( token = fdict [ "field" ] ) ) msg = msg . replace ( "*[{... | Substitute parameters in exception message . | 143 | 8 |
8,060 | def _get_exceptions_db ( self ) : template = "{extype} ({exmsg}){raised}" if not self . _full_cname : # When full callable name is not used the calling path is # irrelevant and there is no function associated with an # exception ret = [ ] for _ , fdict in self . _ex_dict . items ( ) : for key in fdict . keys ( ) : ret ... | Return a list of dictionaries suitable to be used with ptrie module . | 334 | 15 |
8,061 | def _get_ex_data ( self ) : func_id , func_name = self . _get_callable_path ( ) if self . _full_cname : func_name = self . encode_call ( func_name ) return func_id , func_name | Return hierarchical function name . | 61 | 5 |
8,062 | def _property_search ( self , fobj ) : # Get class object scontext = fobj . f_locals . get ( "self" , None ) class_obj = scontext . __class__ if scontext is not None else None if not class_obj : del fobj , scontext , class_obj return None # Get class properties objects class_props = [ ( member_name , member_obj ) for m... | Return full name if object is a class property otherwise return None . | 647 | 13 |
8,063 | def _raise_exception ( self , eobj , edata = None ) : _ , _ , tbobj = sys . exc_info ( ) if edata : emsg = self . _format_msg ( eobj [ "msg" ] , edata ) _rwtb ( eobj [ "type" ] , emsg , tbobj ) else : _rwtb ( eobj [ "type" ] , eobj [ "msg" ] , tbobj ) | Raise exception by name . | 105 | 6 |
8,064 | def _unwrap_obj ( self , fobj , fun ) : try : prev_func_obj , next_func_obj = ( fobj . f_globals [ fun ] , getattr ( fobj . f_globals [ fun ] , "__wrapped__" , None ) , ) while next_func_obj : prev_func_obj , next_func_obj = ( next_func_obj , getattr ( next_func_obj , "__wrapped__" , None ) , ) return ( prev_func_obj ,... | Unwrap decorators . | 220 | 5 |
8,065 | def _validate_edata ( self , edata ) : # pylint: disable=R0916 if edata is None : return True if not ( isinstance ( edata , dict ) or _isiterable ( edata ) ) : return False edata = [ edata ] if isinstance ( edata , dict ) else edata for edict in edata : if ( not isinstance ( edict , dict ) ) or ( isinstance ( edict , d... | Validate edata argument of raise_exception_if method . | 158 | 14 |
8,066 | def add_exception ( self , exname , extype , exmsg ) : if not isinstance ( exname , str ) : raise RuntimeError ( "Argument `exname` is not valid" ) number = True try : int ( exname ) except ValueError : number = False if number : raise RuntimeError ( "Argument `exname` is not valid" ) if not isinstance ( exmsg , str ) ... | r Add an exception to the handler . | 380 | 8 |
8,067 | def decode_call ( self , call ) : # Callable name is None when callable is part of exclude list if call is None : return None itokens = call . split ( self . _callables_separator ) odict = { } for key , value in self . _clut . items ( ) : if value in itokens : odict [ itokens [ itokens . index ( value ) ] ] = key retur... | Replace callable tokens with callable names . | 122 | 10 |
8,068 | def encode_call ( self , call ) : # Callable name is None when callable is part of exclude list if call is None : return None itokens = call . split ( self . _callables_separator ) otokens = [ ] for itoken in itokens : otoken = self . _clut . get ( itoken , None ) if not otoken : otoken = str ( len ( self . _clut ) ) s... | Replace callables with tokens to reduce object memory footprint . | 134 | 12 |
8,069 | def default ( self , obj ) : try : if isinstance ( obj , datetime . datetime ) : # do the datetime thing, or encoded = arrow . get ( obj ) . isoformat ( ) else : # try the normal encoder encoded = json . JSONEncoder . default ( self , obj ) except TypeError as e : # if that fails, check for the to_dict method, if hasat... | Default JSON encoding . | 128 | 4 |
8,070 | def _fix_up_fields ( cls ) : cls . _arguments = dict ( ) if cls . __module__ == __name__ : # skip the classes in this file return for name in set ( dir ( cls ) ) : attr = getattr ( cls , name , None ) if isinstance ( attr , BaseArgument ) : if name . startswith ( '_' ) : raise TypeError ( "Endpoint argument %s cannot b... | Add names to all of the Endpoint s Arguments . | 167 | 12 |
8,071 | def _execute ( self , request , * * kwargs ) : try : self . _create_context ( request ) self . _authenticate ( ) context = get_current_context ( ) self . _parse_args ( ) if hasattr ( self , '_before_handlers' ) and isinstance ( self . _before_handlers , ( list , tuple ) ) : for handler in self . _before_handlers : hand... | The top - level execute function for the endpoint . | 665 | 10 |
8,072 | def construct_concierge_header ( self , url ) : concierge_request_header = ( etree . Element ( etree . QName ( XHTML_NAMESPACE , "ConciergeRequestHeader" ) , nsmap = { 'sch' : XHTML_NAMESPACE } ) ) if self . session_id : session = ( etree . SubElement ( concierge_request_header , etree . QName ( XHTML_NAMESPACE , "Sess... | Constructs the Concierge Request Header lxml object to be used as the _soapheaders argument for WSDL methods . | 294 | 27 |
8,073 | def options_string_builder ( option_mapping , args ) : options_string = "" for option , flag in option_mapping . items ( ) : if option in args : options_string += str ( " %s %s" % ( flag , str ( args [ option ] ) ) ) return options_string | Return arguments for CLI invocation of kal . | 68 | 9 |
8,074 | def build_kal_scan_band_string ( kal_bin , band , args ) : option_mapping = { "gain" : "-g" , "device" : "-d" , "error" : "-e" } if not sanity . scan_band_is_valid ( band ) : err_txt = "Unsupported band designation: %" % band raise ValueError ( err_txt ) base_string = "%s -v -s %s" % ( kal_bin , band ) base_string += o... | Return string for CLI invocation of kal for band scan . | 134 | 12 |
8,075 | def build_kal_scan_channel_string ( kal_bin , channel , args ) : option_mapping = { "gain" : "-g" , "device" : "-d" , "error" : "-e" } base_string = "%s -v -c %s" % ( kal_bin , channel ) base_string += options_string_builder ( option_mapping , args ) return ( base_string ) | Return string for CLI invocation of kal for channel scan . | 97 | 12 |
8,076 | def determine_final_freq ( base , direction , modifier ) : result = 0 if direction == "+" : result = base + modifier elif direction == "-" : result = base - modifier return ( result ) | Return integer for frequency . | 45 | 5 |
8,077 | def to_eng ( num_in ) : x = decimal . Decimal ( str ( num_in ) ) eng_not = x . normalize ( ) . to_eng_string ( ) return ( eng_not ) | Return number in engineering notation . | 48 | 6 |
8,078 | def determine_device ( kal_out ) : device = "" while device == "" : for line in kal_out . splitlines ( ) : if "Using device " in line : device = str ( line . split ( ' ' , 2 ) [ - 1 ] ) if device == "" : device = None return device | Extract and return device from scan results . | 68 | 9 |
8,079 | def extract_value_from_output ( canary , split_offset , kal_out ) : retval = "" while retval == "" : for line in kal_out . splitlines ( ) : if canary in line : retval = str ( line . split ( ) [ split_offset ] ) if retval == "" : retval = None return retval | Return value parsed from output . | 80 | 6 |
8,080 | def determine_chan_detect_threshold ( kal_out ) : channel_detect_threshold = "" while channel_detect_threshold == "" : for line in kal_out . splitlines ( ) : if "channel detect threshold: " in line : channel_detect_threshold = str ( line . split ( ) [ - 1 ] ) if channel_detect_threshold == "" : print ( "Unable to parse... | Return channel detect threshold from kal output . | 119 | 9 |
8,081 | def determine_band_channel ( kal_out ) : band = "" channel = "" tgt_freq = "" while band == "" : for line in kal_out . splitlines ( ) : if "Using " in line and " channel " in line : band = str ( line . split ( ) [ 1 ] ) channel = str ( line . split ( ) [ 3 ] ) tgt_freq = str ( line . split ( ) [ 4 ] ) . replace ( "(" ,... | Return band channel target frequency from kal output . | 136 | 10 |
8,082 | def parse_kal_scan ( kal_out ) : kal_data = [ ] scan_band = determine_scan_band ( kal_out ) scan_gain = determine_scan_gain ( kal_out ) scan_device = determine_device ( kal_out ) sample_rate = determine_sample_rate ( kal_out ) chan_detect_threshold = determine_chan_detect_threshold ( kal_out ) for line in kal_out . spl... | Parse kal band scan output . | 408 | 8 |
8,083 | def parse_kal_channel ( kal_out ) : scan_band , scan_channel , tgt_freq = determine_band_channel ( kal_out ) kal_data = { "device" : determine_device ( kal_out ) , "sample_rate" : determine_sample_rate ( kal_out ) , "gain" : determine_scan_gain ( kal_out ) , "band" : scan_band , "channel" : scan_channel , "frequency" :... | Parse kal channel scan output . | 186 | 8 |
8,084 | def get_measurements_from_kal_scan ( kal_out ) : result = [ ] for line in kal_out . splitlines ( ) : if "offset " in line : p_line = line . split ( ' ' ) result . append ( p_line [ - 1 ] ) return result | Return a list of all measurements from kalibrate channel scan . | 69 | 14 |
8,085 | def render ( self , obj , name , context ) : if self . value_lambda is not None : val = self . value_lambda ( obj ) else : attr_name = name if self . property_name is not None : attr_name = self . property_name if isinstance ( obj , dict ) : val = obj . get ( attr_name , None ) else : val = getattr ( obj , attr_name , ... | The default field renderer . | 148 | 6 |
8,086 | def doc_dict ( self ) : doc = { 'type' : self . value_type , 'description' : self . description , 'extended_description' : self . details } return doc | Generate the documentation for this field . | 42 | 8 |
8,087 | def capability ( self , cap_name ) : if cap_name in self . __class_capabilities__ : function_name = self . __class_capabilities__ [ cap_name ] return getattr ( self , function_name ) | Return capability by its name | 51 | 5 |
8,088 | def has_capabilities ( self , * cap_names ) : for name in cap_names : if name not in self . __class_capabilities__ : return False return True | Check if class has all of the specified capabilities | 38 | 9 |
8,089 | def add_entity_errors ( self , property_name , direct_errors = None , schema_errors = None ) : if direct_errors is None and schema_errors is None : return self # direct errors if direct_errors is not None : if property_name not in self . errors : self . errors [ property_name ] = dict ( ) if 'direct' not in self . erro... | Attach nested entity errors Accepts a list errors coming from validators attached directly or a dict of errors produced by a nested schema . | 323 | 26 |
8,090 | def add_collection_errors ( self , property_name , direct_errors = None , collection_errors = None ) : if direct_errors is None and collection_errors is None : return self # direct errors if direct_errors is not None : if type ( direct_errors ) is not list : direct_errors = [ direct_errors ] if property_name not in sel... | Add collection errors Accepts a list errors coming from validators attached directly or a list of schema results for each item in the collection . | 385 | 27 |
8,091 | def merge_errors ( self , errors_local , errors_remote ) : for prop in errors_remote : # create if doesn't exist if prop not in errors_local : errors_local [ prop ] = errors_remote [ prop ] continue local = errors_local [ prop ] local = local . errors if isinstance ( local , Result ) else local remote = errors_remote [... | Merge errors Recursively traverses error graph to merge remote errors into local errors to return a new joined graph . | 525 | 24 |
8,092 | def merge ( self , another ) : if isinstance ( another , Result ) : another = another . errors self . errors = self . merge_errors ( self . errors , another ) | Merges another validation result graph into itself | 38 | 8 |
8,093 | def get_messages ( self , locale = None ) : if locale is None : locale = self . locale if self . translator : def translate ( error ) : return self . translator . translate ( error , locale ) else : def translate ( error ) : return error errors = deepcopy ( self . errors ) errors = self . _translate_errors ( errors , t... | Get a dictionary of translated messages | 80 | 6 |
8,094 | def _translate_errors ( self , errors , translate ) : for prop in errors : prop_errors = errors [ prop ] # state and simple if type ( prop_errors ) is list : for index , error in enumerate ( prop_errors ) : message = translate ( error . message ) message = self . format_error ( message , error . kwargs ) errors [ prop ... | Recursively apply translate callback to each error message | 295 | 10 |
8,095 | def make_url ( self , path , api_root = u'/v2/' ) : return urljoin ( urljoin ( self . url , api_root ) , path ) | Gets a full URL from just path . | 39 | 9 |
8,096 | def make_key_url ( self , key ) : if type ( key ) is bytes : key = key . decode ( 'utf-8' ) buf = io . StringIO ( ) buf . write ( u'keys' ) if not key . startswith ( u'/' ) : buf . write ( u'/' ) buf . write ( key ) return self . make_url ( buf . getvalue ( ) ) | Gets a URL for a key . | 90 | 8 |
8,097 | def get ( self , key , recursive = False , sorted = False , quorum = False , wait = False , wait_index = None , timeout = None ) : url = self . make_key_url ( key ) params = self . build_args ( { 'recursive' : ( bool , recursive or None ) , 'sorted' : ( bool , sorted or None ) , 'quorum' : ( bool , quorum or None ) , '... | Requests to get a node by the given key . | 240 | 11 |
8,098 | def delete ( self , key , dir = False , recursive = False , prev_value = None , prev_index = None , timeout = None ) : url = self . make_key_url ( key ) params = self . build_args ( { 'dir' : ( bool , dir or None ) , 'recursive' : ( bool , recursive or None ) , 'prevValue' : ( six . text_type , prev_value ) , 'prevInde... | Requests to delete a node by the given key . | 147 | 11 |
8,099 | def login_to_portal ( username , password , client , retries = 2 , delay = 0 ) : if not client . session_id : client . request_session ( ) concierge_request_header = client . construct_concierge_header ( url = ( "http://membersuite.com/contracts/IConciergeAPIService/" "LoginToPortal" ) ) attempts = 0 while attempts < r... | Log username into the MemberSuite Portal . | 333 | 9 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.