code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
major_service = []
for i in BTCoD._MAJOR_SERVICE_CLASS.keys():
if (self.cod & i):
major_service.append(BTCoD._MAJOR_SERVICE_CLASS[i])
return major_service | def major_service_class(self) | Return the major service class property decoded e.g.,
Audio, Telephony, etc | 6.074833 | 5.835236 | 1.04106 |
minor_device = []
minor_lookup = BTCoD._MINOR_DEVICE_CLASS.get(self.cod &
BTCoD._MAJOR_DEVICE_MASK,
[])
for i in minor_lookup:
minor_value = self.cod & i.get('mask')
... | def minor_device_class(self) | Return the minor device class property decoded e.g.,
Scanner, Printer, Loudspeaker, Camera, etc. | 7.394082 | 6.53556 | 1.131362 |
url_string = "{}/users/me/session".format(WinkApiInterface.BASE_URL)
nonce = ''.join([str(random.randint(0, 9)) for i in range(9)])
_json = {"nonce": str(nonce)}
try:
arequest = requests.post(url_string,
data=json.dumps(_json),
... | def post_session() | This endpoint appears to be required in order to keep pubnub updates flowing for some user.
This just posts a random nonce to the /users/me/session endpoint and returns the result. | 4.568731 | 3.848251 | 1.187223 |
items = response_dict.get('data')
devices = []
api_interface = WinkApiInterface()
check_list = isinstance(device_type, (list,))
for item in items:
if (check_list and get_object_type(item) in device_type) or \
(not check_list and get_object_type(item) == device_type):
... | def get_devices_from_response_dict(response_dict, device_type) | :rtype: list of WinkDevice | 3.673956 | 3.138572 | 1.170582 |
_LOGGER.info("Setting state via online API")
object_id = id_override or device.object_id()
object_type = type_override or device.object_type()
url_string = "{}/{}s/{}".format(self.BASE_URL,
object_type,
... | def set_device_state(self, device, state, id_override=None, type_override=None) | Set device state via online API.
Args:
device (WinkDevice): The device the change is being requested for.
state (Dict): The state being requested.
id_override (String, optional): A device ID used to override the
passed in device's ID. Used to make changes on ... | 2.511704 | 2.346839 | 1.07025 |
if ALLOW_LOCAL_CONTROL:
if device.local_id() is not None:
hub = HUBS.get(device.hub_id())
if hub is None or hub["token"] is None:
return self.set_device_state(device, state, id_override, type_override)
else:
ret... | def local_set_state(self, device, state, id_override=None, type_override=None) | Set device state via local API, and fall back to online API.
Args:
device (WinkDevice): The device the change is being requested for.
state (Dict): The state being requested.
id_override (String, optional): A device ID used to override the
passed in device's ... | 2.915277 | 2.898259 | 1.005872 |
_LOGGER.info("Getting state via online API")
object_id = id_override or device.object_id()
object_type = type_override or device.object_type()
url_string = "{}/{}s/{}".format(self.BASE_URL,
object_type, object_id)
arequest = reques... | def get_device_state(self, device, id_override=None, type_override=None) | Get device state via online API.
Args:
device (WinkDevice): The device the change is being requested for.
id_override (String, optional): A device ID used to override the
passed in device's ID. Used to make changes on sub-devices.
i.e. Outlet in a Powerst... | 3.80635 | 3.440643 | 1.106291 |
if ALLOW_LOCAL_CONTROL:
if device.local_id() is not None:
hub = HUBS.get(device.hub_id())
if hub is not None and hub["token"] is not None:
ip = hub["ip"]
access_token = hub["token"]
else:
... | def local_get_state(self, device, id_override=None, type_override=None) | Get device state via local API, and fall back to online API.
Args:
device (WinkDevice): The device the change is being requested for.
id_override (String, optional): A device ID used to override the
passed in device's ID. Used to make changes on sub-devices.
... | 2.907107 | 2.896919 | 1.003517 |
object_id = id_override or device.object_id()
object_type = type_override or device.object_type()
url_string = "{}/{}s/{}/update_firmware".format(self.BASE_URL,
object_type,
o... | def update_firmware(self, device, id_override=None, type_override=None) | Make a call to the update_firmware endpoint. As far as I know this
is only valid for Wink hubs.
Args:
device (WinkDevice): The device the change is being requested for.
id_override (String, optional): A device ID used to override the
passed in device's ID. Used t... | 3.150928 | 3.386185 | 0.930524 |
object_id = id_override or device.object_id()
object_type = type_override or device.object_type()
url_string = "{}/{}s/{}".format(self.BASE_URL,
object_type,
object_id)
try:
arequest = r... | def remove_device(self, device, id_override=None, type_override=None) | Remove a device.
Args:
device (WinkDevice): The device the change is being requested for.
id_override (String, optional): A device ID used to override the
passed in device's ID. Used to make changes on sub-devices.
i.e. Outlet in a Powerstrip. The Parent ... | 2.600905 | 2.849115 | 0.912882 |
object_id = id_override or device.object_id()
object_type = type_override or device.object_type()
url_string = "{}/{}s/{}/keys".format(self.BASE_URL,
object_type,
object_id)
try:
... | def create_lock_key(self, device, new_device_json, id_override=None, type_override=None) | Create a new lock key code.
Args:
device (WinkDevice): The device the change is being requested for.
new_device_json (String): The JSON string required to create the device.
id_override (String, optional): A device ID used to override the
passed in device's I... | 2.90576 | 3.122558 | 0.93057 |
url_string = "{}/{}s/{}/deposits".format(self.BASE_URL,
device.object_type(),
device.object_id())
try:
arequest = requests.post(url_string,
data=jso... | def piggy_bank_deposit(self, device, _json) | Args:
device (WinkPorkfolioBalanceSensor): The piggy bank device to deposit to/withdrawal from.
_json (String): The JSON string to perform the deposit/withdrawal.
Returns:
response_json (Dict): The API's response in dictionary format | 3.770701 | 3.905914 | 0.965383 |
if not(inspect.isclass(model) and issubclass(model, models.Model)):
model = get_model_by_name(model)
return model | def get_concrete_model(model) | Get model defined in Meta.
:param str or django.db.models.Model model:
:return: model or None
:rtype django.db.models.Model or None:
:raise ValueError: model is not found or abstract | 3.364967 | 4.26466 | 0.789035 |
if meta.name is None and not meta.is_model:
msg = "Either name or model for resource.Meta shoud be provided"
raise ValueError(msg)
name = meta.name or get_model_name(get_concrete_model(meta.model))
return name | def get_resource_name(meta) | Define resource name based on Meta information.
:param Resource.Meta meta: resource meta information
:return: name of resource
:rtype: str
:raises ValueError: | 5.961936 | 5.61864 | 1.061099 |
metadict = {}
for meta in metas:
metadict.update(meta.__dict__)
metadict = {k: v for k, v in metadict.items() if not k.startswith('__')}
return type('Meta', (object, ), metadict) | def merge_metas(*metas) | Merge meta parameters.
next meta has priority over current, it will overwrite attributes.
:param class or None meta: class with properties.
:return class: merged meta. | 2.371677 | 2.694139 | 0.88031 |
speed = speed or self.current_fan_speed()
if state:
desired_state = {"powered": state, "mode": speed}
else:
desired_state = {"powered": state}
response = self.api_interface.set_device_state(self, {
"desired_state": desired_state
})
... | def set_state(self, state, speed=None) | :param state: bool
:param speed: a string one of ["lowest", "low",
"medium", "high", "auto"] defaults to last speed
:return: nothing | 4.317179 | 4.677783 | 0.922911 |
desired_state = {"direction": direction}
response = self.api_interface.set_device_state(self, {
"desired_state": desired_state
})
self._update_state_from_response(response) | def set_fan_direction(self, direction) | :param direction: a string one of ["forward", "reverse"]
:return: nothing | 4.700428 | 5.384606 | 0.872938 |
desired_state = {"timer": timer}
resp = self.api_interface.set_device_state(self, {
"desired_state": desired_state
})
self._update_state_from_response(resp) | def set_fan_timer(self, timer) | :param timer: an int between fan_timer_range
:return: nothing | 5.224606 | 5.953027 | 0.877638 |
desired_state = {"powered": state}
if state:
brightness = self._to_brightness.get(speed or self.current_fan_speed(), 0.33)
desired_state.update({'brightness': brightness})
response = self.api_interface.set_device_state(self, {
"desired_state": desire... | def set_state(self, state, speed=None) | :param state: bool
:param speed: a string one of ["lowest", "low",
"medium", "high", "auto"] defaults to last speed
:return: nothing | 5.688228 | 6.130267 | 0.927892 |
def activate(self):
response = self.api_interface.set_device_state(self, None)
self._update_state_from_response(response) | Activate the scene. | null | null | null | |
return VCFView(filename, chrom=chrom, start=start, stop=stop,
samples=samples) | def fromvcf(filename, chrom=None, start=None, stop=None, samples=True) | Returns a table providing access to data from a variant call file (VCF).
E.g.::
>>> import petl as etl
>>> # activate bio extensions
... import petlx.bio
>>> table1 = etl.fromvcf('fixture/sample.vcf')
>>> table1.look(truncate=20)
+-------+---------+-------------+----... | 3.896902 | 6.905177 | 0.564345 |
result = etl.unpackdict(table, 'INFO', keys=keys)
return result | def vcfunpackinfo(table, *keys) | Unpack the INFO field into separate fields. E.g.::
>>> import petl as etl
>>> # activate bio extensions
... import petlx.bio
>>> table1 = (
... etl
... .fromvcf('fixture/sample.vcf', samples=None)
... .vcfunpackinfo()
... )
>>> table1
... | 16.00935 | 20.990973 | 0.762678 |
result = etl.melt(table, key=VCF_HEADER, variables=samples,
variablefield='SAMPLE', valuefield='CALL')
return result | def vcfmeltsamples(table, *samples) | Melt the samples columns. E.g.::
>>> import petl as etl
>>> # activate bio extensions
... import petlx.bio
>>> table1 = (
... etl
... .fromvcf('fixture/sample.vcf')
... .vcfmeltsamples()
... )
>>> table1
+-------+-----+----... | 17.298149 | 18.252975 | 0.947689 |
result = (
etl.wrap(table)
.convert('CALL', lambda v: v.data._asdict())
.unpackdict('CALL', keys=keys)
)
return result | def vcfunpackcall(table, *keys) | Unpack the call column. E.g.::
>>> import petl as etl
>>> # activate bio extensions
... import petlx.bio
>>> table1 = (
... etl
... .fromvcf('fixture/sample.vcf')
... .vcfmeltsamples()
... .vcfunpackcall()
... )
>>> tab... | 12.805155 | 15.202895 | 0.842284 |
if isinstance(model_name, six.string_types) and \
len(model_name.split('.')) == 2:
app_name, model_name = model_name.split('.')
if django.VERSION[:2] < (1, 8):
model = models.get_model(app_name, model_name)
else:
from django.apps import apps
... | def get_model_by_name(model_name) | Get model by its name.
:param str model_name: name of model.
:return django.db.models.Model:
Example:
get_concrete_model_by_name('auth.User')
django.contrib.auth.models.User | 2.067066 | 2.183795 | 0.946548 |
opts = model._meta
if django.VERSION[:2] < (1, 7):
model_name = opts.module_name
else:
model_name = opts.model_name
return model_name | def get_model_name(model) | Get model name for the field.
Django 1.5 uses module_name, does not support model_name
Django 1.6 uses module_name and model_name
DJango 1.7 uses model_name, module_name raises RemovedInDjango18Warning | 3.21161 | 2.412175 | 1.331417 |
loading_cache = django.db.models.loading.cache
if django.VERSION[:2] < (1, 7):
loading_cache.app_models[app_name].clear()
else:
loading_cache.all_models[app_name].clear() | def clear_app_cache(app_name) | Clear django cache for models.
:param str ap_name: name of application to clear model cache | 3.778252 | 3.897057 | 0.969514 |
def set_state(self, color_hex):
root_name = self.json_state.get('piggy_bank_id', self.name())
response = self.api_interface.set_device_state(self, {
"nose_color": color_hex
}, root_name)
self._update_state_from_response(response) | :param color_hex: a hex string indicating the color of the porkfolio nose
:return: nothing
From the api...
"the color of the nose is not in the desired_state
but on the object itself." | null | null | null | |
def deposit(self, amount):
_json = {"amount": amount}
self.api_interface.piggy_bank_deposit(self, _json) | :param amount: (int +/-) amount to be deposited or withdrawn in cents | null | null | null | |
if (config.channel_mode == SBCChannelMode.CHANNEL_MODE_MONO):
self.config.mode = self.codec.SBC_MODE_MONO
elif (config.channel_mode == SBCChannelMode.CHANNEL_MODE_STEREO):
self.config.mode = self.codec.SBC_MODE_STEREO
elif (config.channel_mode == SBCChannelMode.C... | def _init_sbc_config(self, config) | Translator from namedtuple config representation to
the sbc_t type.
:param namedtuple config: See :py:class:`.SBCCodecConfig`
:returns: | 1.588516 | 1.579047 | 1.005997 |
self.codec.rtp_sbc_encode_to_fd(self.config,
ffi.new('char[]',
data),
len(data),
mtu,
self.ts,
... | def encode(self, fd, mtu, data) | Encode the supplied data (byte array) and write to
the media transport file descriptor encapsulated
as RTP packets. The encoder will calculate the
required number of SBC frames and encapsulate as
RTP to fit the MTU size.
:param int fd: Media transport file descriptor
:p... | 8.082991 | 8.980964 | 0.900014 |
output_buffer = ffi.new('char[]', max_len)
sz = self.codec.rtp_sbc_decode_from_fd(self.config,
output_buffer,
max_len,
mtu,
... | def decode(self, fd, mtu, max_len=2560) | Read the media transport descriptor, depay
the RTP payload and decode the SBC frames into
a byte array. The maximum number of bytes to
be returned may be passed as an argument and all
available bytes are returned to the caller.
:param int fd: Media transport file descriptor
... | 5.08548 | 5.060328 | 1.00497 |
attributes = dict()
fields = attributes_string.split(';')
for f in fields:
if '=' in f:
key, value = f.split('=')
attributes[unquote_plus(key).strip()] = unquote_plus(value.strip())
elif len(f) > 0:
# not strictly kosher
attributes[un... | def gff3_parse_attributes(attributes_string) | Parse a string of GFF3 attributes ('key=value' pairs delimited by ';')
and return a dictionary. | 2.915025 | 2.843809 | 1.025043 |
if(self.user_cb):
self.user_cb(self.user_arg)
return True | def _transport_ready_handler(self, fd, cb_condition) | Wrapper for calling user callback routine to notify
when transport data is ready to read | 8.224565 | 8.447752 | 0.97358 |
self.user_cb = user_cb
self.user_arg = user_arg | def register_transport_ready_event(self, user_cb, user_arg) | Register for transport ready events. The `transport ready`
event is raised via a user callback. If the endpoint
is configured as a source, then the user may then
call :py:meth:`write_transport` in order to send data to
the associated sink.
Otherwise, if the endpoint is configur... | 2.539136 | 4.25927 | 0.596143 |
if ('r' not in self.access_type):
raise BTIncompatibleTransportAccessType
return self.codec.decode(self.fd, self.read_mtu) | def read_transport(self) | Read data from media transport.
The returned data payload is SBC decoded and has
all RTP encapsulation removed.
:return data: Payload data that has been decoded,
with RTP encapsulation removed.
:rtype: array{byte} | 19.42318 | 20.113916 | 0.965659 |
if ('w' not in self.access_type):
raise BTIncompatibleTransportAccessType
return self.codec.encode(self.fd, self.write_mtu, data) | def write_transport(self, data) | Write data to media transport. The data is
encoded using the SBC codec and RTP encapsulated
before being written to the transport file
descriptor.
:param array{byte} data: Payload data to encode,
encapsulate and send. | 17.30022 | 18.80357 | 0.92005 |
if (self.path):
self._release_media_transport(self.path,
self.access_type)
self.path = None | def close_transport(self) | Forcibly close previously acquired media transport.
.. note:: The user should first make sure any transport
event handlers are unregistered first. | 10.62504 | 8.478232 | 1.253214 |
transport = BTMediaTransport(path=path)
(fd, read_mtu, write_mtu) = transport.acquire(access_type)
self.fd = fd.take() # We must do the clean-up later
self.write_mtu = write_mtu
self.read_mtu = read_mtu
self.access_type = access_type
self.path = path
... | def _acquire_media_transport(self, path, access_type) | Should be called by subclass when it is ready
to acquire the media transport file descriptor | 5.650129 | 5.539792 | 1.019917 |
try:
self._uninstall_transport_ready()
os.close(self.fd) # Clean-up previously taken fd
transport = BTMediaTransport(path=path)
transport.release(access_type)
except:
pass | def _release_media_transport(self, path, access_type) | Should be called by subclass when it is finished
with the media transport file descriptor | 10.834358 | 10.586243 | 1.023438 |
# The SBC config encoding is taken from a2dp_codecs.h, in particular,
# the a2dp_sbc_t type is converted into a 4-byte array:
# uint8_t channel_mode:4
# uint8_t frequency:4
# uint8_t allocation_method:2
# uint8_t subbands:2
# uint8_t block_lengt... | def _make_config(config) | Helper to turn SBC codec configuration params into a
a2dp_sbc_t structure usable by bluez | 4.726464 | 3.719982 | 1.270561 |
frequency = config[0] >> 4
channel_mode = config[0] & 0xF
allocation_method = config[1] & 0x03
subbands = (config[1] >> 2) & 0x03
block_length = (config[1] >> 4) & 0x0F
min_bitpool = config[2]
max_bitpool = config[3]
return SBCCodecConfig(channel_... | def _parse_config(config) | Helper to turn a2dp_sbc_t structure into a
more usable set of SBC codec configuration params | 3.484342 | 2.993236 | 1.164072 |
current_state = self.source.State
if (self.state == 'connected' and current_state == 'playing'):
self._acquire_media_transport(transport, 'r')
elif (self.state == 'playing' and current_state == 'connected'):
self._release_media_transport(transport, 'r')
s... | def _property_change_event_handler(self, signal, transport, *args) | Handler for property change event. We catch certain state
transitions in order to trigger media transport
acquisition/release | 3.968392 | 3.452363 | 1.149471 |
self.source = BTAudioSource(dev_path=path)
self.state = self.source.State
self.source.add_signal_receiver(self._property_change_event_handler,
BTAudioSource.SIGNAL_PROPERTY_CHANGED, # noqa
transport) | def _notify_media_transport_available(self, path, transport) | Called by the endpoint when a new media transport is
available | 8.246096 | 8.791417 | 0.937971 |
self.sink = BTAudioSink(dev_path=path)
self.state = self.sink.State
self.sink.add_signal_receiver(self._property_change_event_handler,
BTAudioSource.SIGNAL_PROPERTY_CHANGED, # noqa
transport) | def _notify_media_transport_available(self, path, transport) | Called by the endpoint when a new media transport is
available | 9.274604 | 9.985627 | 0.928795 |
if mode == "off":
desired_state = {"powered": False}
else:
desired_state = {"powered": True, "mode": mode}
response = self.api_interface.set_device_state(self, {
"desired_state": desired_state
})
self._update_state_from_response(resp... | def set_operation_mode(self, mode) | :param mode: a string one of self.modes()
:return: nothing | 3.58538 | 3.706678 | 0.967276 |
response = self.api_interface.set_device_state(self, {
"desired_state": {'set_point': set_point}
})
self._update_state_from_response(response) | def set_temperature(self, set_point) | :param set_point: a float for the set point value in celsius
:return: nothing | 5.271444 | 5.968899 | 0.883152 |
values = {"desired_state": {"vacation_mode": state}}
response = self.api_interface.local_set_state(self, values)
self._update_state_from_response(response) | def set_vacation_mode(self, state) | :param state: a boolean of ture (on) or false ('off')
:return: nothing | 6.448907 | 7.134491 | 0.903906 |
return SortComponent(key=key, reverse=reverse, buffersize=buffersize) | def sort(key=None, reverse=False, buffersize=None) | Sort rows based on some key field or fields. E.g.::
>>> from petlx.push import sort, tocsv
>>> p = sort('foo')
>>> p.pipe(tocsv('sorted_by_foo.csv'))
>>> p.push(sometable) | 6.491612 | 10.092404 | 0.643218 |
color_x = self._last_reading.get('color_x')
color_y = self._last_reading.get('color_y')
if color_x is not None and color_y is not None:
return [float(color_x), float(color_y)]
return None | def color_xy(self) | XY colour value: [float, float] or None
:rtype: list float | 2.451438 | 2.282442 | 1.074042 |
desired_state = {"powered": state}
color_state = self._format_color_data(color_hue_saturation, color_kelvin, color_xy)
if color_state is not None:
desired_state.update(color_state)
if brightness is not None:
desired_state.update({'brightness': brightnes... | def set_state(self, state, brightness=None,
color_kelvin=None, color_xy=None,
color_hue_saturation=None) | :param state: a boolean of true (on) or false ('off')
:param brightness: a float from 0 to 1 to set the brightness of
this bulb
:param color_kelvin: an integer greater than 0 which is a color in
degrees Kelvin
:param color_xy: a pair of floats in a list which specify the desi... | 3.036148 | 3.613585 | 0.840204 |
response = self.api_interface.set_device_state(self, {"tare": tare})
self._update_state_from_response(response) | def set_tare(self, tare) | :param tare: weight of tank as printed on can
:return: nothing
tare is not set in desired state, but on the main device. | 5.432967 | 5.555537 | 0.977937 |
def set_alarm_sensitivity(self, mode):
values = {"desired_state": {"alarm_sensitivity": mode}}
response = self.api_interface.set_device_state(self, values)
self._update_state_from_response(response) | :param mode: 1.0 for Very sensitive, 0.2 for not sensitive.
Steps in values of 0.2.
:return: nothing | null | null | null | |
def set_alarm_mode(self, mode):
values = {"desired_state": {"alarm_mode": mode}}
response = self.api_interface.set_device_state(self, values)
self._update_state_from_response(response) | :param mode: one of [None, "activity", "tamper", "forced_entry"]
:return: nothing | null | null | null | |
def set_alarm_state(self, state):
values = {"desired_state": {"alarm_enabled": state}}
response = self.api_interface.set_device_state(self, values)
self._update_state_from_response(response) | :param state: a boolean of ture (on) or false ('off')
:return: nothing | null | null | null | |
def set_vacation_mode(self, state):
values = {"desired_state": {"vacation_mode_enabled": state}}
response = self.api_interface.set_device_state(self, values)
self._update_state_from_response(response) | :param state: a boolean of ture (on) or false ('off')
:return: nothing | null | null | null | |
def set_beeper_mode(self, state):
values = {"desired_state": {"beeper_enabled": state}}
response = self.api_interface.set_device_state(self, values)
self._update_state_from_response(response) | :param state: a boolean of ture (on) or false ('off')
:return: nothing | null | null | null | |
def set_state(self, state):
values = {"desired_state": {"locked": state}}
response = self.api_interface.local_set_state(self, values)
self._update_state_from_response(response) | :param state: a boolean of true (on) or false ('off')
:return: nothing | null | null | null | |
def add_new_key(self, code, name):
device_json = {"code": code, "name": name}
return self.api_interface.create_lock_key(self, device_json) | Add a new user key code. | null | null | null | |
return self._interface.CreatePairedDevice(dev_id,
agent_path,
capability,
reply_handler=cb_notify_device, # noqa
... | def create_paired_device(self, dev_id, agent_path,
capability, cb_notify_device, cb_notify_error) | Creates a new object path for a remote device. This
method will connect to the remote device and retrieve
all SDP records and then initiate the pairing.
If a previously :py:meth:`create_device` was used
successfully, this method will only initiate the pairing.
Compared to :py:m... | 3.620195 | 3.864666 | 0.936742 |
if (node.body and isinstance(node.body[0], ast.Expr) and
self.is_base_string(node.body[0].value)):
node.body[0].value.is_docstring = True
self.visit(node.body[0].value)
for sub_node in node.body:
self.visit(sub_node) | def _visit_body(self, node) | Traverse the body of the node manually.
If the first node is an expression which contains a string or bytes it
marks that as a docstring. | 2.991468 | 2.369993 | 1.262226 |
response = self.api_interface.get_device_state(self, type_override="button")
return self._update_state_from_response(response) | def update_state(self) | Update state with latest info from Wink API. | 10.229605 | 8.160582 | 1.253539 |
last_full_builtwith_scan_date = None
if self.api_version == 7 and isinstance(domain, list):
domain = ','.join(domain)
if self.api_version in [2, 7]:
last_updates_resp = requests.get(ENDPOINTS_BY_API_VERSION[self.api_version], params={'UPDATE': 1})
... | def lookup(self, domain, get_last_full_query=True) | Lookup BuiltWith results for the given domain. If API version 2 is used and the get_last_full_query flag
enabled, it also queries for the date of the last full BuiltWith scan. | 2.877551 | 2.529794 | 1.137465 |
desired_state = {"schedule_enabled": state}
response = self.api_interface.set_device_state(self, {
"desired_state": desired_state
})
self._update_state_from_response(response) | def set_schedule_enabled(self, state) | :param state: a boolean True (on) or False (off)
:return: nothing | 4.870582 | 5.587078 | 0.871758 |
desired_state = {"fan_speed": speed}
response = self.api_interface.set_device_state(self, {
"desired_state": desired_state
})
self._update_state_from_response(response) | def set_ac_fan_speed(self, speed) | :param speed: a float from 0.0 to 1.0 (0 - 100%)
:return: nothing | 4.604715 | 5.248979 | 0.877259 |
desired_state = {}
if max_set_point:
desired_state['max_set_point'] = max_set_point
response = self.api_interface.set_device_state(self, {
"desired_state": desired_state
})
self._update_state_from_response(response) | def set_temperature(self, max_set_point=None) | :param max_set_point: a float for the max set point value in celsius
:return: nothing | 3.162153 | 3.553936 | 0.889761 |
if resource is None:
def wrapper(resource):
return self.register(resource, **kwargs)
return wrapper
for key, value in kwargs.items():
setattr(resource.Meta, key, value)
if resource.Meta.name in self.resource_map:
raise Va... | def register(self, resource=None, **kwargs) | Register resource for currnet API.
:param resource: Resource to be registered
:type resource: jsonapi.resource.Resource or None
:return: resource
:rtype: jsonapi.resource.Resource
.. versionadded:: 0.4.1
:param kwargs: Extra meta parameters | 2.458173 | 2.569865 | 0.956538 |
from django.conf.urls import url
urls = [
url(r'^$', self.documentation),
url(r'^map$', self.map_view),
]
for resource_name in self.resource_map:
urls.extend([
url(r'(?P<resource_name>{})$'.format(
resource... | def urls(self) | Get all of the api endpoints.
NOTE: only for django as of now.
NOTE: urlpatterns are deprecated since Django1.8
:return list: urls | 3.037642 | 3.028327 | 1.003076 |
http_host = request.META.get('HTTP_HOST', None)
if http_host is None:
http_host = request.META['SERVER_NAME']
if request.META['SERVER_PORT'] not in ('80', '443'):
http_host = "{}:{}".format(
http_host, request.META['SERVER_PORT'])
... | def update_urls(self, request, resource_name=None, ids=None) | Update url configuration.
:param request:
:param resource_name:
:type resource_name: str or None
:param ids:
:rtype: None | 1.809755 | 1.930157 | 0.937621 |
self.update_urls(request)
resource_info = {
"resources": [{
"id": index + 1,
"href": "{}/{}".format(self.api_url, resource_name),
} for index, (resource_name, resource) in enumerate(
sorted(self.resource_map.items()))
... | def map_view(self, request) | Show information about available resources.
.. versionadded:: 0.5.7
Content-Type check
:return django.http.HttpResponse | 4.582482 | 4.874464 | 0.9401 |
self.update_urls(request)
context = {
"resources": sorted(self.resource_map.items())
}
return render(request, "jsonapi/index.html", context) | def documentation(self, request) | Resource documentation.
.. versionadded:: 0.7.2
Content-Type check
:return django.http.HttpResponse | 5.620955 | 7.179668 | 0.782899 |
signal_request.send(sender=self, request=request)
time_start = time.time()
self.update_urls(request, resource_name=resource_name, ids=ids)
resource = self.resource_map[resource_name]
allowed_http_methods = resource.Meta.allowed_methods
if request.method not in a... | def handler_view(self, request, resource_name, ids=None) | Handler for resources.
.. versionadded:: 0.5.7
Content-Type check
:return django.http.HttpResponse | 2.113963 | 2.166386 | 0.975802 |
nest = self._last_reading.get('users_away', None)
ecobee = self.profile()
if nest is not None:
return nest
if ecobee is not None:
if ecobee == "home":
return False
return True
return None | def away(self) | This function handles both ecobee and nest thermostats
which use a different field for away/home status. | 9.629835 | 5.583009 | 1.724847 |
desired_state = {"fan_mode": mode}
response = self.api_interface.set_device_state(self, {
"desired_state": desired_state
})
self._update_state_from_response(response) | def set_fan_mode(self, mode) | :param mode: a string one of ["on", "auto"]
:return: nothing | 4.383995 | 4.81516 | 0.910457 |
if self.profile() is not None:
if away:
desired_state = {"profile": "away"}
else:
desired_state = {"profile": "home"}
else:
desired_state = {"users_away": away}
response = self.api_interface.set_device_state(self, {
... | def set_away(self, away=True) | :param away: a boolean of true (away) or false ('home')
:return nothing
This function handles both ecobee and nest thermostats
which use a different field for away/home status. | 4.182965 | 4.259611 | 0.982006 |
def _parse_ical_string(ical_string):
start_time = ical_string.splitlines()[0].replace(DTSTART, '')
if "RRULE" in ical_string:
days = ical_string.splitlines()[1].replace(REPEAT, '')
if days == "RRULE:FREQ=DAILY":
days = ['DAILY']
else:
days = days.spli... | SU,MO,TU,WE,TH,FR,SA
DTSTART;TZID=America/New_York:20180804T233251\nRRULE:FREQ=WEEKLY;BYDAY=SA
DTSTART;TZID=America/New_York:20180804T233251\nRRULE:FREQ=DAILY
DTSTART;TZID=America/New_York:20180804T233251\nRRULE:FREQ=WEEKLY;BYDAY=MO,TU,WE,TH,FR,SA
DTSTART;TZID=America/New_York:20180718T174500 | null | null | null | |
def set_dial(self, json_value, index, timezone=None):
values = self.json_state
values["nonce"] = str(random.randint(0, 1000000000))
if timezone is None:
json_value["channel_configuration"] = {"channel_id": "10"}
values["dials"][index] = json_value
... | :param json_value: The value to set
:param index: The dials index
:param timezone: The time zone to use for a time dial
:return: | null | null | null | |
def update_state(self):
response = self.api_interface.get_device_state(self, id_override=self.parent.object_id(),
type_override=self.parent.object_type())
self._update_state_from_response(response) | Update state with latest info from Wink API. | null | null | null | |
def _update_state_from_response(self, response_json):
if 'data' in response_json and response_json['data']['object_type'] == "cloud_clock":
cloud_clock = response_json.get('data')
if cloud_clock is None:
return False
alarms = cloud_clock.get('... | :param response_json: the json obj returned from query
:return: | null | null | null | |
def set_recurrence(self, date, days=None):
if self.parent.get_time_dial() is None:
_LOGGER.error("Not setting alarm, no time dial.")
return False
timezone_string = self.parent.get_time_dial()["channel_configuration"]["timezone"]
ical_string = _create_ical_s... | :param date: Datetime object time to start/repeat
:param days: days to repeat (Defaults to one time alarm)
:return: | null | null | null | |
def update_state(self):
response = self.api_interface.get_device_state(self, id_override=self.parent_id(),
type_override=self.parent_object_type())
self._update_state_from_response(response) | Update state with latest info from Wink API. | null | null | null | |
def _update_state_from_response(self, response_json):
if response_json.get('data') is not None:
cloud_clock = response_json.get('data')
else:
cloud_clock = response_json
self.parent.json_state = cloud_clock
cloud_clock_last_reading = cloud_clock.... | :param response_json: the json obj returned from query
:return: | null | null | null | |
def set_configuration(self, min_value, max_value, rotation="cw", scale="linear", ticks=12, min_position=0,
max_position=360):
_json = {"min_value": min_value, "max_value": max_value, "rotation": rotation, "scale_type": scale,
"num_ticks": ticks, "min_pos... | :param min_value: Any number
:param max_value: Any number above min_value
:param rotation: (String) cw or ccw
:param scale: (String) linear or log
:param ticks:(Int) number of ticks of the clock up to 360?
:param min_position: (Int) 0-360
:param max_position: (Int) ... | null | null | null | |
def set_state(self, value, labels=None):
values = {"value": value}
json_labels = []
if labels:
for label in labels:
json_labels.append(str(label).upper())
values["labels"] = json_labels
self._update_state_from_response(self.par... | :param value: Any number
:param labels: A list of two Strings sending None won't change the current values.
:return: | null | null | null | |
def make_time_dial(self, timezone_string):
self._update_state_from_response(self.parent.set_dial({}, self.index(), timezone_string)) | :param timezone_string:
:return: | null | null | null | |
return TabixView(filename, reference, start, stop, region, header) | def fromtabix(filename, reference=None, start=None, stop=None, region=None,
header=None) | Extract rows from a tabix indexed file, e.g.::
>>> import petl as etl
>>> # activate bio extensions
... import petlx.bio
>>> table1 = etl.fromtabix('fixture/test.bed.gz',
... region='Pf3D7_02_v3')
>>> table1
+---------------+----------+----... | 5.87329 | 15.831596 | 0.370985 |
def pair_new_device(self, pairing_mode, pairing_mode_duration=60, pairing_device_type_selector=None,
kidde_radio_code=None):
if pairing_mode == "lutron" and pairing_mode_duration < 120:
pairing_mode_duration = 120
elif pairing_mode == "zwave_network_redi... | :param pairing_mode: a string one of ["zigbee", "zwave", "zwave_exclusion",
"zwave_network_rediscovery", "lutron", "bluetooth", "kidde"]
:param pairing_mode_duration: an int in seconds defaults to 60
:param pairing_device_type_selector: a string I believe this is only for bluetooth device... | null | null | null | |
# If no offset is selected, pick random one with sufficient distance
# from original.
if self.offset is False:
self.offset = randrange(5, 25)
logging.info("Random offset selected: {0}".format(self.offset))
logging.debug("Offset set: {0}".format(self.offse... | def cipher(self) | Applies the Caesar shift cipher.
Based on the attributes of the object, applies the Caesar shift cipher
to the message attribute. Accepts positive and negative integers as
offsets.
Required attributes:
message
offset
Returns:
String with cip... | 2.839948 | 2.839888 | 1.000021 |
total = 0
for char in entropy_string:
if char.isalpha():
prob = self.frequency[char.lower()]
total += - math.log(prob) / math.log(2)
logging.debug("Entropy score: {0}".format(total))
return total | def calculate_entropy(self, entropy_string) | Calculates the entropy of a string based on known frequency of
English letters.
Args:
entropy_string: A str representing the string to calculate.
Returns:
A negative float with the total entropy of the string (higher
is better). | 3.586847 | 3.574595 | 1.003427 |
logging.info("Cracking message: {0}".format(self.message))
entropy_values = {}
attempt_cache = {}
message = self.message
for i in range(25):
self.message = message
self.offset = i * -1
logging.debug("Attempting crack with offset: "
... | def cracked(self) | Attempts to crack ciphertext using frequency of letters in English.
Returns:
String of most likely message. | 2.663547 | 2.532109 | 1.051909 |
logging.info("Decoding message: {0}".format(self.message))
self.offset = self.offset * -1
return self.cipher() | def decoded(self) | Decodes message using Caesar shift cipher
Inverse operation of encoding, applies negative offset to Caesar shift
cipher.
Returns:
String decoded with cipher. | 11.015304 | 5.241239 | 2.10166 |
for key in querydict.keys():
if not any((key in JSONAPIQueryDict._fields,
cls.RE_FIELDS.match(key))):
msg = "Query parameter {} is not known".format(key)
raise ValueError(msg)
result = JSONAPIQueryDict(
distinct=c... | def parse(cls, querydict) | Parse querydict data.
There are expected agruments:
distinct, fields, filter, include, page, sort
Parameters
----------
querydict : django.http.request.QueryDict
MultiValueDict with query arguments.
Returns
-------
result : dict
... | 3.48072 | 2.884511 | 1.206693 |
def set_state(self, state):
desired_state = {"desired_state": {"powered": state}}
response = self.api_interface.set_device_state(self, desired_state)
self._update_state_from_response(response) | :param state: a boolean of true (on) or false ('off')
:return: nothing | null | null | null | |
def _update_state_from_response(self, response_json):
power_strip = response_json.get('data')
power_strip_reading = power_strip.get('last_reading')
outlets = power_strip.get('outlets')
for outlet in outlets:
if outlet.get('outlet_id') == str(self.object_id())... | :param response_json: the json obj returned from query
:return: | null | null | null | |
def set_state(self, state):
if self.index() == 0:
values = {"outlets": [{"desired_state": {"powered": state}}, {}]}
else:
values = {"outlets": [{}, {"desired_state": {"powered": state}}]}
response = self.api_interface.set_device_state(self, values, id_ove... | :param state: a boolean of true (on) or false ('off')
:return: nothing | null | null | null | |
def set_state(self, state):
_field = self.binary_state_name()
values = {"desired_state": {_field: state}}
response = self.api_interface.local_set_state(self, values, type_override="binary_switche")
self._update_state_from_response(response) | :param state: a boolean of true (on) or false ('off')
:return: nothing | null | null | null | |
def binary_state_name(self):
return_field = "powered"
_capabilities = self.json_state.get('capabilities')
if _capabilities is not None:
_fields = _capabilities.get('fields')
if _fields is not None:
for field in _fields:
... | Search all of the capabilities of the device and return the supported binary state field.
Default to returning powered. | null | null | null | |
def update_state(self):
response = self.api_interface.local_get_state(self, type_override="binary_switche")
return self._update_state_from_response(response) | Update state with latest info from Wink API. | null | null | null | |
def set_siren_volume(self, volume):
values = {
"desired_state": {
"siren_volume": volume
}
}
response = self.api_interface.set_device_state(self, values)
self._update_state_from_response(response) | :param volume: one of [low, medium, high] | null | null | null | |
def set_chime_volume(self, volume):
values = {
"desired_state": {
"chime_volume": volume
}
}
response = self.api_interface.set_device_state(self, values)
self._update_state_from_response(response) | :param volume: one of [low, medium, high] | null | null | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.