code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
tenant_name = fw_dict.get('tenant_name') try: net, subnet = self._create_os_nwk(tenant_id, tenant_name, "in", is_fw_virt=is_fw_virt) if net is None or subnet is None: return False except Exception as e...
def create_os_in_nwk(self, tenant_id, fw_dict, is_fw_virt=False)
Create the Openstack IN network and stores the values in DB.
4.178375
4.012586
1.041317
serv_obj = self.get_service_obj(tenant_id) fw_dict = serv_obj.get_fw_dict() fw_id = fw_dict.get('fw_id') fw_data, fw_data_dict = self.get_fw(fw_id) if fw_data is None: LOG.error("Unable to get fw_data for tenant %s", tenant_name) return False ...
def _delete_os_nwk(self, tenant_id, tenant_name, direc, is_fw_virt=False)
Delete the network created in Openstack. Function to delete Openstack network, It also releases the associated segmentation, VLAN and subnets.
2.589296
2.45012
1.056804
ret = True tenant_name = fw_dict.get('tenant_name') try: ret = self._delete_os_nwk(tenant_id, tenant_name, "in", is_fw_virt=is_fw_virt) except Exception as exc: LOG.error("Deletion of In Openstack Network failed tenan...
def delete_os_in_nwk(self, tenant_id, fw_dict, is_fw_virt=False)
Deletes the Openstack In network and update the DB.
3.283157
2.95812
1.109879
ret = True tenant_name = fw_dict.get('tenant_name') try: ret = self._delete_os_nwk(tenant_id, tenant_name, "out", is_fw_virt=is_fw_virt) except Exception as exc: LOG.error("Deletion of Out Openstack Network failed ten...
def delete_os_out_nwk(self, tenant_id, fw_dict, is_fw_virt=False)
Deletes the Openstack Out network and update the DB.
3.193747
2.924394
1.092106
res = fw_const.OS_DUMMY_RTR_CREATE_SUCCESS tenant_name = fw_dict.get('tenant_name') try: rtr_id = fw_dict.get('router_id') if rtr_id is None: LOG.error("Invalid router id, attaching dummy interface" " failed") ...
def create_os_dummy_rtr(self, tenant_id, fw_dict, is_fw_virt=False)
Create the dummy interface and attach it to router. Attach the dummy interface to the Openstack router and store the info in DB.
3.107093
2.970562
1.045961
ret = True tenant_name = fw_dict.get('tenant_name') try: rtr_id = fw_dict.get('router_id') if not rtr_id: LOG.error("Invalid router id, deleting dummy interface" " failed") return False if not ...
def delete_os_dummy_rtr(self, tenant_id, fw_dict, is_fw_virt=False)
Delete the Openstack Dummy router and store the info in DB.
3.501328
3.409636
1.026892
tenant_name = fw_dict.get('tenant_name') ret = self._create_service_nwk(tenant_id, tenant_name, 'in') if ret: res = fw_const.DCNM_IN_NETWORK_CREATE_SUCCESS LOG.info("In Service network created for tenant %s", tenant_id) else: ...
def create_dcnm_in_nwk(self, tenant_id, fw_dict, is_fw_virt=False)
Create the DCNM In Network and store the result in DB.
2.94957
2.77434
1.063161
tenant_name = fw_dict.get('tenant_name') ret = self._delete_service_nwk(tenant_id, tenant_name, 'in') if ret: res = fw_const.DCNM_IN_NETWORK_DEL_SUCCESS LOG.info("In Service network deleted for tenant %s", tenant_id) else: ...
def delete_dcnm_in_nwk(self, tenant_id, fw_dict, is_fw_virt=False)
Delete the DCNM In Network and store the result in DB.
2.997145
2.813485
1.065278
res = fw_const.DCNM_IN_PART_UPDATE_SUCCESS tenant_name = fw_dict.get('tenant_name') ret = True try: self._update_partition_in_create(tenant_id, tenant_name) except Exception as exc: LOG.error("Update of In Partition failed for tenant %(tenant)s" ...
def update_dcnm_in_part(self, tenant_id, fw_dict, is_fw_virt=False)
Update DCNM's in partition information. Update the In partition service node IP address in DCNM and update the result
3.636791
3.475901
1.046287
res = fw_const.DCNM_IN_PART_UPDDEL_SUCCESS tenant_name = fw_dict.get('tenant_name') ret = True try: self._update_partition_in_delete(tenant_name) except Exception as exc: LOG.error("Clear of In Partition failed for tenant %(tenant)s" ...
def clear_dcnm_in_part(self, tenant_id, fw_dict, is_fw_virt=False)
Clear the DCNM in partition service information. Clear the In partition service node IP address in DCNM and update the result.
4.473464
4.156216
1.076331
res = fw_const.DCNM_OUT_PART_CREATE_SUCCESS tenant_name = fw_dict.get('tenant_name') ret = True try: self._create_out_partition(tenant_id, tenant_name) except Exception as exc: LOG.error("Create of Out Partition failed for tenant " ...
def create_dcnm_out_part(self, tenant_id, fw_dict, is_fw_virt=False)
Create the DCNM OUT partition and update the result.
2.849386
2.782669
1.023976
res = fw_const.DCNM_OUT_PART_DEL_SUCCESS tenant_name = fw_dict.get('tenant_name') ret = True try: self._delete_partition(tenant_id, tenant_name) except Exception as exc: LOG.error("deletion of Out Partition failed for tenant " ...
def delete_dcnm_out_part(self, tenant_id, fw_dict, is_fw_virt=False)
Delete the DCNM OUT partition and update the result.
2.937738
2.811763
1.044803
tenant_name = fw_dict.get('tenant_name') ret = self._create_service_nwk(tenant_id, tenant_name, 'out') if ret: res = fw_const.DCNM_OUT_NETWORK_CREATE_SUCCESS LOG.info("out Service network created for tenant %s", tenant_id) else: ...
def create_dcnm_out_nwk(self, tenant_id, fw_dict, is_fw_virt=False)
Create the DCNM OUT Network and update the result.
3.002852
2.799345
1.072698
tenant_name = fw_dict.get('tenant_name') ret = self._delete_service_nwk(tenant_id, tenant_name, 'out') if ret: res = fw_const.DCNM_OUT_NETWORK_DEL_SUCCESS LOG.info("out Service network deleted for tenant %s", tenant_id) else: ...
def delete_dcnm_out_nwk(self, tenant_id, fw_dict, is_fw_virt=False)
Delete the DCNM OUT network and update the result.
2.969695
2.79274
1.063362
res = fw_const.DCNM_OUT_PART_UPDATE_SUCCESS tenant_name = fw_dict.get('tenant_name') ret = True try: ret = self._update_partition_out_create(tenant_id, tenant_name) if not ret: res = fw_const.DCNM_OUT_PART_UPDATE_FAIL except Except...
def update_dcnm_out_part(self, tenant_id, fw_dict, is_fw_virt=False)
Update DCNM OUT partition service node IP address and result.
3.199207
3.061453
1.044996
res = fw_const.DCNM_OUT_PART_UPDDEL_SUCCESS self.update_fw_db_result(tenant_id, dcnm_status=res) LOG.info("Out partition cleared -noop- with service ip addr") return True
def clear_dcnm_out_part(self, tenant_id, fw_dict, is_fw_virt=False)
Clear DCNM out partition information. Clear the DCNM OUT partition service node IP address and update the result
14.740334
12.391452
1.189557
if ret: if state == fw_const.FABRIC_PREPARE_DONE_STATE: return state else: return state + 1 else: return state
def get_next_create_state(self, state, ret)
Return the next create state from previous state.
5.694981
5.238773
1.087083
if ret: if state == fw_const.INIT_STATE: return state else: return state - 1 else: return state
def get_next_del_state(self, state, ret)
Return the next delete state from previous state.
5.390104
4.685828
1.150299
if oper == fw_const.FW_CR_OP: return self.get_next_create_state(state, ret) else: return self.get_next_del_state(state, ret)
def get_next_state(self, state, ret, oper)
Returns the next state for a create or delete operation.
4.530061
2.649558
1.709742
ret = True serv_obj = self.get_service_obj(tenant_id) state = serv_obj.get_state() # Preserve the ordering of the next lines till while new_state = serv_obj.fixup_state(fw_const.FW_CR_OP, state) serv_obj.store_local_final_result(fw_const.RESULT_FW_CREATE_INIT) ...
def run_create_sm(self, tenant_id, fw_dict, is_fw_virt)
Runs the create State Machine. Goes through every state function until the end or when one state returns failure.
3.540843
3.42068
1.035128
# Read the current state from the DB ret = True serv_obj = self.get_service_obj(tenant_id) state = serv_obj.get_state() # Preserve the ordering of the next lines till while new_state = serv_obj.fixup_state(fw_const.FW_DEL_OP, state) serv_obj.store_local_f...
def run_delete_sm(self, tenant_id, fw_dict, is_fw_virt)
Runs the delete State Machine. Goes through every state function until the end or when one state returns failure.
3.930246
3.826124
1.027213
for key, val in state_dict.items(): if val == status: return key
def get_key_state(self, status, state_dict)
Returns the key associated with the dict.
3.880008
2.563239
1.513713
res_list = compl_result.split('(') state_num = None if len(res_list) > 1: state_num = int(res_list[1].split(')')[0]) else: if res_list[0] == fw_const.RESULT_FW_CREATE_INIT: if os_status is None: state_num = fw_const.INI...
def pop_fw_state(self, compl_result, os_status, dcnm_status)
Populate the state information in the cache. Check if state information is embedded in result If not: a. It's still in Init state and no SM is called yet b. The SM has completely run c. Delete has started and before any SM is run, it restarted.
2.422746
2.454076
0.987234
net = self.get_network(net_id) serv_obj = self.get_service_obj(tenant_id) serv_obj.update_fw_local_cache(net_id, direc, node_ip) if net is not None: net_dict = self.fill_dcnm_net_info(tenant_id, direc, net.vlan, net.segm...
def pop_fw_local(self, tenant_id, net_id, direc, node_ip)
Populate the local cache. Read the Network DB and populate the local cache. Read the subnet from the Subnet DB, given the net_id and populate the cache.
2.530107
2.465214
1.026323
tenant_id = fw_data.get('tenant_id') self.create_serv_obj(tenant_id) serv_obj = self.get_service_obj(tenant_id) serv_obj.create_fw_db(fw_id, fw_data.get('name'), tenant_id) self.pop_fw_local(tenant_id, fw_data.get('in_network_id'), "in", fw_data...
def populate_local_cache_tenant(self, fw_id, fw_data)
Populate the cache for a given tenant. Calls routines to Populate the in and out information. Update the result information. Populate the state information. Populate the router information.
3.079371
2.955554
1.041893
fw_dict = self.get_all_fw_db() for fw_id in fw_dict: LOG.info("Populating cache for FW %s", fw_id) fw_data = fw_dict[fw_id] self.populate_local_cache_tenant(fw_id, fw_data)
def populate_local_cache(self)
Populate the local cache from DB. Read the entries from FW DB and Calls routines to populate the cache.
3.498012
3.083251
1.134521
subnet_lst = set() subnet_lst.add(subnet_id) ret = self.os_helper.delete_intf_router(None, None, rtr_id, subnet_lst) if not ret: return ret return self.os_helper.delete_network_all_subnets(net_id)
def delete_os_dummy_rtr_nwk(self, rtr_id, net_id, subnet_id)
Delete the dummy interface to the router.
4.004504
3.930619
1.018797
if seg is not None: self.service_segs.release_segmentation_id(seg) if vlan is not None: self.service_vlans.release_segmentation_id(vlan) self.os_helper.delete_network_all_subnets(net_id) # There's a chance that OS network got created but it's ID #...
def delete_os_nwk_db(self, net_id, seg, vlan)
Delete the Openstack Network from the database. Release the segmentation ID, VLAN associated with the net. Delete the network given the partial name. Delete the entry from Network DB, given the net ID. Delete the entry from Firewall DB, given the net ID. Release the IN/OUT sug=b...
5.379809
4.831573
1.11347
if not self.auto_nwk_create: LOG.info("Auto network creation disabled") return False try: tenant_name = fw_dict.get('tenant_name') fw_id = fw_dict.get('fw_id') fw_name = fw_dict.get('fw_name') # TODO(padkrish) More than 1 F...
def _prepare_fabric_fw_internal(self, tenant_id, fw_dict, is_fw_virt, result)
Internal routine to prepare the fabric. This creates an entry in FW DB and runs the SM.
3.080527
2.917144
1.056008
try: with self.mutex_lock: ret = self._prepare_fabric_fw_internal(tenant_id, fw_dict, is_fw_virt, result) except Exception as exc: LOG.error("Exception raised in create fabric %s", str(exc)) ...
def prepare_fabric_fw(self, tenant_id, fw_dict, is_fw_virt, result)
Top level routine to prepare the fabric.
3.804219
3.798104
1.00161
if not self.auto_nwk_create: LOG.info("Auto network creation disabled") return False try: tenant_name = fw_dict.get('tenant_name') fw_name = fw_dict.get('fw_name') if tenant_id not in self.service_attr: LOG.error("Servi...
def delete_fabric_fw_internal(self, tenant_id, fw_dict, is_fw_virt, result)
Internal routine to delete the fabric configuration. This runs the SM and deletes the entries from DB and local cache.
4.496861
4.382889
1.026004
try: with self.mutex_lock: ret = self.delete_fabric_fw_internal(tenant_id, fw_dict, is_fw_virt, result) except Exception as exc: LOG.error("Exception raised in delete fabric %s", str(exc)) r...
def delete_fabric_fw(self, tenant_id, fw_dict, is_fw_virt, result)
Top level routine to unconfigure the fabric.
3.368091
3.312189
1.016878
if not self.auto_nwk_create: LOG.info("Auto network creation disabled") return False try: # TODO(padkrish) More than 1 FW per tenant not supported if tenant_id not in self.service_attr: LOG.error("Tenant Obj not created") ...
def retry_failure_internal(self, tenant_id, tenant_name, fw_data, is_fw_virt, result)
Internal routine to retry the failed cases.
4.408823
4.405517
1.00075
try: with self.mutex_lock: ret = self.retry_failure_internal(tenant_id, tenant_name, fw_data, is_fw_virt, result) except Exception as exc: LOG.error("Exception raised in create fabric %s", str(exc)) ...
def retry_failure(self, tenant_id, tenant_name, fw_data, is_fw_virt, result)
Top level retry failure routine.
3.950067
3.746532
1.054326
conf_dict = {} for uuid, val in cfg.CONF.get(prefix, {}).items(): conf_dict[uuid] = dict(val) return conf_dict
def get_specific_config(prefix)
Retrieve config based on the format [<prefix>:<value>]. returns: a dict, {<UUID>: {<key1>:<value1>, <key2>:<value2>, ...}}
4.845345
4.428593
1.094105
if ((bc.NEUTRON_VERSION >= bc.NEUTRON_NEWTON_VERSION) and 'tenant_id' in res_dict): res_dict['project_id'] = res_dict['tenant_id'] if is_create: # POST for attr, attr_vals in six.iteritems(attr_info): if attr_vals['allow_post']: if 'default' not in a...
def verify_resource_dict(res_dict, is_create, attr_info)
Verifies required attributes are in resource dictionary, res_dict. Also checking that an attribute is only specified if it is allowed for the given operation (create/update). Attribute with default values are considered to be optional. This function contains code taken from function 'prepare_request_...
2.301891
2.282218
1.00862
if uuidutils.is_uuid_like(val): return val else: try: int_val = int(val, 16) except ValueError: with excutils.save_and_reraise_exception(): LOG.error("Invalid UUID format %s. Please provide an " "integer in decimal (0...
def uuidify(val)
Takes an integer and transforms it to a UUID format. returns: UUID formatted version of input.
2.968313
3.060082
0.970011
if rule == 'type:uuid' or (rule == 'type:uuid_or_none' and res_dict[attribute]): res_dict[attribute] = uuidify(res_dict[attribute]) elif rule == 'type:uuid_list': if not res_dict[attribute]: res_dict[attribute] = [] else: temp_l...
def _ensure_format(rule, attribute, res_dict)
Verifies that attribute in res_dict is properly formatted. Since, in the .ini-files, lists are specified as ':' separated text and UUID values can be plain integers we need to transform any such values into proper format. Empty strings are converted to None if validator specifies that None value is acc...
2.482276
2.377728
1.04397
cred_dict = get_specific_config('cisco_hosting_device_credential') attr_info = { 'name': {'allow_post': True, 'allow_put': True, 'validate': {'type:string': None}, 'is_visible': True, 'default': ''}, 'description': {'allow_post': True, 'allow_put': True, ...
def obtain_hosting_device_credentials_from_config()
Obtains credentials from config file and stores them in memory. To be called before hosting device templates defined in the config file are created.
2.028758
2.042733
0.993159
plural_mappings = resource_helper.build_plural_mappings( {}, RESOURCE_ATTRIBUTE_MAP) if NEUTRON_VERSION.version[0] <= NEUTRON_NEWTON_VERSION.version[0]: attr.PLURALS.update(plural_mappings) return resource_helper.build_resource_info(plural_mappings, ...
def get_resources(cls)
Returns Ext Resources.
4.775208
4.443161
1.074732
pass
def get_routertypes(self, context, filters=None, fields=None, sorts=None, limit=None, marker=None, page_reverse=False)
Lists defined router types.
5,088.733398
2,956.161133
1.721399
set_mysql_engine() engine = session.create_engine(neutron_config.database.connection) connection = engine.connect() context.configure( connection=connection, target_metadata=target_metadata, include_object=include_object, version_table=alembic_migrations.VERSION_TAB...
def run_migrations_online()
Run migrations in 'online' mode. In this scenario we need to create an Engine and associate a connection with the context.
3.108501
3.109146
0.999793
''' Check whether the Launch Paramters set the role. ''' return self.roles and any([re.search(role, our_role, re.I) for our_role in self.roles])
def has_role(self, role)
Check whether the Launch Paramters set the role.
12.465363
4.388746
2.840302
''' Return the full, given, or family name if set. ''' if self.lis_person_name_given: return self.lis_person_name_given elif self.lis_person_name_family: return self.lis_person_name_family elif self.lis_person_name_full: return self.lis...
def username(self, default=None)
Return the full, given, or family name if set.
2.735395
1.763833
1.550824
''' POSTs the given score to the Tool Consumer with a replaceResult. Returns OutcomeResponse object and stores it in self.outcome_request OPTIONAL: result_data must be a dictionary Note: ONLY ONE of these values can be in the dict at a time, due to t...
def post_replace_result(self, score, outcome_opts=defaultdict(lambda:None), result_data=None)
POSTs the given score to the Tool Consumer with a replaceResult. Returns OutcomeResponse object and stores it in self.outcome_request OPTIONAL: result_data must be a dictionary Note: ONLY ONE of these values can be in the dict at a time, due to the Canvas specificat...
14.501911
1.71535
8.454199
''' If the Tool Consumer sent a return URL, add any set messages to the URL. ''' if not self.launch_presentation_return_url: return None lti_message_fields = ['lti_errormsg', 'lti_errorlog', 'lti_msg', 'lti_log'] message...
def build_return_url(self)
If the Tool Consumer sent a return URL, add any set messages to the URL.
4.537421
3.21747
1.410245
''' Shortcut for redirecting Django view to LTI Consumer with messages ''' from django.shortcuts import redirect self.lti_msg = msg self.lti_log = log return redirect(self.build_return_url())
def success_redirect(self, msg='', log='')
Shortcut for redirecting Django view to LTI Consumer with messages
8.046177
3.288554
2.446722
''' Shortcut for redirecting Django view to LTI Consumer with errors ''' from django.shortcuts import redirect self.lti_errormsg = errormsg self.lti_errorlog = errorlog return redirect(self.build_return_url())
def error_redirect(self, errormsg='', errorlog='')
Shortcut for redirecting Django view to LTI Consumer with errors
6.570429
2.96547
2.215645
try: with self.__private_things: self.__private_things[to_lid] = self.__private_things.pop(from_lid) except KeyError: logger.warning('Thing %s renamed (to %s), but not in private lookup table', from_lid, to_lid) else: # renaming could ...
def _notify_thing_lid_change(self, from_lid, to_lid)
Used by Thing instances to indicate that a rename operation has happened
3.999624
3.843263
1.040684
if callback_parsed: callback = self._get_parsed_feed_callback(callback_parsed, callback) return self.__client.register_callback_feeddata(callback)
def register_catchall_feeddata(self, callback, callback_parsed=None)
Registers a callback that is called for all feeddata your Thing receives `Example` #!python def feeddata_callback(data): print(data) ... client.register_catchall_feeddata(feeddata_callback) `callback` (required) the function name that yo...
4.565852
7.466394
0.61152
if callback_parsed: callback = self._get_parsed_control_callback(callback_parsed, callback) return self.__client.register_callback_controlreq(callback)
def register_catchall_controlreq(self, callback, callback_parsed=None)
Registers a callback that is called for all control requests received by your Thing `Example` #!python def controlreq_callback(data): print(data) ... client.register_catchall_controlreq(controlreq_callback) `callback` (required) the func...
4.497148
6.529525
0.68874
self.__client.register_callback_created(partial(self.__callback_payload_only, func), serialised=serialised)
def register_callback_created(self, func, serialised=True)
Register a callback for resource creation. This will be called when any *new* resource is created within your agent. If `serialised` is not set, the callbacks might arrive in a different order to they were requested. The payload passed to your callback is an OrderedDict with the following key...
7.85663
11.351714
0.69211
self.__client.register_callback_duplicate(partial(self.__callback_payload_only, func), serialised=serialised)
def register_callback_duplicate(self, func, serialised=True)
Register a callback for resource creation but where the resource already exists in Iotic Space. In this case the existing reference is passed to you. If `serialised` is not set, the callbacks might arrive in a different order to they were requested. The payload passed to your callback is an Ord...
8.191312
12.615526
0.649304
self.__client.register_callback_renamed(partial(self.__callback_payload_only, func), serialised=serialised)
def register_callback_renamed(self, func, serialised=True)
Register a callback for resource rename. This will be called when any resource is renamed within your agent. If `serialised` is not set, the callbacks might arrive in a different order to they were requested. The payload passed to your callback is an OrderedDict with the following keys ...
7.886672
9.661842
0.81627
self.__client.register_callback_deleted(partial(self.__callback_payload_only, func), serialised=serialised)
def register_callback_deleted(self, func, serialised=True)
Register a callback for resource deletion. This will be called when any resource is deleted within your agent. If `serialised` is not set, the callbacks might arrive in a different order to they were requested. The payload passed to your callback is an OrderedDict with the following keys ...
8.507364
11.178221
0.761066
self.__client.register_callback_reassigned(partial(self.__callback_payload_only, func), serialised)
def register_callback_reassigned(self, func, serialised=True)
Register a callback for resource reassignment. This will be called when any resource is reassigned to or from your agent. If `serialised` is not set, the callbacks might arrive in a different order to they were requested. The payload passed to your callback is an OrderedDict with the following...
9.333194
12.703176
0.734713
return self.__client.register_callback_created(partial(self.__callback_subscribed_filter, callback), serialised=False)
def register_callback_subscribed(self, callback)
Register a callback for new subscription. This gets called whenever one of *your* things subscribes to something else. `Note` it is not called when whenever something else subscribes to your thing. The payload passed to your callback is either a [RemoteControl](RemotePoint.m.html#Iotic...
17.007301
19.333
0.879703
self.__client.simulate_feeddata(feedid, data, mime, time)
def simulate_feeddata(self, feedid, data, mime=None, time=None)
Simulate the last feeddata received for given feedid Calls the registered callback for the feed with the last recieved feed data. Allows you to test your code without having to wait for the remote thing to share again. `feedid` (required) (string) local id of your Feed `data` (optional...
4.116549
5.718212
0.719901
logger.info("confirm_tell(success=%s) [lid=\"%s\",pid=\"%s\"]", success, data[P_ENTITY_LID], data[P_LID]) evt = self._request_point_confirm_tell(R_CONTROL, data[P_ENTITY_LID], data[P_LID], success, data['requestId']) self._wait_and_except_if_failed(evt)
def confirm_tell(self, data, success)
Confirm that you've done as you were told. Call this from your control callback to confirm action. Used when you are advertising a control and you want to tell the remote requestor that you have done what they asked you to. `Example:` this is a minimal example to show the idea. Note - no Exce...
7.73266
8.712523
0.887534
self.__config.set('agent', 'seqnum', self.__client.get_seqnum()) self.__config.set('agent', 'lang', self.__client.default_lang) self.__config.save()
def save_config(self)
Save the config, update the seqnum & default language
5.569489
3.247752
1.714875
with self.__point_data_handlers: try: return self.__point_data_handlers[point] except KeyError: return self.__point_data_handlers.setdefault(point, PointDataObjectHandler(point, self))
def _get_point_data_handler_for(self, point)
Used by point instances and data callbacks
3.008162
2.868119
1.048828
# used by PointDataObjectHandler as reference if foc == R_FEED: point_ref = data['pid'] else: # R_CONTROL point_ref = Control(self, data[P_ENTITY_LID], data[P_LID], '0' * 32) try: data['parsed'] = self._get_point_data_handler_for(point_ref)....
def _parsed_callback_wrapper(self, callback_parsed, callback_plain, foc, data)
Used to by register_catchall_*data() and Thing class (follow, create_point) to present point data as an object.
7.618971
7.185107
1.060384
event.wait(timeout or self.__sync_timeout) self._except_if_failed(event)
def _wait_and_except_if_failed(self, event, timeout=None)
Combines waiting for event and call to `_except_if_failed`. If timeout is not specified the configured sync_timeout is used.
8.101561
3.415649
2.371895
if event.success is None: raise IOTSyncTimeout('Requested timed out', event) if not event.success: msg = "Request failed, unknown error" if isinstance(event.payload, Mapping): if P_MESSAGE in event.payload: msg = event.payl...
def _except_if_failed(cls, event)
Raises an IOTException from the given event if it was not successful. Assumes timeout success flag on event has not been set yet.
4.749716
3.899136
1.218146
logger.info("list(all_my_agents=%s, limit=%s, offset=%s)", all_my_agents, limit, offset) if all_my_agents: evt = self._request_entity_list_all(limit=limit, offset=offset) else: evt = self._request_entity_list(limit=limit, offset=offset) self._wait_and_ex...
def list(self, all_my_agents=False, limit=500, offset=0)
List `all` the things created by this client on this or all your agents Returns QAPI list function payload Raises [LinkException](../Core/AmqpLink.m.html#IoticAgent.Core.AmqpLink.LinkException) if there is a communications problem between you and the infrastructure `all_my_agents` (op...
2.821154
3.098098
0.910608
with self.__new_things: try: return self.__new_things.pop(lid) except KeyError as ex: raise_from(KeyError('Thing %s not know as new' % lid), ex)
def get_thing(self, lid)
Get the details of a newly created Thing. This only applies to asynchronous creation of Things and the new Thing instance can only be retrieved once. Returns a [Thing](Thing.m.html#IoticAgent.IOT.Thing.Thing) object, which corresponds to the Thing with the given local id (nickname) Rai...
5.78836
5.933437
0.975549
evt = self.create_thing_async(lid) self._wait_and_except_if_failed(evt) try: with self.__new_things: return self.__new_things.pop(lid) except KeyError as ex: raise raise_from(IOTClientError('Thing %s not in cache (post-create)' % lid), ex)
def create_thing(self, lid)
Create a new Thing with a local id (lid). Returns a [Thing](Thing.m.html#IoticAgent.IOT.Thing.Thing) object if successful or if the Thing already exists Raises [IOTException](./Exceptions.m.html#IoticAgent.IOT.Exceptions.IOTException) containing the error if the infrastructure detects...
6.805871
7.583731
0.89743
logger.info("delete_thing(lid=\"%s\")", lid) evt = self.delete_thing_async(lid) self._wait_and_except_if_failed(evt)
def delete_thing(self, lid)
Delete a Thing Raises [IOTException](./Exceptions.m.html#IoticAgent.IOT.Exceptions.IOTException) containing the error if the infrastructure detects a problem Raises [LinkException](../Core/AmqpLink.m.html#IoticAgent.Core.AmqpLink.LinkException) if there is a communications problem betw...
5.886864
7.526738
0.782127
return self.search(text, lang, location, unit, limit, offset, reduced=True, local=local, scope=scope)
def search_reduced(self, text=None, lang=None, location=None, unit=None, limit=100, offset=0, local=None, scope=SearchScope.PUBLIC)
Shorthand for [search()](#IoticAgent.IOT.Client.Client.search) with `reduced=True`
3.203671
2.501198
1.280855
logger.info("search_located(text=\"%s\", lang=\"%s\", location=\"%s\", unit=\"%s\", limit=%s, offset=%s)", text, lang, location, unit, limit, offset) evt = self._request_search(text, lang, location, unit, limit, offset, SearchType.LOCATED, local, scope) self._wait_a...
def search_located(self, text=None, lang=None, location=None, unit=None, limit=100, offset=0, local=None, scope=SearchScope.PUBLIC)
See [search()](#IoticAgent.IOT.Client.Client.search) for general documentation. Provides a thing-only result set comprised only of things which have a location set, e.g.: #!python { # Keyed by thing id '2b2d8b068e404861b19f9e060877e002': ...
3.117546
3.221726
0.967663
if isinstance(guid_or_resource, self.__guid_resources): guid = guid_or_resource.guid elif isinstance(guid_or_resource, string_types): guid = uuid_to_hex(guid_or_resource) else: raise ValueError("describe requires guid string or Thing, Point, RemoteFee...
def describe(self, guid_or_resource, lang=None, local=None, scope=DescribeScope.AUTO)
Describe returns the public (or local) description of a Thing or Point Returns the description dict (see below for Thing example) if available, otherwise `None` #!python { "type": "Entity", "meta": { "long": 0.716356, ...
5.945595
4.91374
1.209994
''' Convenience method for creating a new OutcomeRequest from a request object. post_request is assumed to be a Django HttpRequest object ''' request = OutcomeRequest() request.post_request = post_request request.process_xml(post_request.data) ret...
def from_post_request(post_request)
Convenience method for creating a new OutcomeRequest from a request object. post_request is assumed to be a Django HttpRequest object
6.735453
3.212973
2.09633
''' POSTs the given score to the Tool Consumer with a replaceResult. OPTIONAL: result_data must be a dictionary Note: ONLY ONE of these values can be in the dict at a time, due to the Canvas specification. 'text' : str text 'url' : st...
def post_replace_result(self, score, result_data=None)
POSTs the given score to the Tool Consumer with a replaceResult. OPTIONAL: result_data must be a dictionary Note: ONLY ONE of these values can be in the dict at a time, due to the Canvas specification. 'text' : str text 'url' : str url
4.388969
2.09374
2.096234
''' POST an OAuth signed request to the Tool Consumer. ''' if not self.has_required_attributes(): raise InvalidLTIConfigError( 'OutcomeRequest does not have all required attributes') consumer = oauth2.Consumer(key=self.consumer_key, ...
def post_outcome_request(self)
POST an OAuth signed request to the Tool Consumer.
3.359681
2.903076
1.157283
''' Parse Outcome Request data from XML. ''' root = objectify.fromstring(xml) self.message_identifier = str( root.imsx_POXHeader.imsx_POXRequestHeaderInfo. imsx_messageIdentifier) try: result = root.imsx_POXBody.replaceResultRequest ...
def process_xml(self, xml)
Parse Outcome Request data from XML.
3.162625
2.826319
1.118991
if hasattr(self, 'sslopts'): self.sock = ssl.wrap_socket(self.sock, **self.sslopts) elif hasattr(self, 'sslctx'): self.sock = self.sslctx.wrap_socket(self.sock, server_hostname=self.hostname) else: self....
def _setup_transport(self)
Wrap the socket in an SSL object.
2.488959
2.160543
1.152006
if self.sock is not None: try: unwrap = self.sock.unwrap except AttributeError: return try: self.sock = unwrap() except ValueError: # Failure within SSL might mean unwrap exists but socket is...
def _shutdown_transport(self)
Unwrap a Python 2.6 SSL socket, so we can call shutdown()
10.74348
8.369261
1.283683
if self.__fname is None: f = os.path.splitext(os.path.basename(argv[0]))[0] + '.ini' cwd = os.getcwd() # todo: prefer script path or current path ?? # print(os.path.realpath(sys.argv[0])) # todo: if os.path.exists(os.path.join(cwd, main.__file...
def _file_loc(self)
_file_loc helper returns a possible config filename. EG /tmp/stuff/fish.py -> /tmp/stuff/fish.ini
4.937777
4.398776
1.122534
logging.getLogger('amqp').setLevel(str_to_logging(self.get('logging', 'amqp'))) logging.getLogger('rdflib').setLevel(str_to_logging(self.get('logging', 'rdflib')))
def setup_logging(self)
Setup logging module based on known modules in the config file
3.852268
3.567838
1.079721
if self.__fname is None and filename is None: raise ValueError('Config loaded from string, no filename specified') conf = self.__config cpa = dict_to_cp(conf) with open(self.__fname if filename is None else filename, 'w') as f: cpa.write(f)
def save(self, filename=None)
Write config to file.
5.692148
5.080448
1.120403
val = val.lower() if section in self.__config: if val in self.__config[section]: # logger.debug('get config %s %s = %s', section, val, self.__config[section][val]) return self.__config[section][val] if section in self.__defaults: i...
def get(self, section, val)
Get a setting or the default `Returns` The current value of the setting `val` or the default, or `None` if not found `section` (mandatory) (string) the section name in the config E.g. `"agent"` `val` (mandatory) (string) the section name in the config E.g. `"host"`
1.81186
1.971798
0.918887
val = val.lower() if section in self.__config: # logger.debug('set %s %s = %s', section, val, data) self.__config[section][val] = data
def set(self, section, val, data)
Add a setting to the config `section` (mandatory) (string) the section name in the config E.g. `"agent"` `val` (mandatory) (string) the section name in the config E.g. `"host"` `data` (mandatory) (as appropriate) the new value for the `val`
3.595572
4.930175
0.729299
k = self.get(section, val) # logger.debug('update %s %s from: %s to: %s', section, val, k, data) if data is not None and k != data: self.set(section, val, data)
def update(self, section, val, data)
Add a setting to the config, but if same as default or None then no action. This saves the .save writing the defaults `section` (mandatory) (string) the section name in the config E.g. `"agent"` `val` (mandatory) (string) the section name in the config E.g. `"host"` `data` (mandatory)...
3.465704
3.557647
0.974156
lat = None lon = None # note: always picks from first triple for _, _, o in self._graph.triples((None, GEO_NS.lat, None)): lat = float(o) break for _, _, o in self._graph.triples((None, GEO_NS.long, None)): lon = float(o) b...
def get_location(self)
Gets the current geo location of your Thing Returns tuple of `(lat, lon)` in `float` or `(None, None)` if location is not set for this Thing
4.00055
4.321743
0.92568
# normally this should only remove one triple each for s, p, o in self._graph.triples((None, GEO_NS.lat, None)): self._graph.remove((s, p, o)) for s, p, o in self._graph.triples((None, GEO_NS.long, None)): self._graph.remove((s, p, o))
def delete_location(self)
Deletes all the `geo:lat` and `geo:long` metadata properties on your Thing
3.232021
2.767379
1.1679
if not (self.__recv_thread or self.__send_thread): self.__end.clear() self.__send_ready.clear() self.__recv_ready.clear() timeout = self.__socket_timeout + 1 ignore_exc = self.__startup_ignore_exc self.__send_exc_clear() ...
def start(self)
start connection threads, blocks until started
3.609005
3.493739
1.032992
if self.__send_ready.is_set() and self.__recv_ready.is_set(): if self.__send_thread is not None and self.__recv_thread is not None: return self.__send_thread.is_alive() and self.__recv_thread.is_alive() return False
def is_alive(self)
Helper function to show if send & recv Threads are running
2.490151
1.965458
1.266957
self.__end.set() if self.__recv_thread: self.__recv_thread.join() self.__recv_thread = None if self.__send_thread: self.__send_thread.join() self.__send_thread = None
def stop(self)
disconnect, blocks until stopped
2.319795
2.083524
1.1134
if self.__send_ready.wait(timeout): try: with self.__send_lock: # access denied response might be received inside send thread rather than here how to best handle? self.__send_channel.basic_publish(msg=Message(body, delivery_mode=2, con...
def send(self, body, content_type='application/ubjson', timeout=5)
timeout indicates amount of time to wait for sending thread to be ready. set to larger than zero to wait (in seconds, fractional) or None to block.
5.333031
5.109461
1.043756
if ((version_info[0] == 2 and (version_info[1] >= 7 and version_info[2] >= 5)) or (version_info[0] == 3 and version_info[1] >= 4)): logger.debug('SSL method for 2.7.5+ / 3.4+') # pylint: disable=no-name-in-module from ssl import SSLContext, PROTOCOL_T...
def __get_ssl_context(cls, sslca=None)
Make an SSLConext for this Python version using public or sslca
2.12076
2.079435
1.019873
try: self.__msg_callback(msg) except: logger.exception("AmqpLink.__recv_cb exception calling msg_callback") finally: # only works if all messages handled in series self.__last_id = msg.delivery_tag self.__unacked += 1
def __recv_cb(self, msg)
Calls user-provided callback and marks message for Ack regardless of success
7.621408
7.341163
1.038174
self.__unacked = 0 self.__last_id = None try: self.__recv_ready.clear() # Ensure event is cleared for EG network failure/retry loop with Connection(userid=self.__prefix + self.__epid, password=self.__passwd, ...
def __recv_run(self): # pylint: disable=too-many-branches,too-many-statements while not self.__end.is_set()
Main receive thread/loop
4.713915
4.632501
1.017575
logger.log( ((logging.DEBUG if self.__recv_exc else logging.ERROR) if level is None else level), msg, exc_info=DEBUG_ENABLED ) self.__recv_exc = exc_info()[1] self.__end.wait(wait_seconds)
def __recv_log_set_exc_and_wait(self, msg, level=None, wait_seconds=CONN_RETRY_DELAY_SECONDS)
Equivalent to __send_log_set_exc_and_wait but for receiver thread
5.963048
5.366626
1.111135
if not (log_if_exc_set is None or self.__recv_exc is None): logger.info(log_if_exc_set) self.__recv_exc = None
def __recv_exc_clear(self, log_if_exc_set=None)
Equivalent to __send_exc_clear
3.363524
3.244237
1.036769
while not self.__end.is_set(): try: with Connection(userid=self.__prefix + self.__epid, password=self.__passwd, virtual_host=self.__vhost, heartbeat=self.__heartbeat, ...
def __send_run(self)
Send request thread
5.223598
5.195362
1.005435
logger.log( ((logging.DEBUG if self.__send_exc else logging.ERROR) if level is None else level), msg, exc_info=DEBUG_ENABLED ) self.__send_exc_time = monotonic() self.__send_exc = exc_info()[1] self.__end.wait(wait_seconds)
def __send_log_set_exc_and_wait(self, msg, level=None, wait_seconds=CONN_RETRY_DELAY_SECONDS)
To be called in exception context only. msg - message to log level - logging level. If not specified, ERROR unless it is a repeated failure in which case DEBUG. If specified, the given level will always be used. wait_seconds - how long to pause for (so retry is not triggered immediately...
5.431031
6.039233
0.899292
if not (log_if_exc_set is None or self.__send_exc is None): logger.info(log_if_exc_set) self.__send_exc_time = None self.__send_exc = None
def __send_exc_clear(self, log_if_exc_set=None)
Clear send exception and time. If exception was previously was set, optionally log log_if_exc_set at INFO level.
3.256645
2.56123
1.271516
if isinstance(type_, unicode_type): match = __IDX_PATTERN.match(type_) if match: return match.group(1) in __IDX_MAPPING else: return __is_ascii(type_, 1, __MAX_LEN) else: return type_ is None and allow_none
def valid_mimetype(type_, allow_none=True)
Checks for validity of given type, optionally allowing for a None value. Note: Unknown idx/NUMBER notation, where NUMBER is not a known shorthand mapping, will be rejected, i.e. type_ is valid if it 1) is an ASCII-only string between 1 & 64 characters long 2a) does not begin with "idx/" OR ...
5.334244
4.576439
1.165588
if isinstance(type_, unicode_type): match = __IDX_PATTERN.match(type_) return __IDX_MAPPING.get(match.group(1), type_) if match else type_ else: return type_
def expand_idx_mimetype(type_)
Returns long equivalent of type_, if available, otherwise type_ itself. Does not raise exceptions
4.005756
3.612805
1.108766
iterations = self.__iterations timestamp = monotonic() outdated_threshold = timestamp - self.__interval with self.__lock: # remove any iterations older than interval try: while iterations[0] < outdated_threshold: itera...
def throttle(self)
Uses time.monotonic() (or time.sleep() if not available) to limit to the desired rate. Should be called once per iteration of action which is to be throttled. Returns None unless a custom wait_cmd was specified in the constructor in which case its return value is used if a wait was required.
5.67667
5.078475
1.11779