idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
46,100 | def get_types_by_attr ( resource , template_id = None ) : resource_type_templates = [ ] attr_ids = [ ] for res_attr in resource . attributes : attr_ids . append ( res_attr . attr_id ) all_resource_attr_ids = set ( attr_ids ) all_types = db . DBSession . query ( TemplateType ) . options ( joinedload_all ( 'typeattrs' ) ... | Using the attributes of the resource get all the types that this resource matches . |
46,101 | def _get_attr_by_name_and_dimension ( name , dimension_id ) : attr = db . DBSession . query ( Attr ) . filter ( Attr . name == name , Attr . dimension_id == dimension_id ) . first ( ) if attr is None : attr = Attr ( ) attr . dimension_id = dimension_id attr . name = name log . debug ( "Attribute not found, creating new... | Search for an attribute with the given name and dimension_id . If such an attribute does not exist create one . |
46,102 | def get_template_as_xml ( template_id , ** kwargs ) : template_xml = etree . Element ( "template_definition" ) template_i = db . DBSession . query ( Template ) . filter ( Template . id == template_id ) . options ( joinedload ( 'templatetypes' ) . joinedload ( 'typeattrs' ) . joinedload ( 'default_dataset' ) . joinedloa... | Turn a template into an xml template |
46,103 | def import_template_json ( template_json_string , allow_update = True , ** kwargs ) : user_id = kwargs . get ( 'user_id' ) try : template_dict = json . loads ( template_json_string ) except : raise HydraError ( "Unable to parse JSON string. Plese ensure it is JSON compatible." ) return import_template_dict ( template_d... | Add the template type and typeattrs described in a JSON file . |
46,104 | def set_network_template ( template_id , network_id , ** kwargs ) : resource_types = [ ] try : network_type = db . DBSession . query ( ResourceType ) . filter ( ResourceType . ref_key == 'NETWORK' , ResourceType . network_id == network_id , ResourceType . type_id == TemplateType . type_id , TemplateType . template_id =... | Apply an existing template to a network . Used when a template has changed and additional attributes must be added to the network s elements . |
46,105 | def remove_template_from_network ( network_id , template_id , remove_attrs , ** kwargs ) : try : network = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . one ( ) except NoResultFound : raise HydraError ( "Network %s not found" % network_id ) try : template = db . DBSession . query ( Templa... | Remove all resource types in a network relating to the specified template . remove_attrs Flag to indicate whether the attributes associated with the template types should be removed from the resources in the network . These will only be removed if they are not shared with another template on the network |
46,106 | def _get_resources_to_remove ( resource , template ) : type_ids = [ tmpltype . id for tmpltype in template . templatetypes ] node_attr_ids = dict ( [ ( ra . attr_id , ra ) for ra in resource . attributes ] ) attrs_to_remove = [ ] attrs_to_keep = [ ] for nt in resource . types : if nt . templatetype . id in type_ids : f... | Given a resource and a template being removed identify the resource attribtes which can be removed . |
46,107 | def get_matching_resource_types ( resource_type , resource_id , ** kwargs ) : resource_i = None if resource_type == 'NETWORK' : resource_i = db . DBSession . query ( Network ) . filter ( Network . id == resource_id ) . one ( ) elif resource_type == 'NODE' : resource_i = db . DBSession . query ( Node ) . filter ( Node .... | Get the possible types of a resource by checking its attributes against all available types . |
46,108 | def check_type_compatibility ( type_1_id , type_2_id ) : errors = [ ] type_1 = db . DBSession . query ( TemplateType ) . filter ( TemplateType . id == type_1_id ) . options ( joinedload_all ( 'typeattrs' ) ) . one ( ) type_2 = db . DBSession . query ( TemplateType ) . filter ( TemplateType . id == type_2_id ) . options... | When applying a type to a resource it may be the case that the resource already has an attribute specified in the new type but the template which defines this pre - existing attribute has a different unit specification to the new template . |
46,109 | def assign_type_to_resource ( type_id , resource_type , resource_id , ** kwargs ) : if resource_type == 'NETWORK' : resource = db . DBSession . query ( Network ) . filter ( Network . id == resource_id ) . one ( ) elif resource_type == 'NODE' : resource = db . DBSession . query ( Node ) . filter ( Node . id == resource_... | Assign new type to a resource . This function checks if the necessary attributes are present and adds them if needed . Non existing attributes are also added when the type is already assigned . This means that this function can also be used to update resources when a resource type has changed . |
46,110 | def remove_type_from_resource ( type_id , resource_type , resource_id , ** kwargs ) : node_id = resource_id if resource_type == 'NODE' else None link_id = resource_id if resource_type == 'LINK' else None group_id = resource_id if resource_type == 'GROUP' else None resourcetype = db . DBSession . query ( ResourceType ) ... | Remove a resource type trom a resource |
46,111 | def add_template ( template , ** kwargs ) : tmpl = Template ( ) tmpl . name = template . name if template . description : tmpl . description = template . description if template . layout : tmpl . layout = get_layout_as_string ( template . layout ) db . DBSession . add ( tmpl ) if template . templatetypes is not None : ... | Add template and a type and typeattrs . |
46,112 | def update_template ( template , ** kwargs ) : tmpl = db . DBSession . query ( Template ) . filter ( Template . id == template . id ) . one ( ) tmpl . name = template . name if template . description : tmpl . description = template . description for tt in tmpl . templatetypes : for ta in tt . typeattrs : ta . attr if t... | Update template and a type and typeattrs . |
46,113 | def delete_template ( template_id , ** kwargs ) : try : tmpl = db . DBSession . query ( Template ) . filter ( Template . id == template_id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "Template %s not found" % ( template_id , ) ) db . DBSession . delete ( tmpl ) db . DBSession . flush ( ) return 'OK... | Delete a template and its type and typeattrs . |
46,114 | def get_template ( template_id , ** kwargs ) : try : tmpl_i = db . DBSession . query ( Template ) . filter ( Template . id == template_id ) . options ( joinedload_all ( 'templatetypes.typeattrs.default_dataset.metadata' ) ) . one ( ) for tmpltype_i in tmpl_i . templatetypes : for typeattr_i in tmpltype_i . typeattrs : ... | Get a specific resource template template by ID . |
46,115 | def get_template_by_name ( name , ** kwargs ) : try : tmpl_i = db . DBSession . query ( Template ) . filter ( Template . name == name ) . options ( joinedload_all ( 'templatetypes.typeattrs.default_dataset.metadata' ) ) . one ( ) return tmpl_i except NoResultFound : log . info ( "%s is not a valid identifier for a temp... | Get a specific resource template by name . |
46,116 | def add_templatetype ( templatetype , ** kwargs ) : type_i = _update_templatetype ( templatetype ) db . DBSession . flush ( ) return type_i | Add a template type with typeattrs . |
46,117 | def update_templatetype ( templatetype , ** kwargs ) : tmpltype_i = db . DBSession . query ( TemplateType ) . filter ( TemplateType . id == templatetype . id ) . one ( ) _update_templatetype ( templatetype , tmpltype_i ) db . DBSession . flush ( ) return tmpltype_i | Update a resource type and its typeattrs . New typeattrs will be added . typeattrs not sent will be ignored . To delete typeattrs call delete_typeattr |
46,118 | def _set_typeattr ( typeattr , existing_ta = None ) : if existing_ta is None : ta = TypeAttr ( attr_id = typeattr . attr_id ) else : ta = existing_ta ta . unit_id = typeattr . unit_id ta . type_id = typeattr . type_id ta . data_type = typeattr . data_type if hasattr ( typeattr , 'default_dataset_id' ) and typeattr . de... | Add or updsate a type attribute . If an existing type attribute is provided then update . |
46,119 | def _update_templatetype ( templatetype , existing_tt = None ) : if existing_tt is None : if "id" in templatetype and templatetype . id is not None : tmpltype_i = db . DBSession . query ( TemplateType ) . filter ( TemplateType . id == templatetype . id ) . one ( ) else : tmpltype_i = TemplateType ( ) else : tmpltype_i ... | Add or update a templatetype . If an existing template type is passed in update that one . Otherwise search for an existing one . If not found add . |
46,120 | def delete_templatetype ( type_id , template_i = None , ** kwargs ) : try : tmpltype_i = db . DBSession . query ( TemplateType ) . filter ( TemplateType . id == type_id ) . one ( ) except NoResultFound : raise ResourceNotFoundError ( "Template Type %s not found" % ( type_id , ) ) if template_i is None : template_i = db... | Delete a template type and its typeattrs . |
46,121 | def get_templatetype ( type_id , ** kwargs ) : templatetype = db . DBSession . query ( TemplateType ) . filter ( TemplateType . id == type_id ) . options ( joinedload_all ( "typeattrs" ) ) . one ( ) return templatetype | Get a specific resource type by ID . |
46,122 | def get_templatetype_by_name ( template_id , type_name , ** kwargs ) : try : templatetype = db . DBSession . query ( TemplateType ) . filter ( TemplateType . id == template_id , TemplateType . name == type_name ) . one ( ) except NoResultFound : raise HydraError ( "%s is not a valid identifier for a type" % ( type_name... | Get a specific resource type by name . |
46,123 | def add_typeattr ( typeattr , ** kwargs ) : tmpltype = get_templatetype ( typeattr . type_id , user_id = kwargs . get ( 'user_id' ) ) ta = _set_typeattr ( typeattr ) tmpltype . typeattrs . append ( ta ) db . DBSession . flush ( ) return ta | Add an typeattr to an existing type . |
46,124 | def delete_typeattr ( typeattr , ** kwargs ) : tmpltype = get_templatetype ( typeattr . type_id , user_id = kwargs . get ( 'user_id' ) ) ta = db . DBSession . query ( TypeAttr ) . filter ( TypeAttr . type_id == typeattr . type_id , TypeAttr . attr_id == typeattr . attr_id ) . one ( ) tmpltype . typeattrs . remove ( ta ... | Remove an typeattr from an existing type |
46,125 | def validate_attr ( resource_attr_id , scenario_id , template_id = None ) : rs = db . DBSession . query ( ResourceScenario ) . filter ( ResourceScenario . resource_attr_id == resource_attr_id , ResourceScenario . scenario_id == scenario_id ) . options ( joinedload_all ( "resourceattr" ) ) . options ( joinedload_all ( "... | Check that a resource attribute satisfies the requirements of all the types of the resource . |
46,126 | def validate_attrs ( resource_attr_ids , scenario_id , template_id = None ) : multi_rs = db . DBSession . query ( ResourceScenario ) . filter ( ResourceScenario . resource_attr_id . in_ ( resource_attr_ids ) , ResourceScenario . scenario_id == scenario_id ) . options ( joinedload_all ( "resourceattr" ) ) . options ( jo... | Check that multiple resource attribute satisfy the requirements of the types of resources to which the they are attached . |
46,127 | def validate_network ( network_id , template_id , scenario_id = None ) : network = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . options ( noload ( 'scenarios' ) ) . first ( ) if network is None : raise HydraError ( "Could not find network %s" % ( network_id ) ) resource_scenario_dict = {... | Given a network scenario and template ensure that all the nodes links & groups in the network have the correct resource attributes as defined by the types in the template . Also ensure valid entries in tresourcetype . This validation will not fail if a resource has more than the required type but will fail if it has fe... |
46,128 | def _make_attr_element_from_typeattr ( parent , type_attr_i ) : attr = _make_attr_element ( parent , type_attr_i . attr ) if type_attr_i . unit_id is not None : attr_unit = etree . SubElement ( attr , 'unit' ) attr_unit . text = units . get_unit ( type_attr_i . unit_id ) . abbreviation attr_is_var = etree . SubElement ... | General function to add an attribute element to a resource element . resource_attr_i can also e a type_attr if being called from get_tempalte_as_xml |
46,129 | def _make_attr_element_from_resourceattr ( parent , resource_attr_i ) : attr = _make_attr_element ( parent , resource_attr_i . attr ) attr_is_var = etree . SubElement ( attr , 'is_var' ) attr_is_var . text = resource_attr_i . attr_is_var return attr | General function to add an attribute element to a resource element . |
46,130 | def _make_attr_element ( parent , attr_i ) : attr = etree . SubElement ( parent , "attribute" ) attr_name = etree . SubElement ( attr , 'name' ) attr_name . text = attr_i . name attr_desc = etree . SubElement ( attr , 'description' ) attr_desc . text = attr_i . description attr_dimension = etree . SubElement ( attr , '... | create an attribute element from an attribute DB object |
46,131 | def valueFromDataset ( cls , datatype , value , metadata = None , tmap = None ) : if tmap is None : tmap = typemap obj = cls . fromDataset ( datatype , value , metadata = metadata , tmap = tmap ) return obj . value | Return the value contained by dataset argument after casting to correct type and performing type - specific validation |
46,132 | def fromDataset ( datatype , value , metadata = None , tmap = None ) : if tmap is None : tmap = typemap return tmap [ datatype . upper ( ) ] . fromDataset ( value , metadata = metadata ) | Return a representation of dataset argument as an instance |
46,133 | def exists_dimension ( dimension_name , ** kwargs ) : try : dimension = db . DBSession . query ( Dimension ) . filter ( Dimension . name == dimension_name ) . one ( ) return True except NoResultFound : raise False | Given a dimension returns True if it exists False otherwise |
46,134 | def convert_units ( values , source_measure_or_unit_abbreviation , target_measure_or_unit_abbreviation , ** kwargs ) : if numpy . isscalar ( values ) : values = [ values ] float_values = [ float ( value ) for value in values ] values_to_return = convert ( float_values , source_measure_or_unit_abbreviation , target_meas... | Convert a value from one unit to another one . |
46,135 | def convert ( values , source_measure_or_unit_abbreviation , target_measure_or_unit_abbreviation ) : source_dimension = get_dimension_by_unit_measure_or_abbreviation ( source_measure_or_unit_abbreviation ) target_dimension = get_dimension_by_unit_measure_or_abbreviation ( target_measure_or_unit_abbreviation ) if source... | Convert a value or a list of values from an unit to another one . The two units must represent the same physical dimension . |
46,136 | def get_empty_dimension ( ** kwargs ) : dimension = JSONObject ( Dimension ( ) ) dimension . id = None dimension . name = '' dimension . description = '' dimension . project_id = None dimension . units = [ ] return dimension | Returns a dimension object initialized with empty values |
46,137 | def get_dimension ( dimension_id , do_accept_dimension_id_none = False , ** kwargs ) : if do_accept_dimension_id_none == True and dimension_id is None : return get_empty_dimension ( ) try : dimension = db . DBSession . query ( Dimension ) . filter ( Dimension . id == dimension_id ) . one ( ) dimension . units return JS... | Given a dimension id returns all its data |
46,138 | def get_dimensions ( ** kwargs ) : dimensions_list = db . DBSession . query ( Dimension ) . options ( load_only ( "id" ) ) . all ( ) return_list = [ ] for dimension in dimensions_list : return_list . append ( get_dimension ( dimension . id ) ) return return_list | Returns a list of objects describing all the dimensions with all the units . |
46,139 | def get_dimension_by_name ( dimension_name , ** kwargs ) : try : if dimension_name is None : dimension_name = '' dimension = db . DBSession . query ( Dimension ) . filter ( func . lower ( Dimension . name ) == func . lower ( dimension_name . strip ( ) ) ) . one ( ) return get_dimension ( dimension . id ) except NoResul... | Given a dimension name returns all its data . Used in convert functions |
46,140 | def get_unit ( unit_id , ** kwargs ) : try : unit = db . DBSession . query ( Unit ) . filter ( Unit . id == unit_id ) . one ( ) return JSONObject ( unit ) except NoResultFound : raise ResourceNotFoundError ( "Unit %s not found" % ( unit_id ) ) | Returns a single unit |
46,141 | def get_units ( ** kwargs ) : units_list = db . DBSession . query ( Unit ) . all ( ) units = [ ] for unit in units_list : new_unit = JSONObject ( unit ) units . append ( new_unit ) return units | Returns all the units |
46,142 | def get_dimension_by_unit_measure_or_abbreviation ( measure_or_unit_abbreviation , ** kwargs ) : unit_abbreviation , factor = _parse_unit ( measure_or_unit_abbreviation ) units = db . DBSession . query ( Unit ) . filter ( Unit . abbreviation == unit_abbreviation ) . all ( ) if len ( units ) == 0 : raise HydraError ( 'U... | Return the physical dimension a given unit abbreviation of a measure or the measure itself refers to . The search key is the abbreviation or the full measure |
46,143 | def get_unit_by_abbreviation ( unit_abbreviation , ** kwargs ) : try : if unit_abbreviation is None : unit_abbreviation = '' unit_i = db . DBSession . query ( Unit ) . filter ( Unit . abbreviation == unit_abbreviation . strip ( ) ) . one ( ) return JSONObject ( unit_i ) except NoResultFound : raise ResourceNotFoundErro... | Returns a single unit by abbreviation . Used as utility function to resolve string to id |
46,144 | def update_dimension ( dimension , ** kwargs ) : db_dimension = None dimension = JSONObject ( dimension ) try : db_dimension = db . DBSession . query ( Dimension ) . filter ( Dimension . id == dimension . id ) . filter ( ) . one ( ) if "description" in dimension and dimension [ "description" ] is not None : db_dimensio... | Update a dimension in the DB . Raises and exception if the dimension does not exist . The key is ALWAYS the name and the name itself is not modificable |
46,145 | def delete_dimension ( dimension_id , ** kwargs ) : try : dimension = db . DBSession . query ( Dimension ) . filter ( Dimension . id == dimension_id ) . one ( ) db . DBSession . query ( Unit ) . filter ( Unit . dimension_id == dimension . id ) . delete ( ) db . DBSession . delete ( dimension ) db . DBSession . flush ( ... | Delete a dimension from the DB . Raises and exception if the dimension does not exist |
46,146 | def bulk_add_dimensions ( dimension_list , ** kwargs ) : added_dimensions = [ ] for dimension in dimension_list : added_dimensions . append ( add_dimension ( dimension , ** kwargs ) ) return JSONObject ( { "dimensions" : added_dimensions } ) | Save all the dimensions contained in the passed list . |
46,147 | def bulk_add_units ( unit_list , ** kwargs ) : added_units = [ ] for unit in unit_list : added_units . append ( add_unit ( unit , ** kwargs ) ) return JSONObject ( { "units" : added_units } ) | Save all the units contained in the passed list with the name of their dimension . |
46,148 | def delete_unit ( unit_id , ** kwargs ) : try : db_unit = db . DBSession . query ( Unit ) . filter ( Unit . id == unit_id ) . one ( ) db . DBSession . delete ( db_unit ) db . DBSession . flush ( ) return True except NoResultFound : raise ResourceNotFoundError ( "Unit (ID=%s) does not exist" % ( unit_id ) ) | Delete a unit from the DB . Raises and exception if the unit does not exist |
46,149 | def update_unit ( unit , ** kwargs ) : try : db_unit = db . DBSession . query ( Unit ) . join ( Dimension ) . filter ( Unit . id == unit [ "id" ] ) . filter ( ) . one ( ) db_unit . name = unit [ "name" ] db_unit . abbreviation = unit . abbreviation db_unit . description = unit . description db_unit . lf = unit [ "lf" ]... | Update a unit in the DB . Raises and exception if the unit does not exist |
46,150 | def encode ( encoding , data ) : data = ensure_bytes ( data , 'utf8' ) try : return ENCODINGS_LOOKUP [ encoding ] . code + ENCODINGS_LOOKUP [ encoding ] . converter . encode ( data ) except KeyError : raise ValueError ( 'Encoding {} not supported.' . format ( encoding ) ) | Encodes the given data using the encoding that is specified |
46,151 | def get_codec ( data ) : try : key = ensure_bytes ( data [ : CODE_LENGTH ] , 'utf8' ) codec = ENCODINGS_LOOKUP [ key ] except KeyError : raise ValueError ( 'Can not determine encoding for {}' . format ( data ) ) else : return codec | Returns the codec used to encode the given data |
46,152 | def _get_role_arn ( ) : role_arn = bottle . request . headers . get ( 'X-Role-ARN' ) if not role_arn : role_arn = _lookup_ip_role_arn ( bottle . request . environ . get ( 'REMOTE_ADDR' ) ) if not role_arn : role_arn = _role_arn return role_arn | Return role arn from X - Role - ARN header lookup role arn from source IP or fall back to command line default . |
46,153 | def _on_dynamodb_exception ( self , error ) : if isinstance ( error , exceptions . ConditionalCheckFailedException ) : raise web . HTTPError ( 409 , reason = 'Condition Check Failure' ) elif isinstance ( error , exceptions . NoCredentialsError ) : if _no_creds_should_return_429 ( ) : raise web . HTTPError ( 429 , reaso... | Dynamically handle DynamoDB exceptions returning HTTP error responses . |
46,154 | def marshall ( values ) : serialized = { } for key in values : serialized [ key ] = _marshall_value ( values [ key ] ) return serialized | Marshall a dict into something DynamoDB likes . |
46,155 | def unmarshall ( values ) : unmarshalled = { } for key in values : unmarshalled [ key ] = _unmarshall_dict ( values [ key ] ) return unmarshalled | Transform a response payload from DynamoDB to a native dict |
46,156 | def _marshall_value ( value ) : if PYTHON3 and isinstance ( value , bytes ) : return { 'B' : base64 . b64encode ( value ) . decode ( 'ascii' ) } elif PYTHON3 and isinstance ( value , str ) : return { 'S' : value } elif not PYTHON3 and isinstance ( value , str ) : if is_binary ( value ) : return { 'B' : base64 . b64enco... | Recursively transform value into an AttributeValue dict |
46,157 | def _unmarshall_dict ( value ) : key = list ( value . keys ( ) ) . pop ( ) if key == 'B' : return base64 . b64decode ( value [ key ] . encode ( 'ascii' ) ) elif key == 'BS' : return set ( [ base64 . b64decode ( v . encode ( 'ascii' ) ) for v in value [ key ] ] ) elif key == 'BOOL' : return value [ key ] elif key == 'L'... | Unmarshall a single dict value from a row that was returned from DynamoDB returning the value as a normal Python dict . |
46,158 | def _unwrap_result ( action , result ) : if not result : return elif action in { 'DeleteItem' , 'PutItem' , 'UpdateItem' } : return _unwrap_delete_put_update_item ( result ) elif action == 'GetItem' : return _unwrap_get_item ( result ) elif action == 'Query' or action == 'Scan' : return _unwrap_query_scan ( result ) el... | Unwrap a request response and return only the response data . |
46,159 | def list_tables ( self , exclusive_start_table_name = None , limit = None ) : payload = { } if exclusive_start_table_name : payload [ 'ExclusiveStartTableName' ] = exclusive_start_table_name if limit : payload [ 'Limit' ] = limit return self . execute ( 'ListTables' , payload ) | Invoke the ListTables _ function . |
46,160 | def get_item ( self , table_name , key_dict , consistent_read = False , expression_attribute_names = None , projection_expression = None , return_consumed_capacity = None ) : payload = { 'TableName' : table_name , 'Key' : utils . marshall ( key_dict ) , 'ConsistentRead' : consistent_read } if expression_attribute_names... | Invoke the GetItem _ function . |
46,161 | def update_item ( self , table_name , key_dict , condition_expression = None , update_expression = None , expression_attribute_names = None , expression_attribute_values = None , return_consumed_capacity = None , return_item_collection_metrics = None , return_values = None ) : payload = { 'TableName' : table_name , 'Ke... | Invoke the UpdateItem _ function . |
46,162 | def query ( self , table_name , index_name = None , consistent_read = None , key_condition_expression = None , filter_expression = None , expression_attribute_names = None , expression_attribute_values = None , projection_expression = None , select = None , exclusive_start_key = None , limit = None , scan_index_forward... | A Query _ operation uses the primary key of a table or a secondary index to directly access items from that table or index . |
46,163 | def scan ( self , table_name , index_name = None , consistent_read = None , projection_expression = None , filter_expression = None , expression_attribute_names = None , expression_attribute_values = None , segment = None , total_segments = None , select = None , limit = None , exclusive_start_key = None , return_consu... | The Scan _ operation returns one or more items and item attributes by accessing every item in a table or a secondary index . |
46,164 | def execute ( self , action , parameters ) : measurements = collections . deque ( [ ] , self . _max_retries ) for attempt in range ( 1 , self . _max_retries + 1 ) : try : result = yield self . _execute ( action , parameters , attempt , measurements ) except ( exceptions . InternalServerError , exceptions . RequestExcep... | Execute a DynamoDB action with the given parameters . The method will retry requests that failed due to OS level errors or when being throttled by DynamoDB . |
46,165 | def set_error_callback ( self , callback ) : self . logger . debug ( 'Setting error callback: %r' , callback ) self . _on_error = callback | Assign a method to invoke when a request has encountered an unrecoverable error in an action execution . |
46,166 | def set_instrumentation_callback ( self , callback ) : self . logger . debug ( 'Setting instrumentation callback: %r' , callback ) self . _instrumentation_callback = callback | Assign a method to invoke when a request has completed gathering measurements . |
46,167 | def _execute ( self , action , parameters , attempt , measurements ) : future = concurrent . Future ( ) start = time . time ( ) def handle_response ( request ) : self . _on_response ( action , parameters . get ( 'TableName' , 'Unknown' ) , attempt , start , request , future , measurements ) ioloop . IOLoop . current ( ... | Invoke a DynamoDB action |
46,168 | def _on_response ( self , action , table , attempt , start , response , future , measurements ) : self . logger . debug ( '%s on %s request #%i = %r' , action , table , attempt , response ) now , exception = time . time ( ) , None try : future . set_result ( self . _process_response ( response ) ) except aws_exceptions... | Invoked when the HTTP request to the DynamoDB has returned and is responsible for setting the future result or exception based upon the HTTP response provided . |
46,169 | def _process_response ( response ) : error = response . exception ( ) if error : if isinstance ( error , aws_exceptions . AWSError ) : if error . args [ 1 ] [ 'type' ] in exceptions . MAP : raise exceptions . MAP [ error . args [ 1 ] [ 'type' ] ] ( error . args [ 1 ] [ 'message' ] ) raise error http_response = response... | Process the raw AWS response returning either the mapped exception or deserialized response . |
46,170 | def write ( self , obj , resource_id = None ) : if resource_id is not None : if self . read ( resource_id ) : raise ValueError ( "There are one object already with this id." ) obj [ '_id' ] = resource_id prepared_creation_tx = self . driver . instance . transactions . prepare ( operation = 'CREATE' , signers = self . u... | Write and obj in bdb . |
46,171 | def _get ( self , tx_id ) : value = [ { 'data' : transaction [ 'metadata' ] , 'id' : transaction [ 'id' ] } for transaction in self . driver . instance . transactions . get ( asset_id = self . get_asset_id ( tx_id ) ) ] [ - 1 ] if value [ 'data' ] [ 'data' ] : self . logger . debug ( 'bdb::read::{}' . format ( value [ ... | Read and obj in bdb using the tx_id . |
46,172 | def _update ( self , metadata , tx_id , resource_id ) : try : if not tx_id : sent_tx = self . write ( metadata , resource_id ) self . logger . debug ( 'bdb::put::{}' . format ( sent_tx [ 'id' ] ) ) return sent_tx else : txs = self . driver . instance . transactions . get ( asset_id = self . get_asset_id ( tx_id ) ) uns... | Update and obj in bdb using the tx_id . |
46,173 | def query ( self , search_model : QueryModel ) : self . logger . debug ( 'bdb::get::{}' . format ( search_model . query ) ) assets = json . loads ( requests . post ( "http://localhost:4000/query" , data = search_model . query ) . content ) [ 'data' ] self . logger . debug ( 'bdb::result::len {}' . format ( len ( assets... | Query to bdb namespace . |
46,174 | def get_asset_id ( self , tx_id ) : tx = self . driver . instance . transactions . retrieve ( txid = tx_id ) assert tx is not None return tx [ 'id' ] if tx [ 'operation' ] == 'CREATE' else tx [ 'asset' ] [ 'id' ] | Return the tx_id of the first transaction . |
46,175 | def hdr ( data , filename ) : hdrobj = data if isinstance ( data , HDRobject ) else HDRobject ( data ) hdrobj . write ( filename ) | write ENVI header files |
46,176 | def write ( self , filename = 'same' ) : if filename == 'same' : filename = self . filename if not filename . endswith ( '.hdr' ) : filename += '.hdr' with open ( filename , 'w' ) as out : out . write ( self . __str__ ( ) ) | write object to an ENVI header file |
46,177 | def GoZero ( self , speed ) : ' Go to Zero position ' self . ReleaseSW ( ) spi . SPI_write_byte ( self . CS , 0x82 | ( self . Dir & 1 ) ) spi . SPI_write_byte ( self . CS , 0x00 ) spi . SPI_write_byte ( self . CS , speed ) while self . IsBusy ( ) : pass time . sleep ( 0.3 ) self . ReleaseSW ( ) | Go to Zero position |
46,178 | def ReadStatusBit ( self , bit ) : ' Report given status bit ' spi . SPI_write_byte ( self . CS , 0x39 ) spi . SPI_write_byte ( self . CS , 0x00 ) data0 = spi . SPI_read_byte ( ) spi . SPI_write_byte ( self . CS , 0x00 ) data1 = spi . SPI_read_byte ( ) if bit > 7 : OutputBit = ( data0 >> ( bit - 8 ) ) & 1 else : Output... | Report given status bit |
46,179 | def SPI_write_byte ( self , chip_select , data ) : 'Writes a data to a SPI device selected by chipselect bit. ' self . bus . write_byte_data ( self . address , chip_select , data ) | Writes a data to a SPI device selected by chipselect bit . |
46,180 | def SPI_write ( self , chip_select , data ) : 'Writes data to SPI device selected by chipselect bit. ' dat = list ( data ) dat . insert ( 0 , chip_select ) return self . bus . write_i2c_block ( self . address , dat ) | Writes data to SPI device selected by chipselect bit . |
46,181 | def SPI_config ( self , config ) : 'Configure SPI interface parameters.' self . bus . write_byte_data ( self . address , 0xF0 , config ) return self . bus . read_byte_data ( self . address , 0xF0 ) | Configure SPI interface parameters . |
46,182 | def GPIO_read ( self ) : 'Reads logic state on GPIO enabled slave-selects pins.' self . bus . write_byte_data ( self . address , 0xF5 , 0x0f ) status = self . bus . read_byte ( self . address ) bits_values = dict ( [ ( 'SS0' , status & 0x01 == 0x01 ) , ( 'SS1' , status & 0x02 == 0x02 ) , ( 'SS2' , status & 0x04 == 0x04... | Reads logic state on GPIO enabled slave - selects pins . |
46,183 | def GPIO_config ( self , gpio_enable , gpio_config ) : 'Enable or disable slave-select pins as gpio.' self . bus . write_byte_data ( self . address , 0xF6 , gpio_enable ) self . bus . write_byte_data ( self . address , 0xF7 , gpio_config ) return | Enable or disable slave - select pins as gpio . |
46,184 | def get_address ( self ) : LOGGER . debug ( "Reading RPS01A sensor's address." , ) return self . bus . read_byte_data ( self . address , self . address_reg ) | Returns sensors I2C address . |
46,185 | def get_zero_position ( self ) : LSB = self . bus . read_byte_data ( self . address , self . zero_position_MSB ) MSB = self . bus . read_byte_data ( self . address , self . zero_position_LSB ) DATA = ( MSB << 6 ) + LSB return DATA | Returns programmed zero position in OTP memory . |
46,186 | def get_agc_value ( self ) : LOGGER . debug ( "Reading RPS01A sensor's AGC settings" , ) return self . bus . read_byte_data ( self . address , self . AGC_reg ) | Returns sensor s Automatic Gain Control actual value . 0 - Represents high magtetic field 0xFF - Represents low magnetic field |
46,187 | def get_angle ( self , verify = False ) : LSB = self . bus . read_byte_data ( self . address , self . angle_LSB ) MSB = self . bus . read_byte_data ( self . address , self . angle_MSB ) DATA = ( MSB << 6 ) + LSB if not verify : return ( 360.0 / 2 ** 14 ) * DATA else : status = self . get_diagnostics ( ) if not ( status... | Retuns measured angle in degrees in range 0 - 360 . |
46,188 | def main ( input_bed , output_file , output_features = False , genome = None , only_canonical = False , short = False , extended = False , high_confidence = False , ambiguities_method = False , coding_only = False , collapse_exons = False , work_dir = False , is_debug = False ) : logger . init ( is_debug_ = is_debug ) ... | Annotating BED file based on reference features annotations . |
46,189 | def StateOfCharge ( self ) : return ( self . bus . read_byte_data ( self . address , 0x02 ) + self . bus . read_byte_data ( self . address , 0x03 ) * 256 ) | % of Full Charge |
46,190 | def Chemistry ( self ) : length = self . bus . read_byte_data ( self . address , 0x79 ) chem = [ ] for n in range ( length ) : chem . append ( self . bus . read_byte_data ( self . address , 0x7A + n ) ) return chem | Get cells chemistry |
46,191 | def single_read ( self , register ) : comm_reg = ( 0b00010 << 3 ) + register if register == self . AD7730_STATUS_REG : bytes_num = 1 elif register == self . AD7730_DATA_REG : bytes_num = 3 elif register == self . AD7730_MODE_REG : bytes_num = 2 elif register == self . AD7730_FILTER_REG : bytes_num = 3 elif register == ... | Reads data from desired register only once . |
46,192 | def getStatus ( self ) : status = self . single_read ( self . AD7730_STATUS_REG ) bits_values = dict ( [ ( 'NOREF' , status [ 0 ] & 0x10 == 0x10 ) , ( 'STBY' , status [ 0 ] & 0x20 == 0x20 ) , ( 'STDY' , status [ 0 ] & 0x40 == 0x40 ) , ( 'RDY' , status [ 0 ] & 0x80 == 0x80 ) ] ) return bits_values | RDY - Ready Bit . This bit provides the status of the RDY flag from the part . The status and function of this bit is the same as the RDY output pin . A number of events set the RDY bit high as indicated in Table XVIII in datasheet |
46,193 | def _calculate_checksum ( value ) : polynomial = 0x131 crc = 0xFF for byteCtr in [ ord ( x ) for x in struct . pack ( ">H" , value ) ] : crc ^= byteCtr for bit in range ( 8 , 0 , - 1 ) : if crc & 0x80 : crc = ( crc << 1 ) ^ polynomial else : crc = ( crc << 1 ) return crc | 4 . 12 Checksum Calculation from an unsigned short input |
46,194 | def run ( self ) : inside = 0 for draws in range ( 1 , self . data [ 'samples' ] ) : r1 , r2 = ( random ( ) , random ( ) ) if r1 ** 2 + r2 ** 2 < 1.0 : inside += 1 if draws % 1000 != 0 : continue yield self . emit ( 'log' , { 'draws' : draws , 'inside' : inside } ) p = inside / draws pi = { 'estimate' : 4.0 * inside / ... | Run when button is pressed . |
46,195 | def init_datastores ( self ) : self . data = Datastore ( self . id_ ) self . data . subscribe ( lambda data : self . emit ( 'data' , data ) ) self . class_data = Datastore ( type ( self ) . __name__ ) self . class_data . subscribe ( lambda data : self . emit ( 'class_data' , data ) ) | Initialize datastores for this analysis instance . |
46,196 | def emit ( self , signal , message = '__nomessagetoken__' ) : if signal == 'log' : self . log_backend . info ( message ) elif signal == 'warn' : self . log_backend . warn ( message ) elif signal == 'error' : self . log_backend . error ( message ) return self . emit_to_frontend ( signal , message ) | Emit a signal to the frontend . |
46,197 | def set ( self , i , value ) : value_encoded = encode ( value , self . get_change_trigger ( i ) ) if i in self . data and self . data [ i ] == value_encoded : return self self . data [ i ] = value_encoded return self . trigger_changed ( i ) | Set value at position i and return a Future . |
46,198 | def set ( self , key , value ) : return DatastoreLegacy . store [ self . domain ] . set ( key , value ) | Set value at key and return a Future |
46,199 | def watch ( ) : sphinx_build [ '-b' , 'html' , '-E' , 'docs' , 'docs/_build/html' ] & FG handler = ShellCommandTrick ( shell_command = 'sphinx-build -b html docs docs/_build/html' , patterns = [ '*.rst' , '*.py' ] , ignore_patterns = [ '_build/*' ] , ignore_directories = [ '.tox' ] , drop_during_process = True ) observ... | Renerate documentation when it changes . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.