Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
TestTrendBinarySensor.test_invert_up | (self) | Test up trend with custom message. | Test up trend with custom message. | def test_invert_up(self):
"""Test up trend with custom message."""
assert setup.setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "trend",
"sensors": {
"test_tr... | [
"def",
"test_invert_up",
"(",
"self",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"trend\"",
",",
"\"sensors\"",
":",
"{",
"\"test_tren... | [
154,
4
] | [
178,
35
] | python | en | ['en', 'en', 'en'] | True |
TestTrendBinarySensor.test_invert_down | (self) | Test down trend with custom message. | Test down trend with custom message. | def test_invert_down(self):
"""Test down trend with custom message."""
assert setup.setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "trend",
"sensors": {
"tes... | [
"def",
"test_invert_down",
"(",
"self",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"trend\"",
",",
"\"sensors\"",
":",
"{",
"\"test_tr... | [
180,
4
] | [
204,
34
] | python | en | ['en', 'en', 'en'] | True |
TestTrendBinarySensor.test_attribute_up | (self) | Test attribute up trend. | Test attribute up trend. | def test_attribute_up(self):
"""Test attribute up trend."""
assert setup.setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "trend",
"sensors": {
"test_trend_sen... | [
"def",
"test_attribute_up",
"(",
"self",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"trend\"",
",",
"\"sensors\"",
":",
"{",
"\"test_t... | [
206,
4
] | [
229,
34
] | python | en | ['en', 'en', 'en'] | True |
TestTrendBinarySensor.test_attribute_down | (self) | Test attribute down trend. | Test attribute down trend. | def test_attribute_down(self):
"""Test attribute down trend."""
assert setup.setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "trend",
"sensors": {
"test_trend... | [
"def",
"test_attribute_down",
"(",
"self",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"trend\"",
",",
"\"sensors\"",
":",
"{",
"\"test... | [
231,
4
] | [
255,
35
] | python | en | ['en', 'en', 'en'] | True |
TestTrendBinarySensor.test_max_samples | (self) | Test that sample count is limited correctly. | Test that sample count is limited correctly. | def test_max_samples(self):
"""Test that sample count is limited correctly."""
assert setup.setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "trend",
"sensors": {
... | [
"def",
"test_max_samples",
"(",
"self",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"trend\"",
",",
"\"sensors\"",
":",
"{",
"\"test_tr... | [
257,
4
] | [
283,
52
] | python | en | ['en', 'en', 'en'] | True |
TestTrendBinarySensor.test_non_numeric | (self) | Test up trend. | Test up trend. | def test_non_numeric(self):
"""Test up trend."""
assert setup.setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "trend",
"sensors": {
"test_trend_sensor": {"ent... | [
"def",
"test_non_numeric",
"(",
"self",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"trend\"",
",",
"\"sensors\"",
":",
"{",
"\"test_tr... | [
285,
4
] | [
306,
35
] | python | en | ['en', 'en', 'en'] | True |
TestTrendBinarySensor.test_missing_attribute | (self) | Test attribute down trend. | Test attribute down trend. | def test_missing_attribute(self):
"""Test attribute down trend."""
assert setup.setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "trend",
"sensors": {
"test_tr... | [
"def",
"test_missing_attribute",
"(",
"self",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"platform\"",
":",
"\"trend\"",
",",
"\"sensors\"",
":",
"{",
"\"t... | [
308,
4
] | [
332,
35
] | python | en | ['en', 'en', 'en'] | True |
TestTrendBinarySensor.test_invalid_name_does_not_create | (self) | Test invalid name. | Test invalid name. | def test_invalid_name_does_not_create(self):
"""Test invalid name."""
with assert_setup_component(0):
assert setup.setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "templa... | [
"def",
"test_invalid_name_does_not_create",
"(",
"self",
")",
":",
"with",
"assert_setup_component",
"(",
"0",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"pl... | [
334,
4
] | [
349,
43
] | python | en | ['en', 'et', 'en'] | True |
TestTrendBinarySensor.test_invalid_sensor_does_not_create | (self) | Test invalid sensor. | Test invalid sensor. | def test_invalid_sensor_does_not_create(self):
"""Test invalid sensor."""
with assert_setup_component(0):
assert setup.setup_component(
self.hass,
"binary_sensor",
{
"binary_sensor": {
"platform": "te... | [
"def",
"test_invalid_sensor_does_not_create",
"(",
"self",
")",
":",
"with",
"assert_setup_component",
"(",
"0",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"... | [
351,
4
] | [
366,
43
] | python | en | ['en', 'et', 'en'] | True |
TestTrendBinarySensor.test_no_sensors_does_not_create | (self) | Test no sensors. | Test no sensors. | def test_no_sensors_does_not_create(self):
"""Test no sensors."""
with assert_setup_component(0):
assert setup.setup_component(
self.hass, "binary_sensor", {"binary_sensor": {"platform": "trend"}}
)
assert self.hass.states.all() == [] | [
"def",
"test_no_sensors_does_not_create",
"(",
"self",
")",
":",
"with",
"assert_setup_component",
"(",
"0",
")",
":",
"assert",
"setup",
".",
"setup_component",
"(",
"self",
".",
"hass",
",",
"\"binary_sensor\"",
",",
"{",
"\"binary_sensor\"",
":",
"{",
"\"plat... | [
368,
4
] | [
374,
43
] | python | ca | ['es', 'ca', 'pt'] | False |
setup_platform | (hass, config, add_entities, discovery_info=None) | Set up the Avea platform. | Set up the Avea platform. | def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Avea platform."""
try:
nearby_bulbs = avea.discover_avea_bulbs()
for bulb in nearby_bulbs:
bulb.get_name()
bulb.get_brightness()
except OSError as err:
raise PlatformNotReady fr... | [
"def",
"setup_platform",
"(",
"hass",
",",
"config",
",",
"add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"try",
":",
"nearby_bulbs",
"=",
"avea",
".",
"discover_avea_bulbs",
"(",
")",
"for",
"bulb",
"in",
"nearby_bulbs",
":",
"bulb",
".",
"g... | [
16,
0
] | [
26,
58
] | python | en | ['en', 'da', 'en'] | True |
AveaLight.__init__ | (self, light) | Initialize an AveaLight. | Initialize an AveaLight. | def __init__(self, light):
"""Initialize an AveaLight."""
self._light = light
self._attr_name = light.name
self._attr_brightness = light.brightness | [
"def",
"__init__",
"(",
"self",
",",
"light",
")",
":",
"self",
".",
"_light",
"=",
"light",
"self",
".",
"_attr_name",
"=",
"light",
".",
"name",
"self",
".",
"_attr_brightness",
"=",
"light",
".",
"brightness"
] | [
34,
4
] | [
38,
48
] | python | en | ['en', 'lb', 'it'] | False |
AveaLight.turn_on | (self, **kwargs) | Instruct the light to turn on. | Instruct the light to turn on. | def turn_on(self, **kwargs):
"""Instruct the light to turn on."""
if not kwargs:
self._light.set_brightness(4095)
else:
if ATTR_BRIGHTNESS in kwargs:
bright = round((kwargs[ATTR_BRIGHTNESS] / 255) * 4095)
self._light.set_brightness(bright)
... | [
"def",
"turn_on",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"kwargs",
":",
"self",
".",
"_light",
".",
"set_brightness",
"(",
"4095",
")",
"else",
":",
"if",
"ATTR_BRIGHTNESS",
"in",
"kwargs",
":",
"bright",
"=",
"round",
"(",
"(",... | [
40,
4
] | [
50,
59
] | python | en | ['en', 'en', 'en'] | True |
AveaLight.turn_off | (self, **kwargs) | Instruct the light to turn off. | Instruct the light to turn off. | def turn_off(self, **kwargs):
"""Instruct the light to turn off."""
self._light.set_brightness(0) | [
"def",
"turn_off",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"_light",
".",
"set_brightness",
"(",
"0",
")"
] | [
52,
4
] | [
54,
37
] | python | en | ['en', 'en', 'en'] | True |
AveaLight.update | (self) | Fetch new state data for this light.
This is the only method that should fetch new data for Home Assistant.
| Fetch new state data for this light. | def update(self):
"""Fetch new state data for this light.
This is the only method that should fetch new data for Home Assistant.
"""
brightness = self._light.get_brightness()
if brightness is not None:
self._attr_is_on = brightness != 0
self._attr_brightn... | [
"def",
"update",
"(",
"self",
")",
":",
"brightness",
"=",
"self",
".",
"_light",
".",
"get_brightness",
"(",
")",
"if",
"brightness",
"is",
"not",
"None",
":",
"self",
".",
"_attr_is_on",
"=",
"brightness",
"!=",
"0",
"self",
".",
"_attr_brightness",
"=... | [
56,
4
] | [
64,
68
] | python | en | ['en', 'en', 'en'] | True |
async_remove_shelly_entity | (
hass: HomeAssistant, domain: str, unique_id: str
) | Remove a Shelly entity. | Remove a Shelly entity. | async def async_remove_shelly_entity(
hass: HomeAssistant, domain: str, unique_id: str
) -> None:
"""Remove a Shelly entity."""
entity_reg = await hass.helpers.entity_registry.async_get_registry()
entity_id = entity_reg.async_get_entity_id(domain, DOMAIN, unique_id)
if entity_id:
_LOGGER.deb... | [
"async",
"def",
"async_remove_shelly_entity",
"(",
"hass",
":",
"HomeAssistant",
",",
"domain",
":",
"str",
",",
"unique_id",
":",
"str",
")",
"->",
"None",
":",
"entity_reg",
"=",
"await",
"hass",
".",
"helpers",
".",
"entity_registry",
".",
"async_get_regist... | [
29,
0
] | [
37,
42
] | python | en | ['en', 'it', 'en'] | True |
temperature_unit | (block_info: dict[str, Any]) | Detect temperature unit. | Detect temperature unit. | def temperature_unit(block_info: dict[str, Any]) -> str:
"""Detect temperature unit."""
if block_info[aioshelly.BLOCK_VALUE_UNIT] == "F":
return TEMP_FAHRENHEIT
return TEMP_CELSIUS | [
"def",
"temperature_unit",
"(",
"block_info",
":",
"dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"str",
":",
"if",
"block_info",
"[",
"aioshelly",
".",
"BLOCK_VALUE_UNIT",
"]",
"==",
"\"F\"",
":",
"return",
"TEMP_FAHRENHEIT",
"return",
"TEMP_CELSIUS"
] | [
40,
0
] | [
44,
23
] | python | en | ['en', 'la', 'en'] | True |
get_device_name | (device: aioshelly.Device) | Naming for device. | Naming for device. | def get_device_name(device: aioshelly.Device) -> str:
"""Naming for device."""
return cast(str, device.settings["name"] or device.settings["device"]["hostname"]) | [
"def",
"get_device_name",
"(",
"device",
":",
"aioshelly",
".",
"Device",
")",
"->",
"str",
":",
"return",
"cast",
"(",
"str",
",",
"device",
".",
"settings",
"[",
"\"name\"",
"]",
"or",
"device",
".",
"settings",
"[",
"\"device\"",
"]",
"[",
"\"hostname... | [
47,
0
] | [
49,
86
] | python | en | ['da', 'en', 'en'] | True |
get_number_of_channels | (device: aioshelly.Device, block: aioshelly.Block) | Get number of channels for block type. | Get number of channels for block type. | def get_number_of_channels(device: aioshelly.Device, block: aioshelly.Block) -> int:
"""Get number of channels for block type."""
channels = None
if block.type == "input":
# Shelly Dimmer/1L has two input channels and missing "num_inputs"
if device.settings["device"]["type"] in ["SHDM-1", "... | [
"def",
"get_number_of_channels",
"(",
"device",
":",
"aioshelly",
".",
"Device",
",",
"block",
":",
"aioshelly",
".",
"Block",
")",
"->",
"int",
":",
"channels",
"=",
"None",
"if",
"block",
".",
"type",
"==",
"\"input\"",
":",
"# Shelly Dimmer/1L has two input... | [
52,
0
] | [
69,
24
] | python | en | ['en', 'en', 'en'] | True |
get_entity_name | (
device: aioshelly.Device,
block: aioshelly.Block,
description: str | None = None,
) | Naming for switch and sensors. | Naming for switch and sensors. | def get_entity_name(
device: aioshelly.Device,
block: aioshelly.Block,
description: str | None = None,
) -> str:
"""Naming for switch and sensors."""
channel_name = get_device_channel_name(device, block)
if description:
return f"{channel_name} {description}"
return channel_name | [
"def",
"get_entity_name",
"(",
"device",
":",
"aioshelly",
".",
"Device",
",",
"block",
":",
"aioshelly",
".",
"Block",
",",
"description",
":",
"str",
"|",
"None",
"=",
"None",
",",
")",
"->",
"str",
":",
"channel_name",
"=",
"get_device_channel_name",
"(... | [
72,
0
] | [
83,
23
] | python | en | ['en', 'en', 'en'] | True |
get_device_channel_name | (
device: aioshelly.Device,
block: aioshelly.Block,
) | Get name based on device and channel name. | Get name based on device and channel name. | def get_device_channel_name(
device: aioshelly.Device,
block: aioshelly.Block,
) -> str:
"""Get name based on device and channel name."""
entity_name = get_device_name(device)
if (
not block
or block.type == "device"
or get_number_of_channels(device, block) == 1
):
... | [
"def",
"get_device_channel_name",
"(",
"device",
":",
"aioshelly",
".",
"Device",
",",
"block",
":",
"aioshelly",
".",
"Block",
",",
")",
"->",
"str",
":",
"entity_name",
"=",
"get_device_name",
"(",
"device",
")",
"if",
"(",
"not",
"block",
"or",
"block",... | [
86,
0
] | [
113,
66
] | python | en | ['en', 'en', 'en'] | True |
is_momentary_input | (settings: dict[str, Any], block: aioshelly.Block) | Return true if input button settings is set to a momentary type. | Return true if input button settings is set to a momentary type. | def is_momentary_input(settings: dict[str, Any], block: aioshelly.Block) -> bool:
"""Return true if input button settings is set to a momentary type."""
# Shelly Button type is fixed to momentary and no btn_type
if settings["device"]["type"] in SHBTN_MODELS:
return True
button = settings.get("r... | [
"def",
"is_momentary_input",
"(",
"settings",
":",
"dict",
"[",
"str",
",",
"Any",
"]",
",",
"block",
":",
"aioshelly",
".",
"Block",
")",
"->",
"bool",
":",
"# Shelly Button type is fixed to momentary and no btn_type",
"if",
"settings",
"[",
"\"device\"",
"]",
... | [
116,
0
] | [
135,
63
] | python | en | ['en', 'en', 'en'] | True |
get_device_uptime | (status: dict[str, Any], last_uptime: str | None) | Return device uptime string, tolerate up to 5 seconds deviation. | Return device uptime string, tolerate up to 5 seconds deviation. | def get_device_uptime(status: dict[str, Any], last_uptime: str | None) -> str:
"""Return device uptime string, tolerate up to 5 seconds deviation."""
delta_uptime = utcnow() - timedelta(seconds=status["uptime"])
if (
not last_uptime
or abs((delta_uptime - datetime.fromisoformat(last_uptime)... | [
"def",
"get_device_uptime",
"(",
"status",
":",
"dict",
"[",
"str",
",",
"Any",
"]",
",",
"last_uptime",
":",
"str",
"|",
"None",
")",
"->",
"str",
":",
"delta_uptime",
"=",
"utcnow",
"(",
")",
"-",
"timedelta",
"(",
"seconds",
"=",
"status",
"[",
"\... | [
138,
0
] | [
149,
22
] | python | en | ['en', 'en', 'en'] | True |
get_input_triggers | (
device: aioshelly.Device, block: aioshelly.Block
) | Return list of input triggers for block. | Return list of input triggers for block. | def get_input_triggers(
device: aioshelly.Device, block: aioshelly.Block
) -> list[tuple[str, str]]:
"""Return list of input triggers for block."""
if "inputEvent" not in block.sensor_ids or "inputEventCnt" not in block.sensor_ids:
return []
if not is_momentary_input(device.settings, block):
... | [
"def",
"get_input_triggers",
"(",
"device",
":",
"aioshelly",
".",
"Device",
",",
"block",
":",
"aioshelly",
".",
"Block",
")",
"->",
"list",
"[",
"tuple",
"[",
"str",
",",
"str",
"]",
"]",
":",
"if",
"\"inputEvent\"",
"not",
"in",
"block",
".",
"senso... | [
152,
0
] | [
179,
19
] | python | en | ['en', 'en', 'en'] | True |
get_coap_context | (hass: HomeAssistant) | Get CoAP context to be used in all Shelly devices. | Get CoAP context to be used in all Shelly devices. | async def get_coap_context(hass: HomeAssistant) -> aioshelly.COAP:
"""Get CoAP context to be used in all Shelly devices."""
context = aioshelly.COAP()
if DOMAIN in hass.data:
port = hass.data[DOMAIN].get(CONF_COAP_PORT, DEFAULT_COAP_PORT)
else:
port = DEFAULT_COAP_PORT
_LOGGER.info("... | [
"async",
"def",
"get_coap_context",
"(",
"hass",
":",
"HomeAssistant",
")",
"->",
"aioshelly",
".",
"COAP",
":",
"context",
"=",
"aioshelly",
".",
"COAP",
"(",
")",
"if",
"DOMAIN",
"in",
"hass",
".",
"data",
":",
"port",
"=",
"hass",
".",
"data",
"[",
... | [
183,
0
] | [
199,
18
] | python | en | ['en', 'en', 'en'] | True |
get_device_sleep_period | (settings: dict[str, Any]) | Return the device sleep period in seconds or 0 for non sleeping devices. | Return the device sleep period in seconds or 0 for non sleeping devices. | def get_device_sleep_period(settings: dict[str, Any]) -> int:
"""Return the device sleep period in seconds or 0 for non sleeping devices."""
sleep_period = 0
if settings.get("sleep_mode", False):
sleep_period = settings["sleep_mode"]["period"]
if settings["sleep_mode"]["unit"] == "h":
... | [
"def",
"get_device_sleep_period",
"(",
"settings",
":",
"dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"int",
":",
"sleep_period",
"=",
"0",
"if",
"settings",
".",
"get",
"(",
"\"sleep_mode\"",
",",
"False",
")",
":",
"sleep_period",
"=",
"settings",
"[... | [
202,
0
] | [
211,
28
] | python | en | ['en', 'en', 'en'] | True |
set_enabled | (component, enabled=True) |
Enable a component for evaluation. If set to False, the component is
skipped, and all components that require it will not execute.
If component is a fully qualified name string of a callable object
instead of the callable object itself, the component's module is loaded
as a side effect of calling ... |
Enable a component for evaluation. If set to False, the component is
skipped, and all components that require it will not execute. | def set_enabled(component, enabled=True):
"""
Enable a component for evaluation. If set to False, the component is
skipped, and all components that require it will not execute.
If component is a fully qualified name string of a callable object
instead of the callable object itself, the component's ... | [
"def",
"set_enabled",
"(",
"component",
",",
"enabled",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"component",
",",
"six",
".",
"string_types",
")",
":",
"component",
"=",
"get_component",
"(",
"component",
")",
"if",
"component",
":",
"ENABLED",
"["... | [
88,
0
] | [
109,
36
] | python | en | ['en', 'error', 'th'] | False |
is_enabled | (component) |
Check to see if a component is enabled.
Args:
component (callable): The component to check. The component must
already be loaded.
Returns:
True if the component is enabled. False otherwise.
|
Check to see if a component is enabled. | def is_enabled(component):
"""
Check to see if a component is enabled.
Args:
component (callable): The component to check. The component must
already be loaded.
Returns:
True if the component is enabled. False otherwise.
"""
return ENABLED[component] | [
"def",
"is_enabled",
"(",
"component",
")",
":",
"return",
"ENABLED",
"[",
"component",
"]"
] | [
112,
0
] | [
123,
29
] | python | en | ['en', 'error', 'th'] | False |
_import_component | (name) |
Returns a class, function, or class method specified by the fully qualified
name.
|
Returns a class, function, or class method specified by the fully qualified
name.
| def _import_component(name):
"""
Returns a class, function, or class method specified by the fully qualified
name.
"""
for f in (_get_from_module, _get_from_class):
try:
return f(name)
except:
pass | [
"def",
"_import_component",
"(",
"name",
")",
":",
"for",
"f",
"in",
"(",
"_get_from_module",
",",
"_get_from_class",
")",
":",
"try",
":",
"return",
"f",
"(",
"name",
")",
"except",
":",
"pass"
] | [
155,
0
] | [
164,
16
] | python | en | ['en', 'error', 'th'] | False |
get_component | (name) | Returns the class or function specified, importing it if necessary. | Returns the class or function specified, importing it if necessary. | def get_component(name):
""" Returns the class or function specified, importing it if necessary. """
return COMPONENT_IMPORT_CACHE[name] | [
"def",
"get_component",
"(",
"name",
")",
":",
"return",
"COMPONENT_IMPORT_CACHE",
"[",
"name",
"]"
] | [
170,
0
] | [
172,
39
] | python | en | ['en', 'en', 'en'] | True |
get_component_by_name | (name) |
Look up a component by its fully qualified name. Return None if the
component hasn't been loaded.
|
Look up a component by its fully qualified name. Return None if the
component hasn't been loaded.
| def get_component_by_name(name):
"""
Look up a component by its fully qualified name. Return None if the
component hasn't been loaded.
"""
return COMPONENTS_BY_NAME[name] | [
"def",
"get_component_by_name",
"(",
"name",
")",
":",
"return",
"COMPONENTS_BY_NAME",
"[",
"name",
"]"
] | [
184,
0
] | [
189,
35
] | python | en | ['en', 'error', 'th'] | False |
get_name | (component) |
Attempt to get the string name of component, including module and class if
applicable.
|
Attempt to get the string name of component, including module and class if
applicable.
| def get_name(component):
"""
Attempt to get the string name of component, including module and class if
applicable.
"""
if six.callable(component):
name = getattr(component, "__qualname__", component.__name__)
return '.'.join([component.__module__, name])
return str(component) | [
"def",
"get_name",
"(",
"component",
")",
":",
"if",
"six",
".",
"callable",
"(",
"component",
")",
":",
"name",
"=",
"getattr",
"(",
"component",
",",
"\"__qualname__\"",
",",
"component",
".",
"__name__",
")",
"return",
"'.'",
".",
"join",
"(",
"[",
... | [
240,
0
] | [
248,
25
] | python | en | ['en', 'error', 'th'] | False |
get_metadata | (component) |
Return any metadata dictionary associated with the component. Defaults to
an empty dictionary.
|
Return any metadata dictionary associated with the component. Defaults to
an empty dictionary.
| def get_metadata(component):
"""
Return any metadata dictionary associated with the component. Defaults to
an empty dictionary.
"""
return get_delegate(component).metadata if component in DELEGATES else {} | [
"def",
"get_metadata",
"(",
"component",
")",
":",
"return",
"get_delegate",
"(",
"component",
")",
".",
"metadata",
"if",
"component",
"in",
"DELEGATES",
"else",
"{",
"}"
] | [
257,
0
] | [
262,
77
] | python | en | ['en', 'error', 'th'] | False |
get_tags | (component) |
Return the set of tags associated with the component. Defaults to
``set()``.
|
Return the set of tags associated with the component. Defaults to
``set()``.
| def get_tags(component):
"""
Return the set of tags associated with the component. Defaults to
``set()``.
"""
return get_delegate(component).tags if component in DELEGATES else set() | [
"def",
"get_tags",
"(",
"component",
")",
":",
"return",
"get_delegate",
"(",
"component",
")",
".",
"tags",
"if",
"component",
"in",
"DELEGATES",
"else",
"set",
"(",
")"
] | [
265,
0
] | [
270,
76
] | python | en | ['en', 'error', 'th'] | False |
get_links | (component) |
Return the dictionary of links associated with the component. Defaults to
``dict()``.
|
Return the dictionary of links associated with the component. Defaults to
``dict()``.
| def get_links(component):
"""
Return the dictionary of links associated with the component. Defaults to
``dict()``.
"""
return get_delegate(component).links if component in DELEGATES else dict() | [
"def",
"get_links",
"(",
"component",
")",
":",
"return",
"get_delegate",
"(",
"component",
")",
".",
"links",
"if",
"component",
"in",
"DELEGATES",
"else",
"dict",
"(",
")"
] | [
273,
0
] | [
278,
78
] | python | en | ['en', 'error', 'th'] | False |
walk_dependencies | (root, visitor) |
Call visitor on root and all dependencies reachable from it in breadth
first order.
Args:
root (component): component function or class
visitor (function): signature is `func(component, parent)`. The
call on root is `visitor(root, None)`.
|
Call visitor on root and all dependencies reachable from it in breadth
first order. | def walk_dependencies(root, visitor):
"""
Call visitor on root and all dependencies reachable from it in breadth
first order.
Args:
root (component): component function or class
visitor (function): signature is `func(component, parent)`. The
call on root is `visitor(root, N... | [
"def",
"walk_dependencies",
"(",
"root",
",",
"visitor",
")",
":",
"def",
"visit",
"(",
"parent",
",",
"visitor",
")",
":",
"for",
"d",
"in",
"get_dependencies",
"(",
"parent",
")",
":",
"visitor",
"(",
"d",
",",
"parent",
")",
"visit",
"(",
"d",
","... | [
314,
0
] | [
330,
24
] | python | en | ['en', 'error', 'th'] | False |
get_dependency_graph | (component) |
Generate a component's graph of dependencies, which can be passed to
:func:`run` or :func:`run_incremental`.
|
Generate a component's graph of dependencies, which can be passed to
:func:`run` or :func:`run_incremental`.
| def get_dependency_graph(component):
"""
Generate a component's graph of dependencies, which can be passed to
:func:`run` or :func:`run_incremental`.
"""
if component not in DEPENDENCIES:
raise Exception("%s is not a registered component." % get_name(component))
if not DEPENDENCIES[comp... | [
"def",
"get_dependency_graph",
"(",
"component",
")",
":",
"if",
"component",
"not",
"in",
"DEPENDENCIES",
":",
"raise",
"Exception",
"(",
"\"%s is not a registered component.\"",
"%",
"get_name",
"(",
"component",
")",
")",
"if",
"not",
"DEPENDENCIES",
"[",
"comp... | [
333,
0
] | [
360,
16
] | python | en | ['en', 'error', 'th'] | False |
get_subgraphs | (graph=None) |
Given a graph of possibly disconnected components, generate all graphs of
connected components. graph is a dictionary of dependencies. Keys are
components, and values are sets of components on which they depend.
|
Given a graph of possibly disconnected components, generate all graphs of
connected components. graph is a dictionary of dependencies. Keys are
components, and values are sets of components on which they depend.
| def get_subgraphs(graph=None):
"""
Given a graph of possibly disconnected components, generate all graphs of
connected components. graph is a dictionary of dependencies. Keys are
components, and values are sets of components on which they depend.
"""
graph = graph or DEPENDENCIES
keys = set(... | [
"def",
"get_subgraphs",
"(",
"graph",
"=",
"None",
")",
":",
"graph",
"=",
"graph",
"or",
"DEPENDENCIES",
"keys",
"=",
"set",
"(",
"graph",
")",
"frontier",
"=",
"set",
"(",
")",
"seen",
"=",
"set",
"(",
")",
"while",
"keys",
":",
"frontier",
".",
... | [
363,
0
] | [
383,
20
] | python | en | ['en', 'error', 'th'] | False |
load_components | (*paths, **kwargs) |
Loads all components on the paths. Each path should be a package or module.
All components beneath a path are loaded.
Args:
paths (str): A package or module to load
Keyword Args:
include (str): A regular expression of packages and modules to include.
Defaults to '.*'
... |
Loads all components on the paths. Each path should be a package or module.
All components beneath a path are loaded. | def load_components(*paths, **kwargs):
"""
Loads all components on the paths. Each path should be a package or module.
All components beneath a path are loaded.
Args:
paths (str): A package or module to load
Keyword Args:
include (str): A regular expression of packages and modules ... | [
"def",
"load_components",
"(",
"*",
"paths",
",",
"*",
"*",
"kwargs",
")",
":",
"num_loaded",
"=",
"0",
"for",
"path",
"in",
"paths",
":",
"num_loaded",
"+=",
"_load_components",
"(",
"path",
",",
"*",
"*",
"kwargs",
")",
"return",
"num_loaded"
] | [
428,
0
] | [
453,
21
] | python | en | ['en', 'error', 'th'] | False |
get_missing_requirements | (func, requires, d) |
.. deprecated:: 1.x
|
.. deprecated:: 1.x
| def get_missing_requirements(func, requires, d):
"""
.. deprecated:: 1.x
"""
if not requires:
return None
if any(i in d for i in IGNORE.get(func, [])):
raise SkipComponent()
req_all, req_any = split_requirements(requires)
d = set(d.keys())
req_all = [r for r in req_all if... | [
"def",
"get_missing_requirements",
"(",
"func",
",",
"requires",
",",
"d",
")",
":",
"if",
"not",
"requires",
":",
"return",
"None",
"if",
"any",
"(",
"i",
"in",
"d",
"for",
"i",
"in",
"IGNORE",
".",
"get",
"(",
"func",
",",
"[",
"]",
")",
")",
"... | [
854,
0
] | [
869,
19
] | python | en | ['en', 'error', 'th'] | False |
add_observer | (o, component_type=ComponentType) |
Add a callback that will get invoked after each component is called.
Args:
o (func): the callback function
Keyword Args:
component_type (ComponentType): the :class:`ComponentType` to observe.
The callback will fire any time an instance of the class or its
subclasse... |
Add a callback that will get invoked after each component is called. | def add_observer(o, component_type=ComponentType):
"""
Add a callback that will get invoked after each component is called.
Args:
o (func): the callback function
Keyword Args:
component_type (ComponentType): the :class:`ComponentType` to observe.
The callback will fire any ... | [
"def",
"add_observer",
"(",
"o",
",",
"component_type",
"=",
"ComponentType",
")",
":",
"TYPE_OBSERVERS",
"[",
"component_type",
"]",
".",
"add",
"(",
"o",
")"
] | [
872,
0
] | [
895,
41
] | python | en | ['en', 'error', 'th'] | False |
observer | (component_type=ComponentType) |
You can use ``@broker.observer()`` as a decorator to your callback
instead of :func:`add_observer`.
|
You can use `` | def observer(component_type=ComponentType):
"""
You can use ``@broker.observer()`` as a decorator to your callback
instead of :func:`add_observer`.
"""
def inner(func):
add_observer(func, component_type)
return func
return inner | [
"def",
"observer",
"(",
"component_type",
"=",
"ComponentType",
")",
":",
"def",
"inner",
"(",
"func",
")",
":",
"add_observer",
"(",
"func",
",",
"component_type",
")",
"return",
"func",
"return",
"inner"
] | [
898,
0
] | [
906,
16
] | python | en | ['en', 'error', 'th'] | False |
run_order | (graph) |
Returns components in an order that satisfies their dependency
relationships.
|
Returns components in an order that satisfies their dependency
relationships.
| def run_order(graph):
"""
Returns components in an order that satisfies their dependency
relationships.
"""
return toposort_flatten(graph, sort=False) | [
"def",
"run_order",
"(",
"graph",
")",
":",
"return",
"toposort_flatten",
"(",
"graph",
",",
"sort",
"=",
"False",
")"
] | [
909,
0
] | [
914,
46
] | python | en | ['en', 'error', 'th'] | False |
run | (components=None, broker=None) |
Executes components in an order that satisfies their dependency
relationships.
Keyword Args:
components: Can be one of a dependency graph, a single component, a
component group, or a component type. If it's anything other than a
dependency graph, the appropriate graph is bu... |
Executes components in an order that satisfies their dependency
relationships. | def run(components=None, broker=None):
"""
Executes components in an order that satisfies their dependency
relationships.
Keyword Args:
components: Can be one of a dependency graph, a single component, a
component group, or a component type. If it's anything other than a
... | [
"def",
"run",
"(",
"components",
"=",
"None",
",",
"broker",
"=",
"None",
")",
":",
"components",
"=",
"components",
"or",
"COMPONENTS",
"[",
"GROUPS",
".",
"single",
"]",
"components",
"=",
"_determine_components",
"(",
"components",
")",
"broker",
"=",
"... | [
937,
0
] | [
982,
17
] | python | en | ['en', 'error', 'th'] | False |
run_incremental | (components=None, broker=None) |
Executes components in an order that satisfies their dependency
relationships. Disjoint subgraphs are executed one at a time and a broker
containing the results for each is yielded. If a broker is passed here, its
instances are used to seed the broker used to hold state for each sub
graph.
Key... |
Executes components in an order that satisfies their dependency
relationships. Disjoint subgraphs are executed one at a time and a broker
containing the results for each is yielded. If a broker is passed here, its
instances are used to seed the broker used to hold state for each sub
graph. | def run_incremental(components=None, broker=None):
"""
Executes components in an order that satisfies their dependency
relationships. Disjoint subgraphs are executed one at a time and a broker
containing the results for each is yielded. If a broker is passed here, its
instances are used to seed the ... | [
"def",
"run_incremental",
"(",
"components",
"=",
"None",
",",
"broker",
"=",
"None",
")",
":",
"for",
"graph",
",",
"_broker",
"in",
"generate_incremental",
"(",
"components",
",",
"broker",
")",
":",
"yield",
"run",
"(",
"graph",
",",
"broker",
"=",
"_... | [
994,
0
] | [
1014,
40
] | python | en | ['en', 'error', 'th'] | False |
ComponentType.__init__ | (self, *deps, **kwargs) |
This constructor is the parameterized part of a decorator.
|
This constructor is the parameterized part of a decorator.
| def __init__(self, *deps, **kwargs):
"""
This constructor is the parameterized part of a decorator.
"""
for k, v in kwargs.items():
setattr(self, k, v)
self.component = None
self.requires = []
self.at_least_one = []
self.deps = []
sel... | [
"def",
"__init__",
"(",
"self",
",",
"*",
"deps",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"k",
",",
"v",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"setattr",
"(",
"self",
",",
"k",
",",
"v",
")",
"self",
".",
"component",
"=",
"None",
"s... | [
594,
4
] | [
640,
29
] | python | en | ['en', 'error', 'th'] | False |
ComponentType.__call__ | (self, component) |
This function is the part of the decorator that receives the function
or class.
|
This function is the part of the decorator that receives the function
or class.
| def __call__(self, component):
"""
This function is the part of the decorator that receives the function
or class.
"""
self.component = component
self.__name__ = component.__name__
self.__module__ = component.__module__
self.__doc__ = component.__doc__
... | [
"def",
"__call__",
"(",
"self",
",",
"component",
")",
":",
"self",
".",
"component",
"=",
"component",
"self",
".",
"__name__",
"=",
"component",
".",
"__name__",
"self",
".",
"__module__",
"=",
"component",
".",
"__module__",
"self",
".",
"__doc__",
"=",... | [
642,
4
] | [
655,
24
] | python | en | ['en', 'error', 'th'] | False |
ComponentType.invoke | (self, results) |
Handles invocation of the component. The default implementation invokes
it with positional arguments based on order of dependency declaration.
|
Handles invocation of the component. The default implementation invokes
it with positional arguments based on order of dependency declaration.
| def invoke(self, results):
"""
Handles invocation of the component. The default implementation invokes
it with positional arguments based on order of dependency declaration.
"""
args = [results.get(d) for d in self.deps]
return self.component(*args) | [
"def",
"invoke",
"(",
"self",
",",
"results",
")",
":",
"args",
"=",
"[",
"results",
".",
"get",
"(",
"d",
")",
"for",
"d",
"in",
"self",
".",
"deps",
"]",
"return",
"self",
".",
"component",
"(",
"*",
"args",
")"
] | [
657,
4
] | [
663,
36
] | python | en | ['en', 'error', 'th'] | False |
ComponentType.get_missing_dependencies | (self, broker) |
Gets required and at-least-one dependencies not provided by the broker.
|
Gets required and at-least-one dependencies not provided by the broker.
| def get_missing_dependencies(self, broker):
"""
Gets required and at-least-one dependencies not provided by the broker.
"""
missing_required = [r for r in self.requires if r not in broker]
missing_at_least_one = [d for d in self.at_least_one if not set(d).intersection(broker)]
... | [
"def",
"get_missing_dependencies",
"(",
"self",
",",
"broker",
")",
":",
"missing_required",
"=",
"[",
"r",
"for",
"r",
"in",
"self",
".",
"requires",
"if",
"r",
"not",
"in",
"broker",
"]",
"missing_at_least_one",
"=",
"[",
"d",
"for",
"d",
"in",
"self",... | [
665,
4
] | [
672,
59
] | python | en | ['en', 'error', 'th'] | False |
ComponentType.process | (self, broker) |
Ensures dependencies have been met before delegating to `self.invoke`.
|
Ensures dependencies have been met before delegating to `self.invoke`.
| def process(self, broker):
"""
Ensures dependencies have been met before delegating to `self.invoke`.
"""
if any(i in broker for i in IGNORE.get(self.component, [])):
raise SkipComponent()
missing = self.get_missing_dependencies(broker)
if missing:
... | [
"def",
"process",
"(",
"self",
",",
"broker",
")",
":",
"if",
"any",
"(",
"i",
"in",
"broker",
"for",
"i",
"in",
"IGNORE",
".",
"get",
"(",
"self",
".",
"component",
",",
"[",
"]",
")",
")",
":",
"raise",
"SkipComponent",
"(",
")",
"missing",
"="... | [
674,
4
] | [
683,
34
] | python | en | ['en', 'error', 'th'] | False |
Broker.observer | (self, component_type=ComponentType) |
You can use ``@broker.observer()`` as a decorator to your callback
instead of :func:`Broker.add_observer`.
|
You can use `` | def observer(self, component_type=ComponentType):
"""
You can use ``@broker.observer()`` as a decorator to your callback
instead of :func:`Broker.add_observer`.
"""
def inner(func):
self.add_observer(func, component_type)
return func
return inner | [
"def",
"observer",
"(",
"self",
",",
"component_type",
"=",
"ComponentType",
")",
":",
"def",
"inner",
"(",
"func",
")",
":",
"self",
".",
"add_observer",
"(",
"func",
",",
"component_type",
")",
"return",
"func",
"return",
"inner"
] | [
745,
4
] | [
753,
20
] | python | en | ['en', 'error', 'th'] | False |
Broker.add_observer | (self, o, component_type=ComponentType) |
Add a callback that will get invoked after each component is called.
Args:
o (func): the callback function
Keyword Args:
component_type (ComponentType): the :class:`ComponentType` to observe.
The callback will fire any time an instance of the class or i... |
Add a callback that will get invoked after each component is called. | def add_observer(self, o, component_type=ComponentType):
"""
Add a callback that will get invoked after each component is called.
Args:
o (func): the callback function
Keyword Args:
component_type (ComponentType): the :class:`ComponentType` to observe.
... | [
"def",
"add_observer",
"(",
"self",
",",
"o",
",",
"component_type",
"=",
"ComponentType",
")",
":",
"self",
".",
"observers",
"[",
"component_type",
"]",
".",
"add",
"(",
"o",
")"
] | [
755,
4
] | [
777,
45
] | python | en | ['en', 'error', 'th'] | False |
Broker.get_by_type | (self, _type) |
Return all of the instances of :class:`ComponentType` ``_type``.
|
Return all of the instances of :class:`ComponentType` ``_type``.
| def get_by_type(self, _type):
"""
Return all of the instances of :class:`ComponentType` ``_type``.
"""
r = {}
for k, v in self.items():
if get_component_type(k) is _type:
r[k] = v
return r | [
"def",
"get_by_type",
"(",
"self",
",",
"_type",
")",
":",
"r",
"=",
"{",
"}",
"for",
"k",
",",
"v",
"in",
"self",
".",
"items",
"(",
")",
":",
"if",
"get_component_type",
"(",
"k",
")",
"is",
"_type",
":",
"r",
"[",
"k",
"]",
"=",
"v",
"retu... | [
811,
4
] | [
819,
16
] | python | en | ['en', 'error', 'th'] | False |
async_setup_platform | (hass, config, async_add_entities, discovery_info=None) | Set up the Netdata sensor. | Set up the Netdata sensor. | async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
"""Set up the Netdata sensor."""
name = config.get(CONF_NAME)
host = config.get(CONF_HOST)
port = config.get(CONF_PORT)
resources = config.get(CONF_RESOURCES)
session = async_get_clientsession(hass)
netd... | [
"async",
"def",
"async_setup_platform",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
",",
"discovery_info",
"=",
"None",
")",
":",
"name",
"=",
"config",
".",
"get",
"(",
"CONF_NAME",
")",
"host",
"=",
"config",
".",
"get",
"(",
"CONF_HOST",
")",... | [
55,
0
] | [
95,
33
] | python | en | ['en', 'da', 'en'] | True |
NetdataSensor.__init__ | (self, netdata, name, sensor, sensor_name, element, icon, unit, invert) | Initialize the Netdata sensor. | Initialize the Netdata sensor. | def __init__(self, netdata, name, sensor, sensor_name, element, icon, unit, invert):
"""Initialize the Netdata sensor."""
self.netdata = netdata
self._state = None
self._sensor = sensor
self._element = element
self._sensor_name = self._sensor if sensor_name is None else s... | [
"def",
"__init__",
"(",
"self",
",",
"netdata",
",",
"name",
",",
"sensor",
",",
"sensor_name",
",",
"element",
",",
"icon",
",",
"unit",
",",
"invert",
")",
":",
"self",
".",
"netdata",
"=",
"netdata",
"self",
".",
"_state",
"=",
"None",
"self",
"."... | [
101,
4
] | [
111,
29
] | python | en | ['en', 'en', 'en'] | True |
NetdataSensor.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"{self._name} {self._sensor_name}" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._name} {self._sensor_name}\""
] | [
114,
4
] | [
116,
50
] | python | en | ['en', 'mi', 'en'] | True |
NetdataSensor.native_unit_of_measurement | (self) | Return the unit the value is expressed in. | Return the unit the value is expressed in. | def native_unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return self._unit_of_measurement | [
"def",
"native_unit_of_measurement",
"(",
"self",
")",
":",
"return",
"self",
".",
"_unit_of_measurement"
] | [
119,
4
] | [
121,
40
] | python | en | ['en', 'en', 'en'] | True |
NetdataSensor.icon | (self) | Return the icon to use in the frontend, if any. | Return the icon to use in the frontend, if any. | def icon(self):
"""Return the icon to use in the frontend, if any."""
return self._icon | [
"def",
"icon",
"(",
"self",
")",
":",
"return",
"self",
".",
"_icon"
] | [
124,
4
] | [
126,
25
] | python | en | ['en', 'en', 'en'] | True |
NetdataSensor.native_value | (self) | Return the state of the resources. | Return the state of the resources. | def native_value(self):
"""Return the state of the resources."""
return self._state | [
"def",
"native_value",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
129,
4
] | [
131,
26
] | python | en | ['en', 'en', 'en'] | True |
NetdataSensor.available | (self) | Could the resource be accessed during the last update call. | Could the resource be accessed during the last update call. | def available(self):
"""Could the resource be accessed during the last update call."""
return self.netdata.available | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"netdata",
".",
"available"
] | [
134,
4
] | [
136,
37
] | python | en | ['en', 'en', 'en'] | True |
NetdataSensor.async_update | (self) | Get the latest data from Netdata REST API. | Get the latest data from Netdata REST API. | async def async_update(self):
"""Get the latest data from Netdata REST API."""
await self.netdata.async_update()
resource_data = self.netdata.api.metrics.get(self._sensor)
self._state = round(resource_data["dimensions"][self._element]["value"], 2) * (
-1 if self._invert else ... | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"await",
"self",
".",
"netdata",
".",
"async_update",
"(",
")",
"resource_data",
"=",
"self",
".",
"netdata",
".",
"api",
".",
"metrics",
".",
"get",
"(",
"self",
".",
"_sensor",
")",
"self",
".",
... | [
138,
4
] | [
144,
9
] | python | en | ['en', 'en', 'en'] | True |
NetdataAlarms.__init__ | (self, netdata, name, host, port) | Initialize the Netdata alarm sensor. | Initialize the Netdata alarm sensor. | def __init__(self, netdata, name, host, port):
"""Initialize the Netdata alarm sensor."""
self.netdata = netdata
self._state = None
self._name = name
self._host = host
self._port = port | [
"def",
"__init__",
"(",
"self",
",",
"netdata",
",",
"name",
",",
"host",
",",
"port",
")",
":",
"self",
".",
"netdata",
"=",
"netdata",
"self",
".",
"_state",
"=",
"None",
"self",
".",
"_name",
"=",
"name",
"self",
".",
"_host",
"=",
"host",
"self... | [
150,
4
] | [
156,
25
] | python | en | ['en', 'da', 'en'] | True |
NetdataAlarms.name | (self) | Return the name of the sensor. | Return the name of the sensor. | def name(self):
"""Return the name of the sensor."""
return f"{self._name} Alarms" | [
"def",
"name",
"(",
"self",
")",
":",
"return",
"f\"{self._name} Alarms\""
] | [
159,
4
] | [
161,
37
] | python | en | ['en', 'mi', 'en'] | True |
NetdataAlarms.native_value | (self) | Return the state of the resources. | Return the state of the resources. | def native_value(self):
"""Return the state of the resources."""
return self._state | [
"def",
"native_value",
"(",
"self",
")",
":",
"return",
"self",
".",
"_state"
] | [
164,
4
] | [
166,
26
] | python | en | ['en', 'en', 'en'] | True |
NetdataAlarms.icon | (self) | Status symbol if type is symbol. | Status symbol if type is symbol. | def icon(self):
"""Status symbol if type is symbol."""
if self._state == "ok":
return "mdi:check"
if self._state == "warning":
return "mdi:alert-outline"
if self._state == "critical":
return "mdi:alert"
return "mdi:crosshairs-question" | [
"def",
"icon",
"(",
"self",
")",
":",
"if",
"self",
".",
"_state",
"==",
"\"ok\"",
":",
"return",
"\"mdi:check\"",
"if",
"self",
".",
"_state",
"==",
"\"warning\"",
":",
"return",
"\"mdi:alert-outline\"",
"if",
"self",
".",
"_state",
"==",
"\"critical\"",
... | [
169,
4
] | [
177,
40
] | python | en | ['en', 'la', 'en'] | True |
NetdataAlarms.available | (self) | Could the resource be accessed during the last update call. | Could the resource be accessed during the last update call. | def available(self):
"""Could the resource be accessed during the last update call."""
return self.netdata.available | [
"def",
"available",
"(",
"self",
")",
":",
"return",
"self",
".",
"netdata",
".",
"available"
] | [
180,
4
] | [
182,
37
] | python | en | ['en', 'en', 'en'] | True |
NetdataAlarms.async_update | (self) | Get the latest alarms from Netdata REST API. | Get the latest alarms from Netdata REST API. | async def async_update(self):
"""Get the latest alarms from Netdata REST API."""
await self.netdata.async_update()
alarms = self.netdata.api.alarms["alarms"]
self._state = None
number_of_alarms = len(alarms)
number_of_relevant_alarms = number_of_alarms
_LOGGER.de... | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"await",
"self",
".",
"netdata",
".",
"async_update",
"(",
")",
"alarms",
"=",
"self",
".",
"netdata",
".",
"api",
".",
"alarms",
"[",
"\"alarms\"",
"]",
"self",
".",
"_state",
"=",
"None",
"number... | [
184,
4
] | [
206,
75
] | python | en | ['en', 'en', 'en'] | True |
NetdataData.__init__ | (self, api) | Initialize the data object. | Initialize the data object. | def __init__(self, api):
"""Initialize the data object."""
self.api = api
self.available = True | [
"def",
"__init__",
"(",
"self",
",",
"api",
")",
":",
"self",
".",
"api",
"=",
"api",
"self",
".",
"available",
"=",
"True"
] | [
212,
4
] | [
215,
29
] | python | en | ['en', 'en', 'en'] | True |
NetdataData.async_update | (self) | Get the latest data from the Netdata REST API. | Get the latest data from the Netdata REST API. | async def async_update(self):
"""Get the latest data from the Netdata REST API."""
try:
await self.api.get_allmetrics()
await self.api.get_alarms()
self.available = True
except NetdataError:
_LOGGER.error("Unable to retrieve data from Netdata")
... | [
"async",
"def",
"async_update",
"(",
"self",
")",
":",
"try",
":",
"await",
"self",
".",
"api",
".",
"get_allmetrics",
"(",
")",
"await",
"self",
".",
"api",
".",
"get_alarms",
"(",
")",
"self",
".",
"available",
"=",
"True",
"except",
"NetdataError",
... | [
218,
4
] | [
227,
34
] | python | en | ['en', 'en', 'en'] | True |
async_setup | (hass, config) | Set up the versasense component. | Set up the versasense component. | async def async_setup(hass, config):
"""Set up the versasense component."""
session = aiohttp_client.async_get_clientsession(hass)
consumer = pyv.Consumer(config[DOMAIN]["host"], session)
hass.data[DOMAIN] = {KEY_CONSUMER: consumer}
await _configure_entities(hass, config, consumer)
# Return b... | [
"async",
"def",
"async_setup",
"(",
"hass",
",",
"config",
")",
":",
"session",
"=",
"aiohttp_client",
".",
"async_get_clientsession",
"(",
"hass",
")",
"consumer",
"=",
"pyv",
".",
"Consumer",
"(",
"config",
"[",
"DOMAIN",
"]",
"[",
"\"host\"",
"]",
",",
... | [
32,
0
] | [
42,
15
] | python | en | ['en', 'ky', 'en'] | True |
_configure_entities | (hass, config, consumer) | Fetch all devices with their peripherals for representation. | Fetch all devices with their peripherals for representation. | async def _configure_entities(hass, config, consumer):
"""Fetch all devices with their peripherals for representation."""
devices = await consumer.fetchDevices()
_LOGGER.debug(devices)
sensor_info_list = []
switch_info_list = []
for mac, device in devices.items():
_LOGGER.info("Device ... | [
"async",
"def",
"_configure_entities",
"(",
"hass",
",",
"config",
",",
"consumer",
")",
":",
"devices",
"=",
"await",
"consumer",
".",
"fetchDevices",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"devices",
")",
"sensor_info_list",
"=",
"[",
"]",
"switch_info_li... | [
45,
0
] | [
73,
64
] | python | en | ['en', 'en', 'en'] | True |
_add_entity_info_to_list | (peripheral, device, entity_info_list) | Add info from a peripheral to specified list. | Add info from a peripheral to specified list. | def _add_entity_info_to_list(peripheral, device, entity_info_list):
"""Add info from a peripheral to specified list."""
for measurement in peripheral.measurements:
entity_info = {
KEY_IDENTIFIER: peripheral.identifier,
KEY_UNIT: measurement.unit,
KEY_MEASUREMENT: meas... | [
"def",
"_add_entity_info_to_list",
"(",
"peripheral",
",",
"device",
",",
"entity_info_list",
")",
":",
"for",
"measurement",
"in",
"peripheral",
".",
"measurements",
":",
"entity_info",
"=",
"{",
"KEY_IDENTIFIER",
":",
"peripheral",
".",
"identifier",
",",
"KEY_U... | [
76,
0
] | [
89,
27
] | python | en | ['en', 'en', 'en'] | True |
_load_platform | (hass, config, entity_type, entity_info_list) | Load platform with list of entity info. | Load platform with list of entity info. | def _load_platform(hass, config, entity_type, entity_info_list):
"""Load platform with list of entity info."""
hass.async_create_task(
async_load_platform(hass, entity_type, DOMAIN, entity_info_list, config)
) | [
"def",
"_load_platform",
"(",
"hass",
",",
"config",
",",
"entity_type",
",",
"entity_info_list",
")",
":",
"hass",
".",
"async_create_task",
"(",
"async_load_platform",
"(",
"hass",
",",
"entity_type",
",",
"DOMAIN",
",",
"entity_info_list",
",",
"config",
")",... | [
92,
0
] | [
96,
5
] | python | en | ['en', 'en', 'en'] | True |
TestAnimal.make_instance | (self, include_optional) | Test Animal
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included | Test Animal
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included | def make_instance(self, include_optional):
"""Test Animal
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# model = petstore_api.models.animal.Animal() # noqa: E501
if inc... | [
"def",
"make_instance",
"(",
"self",
",",
"include_optional",
")",
":",
"# model = petstore_api.models.animal.Animal() # noqa: E501",
"if",
"include_optional",
":",
"return",
"Animal",
"(",
"class_name",
"=",
"''",
",",
"color",
"=",
"'red'",
")",
"else",
":",
"ret... | [
30,
4
] | [
44,
9
] | python | en | ['en', 'et', 'en'] | False |
TestAnimal.testAnimal | (self) | Test Animal | Test Animal | def testAnimal(self):
"""Test Animal"""
inst_req_only = self.make_instance(include_optional=False)
inst_req_and_optional = self.make_instance(include_optional=True) | [
"def",
"testAnimal",
"(",
"self",
")",
":",
"inst_req_only",
"=",
"self",
".",
"make_instance",
"(",
"include_optional",
"=",
"False",
")",
"inst_req_and_optional",
"=",
"self",
".",
"make_instance",
"(",
"include_optional",
"=",
"True",
")"
] | [
46,
4
] | [
49,
73
] | python | en | ['en', 'et', 'en'] | False |
async_setup_entry | (hass, config, async_add_entities) | Initialize a Blink sensor. | Initialize a Blink sensor. | async def async_setup_entry(hass, config, async_add_entities):
"""Initialize a Blink sensor."""
data = hass.data[DOMAIN][config.entry_id]
entities = [
BlinkSensor(data, camera, description)
for camera in data.cameras
for description in SENSOR_TYPES
]
async_add_entities(entit... | [
"async",
"def",
"async_setup_entry",
"(",
"hass",
",",
"config",
",",
"async_add_entities",
")",
":",
"data",
"=",
"hass",
".",
"data",
"[",
"DOMAIN",
"]",
"[",
"config",
".",
"entry_id",
"]",
"entities",
"=",
"[",
"BlinkSensor",
"(",
"data",
",",
"camer... | [
33,
0
] | [
42,
32
] | python | da | ['en', 'da', 'it'] | False |
BlinkSensor.__init__ | (self, data, camera, description: SensorEntityDescription) | Initialize sensors from Blink camera. | Initialize sensors from Blink camera. | def __init__(self, data, camera, description: SensorEntityDescription):
"""Initialize sensors from Blink camera."""
self.entity_description = description
self._attr_name = f"{DOMAIN} {camera} {description.name}"
self.data = data
self._camera = data.cameras[camera]
self._a... | [
"def",
"__init__",
"(",
"self",
",",
"data",
",",
"camera",
",",
"description",
":",
"SensorEntityDescription",
")",
":",
"self",
".",
"entity_description",
"=",
"description",
"self",
".",
"_attr_name",
"=",
"f\"{DOMAIN} {camera} {description.name}\"",
"self",
".",... | [
48,
4
] | [
59,
9
] | python | en | ['en', 'en', 'en'] | True |
BlinkSensor.update | (self) | Retrieve sensor data from the camera. | Retrieve sensor data from the camera. | def update(self):
"""Retrieve sensor data from the camera."""
self.data.refresh()
try:
self._attr_native_value = self._camera.attributes[self._sensor_key]
except KeyError:
self._attr_native_value = None
_LOGGER.error(
"%s not a valid ca... | [
"def",
"update",
"(",
"self",
")",
":",
"self",
".",
"data",
".",
"refresh",
"(",
")",
"try",
":",
"self",
".",
"_attr_native_value",
"=",
"self",
".",
"_camera",
".",
"attributes",
"[",
"self",
".",
"_sensor_key",
"]",
"except",
"KeyError",
":",
"self... | [
61,
4
] | [
70,
13
] | python | en | ['en', 'pt', 'en'] | True |
RoonServer.__init__ | (self, hass, config_entry) | Initialize the system. | Initialize the system. | def __init__(self, hass, config_entry):
"""Initialize the system."""
self.config_entry = config_entry
self.hass = hass
self.roonapi = None
self.roon_id = None
self.all_player_ids = set()
self.all_playlists = []
self.offline_devices = set()
self._ex... | [
"def",
"__init__",
"(",
"self",
",",
"hass",
",",
"config_entry",
")",
":",
"self",
".",
"config_entry",
"=",
"config_entry",
"self",
".",
"hass",
"=",
"hass",
"self",
".",
"roonapi",
"=",
"None",
"self",
".",
"roon_id",
"=",
"None",
"self",
".",
"all_... | [
19,
4
] | [
30,
34
] | python | en | ['en', 'en', 'en'] | True |
RoonServer.async_setup | (self, tries=0) | Set up a roon server based on config parameters. | Set up a roon server based on config parameters. | async def async_setup(self, tries=0):
"""Set up a roon server based on config parameters."""
hass = self.hass
# Host will be None for configs using discovery
host = self.config_entry.data[CONF_HOST]
token = self.config_entry.data[CONF_API_KEY]
# Default to None for compat... | [
"async",
"def",
"async_setup",
"(",
"self",
",",
"tries",
"=",
"0",
")",
":",
"hass",
"=",
"self",
".",
"hass",
"# Host will be None for configs using discovery",
"host",
"=",
"self",
".",
"config_entry",
".",
"data",
"[",
"CONF_HOST",
"]",
"token",
"=",
"se... | [
32,
4
] | [
62,
19
] | python | en | ['en', 'en', 'en'] | True |
RoonServer.async_reset | (self) | Reset this connection to default state.
Will cancel any scheduled setup retry and will unload
the config entry.
| Reset this connection to default state. | async def async_reset(self):
"""Reset this connection to default state.
Will cancel any scheduled setup retry and will unload
the config entry.
"""
self.stop_roon()
return True | [
"async",
"def",
"async_reset",
"(",
"self",
")",
":",
"self",
".",
"stop_roon",
"(",
")",
"return",
"True"
] | [
64,
4
] | [
71,
19
] | python | en | ['en', 'en', 'en'] | True |
RoonServer.zones | (self) | Return list of zones. | Return list of zones. | def zones(self):
"""Return list of zones."""
return self.roonapi.zones | [
"def",
"zones",
"(",
"self",
")",
":",
"return",
"self",
".",
"roonapi",
".",
"zones"
] | [
74,
4
] | [
76,
33
] | python | en | ['en', 'nl', 'en'] | True |
RoonServer.add_player_id | (self, entity_id, roon_name) | Register a roon player. | Register a roon player. | def add_player_id(self, entity_id, roon_name):
"""Register a roon player."""
self._roon_name_by_id[entity_id] = roon_name
self._id_by_roon_name[roon_name] = entity_id | [
"def",
"add_player_id",
"(",
"self",
",",
"entity_id",
",",
"roon_name",
")",
":",
"self",
".",
"_roon_name_by_id",
"[",
"entity_id",
"]",
"=",
"roon_name",
"self",
".",
"_id_by_roon_name",
"[",
"roon_name",
"]",
"=",
"entity_id"
] | [
78,
4
] | [
81,
52
] | python | en | ['en', 'en', 'en'] | True |
RoonServer.roon_name | (self, entity_id) | Get the name of the roon player from entity_id. | Get the name of the roon player from entity_id. | def roon_name(self, entity_id):
"""Get the name of the roon player from entity_id."""
return self._roon_name_by_id.get(entity_id) | [
"def",
"roon_name",
"(",
"self",
",",
"entity_id",
")",
":",
"return",
"self",
".",
"_roon_name_by_id",
".",
"get",
"(",
"entity_id",
")"
] | [
83,
4
] | [
85,
51
] | python | en | ['en', 'en', 'en'] | True |
RoonServer.entity_id | (self, roon_name) | Get the id of the roon player from the roon name. | Get the id of the roon player from the roon name. | def entity_id(self, roon_name):
"""Get the id of the roon player from the roon name."""
return self._id_by_roon_name.get(roon_name) | [
"def",
"entity_id",
"(",
"self",
",",
"roon_name",
")",
":",
"return",
"self",
".",
"_id_by_roon_name",
".",
"get",
"(",
"roon_name",
")"
] | [
87,
4
] | [
89,
51
] | python | en | ['en', 'en', 'en'] | True |
RoonServer.stop_roon | (self) | Stop background worker. | Stop background worker. | def stop_roon(self):
"""Stop background worker."""
self.roonapi.stop()
self._exit = True | [
"def",
"stop_roon",
"(",
"self",
")",
":",
"self",
".",
"roonapi",
".",
"stop",
"(",
")",
"self",
".",
"_exit",
"=",
"True"
] | [
91,
4
] | [
94,
25
] | python | en | ['en', 'en', 'en'] | True |
RoonServer.roonapi_state_callback | (self, event, changed_zones) | Callbacks from the roon api websockets. | Callbacks from the roon api websockets. | def roonapi_state_callback(self, event, changed_zones):
"""Callbacks from the roon api websockets."""
self.hass.add_job(self.async_update_changed_players(changed_zones)) | [
"def",
"roonapi_state_callback",
"(",
"self",
",",
"event",
",",
"changed_zones",
")",
":",
"self",
".",
"hass",
".",
"add_job",
"(",
"self",
".",
"async_update_changed_players",
"(",
"changed_zones",
")",
")"
] | [
96,
4
] | [
98,
75
] | python | en | ['en', 'mg', 'en'] | True |
RoonServer.async_do_loop | (self) | Background work loop. | Background work loop. | async def async_do_loop(self):
"""Background work loop."""
self._exit = False
while not self._exit:
await self.async_update_players()
# await self.async_update_playlists()
await asyncio.sleep(FULL_SYNC_INTERVAL) | [
"async",
"def",
"async_do_loop",
"(",
"self",
")",
":",
"self",
".",
"_exit",
"=",
"False",
"while",
"not",
"self",
".",
"_exit",
":",
"await",
"self",
".",
"async_update_players",
"(",
")",
"# await self.async_update_playlists()",
"await",
"asyncio",
".",
"sl... | [
100,
4
] | [
106,
51
] | python | en | ['en', 'af', 'en'] | True |
RoonServer.async_update_changed_players | (self, changed_zones_ids) | Update the players which were reported as changed by the Roon API. | Update the players which were reported as changed by the Roon API. | async def async_update_changed_players(self, changed_zones_ids):
"""Update the players which were reported as changed by the Roon API."""
for zone_id in changed_zones_ids:
if zone_id not in self.roonapi.zones:
# device was removed ?
continue
zone =... | [
"async",
"def",
"async_update_changed_players",
"(",
"self",
",",
"changed_zones_ids",
")",
":",
"for",
"zone_id",
"in",
"changed_zones_ids",
":",
"if",
"zone_id",
"not",
"in",
"self",
".",
"roonapi",
".",
"zones",
":",
"# device was removed ?",
"continue",
"zone"... | [
108,
4
] | [
127,
47
] | python | en | ['en', 'en', 'en'] | True |
RoonServer.async_update_players | (self) | Periodic full scan of all devices. | Periodic full scan of all devices. | async def async_update_players(self):
"""Periodic full scan of all devices."""
zone_ids = self.roonapi.zones.keys()
await self.async_update_changed_players(zone_ids)
# check for any removed devices
all_devs = {}
for zone in self.roonapi.zones.values():
for dev... | [
"async",
"def",
"async_update_players",
"(",
"self",
")",
":",
"zone_ids",
"=",
"self",
".",
"roonapi",
".",
"zones",
".",
"keys",
"(",
")",
"await",
"self",
".",
"async_update_changed_players",
"(",
"zone_ids",
")",
"# check for any removed devices",
"all_devs",
... | [
129,
4
] | [
147,
44
] | python | en | ['en', 'en', 'en'] | True |
RoonServer.async_create_player_data | (self, zone, output) | Create player object dict by combining zone with output. | Create player object dict by combining zone with output. | async def async_create_player_data(self, zone, output):
"""Create player object dict by combining zone with output."""
new_dict = zone.copy()
new_dict.update(output)
new_dict.pop("outputs")
new_dict["roon_id"] = self.roon_id
new_dict["is_synced"] = len(zone["outputs"]) > ... | [
"async",
"def",
"async_create_player_data",
"(",
"self",
",",
"zone",
",",
"output",
")",
":",
"new_dict",
"=",
"zone",
".",
"copy",
"(",
")",
"new_dict",
".",
"update",
"(",
"output",
")",
"new_dict",
".",
"pop",
"(",
"\"outputs\"",
")",
"new_dict",
"["... | [
149,
4
] | [
161,
23
] | python | en | ['en', 'en', 'en'] | True |
TestMixedPropertiesAndAdditionalPropertiesClass.make_instance | (self, include_optional) | Test MixedPropertiesAndAdditionalPropertiesClass
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included | Test MixedPropertiesAndAdditionalPropertiesClass
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included | def make_instance(self, include_optional):
"""Test MixedPropertiesAndAdditionalPropertiesClass
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# model = petstore_api.models.mixed_p... | [
"def",
"make_instance",
"(",
"self",
",",
"include_optional",
")",
":",
"# model = petstore_api.models.mixed_properties_and_additional_properties_class.MixedPropertiesAndAdditionalPropertiesClass() # noqa: E501",
"if",
"include_optional",
":",
"return",
"MixedPropertiesAndAdditionalProper... | [
30,
4
] | [
48,
9
] | python | en | ['en', 'lb', 'en'] | False |
TestMixedPropertiesAndAdditionalPropertiesClass.testMixedPropertiesAndAdditionalPropertiesClass | (self) | Test MixedPropertiesAndAdditionalPropertiesClass | Test MixedPropertiesAndAdditionalPropertiesClass | def testMixedPropertiesAndAdditionalPropertiesClass(self):
"""Test MixedPropertiesAndAdditionalPropertiesClass"""
inst_req_only = self.make_instance(include_optional=False)
inst_req_and_optional = self.make_instance(include_optional=True) | [
"def",
"testMixedPropertiesAndAdditionalPropertiesClass",
"(",
"self",
")",
":",
"inst_req_only",
"=",
"self",
".",
"make_instance",
"(",
"include_optional",
"=",
"False",
")",
"inst_req_and_optional",
"=",
"self",
".",
"make_instance",
"(",
"include_optional",
"=",
"... | [
50,
4
] | [
53,
73
] | python | en | ['en', 'lb', 'en'] | False |
ascii_lower | (string) | r"""Transform (only) ASCII letters to lower case: A-Z is mapped to a-z.
:param string: An Unicode string.
:returns: A new Unicode string.
This is used for `ASCII case-insensitive
<http://encoding.spec.whatwg.org/#ascii-case-insensitive>`_
matching of encoding labels.
The same matching is also ... | r"""Transform (only) ASCII letters to lower case: A-Z is mapped to a-z. | def ascii_lower(string):
r"""Transform (only) ASCII letters to lower case: A-Z is mapped to a-z.
:param string: An Unicode string.
:returns: A new Unicode string.
This is used for `ASCII case-insensitive
<http://encoding.spec.whatwg.org/#ascii-case-insensitive>`_
matching of encoding labels.
... | [
"def",
"ascii_lower",
"(",
"string",
")",
":",
"# This turns out to be faster than unicode.translate()",
"return",
"string",
".",
"encode",
"(",
"'utf8'",
")",
".",
"lower",
"(",
")",
".",
"decode",
"(",
"'utf8'",
")"
] | [
34,
0
] | [
57,
55
] | python | en | ['en', 'en', 'en'] | True |
lookup | (label) |
Look for an encoding by its label.
This is the spec’s `get an encoding
<http://encoding.spec.whatwg.org/#concept-encoding-get>`_ algorithm.
Supported labels are listed there.
:param label: A string.
:returns:
An :class:`Encoding` object, or :obj:`None` for an unknown label.
|
Look for an encoding by its label.
This is the spec’s `get an encoding
<http://encoding.spec.whatwg.org/#concept-encoding-get>`_ algorithm.
Supported labels are listed there. | def lookup(label):
"""
Look for an encoding by its label.
This is the spec’s `get an encoding
<http://encoding.spec.whatwg.org/#concept-encoding-get>`_ algorithm.
Supported labels are listed there.
:param label: A string.
:returns:
An :class:`Encoding` object, or :obj:`None` for an ... | [
"def",
"lookup",
"(",
"label",
")",
":",
"# Only strip ASCII whitespace: U+0009, U+000A, U+000C, U+000D, and U+0020.",
"label",
"=",
"ascii_lower",
"(",
"label",
".",
"strip",
"(",
"'\\t\\n\\f\\r '",
")",
")",
"name",
"=",
"LABELS",
".",
"get",
"(",
"label",
")",
... | [
60,
0
] | [
87,
19
] | python | en | ['en', 'error', 'th'] | False |
_get_encoding | (encoding_or_label) |
Accept either an encoding object or label.
:param encoding: An :class:`Encoding` object or a label string.
:returns: An :class:`Encoding` object.
:raises: :exc:`~exceptions.LookupError` for an unknown label.
|
Accept either an encoding object or label. | def _get_encoding(encoding_or_label):
"""
Accept either an encoding object or label.
:param encoding: An :class:`Encoding` object or a label string.
:returns: An :class:`Encoding` object.
:raises: :exc:`~exceptions.LookupError` for an unknown label.
"""
if hasattr(encoding_or_label, 'codec... | [
"def",
"_get_encoding",
"(",
"encoding_or_label",
")",
":",
"if",
"hasattr",
"(",
"encoding_or_label",
",",
"'codec_info'",
")",
":",
"return",
"encoding_or_label",
"encoding",
"=",
"lookup",
"(",
"encoding_or_label",
")",
"if",
"encoding",
"is",
"None",
":",
"r... | [
90,
0
] | [
105,
19
] | python | en | ['en', 'error', 'th'] | False |
decode | (input, fallback_encoding, errors='replace') |
Decode a single string.
:param input: A byte string
:param fallback_encoding:
An :class:`Encoding` object or a label string.
The encoding to use if :obj:`input` does note have a BOM.
:param errors: Type of error handling. See :func:`codecs.register`.
:raises: :exc:`~exceptions.Look... |
Decode a single string. | def decode(input, fallback_encoding, errors='replace'):
"""
Decode a single string.
:param input: A byte string
:param fallback_encoding:
An :class:`Encoding` object or a label string.
The encoding to use if :obj:`input` does note have a BOM.
:param errors: Type of error handling. S... | [
"def",
"decode",
"(",
"input",
",",
"fallback_encoding",
",",
"errors",
"=",
"'replace'",
")",
":",
"# Fail early if `encoding` is an invalid label.",
"fallback_encoding",
"=",
"_get_encoding",
"(",
"fallback_encoding",
")",
"bom_encoding",
",",
"input",
"=",
"_detect_b... | [
138,
0
] | [
157,
65
] | python | en | ['en', 'error', 'th'] | False |
_detect_bom | (input) | Return (bom_encoding, input), with any BOM removed from the input. | Return (bom_encoding, input), with any BOM removed from the input. | def _detect_bom(input):
"""Return (bom_encoding, input), with any BOM removed from the input."""
if input.startswith(b'\xFF\xFE'):
return _UTF16LE, input[2:]
if input.startswith(b'\xFE\xFF'):
return _UTF16BE, input[2:]
if input.startswith(b'\xEF\xBB\xBF'):
return UTF8, input[3:]
... | [
"def",
"_detect_bom",
"(",
"input",
")",
":",
"if",
"input",
".",
"startswith",
"(",
"b'\\xFF\\xFE'",
")",
":",
"return",
"_UTF16LE",
",",
"input",
"[",
"2",
":",
"]",
"if",
"input",
".",
"startswith",
"(",
"b'\\xFE\\xFF'",
")",
":",
"return",
"_UTF16BE"... | [
160,
0
] | [
168,
22
] | python | en | ['en', 'en', 'en'] | True |
encode | (input, encoding=UTF8, errors='strict') |
Encode a single string.
:param input: An Unicode string.
:param encoding: An :class:`Encoding` object or a label string.
:param errors: Type of error handling. See :func:`codecs.register`.
:raises: :exc:`~exceptions.LookupError` for an unknown encoding label.
:return: A byte string.
|
Encode a single string. | def encode(input, encoding=UTF8, errors='strict'):
"""
Encode a single string.
:param input: An Unicode string.
:param encoding: An :class:`Encoding` object or a label string.
:param errors: Type of error handling. See :func:`codecs.register`.
:raises: :exc:`~exceptions.LookupError` for an unkn... | [
"def",
"encode",
"(",
"input",
",",
"encoding",
"=",
"UTF8",
",",
"errors",
"=",
"'strict'",
")",
":",
"return",
"_get_encoding",
"(",
"encoding",
")",
".",
"codec_info",
".",
"encode",
"(",
"input",
",",
"errors",
")",
"[",
"0",
"]"
] | [
171,
0
] | [
182,
70
] | python | en | ['en', 'error', 'th'] | False |
iter_decode | (input, fallback_encoding, errors='replace') |
"Pull"-based decoder.
:param input:
An iterable of byte strings.
The input is first consumed just enough to determine the encoding
based on the precense of a BOM,
then consumed on demand when the return value is.
:param fallback_encoding:
An :class:`Encoding` objec... |
"Pull"-based decoder. | def iter_decode(input, fallback_encoding, errors='replace'):
"""
"Pull"-based decoder.
:param input:
An iterable of byte strings.
The input is first consumed just enough to determine the encoding
based on the precense of a BOM,
then consumed on demand when the return value ... | [
"def",
"iter_decode",
"(",
"input",
",",
"fallback_encoding",
",",
"errors",
"=",
"'replace'",
")",
":",
"decoder",
"=",
"IncrementalDecoder",
"(",
"fallback_encoding",
",",
"errors",
")",
"generator",
"=",
"_iter_decode_generator",
"(",
"input",
",",
"decoder",
... | [
185,
0
] | [
210,
30
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.