id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
45,000 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._wire_events | def _wire_events(self):
"""
Wires up the internal device events.
"""
self._device.on_open += self._on_open
self._device.on_close += self._on_close
self._device.on_read += self._on_read
self._device.on_write += self._on_write
self._zonetracker.on_fault += s... | python | def _wire_events(self):
"""
Wires up the internal device events.
"""
self._device.on_open += self._on_open
self._device.on_close += self._on_close
self._device.on_read += self._on_read
self._device.on_write += self._on_write
self._zonetracker.on_fault += s... | [
"def",
"_wire_events",
"(",
"self",
")",
":",
"self",
".",
"_device",
".",
"on_open",
"+=",
"self",
".",
"_on_open",
"self",
".",
"_device",
".",
"on_close",
"+=",
"self",
".",
"_on_close",
"self",
".",
"_device",
".",
"on_read",
"+=",
"self",
".",
"_o... | Wires up the internal device events. | [
"Wires",
"up",
"the",
"internal",
"device",
"events",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L388-L397 |
45,001 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._handle_message | def _handle_message(self, data):
"""
Parses keypad messages from the panel.
:param data: keypad data to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.Message`
"""
try:
data = data.decode('utf-8')
except:
ra... | python | def _handle_message(self, data):
"""
Parses keypad messages from the panel.
:param data: keypad data to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.Message`
"""
try:
data = data.decode('utf-8')
except:
ra... | [
"def",
"_handle_message",
"(",
"self",
",",
"data",
")",
":",
"try",
":",
"data",
"=",
"data",
".",
"decode",
"(",
"'utf-8'",
")",
"except",
":",
"raise",
"InvalidMessageError",
"(",
"'Decode failed for message: {0}'",
".",
"format",
"(",
"data",
")",
")",
... | Parses keypad messages from the panel.
:param data: keypad data to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.Message` | [
"Parses",
"keypad",
"messages",
"from",
"the",
"panel",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L410-L461 |
45,002 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._handle_keypad_message | def _handle_keypad_message(self, data):
"""
Handle keypad messages.
:param data: keypad message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.Message`
"""
msg = Message(data)
if self._internal_address_mask & msg.mask > 0:
... | python | def _handle_keypad_message(self, data):
"""
Handle keypad messages.
:param data: keypad message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.Message`
"""
msg = Message(data)
if self._internal_address_mask & msg.mask > 0:
... | [
"def",
"_handle_keypad_message",
"(",
"self",
",",
"data",
")",
":",
"msg",
"=",
"Message",
"(",
"data",
")",
"if",
"self",
".",
"_internal_address_mask",
"&",
"msg",
".",
"mask",
">",
"0",
":",
"if",
"not",
"self",
".",
"_ignore_message_states",
":",
"s... | Handle keypad messages.
:param data: keypad message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.Message` | [
"Handle",
"keypad",
"messages",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L463-L481 |
45,003 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._handle_expander_message | def _handle_expander_message(self, data):
"""
Handle expander messages.
:param data: expander message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.ExpanderMessage`
"""
msg = ExpanderMessage(data)
self._update_internal_states(m... | python | def _handle_expander_message(self, data):
"""
Handle expander messages.
:param data: expander message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.ExpanderMessage`
"""
msg = ExpanderMessage(data)
self._update_internal_states(m... | [
"def",
"_handle_expander_message",
"(",
"self",
",",
"data",
")",
":",
"msg",
"=",
"ExpanderMessage",
"(",
"data",
")",
"self",
".",
"_update_internal_states",
"(",
"msg",
")",
"self",
".",
"on_expander_message",
"(",
"message",
"=",
"msg",
")",
"return",
"m... | Handle expander messages.
:param data: expander message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.ExpanderMessage` | [
"Handle",
"expander",
"messages",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L483-L497 |
45,004 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._handle_rfx | def _handle_rfx(self, data):
"""
Handle RF messages.
:param data: RF message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.RFMessage`
"""
msg = RFMessage(data)
self.on_rfx_message(message=msg)
return msg | python | def _handle_rfx(self, data):
"""
Handle RF messages.
:param data: RF message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.RFMessage`
"""
msg = RFMessage(data)
self.on_rfx_message(message=msg)
return msg | [
"def",
"_handle_rfx",
"(",
"self",
",",
"data",
")",
":",
"msg",
"=",
"RFMessage",
"(",
"data",
")",
"self",
".",
"on_rfx_message",
"(",
"message",
"=",
"msg",
")",
"return",
"msg"
] | Handle RF messages.
:param data: RF message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.RFMessage` | [
"Handle",
"RF",
"messages",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L499-L512 |
45,005 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._handle_lrr | def _handle_lrr(self, data):
"""
Handle Long Range Radio messages.
:param data: LRR message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.LRRMessage`
"""
msg = LRRMessage(data)
if not self._ignore_lrr_states:
self._... | python | def _handle_lrr(self, data):
"""
Handle Long Range Radio messages.
:param data: LRR message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.LRRMessage`
"""
msg = LRRMessage(data)
if not self._ignore_lrr_states:
self._... | [
"def",
"_handle_lrr",
"(",
"self",
",",
"data",
")",
":",
"msg",
"=",
"LRRMessage",
"(",
"data",
")",
"if",
"not",
"self",
".",
"_ignore_lrr_states",
":",
"self",
".",
"_lrr_system",
".",
"update",
"(",
"msg",
")",
"self",
".",
"on_lrr_message",
"(",
"... | Handle Long Range Radio messages.
:param data: LRR message to parse
:type data: string
:returns: :py:class:`~alarmdecoder.messages.LRRMessage` | [
"Handle",
"Long",
"Range",
"Radio",
"messages",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L514-L529 |
45,006 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._handle_aui | def _handle_aui(self, data):
"""
Handle AUI messages.
:param data: RF message to parse
:type data: string
:returns: :py:class`~alarmdecoder.messages.AUIMessage`
"""
msg = AUIMessage(data)
self.on_aui_message(message=msg)
return msg | python | def _handle_aui(self, data):
"""
Handle AUI messages.
:param data: RF message to parse
:type data: string
:returns: :py:class`~alarmdecoder.messages.AUIMessage`
"""
msg = AUIMessage(data)
self.on_aui_message(message=msg)
return msg | [
"def",
"_handle_aui",
"(",
"self",
",",
"data",
")",
":",
"msg",
"=",
"AUIMessage",
"(",
"data",
")",
"self",
".",
"on_aui_message",
"(",
"message",
"=",
"msg",
")",
"return",
"msg"
] | Handle AUI messages.
:param data: RF message to parse
:type data: string
:returns: :py:class`~alarmdecoder.messages.AUIMessage` | [
"Handle",
"AUI",
"messages",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L531-L544 |
45,007 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._handle_version | def _handle_version(self, data):
"""
Handles received version data.
:param data: Version string to parse
:type data: string
"""
_, version_string = data.split(':')
version_parts = version_string.split(',')
self.serial_number = version_parts[0]
s... | python | def _handle_version(self, data):
"""
Handles received version data.
:param data: Version string to parse
:type data: string
"""
_, version_string = data.split(':')
version_parts = version_string.split(',')
self.serial_number = version_parts[0]
s... | [
"def",
"_handle_version",
"(",
"self",
",",
"data",
")",
":",
"_",
",",
"version_string",
"=",
"data",
".",
"split",
"(",
"':'",
")",
"version_parts",
"=",
"version_string",
".",
"split",
"(",
"','",
")",
"self",
".",
"serial_number",
"=",
"version_parts",... | Handles received version data.
:param data: Version string to parse
:type data: string | [
"Handles",
"received",
"version",
"data",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L546-L559 |
45,008 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._handle_config | def _handle_config(self, data):
"""
Handles received configuration data.
:param data: Configuration string to parse
:type data: string
"""
_, config_string = data.split('>')
for setting in config_string.split('&'):
key, val = setting.split('=')
... | python | def _handle_config(self, data):
"""
Handles received configuration data.
:param data: Configuration string to parse
:type data: string
"""
_, config_string = data.split('>')
for setting in config_string.split('&'):
key, val = setting.split('=')
... | [
"def",
"_handle_config",
"(",
"self",
",",
"data",
")",
":",
"_",
",",
"config_string",
"=",
"data",
".",
"split",
"(",
"'>'",
")",
"for",
"setting",
"in",
"config_string",
".",
"split",
"(",
"'&'",
")",
":",
"key",
",",
"val",
"=",
"setting",
".",
... | Handles received configuration data.
:param data: Configuration string to parse
:type data: string | [
"Handles",
"received",
"configuration",
"data",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L561-L591 |
45,009 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._handle_sending | def _handle_sending(self, data):
"""
Handles results of a keypress send.
:param data: Sending string to parse
:type data: string
"""
matches = re.match('^!Sending(\.{1,5})done.*', data)
if matches is not None:
good_send = False
if len(mat... | python | def _handle_sending(self, data):
"""
Handles results of a keypress send.
:param data: Sending string to parse
:type data: string
"""
matches = re.match('^!Sending(\.{1,5})done.*', data)
if matches is not None:
good_send = False
if len(mat... | [
"def",
"_handle_sending",
"(",
"self",
",",
"data",
")",
":",
"matches",
"=",
"re",
".",
"match",
"(",
"'^!Sending(\\.{1,5})done.*'",
",",
"data",
")",
"if",
"matches",
"is",
"not",
"None",
":",
"good_send",
"=",
"False",
"if",
"len",
"(",
"matches",
"."... | Handles results of a keypress send.
:param data: Sending string to parse
:type data: string | [
"Handles",
"results",
"of",
"a",
"keypress",
"send",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L593-L607 |
45,010 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_internal_states | def _update_internal_states(self, message):
"""
Updates internal device states.
:param message: :py:class:`~alarmdecoder.messages.Message` to update internal states with
:type message: :py:class:`~alarmdecoder.messages.Message`, :py:class:`~alarmdecoder.messages.ExpanderMessage`, :py:cl... | python | def _update_internal_states(self, message):
"""
Updates internal device states.
:param message: :py:class:`~alarmdecoder.messages.Message` to update internal states with
:type message: :py:class:`~alarmdecoder.messages.Message`, :py:class:`~alarmdecoder.messages.ExpanderMessage`, :py:cl... | [
"def",
"_update_internal_states",
"(",
"self",
",",
"message",
")",
":",
"if",
"isinstance",
"(",
"message",
",",
"Message",
")",
"and",
"not",
"self",
".",
"_ignore_message_states",
":",
"self",
".",
"_update_armed_ready_status",
"(",
"message",
")",
"self",
... | Updates internal device states.
:param message: :py:class:`~alarmdecoder.messages.Message` to update internal states with
:type message: :py:class:`~alarmdecoder.messages.Message`, :py:class:`~alarmdecoder.messages.ExpanderMessage`, :py:class:`~alarmdecoder.messages.LRRMessage`, or :py:class:`~alarmdec... | [
"Updates",
"internal",
"device",
"states",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L609-L628 |
45,011 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_power_status | def _update_power_status(self, message=None, status=None):
"""
Uses the provided message to update the AC power state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: power status, overrides message bits.
... | python | def _update_power_status(self, message=None, status=None):
"""
Uses the provided message to update the AC power state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: power status, overrides message bits.
... | [
"def",
"_update_power_status",
"(",
"self",
",",
"message",
"=",
"None",
",",
"status",
"=",
"None",
")",
":",
"power_status",
"=",
"status",
"if",
"isinstance",
"(",
"message",
",",
"Message",
")",
":",
"power_status",
"=",
"message",
".",
"ac_power",
"if... | Uses the provided message to update the AC power state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: power status, overrides message bits.
:type status: bool
:returns: bool indicating the new status | [
"Uses",
"the",
"provided",
"message",
"to",
"update",
"the",
"AC",
"power",
"state",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L630-L654 |
45,012 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_chime_status | def _update_chime_status(self, message=None, status=None):
"""
Uses the provided message to update the Chime state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: chime status, overrides message bits.
:ty... | python | def _update_chime_status(self, message=None, status=None):
"""
Uses the provided message to update the Chime state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: chime status, overrides message bits.
:ty... | [
"def",
"_update_chime_status",
"(",
"self",
",",
"message",
"=",
"None",
",",
"status",
"=",
"None",
")",
":",
"chime_status",
"=",
"status",
"if",
"isinstance",
"(",
"message",
",",
"Message",
")",
":",
"chime_status",
"=",
"message",
".",
"chime_on",
"if... | Uses the provided message to update the Chime state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: chime status, overrides message bits.
:type status: bool
:returns: bool indicating the new status | [
"Uses",
"the",
"provided",
"message",
"to",
"update",
"the",
"Chime",
"state",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L656-L680 |
45,013 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_alarm_status | def _update_alarm_status(self, message=None, status=None, zone=None, user=None):
"""
Uses the provided message to update the alarm state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: alarm status, overrides mes... | python | def _update_alarm_status(self, message=None, status=None, zone=None, user=None):
"""
Uses the provided message to update the alarm state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: alarm status, overrides mes... | [
"def",
"_update_alarm_status",
"(",
"self",
",",
"message",
"=",
"None",
",",
"status",
"=",
"None",
",",
"zone",
"=",
"None",
",",
"user",
"=",
"None",
")",
":",
"alarm_status",
"=",
"status",
"alarm_zone",
"=",
"zone",
"if",
"isinstance",
"(",
"message... | Uses the provided message to update the alarm state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: alarm status, overrides message bits.
:type status: bool
:param user: user associated with alarm event
:... | [
"Uses",
"the",
"provided",
"message",
"to",
"update",
"the",
"alarm",
"state",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L682-L711 |
45,014 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_zone_bypass_status | def _update_zone_bypass_status(self, message=None, status=None, zone=None):
"""
Uses the provided message to update the zone bypass state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: bypass status, overrides m... | python | def _update_zone_bypass_status(self, message=None, status=None, zone=None):
"""
Uses the provided message to update the zone bypass state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: bypass status, overrides m... | [
"def",
"_update_zone_bypass_status",
"(",
"self",
",",
"message",
"=",
"None",
",",
"status",
"=",
"None",
",",
"zone",
"=",
"None",
")",
":",
"bypass_status",
"=",
"status",
"if",
"isinstance",
"(",
"message",
",",
"Message",
")",
":",
"bypass_status",
"=... | Uses the provided message to update the zone bypass state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: bypass status, overrides message bits.
:type status: bool
:param zone: zone associated with bypass event
... | [
"Uses",
"the",
"provided",
"message",
"to",
"update",
"the",
"zone",
"bypass",
"state",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L713-L746 |
45,015 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_armed_status | def _update_armed_status(self, message=None, status=None, status_stay=None):
"""
Uses the provided message to update the armed state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: armed status, overrides message... | python | def _update_armed_status(self, message=None, status=None, status_stay=None):
"""
Uses the provided message to update the armed state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: armed status, overrides message... | [
"def",
"_update_armed_status",
"(",
"self",
",",
"message",
"=",
"None",
",",
"status",
"=",
"None",
",",
"status_stay",
"=",
"None",
")",
":",
"arm_status",
"=",
"status",
"stay_status",
"=",
"status_stay",
"if",
"isinstance",
"(",
"message",
",",
"Message"... | Uses the provided message to update the armed state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: armed status, overrides message bits
:type status: bool
:param status_stay: armed stay status, overrides message... | [
"Uses",
"the",
"provided",
"message",
"to",
"update",
"the",
"armed",
"state",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L794-L826 |
45,016 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_battery_status | def _update_battery_status(self, message=None, status=None):
"""
Uses the provided message to update the battery state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: battery status, overrides message bits
... | python | def _update_battery_status(self, message=None, status=None):
"""
Uses the provided message to update the battery state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: battery status, overrides message bits
... | [
"def",
"_update_battery_status",
"(",
"self",
",",
"message",
"=",
"None",
",",
"status",
"=",
"None",
")",
":",
"battery_status",
"=",
"status",
"if",
"isinstance",
"(",
"message",
",",
"Message",
")",
":",
"battery_status",
"=",
"message",
".",
"battery_lo... | Uses the provided message to update the battery state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: battery status, overrides message bits
:type status: bool
:returns: boolean indicating the new status | [
"Uses",
"the",
"provided",
"message",
"to",
"update",
"the",
"battery",
"state",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L828-L854 |
45,017 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_fire_status | def _update_fire_status(self, message=None, status=None):
"""
Uses the provided message to update the fire alarm state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: fire status, overrides message bits
:... | python | def _update_fire_status(self, message=None, status=None):
"""
Uses the provided message to update the fire alarm state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: fire status, overrides message bits
:... | [
"def",
"_update_fire_status",
"(",
"self",
",",
"message",
"=",
"None",
",",
"status",
"=",
"None",
")",
":",
"fire_status",
"=",
"status",
"last_status",
"=",
"self",
".",
"_fire_status",
"if",
"isinstance",
"(",
"message",
",",
"Message",
")",
":",
"# Qu... | Uses the provided message to update the fire alarm state.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.Message`
:param status: fire status, overrides message bits
:type status: bool
:returns: boolean indicating the new status | [
"Uses",
"the",
"provided",
"message",
"to",
"update",
"the",
"fire",
"alarm",
"state",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L856-L886 |
45,018 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_panic_status | def _update_panic_status(self, status=None):
"""
Updates the panic status of the alarm panel.
:param status: status to use to update
:type status: boolean
:returns: boolean indicating the new status
"""
if status is None:
return
if status !=... | python | def _update_panic_status(self, status=None):
"""
Updates the panic status of the alarm panel.
:param status: status to use to update
:type status: boolean
:returns: boolean indicating the new status
"""
if status is None:
return
if status !=... | [
"def",
"_update_panic_status",
"(",
"self",
",",
"status",
"=",
"None",
")",
":",
"if",
"status",
"is",
"None",
":",
"return",
"if",
"status",
"!=",
"self",
".",
"_panic_status",
":",
"self",
".",
"_panic_status",
",",
"old_status",
"=",
"status",
",",
"... | Updates the panic status of the alarm panel.
:param status: status to use to update
:type status: boolean
:returns: boolean indicating the new status | [
"Updates",
"the",
"panic",
"status",
"of",
"the",
"alarm",
"panel",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L888-L906 |
45,019 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._update_expander_status | def _update_expander_status(self, message):
"""
Uses the provided message to update the expander states.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.ExpanderMessage`
:returns: boolean indicating the new status
"""
i... | python | def _update_expander_status(self, message):
"""
Uses the provided message to update the expander states.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.ExpanderMessage`
:returns: boolean indicating the new status
"""
i... | [
"def",
"_update_expander_status",
"(",
"self",
",",
"message",
")",
":",
"if",
"message",
".",
"type",
"==",
"ExpanderMessage",
".",
"RELAY",
":",
"self",
".",
"_relay_status",
"[",
"(",
"message",
".",
"address",
",",
"message",
".",
"channel",
")",
"]",
... | Uses the provided message to update the expander states.
:param message: message to use to update
:type message: :py:class:`~alarmdecoder.messages.ExpanderMessage`
:returns: boolean indicating the new status | [
"Uses",
"the",
"provided",
"message",
"to",
"update",
"the",
"expander",
"states",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L908-L923 |
45,020 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._on_open | def _on_open(self, sender, *args, **kwargs):
"""
Internal handler for opening the device.
"""
self.get_config()
self.get_version()
self.on_open() | python | def _on_open(self, sender, *args, **kwargs):
"""
Internal handler for opening the device.
"""
self.get_config()
self.get_version()
self.on_open() | [
"def",
"_on_open",
"(",
"self",
",",
"sender",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"get_config",
"(",
")",
"self",
".",
"get_version",
"(",
")",
"self",
".",
"on_open",
"(",
")"
] | Internal handler for opening the device. | [
"Internal",
"handler",
"for",
"opening",
"the",
"device",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L944-L951 |
45,021 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._on_read | def _on_read(self, sender, *args, **kwargs):
"""
Internal handler for reading from the device.
"""
data = kwargs.get('data', None)
self.on_read(data=data)
self._handle_message(data) | python | def _on_read(self, sender, *args, **kwargs):
"""
Internal handler for reading from the device.
"""
data = kwargs.get('data', None)
self.on_read(data=data)
self._handle_message(data) | [
"def",
"_on_read",
"(",
"self",
",",
"sender",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"kwargs",
".",
"get",
"(",
"'data'",
",",
"None",
")",
"self",
".",
"on_read",
"(",
"data",
"=",
"data",
")",
"self",
".",
"_handle_m... | Internal handler for reading from the device. | [
"Internal",
"handler",
"for",
"reading",
"from",
"the",
"device",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L959-L966 |
45,022 | nutechsoftware/alarmdecoder | alarmdecoder/decoder.py | AlarmDecoder._on_write | def _on_write(self, sender, *args, **kwargs):
"""
Internal handler for writing to the device.
"""
self.on_write(data=kwargs.get('data', None)) | python | def _on_write(self, sender, *args, **kwargs):
"""
Internal handler for writing to the device.
"""
self.on_write(data=kwargs.get('data', None)) | [
"def",
"_on_write",
"(",
"self",
",",
"sender",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"on_write",
"(",
"data",
"=",
"kwargs",
".",
"get",
"(",
"'data'",
",",
"None",
")",
")"
] | Internal handler for writing to the device. | [
"Internal",
"handler",
"for",
"writing",
"to",
"the",
"device",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/decoder.py#L968-L972 |
45,023 | nutechsoftware/alarmdecoder | alarmdecoder/zonetracking.py | Zonetracker.update | def update(self, message):
"""
Update zone statuses based on the current message.
:param message: message to use to update the zone tracking
:type message: :py:class:`~alarmdecoder.messages.Message` or :py:class:`~alarmdecoder.messages.ExpanderMessage`
"""
if isinstance(... | python | def update(self, message):
"""
Update zone statuses based on the current message.
:param message: message to use to update the zone tracking
:type message: :py:class:`~alarmdecoder.messages.Message` or :py:class:`~alarmdecoder.messages.ExpanderMessage`
"""
if isinstance(... | [
"def",
"update",
"(",
"self",
",",
"message",
")",
":",
"if",
"isinstance",
"(",
"message",
",",
"ExpanderMessage",
")",
":",
"zone",
"=",
"-",
"1",
"if",
"message",
".",
"type",
"==",
"ExpanderMessage",
".",
"ZONE",
":",
"zone",
"=",
"self",
".",
"e... | Update zone statuses based on the current message.
:param message: message to use to update the zone tracking
:type message: :py:class:`~alarmdecoder.messages.Message` or :py:class:`~alarmdecoder.messages.ExpanderMessage` | [
"Update",
"zone",
"statuses",
"based",
"on",
"the",
"current",
"message",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/zonetracking.py#L133-L213 |
45,024 | nutechsoftware/alarmdecoder | alarmdecoder/zonetracking.py | Zonetracker.expander_to_zone | def expander_to_zone(self, address, channel, panel_type=ADEMCO):
"""
Convert an address and channel into a zone number.
:param address: expander address
:type address: int
:param channel: channel
:type channel: int
:returns: zone number associated with an addres... | python | def expander_to_zone(self, address, channel, panel_type=ADEMCO):
"""
Convert an address and channel into a zone number.
:param address: expander address
:type address: int
:param channel: channel
:type channel: int
:returns: zone number associated with an addres... | [
"def",
"expander_to_zone",
"(",
"self",
",",
"address",
",",
"channel",
",",
"panel_type",
"=",
"ADEMCO",
")",
":",
"zone",
"=",
"-",
"1",
"if",
"panel_type",
"==",
"ADEMCO",
":",
"# TODO: This is going to need to be reworked to support the larger",
"# panels wi... | Convert an address and channel into a zone number.
:param address: expander address
:type address: int
:param channel: channel
:type channel: int
:returns: zone number associated with an address and channel | [
"Convert",
"an",
"address",
"and",
"channel",
"into",
"a",
"zone",
"number",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/zonetracking.py#L215-L239 |
45,025 | nutechsoftware/alarmdecoder | alarmdecoder/zonetracking.py | Zonetracker._clear_zones | def _clear_zones(self, zone):
"""
Clear all expired zones from our status list.
:param zone: current zone being processed
:type zone: int
"""
cleared_zones = []
found_last_faulted = found_current = at_end = False
# First pass: Find our start spot.
... | python | def _clear_zones(self, zone):
"""
Clear all expired zones from our status list.
:param zone: current zone being processed
:type zone: int
"""
cleared_zones = []
found_last_faulted = found_current = at_end = False
# First pass: Find our start spot.
... | [
"def",
"_clear_zones",
"(",
"self",
",",
"zone",
")",
":",
"cleared_zones",
"=",
"[",
"]",
"found_last_faulted",
"=",
"found_current",
"=",
"at_end",
"=",
"False",
"# First pass: Find our start spot.",
"it",
"=",
"iter",
"(",
"self",
".",
"_zones_faulted",
")",
... | Clear all expired zones from our status list.
:param zone: current zone being processed
:type zone: int | [
"Clear",
"all",
"expired",
"zones",
"from",
"our",
"status",
"list",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/zonetracking.py#L241-L299 |
45,026 | nutechsoftware/alarmdecoder | alarmdecoder/zonetracking.py | Zonetracker._clear_expired_zones | def _clear_expired_zones(self):
"""
Update zone status for all expired zones.
"""
zones = []
for z in list(self._zones.keys()):
zones += [z]
for z in zones:
if self._zones[z].status != Zone.CLEAR and self._zone_expired(z):
self._u... | python | def _clear_expired_zones(self):
"""
Update zone status for all expired zones.
"""
zones = []
for z in list(self._zones.keys()):
zones += [z]
for z in zones:
if self._zones[z].status != Zone.CLEAR and self._zone_expired(z):
self._u... | [
"def",
"_clear_expired_zones",
"(",
"self",
")",
":",
"zones",
"=",
"[",
"]",
"for",
"z",
"in",
"list",
"(",
"self",
".",
"_zones",
".",
"keys",
"(",
")",
")",
":",
"zones",
"+=",
"[",
"z",
"]",
"for",
"z",
"in",
"zones",
":",
"if",
"self",
"."... | Update zone status for all expired zones. | [
"Update",
"zone",
"status",
"for",
"all",
"expired",
"zones",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/zonetracking.py#L301-L312 |
45,027 | nutechsoftware/alarmdecoder | alarmdecoder/zonetracking.py | Zonetracker._add_zone | def _add_zone(self, zone, name='', status=Zone.CLEAR, expander=False):
"""
Adds a zone to the internal zone list.
:param zone: zone number
:type zone: int
:param name: human readable zone name
:type name: string
:param status: zone status
:type status: in... | python | def _add_zone(self, zone, name='', status=Zone.CLEAR, expander=False):
"""
Adds a zone to the internal zone list.
:param zone: zone number
:type zone: int
:param name: human readable zone name
:type name: string
:param status: zone status
:type status: in... | [
"def",
"_add_zone",
"(",
"self",
",",
"zone",
",",
"name",
"=",
"''",
",",
"status",
"=",
"Zone",
".",
"CLEAR",
",",
"expander",
"=",
"False",
")",
":",
"if",
"not",
"zone",
"in",
"self",
".",
"_zones",
":",
"self",
".",
"_zones",
"[",
"zone",
"]... | Adds a zone to the internal zone list.
:param zone: zone number
:type zone: int
:param name: human readable zone name
:type name: string
:param status: zone status
:type status: int | [
"Adds",
"a",
"zone",
"to",
"the",
"internal",
"zone",
"list",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/zonetracking.py#L314-L328 |
45,028 | nutechsoftware/alarmdecoder | alarmdecoder/zonetracking.py | Zonetracker._update_zone | def _update_zone(self, zone, status=None):
"""
Updates a zones status.
:param zone: zone number
:type zone: int
:param status: zone status
:type status: int
:raises: IndexError
"""
if not zone in self._zones:
raise IndexError('Zone do... | python | def _update_zone(self, zone, status=None):
"""
Updates a zones status.
:param zone: zone number
:type zone: int
:param status: zone status
:type status: int
:raises: IndexError
"""
if not zone in self._zones:
raise IndexError('Zone do... | [
"def",
"_update_zone",
"(",
"self",
",",
"zone",
",",
"status",
"=",
"None",
")",
":",
"if",
"not",
"zone",
"in",
"self",
".",
"_zones",
":",
"raise",
"IndexError",
"(",
"'Zone does not exist and cannot be updated: %d'",
",",
"zone",
")",
"old_status",
"=",
... | Updates a zones status.
:param zone: zone number
:type zone: int
:param status: zone status
:type status: int
:raises: IndexError | [
"Updates",
"a",
"zones",
"status",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/zonetracking.py#L330-L358 |
45,029 | nutechsoftware/alarmdecoder | alarmdecoder/zonetracking.py | Zonetracker._zone_expired | def _zone_expired(self, zone):
"""
Determine if a zone is expired or not.
:param zone: zone number
:type zone: int
:returns: whether or not the zone is expired
"""
return (time.time() > self._zones[zone].timestamp + Zonetracker.EXPIRE) and self._zones[zone].expa... | python | def _zone_expired(self, zone):
"""
Determine if a zone is expired or not.
:param zone: zone number
:type zone: int
:returns: whether or not the zone is expired
"""
return (time.time() > self._zones[zone].timestamp + Zonetracker.EXPIRE) and self._zones[zone].expa... | [
"def",
"_zone_expired",
"(",
"self",
",",
"zone",
")",
":",
"return",
"(",
"time",
".",
"time",
"(",
")",
">",
"self",
".",
"_zones",
"[",
"zone",
"]",
".",
"timestamp",
"+",
"Zonetracker",
".",
"EXPIRE",
")",
"and",
"self",
".",
"_zones",
"[",
"zo... | Determine if a zone is expired or not.
:param zone: zone number
:type zone: int
:returns: whether or not the zone is expired | [
"Determine",
"if",
"a",
"zone",
"is",
"expired",
"or",
"not",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/zonetracking.py#L360-L369 |
45,030 | nutechsoftware/alarmdecoder | examples/virtual_zone_expander.py | main | def main():
"""
Example application that periodically faults a virtual zone and then
restores it.
This is an advanced feature that allows you to emulate a virtual zone. When
the AlarmDecoder is configured to emulate a zone expander we can fault and
restore those zones programmatically at will.... | python | def main():
"""
Example application that periodically faults a virtual zone and then
restores it.
This is an advanced feature that allows you to emulate a virtual zone. When
the AlarmDecoder is configured to emulate a zone expander we can fault and
restore those zones programmatically at will.... | [
"def",
"main",
"(",
")",
":",
"try",
":",
"# Retrieve the first USB device",
"device",
"=",
"AlarmDecoder",
"(",
"SerialDevice",
"(",
"interface",
"=",
"SERIAL_DEVICE",
")",
")",
"# Set up an event handlers and open the device",
"device",
".",
"on_zone_fault",
"+=",
"... | Example application that periodically faults a virtual zone and then
restores it.
This is an advanced feature that allows you to emulate a virtual zone. When
the AlarmDecoder is configured to emulate a zone expander we can fault and
restore those zones programmatically at will. These events can also b... | [
"Example",
"application",
"that",
"periodically",
"faults",
"a",
"virtual",
"zone",
"and",
"then",
"restores",
"it",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/examples/virtual_zone_expander.py#L12-L51 |
45,031 | nutechsoftware/alarmdecoder | alarmdecoder/util.py | bytes_available | def bytes_available(device):
"""
Determines the number of bytes available for reading from an
AlarmDecoder device
:param device: the AlarmDecoder device
:type device: :py:class:`~alarmdecoder.devices.Device`
:returns: int
"""
bytes_avail = 0
if isinstance(device, alarmdecoder.devi... | python | def bytes_available(device):
"""
Determines the number of bytes available for reading from an
AlarmDecoder device
:param device: the AlarmDecoder device
:type device: :py:class:`~alarmdecoder.devices.Device`
:returns: int
"""
bytes_avail = 0
if isinstance(device, alarmdecoder.devi... | [
"def",
"bytes_available",
"(",
"device",
")",
":",
"bytes_avail",
"=",
"0",
"if",
"isinstance",
"(",
"device",
",",
"alarmdecoder",
".",
"devices",
".",
"SerialDevice",
")",
":",
"if",
"hasattr",
"(",
"device",
".",
"_device",
",",
"\"in_waiting\"",
")",
"... | Determines the number of bytes available for reading from an
AlarmDecoder device
:param device: the AlarmDecoder device
:type device: :py:class:`~alarmdecoder.devices.Device`
:returns: int | [
"Determines",
"the",
"number",
"of",
"bytes",
"available",
"for",
"reading",
"from",
"an",
"AlarmDecoder",
"device"
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/util.py#L61-L81 |
45,032 | nutechsoftware/alarmdecoder | alarmdecoder/util.py | bytes_hack | def bytes_hack(buf):
"""
Hacky workaround for old installs of the library on systems without python-future that were
keeping the 2to3 update from working after auto-update.
"""
ub = None
if sys.version_info > (3,):
ub = buf
else:
ub = bytes(buf)
return ub | python | def bytes_hack(buf):
"""
Hacky workaround for old installs of the library on systems without python-future that were
keeping the 2to3 update from working after auto-update.
"""
ub = None
if sys.version_info > (3,):
ub = buf
else:
ub = bytes(buf)
return ub | [
"def",
"bytes_hack",
"(",
"buf",
")",
":",
"ub",
"=",
"None",
"if",
"sys",
".",
"version_info",
">",
"(",
"3",
",",
")",
":",
"ub",
"=",
"buf",
"else",
":",
"ub",
"=",
"bytes",
"(",
"buf",
")",
"return",
"ub"
] | Hacky workaround for old installs of the library on systems without python-future that were
keeping the 2to3 update from working after auto-update. | [
"Hacky",
"workaround",
"for",
"old",
"installs",
"of",
"the",
"library",
"on",
"systems",
"without",
"python",
"-",
"future",
"that",
"were",
"keeping",
"the",
"2to3",
"update",
"from",
"working",
"after",
"auto",
"-",
"update",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/util.py#L83-L94 |
45,033 | nutechsoftware/alarmdecoder | alarmdecoder/util.py | read_firmware_file | def read_firmware_file(file_path):
"""
Reads a firmware file into a dequeue for processing.
:param file_path: Path to the firmware file
:type file_path: string
:returns: deque
"""
data_queue = deque()
with open(file_path) as firmware_handle:
for line in firmware_handle:
... | python | def read_firmware_file(file_path):
"""
Reads a firmware file into a dequeue for processing.
:param file_path: Path to the firmware file
:type file_path: string
:returns: deque
"""
data_queue = deque()
with open(file_path) as firmware_handle:
for line in firmware_handle:
... | [
"def",
"read_firmware_file",
"(",
"file_path",
")",
":",
"data_queue",
"=",
"deque",
"(",
")",
"with",
"open",
"(",
"file_path",
")",
"as",
"firmware_handle",
":",
"for",
"line",
"in",
"firmware_handle",
":",
"line",
"=",
"line",
".",
"rstrip",
"(",
")",
... | Reads a firmware file into a dequeue for processing.
:param file_path: Path to the firmware file
:type file_path: string
:returns: deque | [
"Reads",
"a",
"firmware",
"file",
"into",
"a",
"dequeue",
"for",
"processing",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/util.py#L96-L113 |
45,034 | nutechsoftware/alarmdecoder | alarmdecoder/util.py | Firmware.read | def read(device):
"""
Reads data from the specified device.
:param device: the AlarmDecoder device
:type device: :py:class:`~alarmdecoder.devices.Device`
:returns: string
"""
response = None
bytes_avail = bytes_available(device)
if isinstance(de... | python | def read(device):
"""
Reads data from the specified device.
:param device: the AlarmDecoder device
:type device: :py:class:`~alarmdecoder.devices.Device`
:returns: string
"""
response = None
bytes_avail = bytes_available(device)
if isinstance(de... | [
"def",
"read",
"(",
"device",
")",
":",
"response",
"=",
"None",
"bytes_avail",
"=",
"bytes_available",
"(",
"device",
")",
"if",
"isinstance",
"(",
"device",
",",
"alarmdecoder",
".",
"devices",
".",
"SerialDevice",
")",
":",
"response",
"=",
"device",
".... | Reads data from the specified device.
:param device: the AlarmDecoder device
:type device: :py:class:`~alarmdecoder.devices.Device`
:returns: string | [
"Reads",
"data",
"from",
"the",
"specified",
"device",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/util.py#L132-L149 |
45,035 | nutechsoftware/alarmdecoder | alarmdecoder/util.py | Firmware.upload | def upload(device, file_path, progress_callback=None, debug=False):
"""
Uploads firmware to an `AlarmDecoder`_ device.
:param file_path: firmware file path
:type file_path: string
:param progress_callback: callback function used to report progress
:type progress_callback... | python | def upload(device, file_path, progress_callback=None, debug=False):
"""
Uploads firmware to an `AlarmDecoder`_ device.
:param file_path: firmware file path
:type file_path: string
:param progress_callback: callback function used to report progress
:type progress_callback... | [
"def",
"upload",
"(",
"device",
",",
"file_path",
",",
"progress_callback",
"=",
"None",
",",
"debug",
"=",
"False",
")",
":",
"def",
"progress_stage",
"(",
"stage",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"Callback to update progress for the specified stage.\"\"... | Uploads firmware to an `AlarmDecoder`_ device.
:param file_path: firmware file path
:type file_path: string
:param progress_callback: callback function used to report progress
:type progress_callback: function
:raises: :py:class:`~alarmdecoder.util.NoDeviceError`, :py:class:`~a... | [
"Uploads",
"firmware",
"to",
"an",
"AlarmDecoder",
"_",
"device",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/util.py#L152-L262 |
45,036 | nutechsoftware/alarmdecoder | examples/usb_detection.py | create_device | def create_device(device_args):
"""
Creates an AlarmDecoder from the specified USB device arguments.
:param device_args: Tuple containing information on the USB device to open.
:type device_args: Tuple (vid, pid, serialnumber, interface_count, description)
"""
device = AlarmDecoder(USBDevice.fi... | python | def create_device(device_args):
"""
Creates an AlarmDecoder from the specified USB device arguments.
:param device_args: Tuple containing information on the USB device to open.
:type device_args: Tuple (vid, pid, serialnumber, interface_count, description)
"""
device = AlarmDecoder(USBDevice.fi... | [
"def",
"create_device",
"(",
"device_args",
")",
":",
"device",
"=",
"AlarmDecoder",
"(",
"USBDevice",
".",
"find",
"(",
"device_args",
")",
")",
"device",
".",
"on_message",
"+=",
"handle_message",
"device",
".",
"open",
"(",
")",
"return",
"device"
] | Creates an AlarmDecoder from the specified USB device arguments.
:param device_args: Tuple containing information on the USB device to open.
:type device_args: Tuple (vid, pid, serialnumber, interface_count, description) | [
"Creates",
"an",
"AlarmDecoder",
"from",
"the",
"specified",
"USB",
"device",
"arguments",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/examples/usb_detection.py#L34-L45 |
45,037 | box/rotunicode | rotunicode/rotunicode.py | RotUnicode.encode | def encode(cls, string, errors='strict'):
"""Return the encoded version of a string.
:param string:
The input string to encode.
:type string:
`basestring`
:param errors:
The error handling scheme. Only 'strict' is supported.
:type errors:
... | python | def encode(cls, string, errors='strict'):
"""Return the encoded version of a string.
:param string:
The input string to encode.
:type string:
`basestring`
:param errors:
The error handling scheme. Only 'strict' is supported.
:type errors:
... | [
"def",
"encode",
"(",
"cls",
",",
"string",
",",
"errors",
"=",
"'strict'",
")",
":",
"if",
"errors",
"!=",
"'strict'",
":",
"raise",
"UnicodeError",
"(",
"'Unsupported error handling {0}'",
".",
"format",
"(",
"errors",
")",
")",
"unicode_string",
"=",
"cls... | Return the encoded version of a string.
:param string:
The input string to encode.
:type string:
`basestring`
:param errors:
The error handling scheme. Only 'strict' is supported.
:type errors:
`basestring`
:return:
T... | [
"Return",
"the",
"encoded",
"version",
"of",
"a",
"string",
"."
] | 6149b6bb5bb50d322db248acfdb910dc3cb1bcc2 | https://github.com/box/rotunicode/blob/6149b6bb5bb50d322db248acfdb910dc3cb1bcc2/rotunicode/rotunicode.py#L50-L73 |
45,038 | box/rotunicode | rotunicode/rotunicode.py | RotUnicode.decode | def decode(cls, string, errors='strict'):
"""Return the decoded version of a string.
:param string:
The input string to decode.
:type string:
`basestring`
:param errors:
The error handling scheme. Only 'strict' is supported.
:type errors:
... | python | def decode(cls, string, errors='strict'):
"""Return the decoded version of a string.
:param string:
The input string to decode.
:type string:
`basestring`
:param errors:
The error handling scheme. Only 'strict' is supported.
:type errors:
... | [
"def",
"decode",
"(",
"cls",
",",
"string",
",",
"errors",
"=",
"'strict'",
")",
":",
"if",
"errors",
"!=",
"'strict'",
":",
"raise",
"UnicodeError",
"(",
"'Unsupported error handling {0}'",
".",
"format",
"(",
"errors",
")",
")",
"unicode_string",
"=",
"cls... | Return the decoded version of a string.
:param string:
The input string to decode.
:type string:
`basestring`
:param errors:
The error handling scheme. Only 'strict' is supported.
:type errors:
`basestring`
:return:
T... | [
"Return",
"the",
"decoded",
"version",
"of",
"a",
"string",
"."
] | 6149b6bb5bb50d322db248acfdb910dc3cb1bcc2 | https://github.com/box/rotunicode/blob/6149b6bb5bb50d322db248acfdb910dc3cb1bcc2/rotunicode/rotunicode.py#L76-L99 |
45,039 | box/rotunicode | rotunicode/rotunicode.py | RotUnicode.search_function | def search_function(cls, encoding):
"""Search function to find 'rotunicode' codec."""
if encoding == cls._codec_name:
return codecs.CodecInfo(
name=cls._codec_name,
encode=cls.encode,
decode=cls.decode,
)
return None | python | def search_function(cls, encoding):
"""Search function to find 'rotunicode' codec."""
if encoding == cls._codec_name:
return codecs.CodecInfo(
name=cls._codec_name,
encode=cls.encode,
decode=cls.decode,
)
return None | [
"def",
"search_function",
"(",
"cls",
",",
"encoding",
")",
":",
"if",
"encoding",
"==",
"cls",
".",
"_codec_name",
":",
"return",
"codecs",
".",
"CodecInfo",
"(",
"name",
"=",
"cls",
".",
"_codec_name",
",",
"encode",
"=",
"cls",
".",
"encode",
",",
"... | Search function to find 'rotunicode' codec. | [
"Search",
"function",
"to",
"find",
"rotunicode",
"codec",
"."
] | 6149b6bb5bb50d322db248acfdb910dc3cb1bcc2 | https://github.com/box/rotunicode/blob/6149b6bb5bb50d322db248acfdb910dc3cb1bcc2/rotunicode/rotunicode.py#L103-L111 |
45,040 | box/rotunicode | rotunicode/rotunicode.py | RotUnicode._ensure_unicode_string | def _ensure_unicode_string(string):
"""Returns a unicode string for string.
:param string:
The input string.
:type string:
`basestring`
:returns:
A unicode string.
:rtype:
`unicode`
"""
if not isinstance(string, si... | python | def _ensure_unicode_string(string):
"""Returns a unicode string for string.
:param string:
The input string.
:type string:
`basestring`
:returns:
A unicode string.
:rtype:
`unicode`
"""
if not isinstance(string, si... | [
"def",
"_ensure_unicode_string",
"(",
"string",
")",
":",
"if",
"not",
"isinstance",
"(",
"string",
",",
"six",
".",
"text_type",
")",
":",
"string",
"=",
"string",
".",
"decode",
"(",
"'utf-8'",
")",
"return",
"string"
] | Returns a unicode string for string.
:param string:
The input string.
:type string:
`basestring`
:returns:
A unicode string.
:rtype:
`unicode` | [
"Returns",
"a",
"unicode",
"string",
"for",
"string",
"."
] | 6149b6bb5bb50d322db248acfdb910dc3cb1bcc2 | https://github.com/box/rotunicode/blob/6149b6bb5bb50d322db248acfdb910dc3cb1bcc2/rotunicode/rotunicode.py#L114-L129 |
45,041 | attilaolah/diffbot.py | diffbot.py | Client._get | def _get(url, params=None):
"""HTTP GET request."""
try:
response = requests.get(url, params=params)
response.raise_for_status()
# If JSON fails, return raw data
# (e.g. when downloading CSV job logs).
try:
return response.json(... | python | def _get(url, params=None):
"""HTTP GET request."""
try:
response = requests.get(url, params=params)
response.raise_for_status()
# If JSON fails, return raw data
# (e.g. when downloading CSV job logs).
try:
return response.json(... | [
"def",
"_get",
"(",
"url",
",",
"params",
"=",
"None",
")",
":",
"try",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"params",
"=",
"params",
")",
"response",
".",
"raise_for_status",
"(",
")",
"# If JSON fails, return raw data",
"# (e.g.... | HTTP GET request. | [
"HTTP",
"GET",
"request",
"."
] | b66d68a36a22c944297c0575413db23687029af4 | https://github.com/attilaolah/diffbot.py/blob/b66d68a36a22c944297c0575413db23687029af4/diffbot.py#L33-L46 |
45,042 | attilaolah/diffbot.py | diffbot.py | Client._post | def _post(url, data, content_type, params=None):
"""HTTP POST request."""
try:
response = requests.post(url, params=params, data=data, headers={
'Content-Type': content_type,
})
response.raise_for_status()
return response.json()
exc... | python | def _post(url, data, content_type, params=None):
"""HTTP POST request."""
try:
response = requests.post(url, params=params, data=data, headers={
'Content-Type': content_type,
})
response.raise_for_status()
return response.json()
exc... | [
"def",
"_post",
"(",
"url",
",",
"data",
",",
"content_type",
",",
"params",
"=",
"None",
")",
":",
"try",
":",
"response",
"=",
"requests",
".",
"post",
"(",
"url",
",",
"params",
"=",
"params",
",",
"data",
"=",
"data",
",",
"headers",
"=",
"{",
... | HTTP POST request. | [
"HTTP",
"POST",
"request",
"."
] | b66d68a36a22c944297c0575413db23687029af4 | https://github.com/attilaolah/diffbot.py/blob/b66d68a36a22c944297c0575413db23687029af4/diffbot.py#L49-L62 |
45,043 | attilaolah/diffbot.py | diffbot.py | Client.api | def api(self, name, url, **kwargs):
"""Generic API method."""
if name not in self._apis:
raise ValueError('API name must be one of {0}, not {1!r}.'.format(
tuple(self._apis), name))
fields = kwargs.get('fields')
timeout = kwargs.get('timeout')
text = k... | python | def api(self, name, url, **kwargs):
"""Generic API method."""
if name not in self._apis:
raise ValueError('API name must be one of {0}, not {1!r}.'.format(
tuple(self._apis), name))
fields = kwargs.get('fields')
timeout = kwargs.get('timeout')
text = k... | [
"def",
"api",
"(",
"self",
",",
"name",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"name",
"not",
"in",
"self",
".",
"_apis",
":",
"raise",
"ValueError",
"(",
"'API name must be one of {0}, not {1!r}.'",
".",
"format",
"(",
"tuple",
"(",
"self"... | Generic API method. | [
"Generic",
"API",
"method",
"."
] | b66d68a36a22c944297c0575413db23687029af4 | https://github.com/attilaolah/diffbot.py/blob/b66d68a36a22c944297c0575413db23687029af4/diffbot.py#L68-L90 |
45,044 | attilaolah/diffbot.py | diffbot.py | Client.crawl | def crawl(self, urls, name='crawl', api='analyze', **kwargs):
"""Crawlbot API.
Returns a diffbot.Job object to check and retrieve crawl status.
"""
# If multiple seed URLs are specified, join with whitespace.
if isinstance(urls, list):
urls = ' '.join(urls)
u... | python | def crawl(self, urls, name='crawl', api='analyze', **kwargs):
"""Crawlbot API.
Returns a diffbot.Job object to check and retrieve crawl status.
"""
# If multiple seed URLs are specified, join with whitespace.
if isinstance(urls, list):
urls = ' '.join(urls)
u... | [
"def",
"crawl",
"(",
"self",
",",
"urls",
",",
"name",
"=",
"'crawl'",
",",
"api",
"=",
"'analyze'",
",",
"*",
"*",
"kwargs",
")",
":",
"# If multiple seed URLs are specified, join with whitespace.",
"if",
"isinstance",
"(",
"urls",
",",
"list",
")",
":",
"u... | Crawlbot API.
Returns a diffbot.Job object to check and retrieve crawl status. | [
"Crawlbot",
"API",
"."
] | b66d68a36a22c944297c0575413db23687029af4 | https://github.com/attilaolah/diffbot.py/blob/b66d68a36a22c944297c0575413db23687029af4/diffbot.py#L116-L139 |
45,045 | nutechsoftware/alarmdecoder | examples/lrr_example.py | handle_lrr_message | def handle_lrr_message(sender, message):
"""
Handles message events from the AlarmDecoder.
"""
print(sender, message.partition, message.event_type, message.event_data) | python | def handle_lrr_message(sender, message):
"""
Handles message events from the AlarmDecoder.
"""
print(sender, message.partition, message.event_type, message.event_data) | [
"def",
"handle_lrr_message",
"(",
"sender",
",",
"message",
")",
":",
"print",
"(",
"sender",
",",
"message",
".",
"partition",
",",
"message",
".",
"event_type",
",",
"message",
".",
"event_data",
")"
] | Handles message events from the AlarmDecoder. | [
"Handles",
"message",
"events",
"from",
"the",
"AlarmDecoder",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/examples/lrr_example.py#L25-L29 |
45,046 | nutechsoftware/alarmdecoder | examples/alarm_email.py | main | def main():
"""
Example application that sends an email when an alarm event is
detected.
"""
try:
# Retrieve the first USB device
device = AlarmDecoder(SerialDevice(interface=SERIAL_DEVICE))
# Set up an event handler and open the device
device.on_alarm += handle_alar... | python | def main():
"""
Example application that sends an email when an alarm event is
detected.
"""
try:
# Retrieve the first USB device
device = AlarmDecoder(SerialDevice(interface=SERIAL_DEVICE))
# Set up an event handler and open the device
device.on_alarm += handle_alar... | [
"def",
"main",
"(",
")",
":",
"try",
":",
"# Retrieve the first USB device",
"device",
"=",
"AlarmDecoder",
"(",
"SerialDevice",
"(",
"interface",
"=",
"SERIAL_DEVICE",
")",
")",
"# Set up an event handler and open the device",
"device",
".",
"on_alarm",
"+=",
"handle... | Example application that sends an email when an alarm event is
detected. | [
"Example",
"application",
"that",
"sends",
"an",
"email",
"when",
"an",
"alarm",
"event",
"is",
"detected",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/examples/alarm_email.py#L19-L35 |
45,047 | nutechsoftware/alarmdecoder | examples/alarm_email.py | handle_alarm | def handle_alarm(sender, **kwargs):
"""
Handles alarm events from the AlarmDecoder.
"""
zone = kwargs.pop('zone', None)
text = "Alarm: Zone {0}".format(zone)
# Build the email message
msg = MIMEText(text)
msg['Subject'] = SUBJECT
msg['From'] = FROM_ADDRESS
msg['To'] = TO_ADDRESS... | python | def handle_alarm(sender, **kwargs):
"""
Handles alarm events from the AlarmDecoder.
"""
zone = kwargs.pop('zone', None)
text = "Alarm: Zone {0}".format(zone)
# Build the email message
msg = MIMEText(text)
msg['Subject'] = SUBJECT
msg['From'] = FROM_ADDRESS
msg['To'] = TO_ADDRESS... | [
"def",
"handle_alarm",
"(",
"sender",
",",
"*",
"*",
"kwargs",
")",
":",
"zone",
"=",
"kwargs",
".",
"pop",
"(",
"'zone'",
",",
"None",
")",
"text",
"=",
"\"Alarm: Zone {0}\"",
".",
"format",
"(",
"zone",
")",
"# Build the email message",
"msg",
"=",
"MI... | Handles alarm events from the AlarmDecoder. | [
"Handles",
"alarm",
"events",
"from",
"the",
"AlarmDecoder",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/examples/alarm_email.py#L37-L60 |
45,048 | nutechsoftware/alarmdecoder | examples/ssl_socket.py | main | def main():
"""
Example application that opens a device that has been exposed to the network
with ser2sock and SSL encryption and authentication.
"""
try:
# Retrieve an AD2 device that has been exposed with ser2sock on localhost:10000.
ssl_device = SocketDevice(interface=('localhost'... | python | def main():
"""
Example application that opens a device that has been exposed to the network
with ser2sock and SSL encryption and authentication.
"""
try:
# Retrieve an AD2 device that has been exposed with ser2sock on localhost:10000.
ssl_device = SocketDevice(interface=('localhost'... | [
"def",
"main",
"(",
")",
":",
"try",
":",
"# Retrieve an AD2 device that has been exposed with ser2sock on localhost:10000.",
"ssl_device",
"=",
"SocketDevice",
"(",
"interface",
"=",
"(",
"'localhost'",
",",
"10000",
")",
")",
"# Enable SSL and set the certificates to be use... | Example application that opens a device that has been exposed to the network
with ser2sock and SSL encryption and authentication. | [
"Example",
"application",
"that",
"opens",
"a",
"device",
"that",
"has",
"been",
"exposed",
"to",
"the",
"network",
"with",
"ser2sock",
"and",
"SSL",
"encryption",
"and",
"authentication",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/examples/ssl_socket.py#L12-L39 |
45,049 | box/rotunicode | rotunicode/utils.py | ruencode | def ruencode(string, extension=False):
"""Encode a string using 'rotunicode' codec.
:param string:
The input string to encode.
:type string:
`basestring`
:param extension:
True if the entire input string should be encoded.
False to split the input string using :func:`os... | python | def ruencode(string, extension=False):
"""Encode a string using 'rotunicode' codec.
:param string:
The input string to encode.
:type string:
`basestring`
:param extension:
True if the entire input string should be encoded.
False to split the input string using :func:`os... | [
"def",
"ruencode",
"(",
"string",
",",
"extension",
"=",
"False",
")",
":",
"if",
"extension",
":",
"file_name",
"=",
"string",
"file_ext",
"=",
"''",
"else",
":",
"file_name",
",",
"file_ext",
"=",
"splitext",
"(",
"string",
")",
"encoded_value",
",",
"... | Encode a string using 'rotunicode' codec.
:param string:
The input string to encode.
:type string:
`basestring`
:param extension:
True if the entire input string should be encoded.
False to split the input string using :func:`os.path.splitext` and
encode only the fi... | [
"Encode",
"a",
"string",
"using",
"rotunicode",
"codec",
"."
] | 6149b6bb5bb50d322db248acfdb910dc3cb1bcc2 | https://github.com/box/rotunicode/blob/6149b6bb5bb50d322db248acfdb910dc3cb1bcc2/rotunicode/utils.py#L27-L54 |
45,050 | box/rotunicode | rotunicode/utils.py | parse_escape_sequences | def parse_escape_sequences(string):
"""Parse a string for possible escape sequences.
Sample usage:
>>> parse_escape_sequences('foo\\nbar')
'foo\nbar'
>>> parse_escape_sequences('foo\\\\u0256')
'foo\\u0256'
:param string:
Any string.
:type string:
`basestring`
:raise... | python | def parse_escape_sequences(string):
"""Parse a string for possible escape sequences.
Sample usage:
>>> parse_escape_sequences('foo\\nbar')
'foo\nbar'
>>> parse_escape_sequences('foo\\\\u0256')
'foo\\u0256'
:param string:
Any string.
:type string:
`basestring`
:raise... | [
"def",
"parse_escape_sequences",
"(",
"string",
")",
":",
"string",
"=",
"safe_unicode",
"(",
"string",
")",
"characters",
"=",
"[",
"]",
"i",
"=",
"0",
"string_len",
"=",
"len",
"(",
"string",
")",
"while",
"i",
"<",
"string_len",
":",
"character",
"=",... | Parse a string for possible escape sequences.
Sample usage:
>>> parse_escape_sequences('foo\\nbar')
'foo\nbar'
>>> parse_escape_sequences('foo\\\\u0256')
'foo\\u0256'
:param string:
Any string.
:type string:
`basestring`
:raises:
:class:`ValueError` if a backsla... | [
"Parse",
"a",
"string",
"for",
"possible",
"escape",
"sequences",
"."
] | 6149b6bb5bb50d322db248acfdb910dc3cb1bcc2 | https://github.com/box/rotunicode/blob/6149b6bb5bb50d322db248acfdb910dc3cb1bcc2/rotunicode/utils.py#L96-L161 |
45,051 | nutechsoftware/alarmdecoder | alarmdecoder/devices/usb_device.py | USBDevice.find_all | def find_all(cls, vid=None, pid=None):
"""
Returns all FTDI devices matching our vendor and product IDs.
:returns: list of devices
:raises: :py:class:`~alarmdecoder.util.CommError`
"""
if not have_pyftdi:
raise ImportError('The USBDevice class has been disabl... | python | def find_all(cls, vid=None, pid=None):
"""
Returns all FTDI devices matching our vendor and product IDs.
:returns: list of devices
:raises: :py:class:`~alarmdecoder.util.CommError`
"""
if not have_pyftdi:
raise ImportError('The USBDevice class has been disabl... | [
"def",
"find_all",
"(",
"cls",
",",
"vid",
"=",
"None",
",",
"pid",
"=",
"None",
")",
":",
"if",
"not",
"have_pyftdi",
":",
"raise",
"ImportError",
"(",
"'The USBDevice class has been disabled due to missing requirement: pyftdi or pyusb.'",
")",
"cls",
".",
"__devic... | Returns all FTDI devices matching our vendor and product IDs.
:returns: list of devices
:raises: :py:class:`~alarmdecoder.util.CommError` | [
"Returns",
"all",
"FTDI",
"devices",
"matching",
"our",
"vendor",
"and",
"product",
"IDs",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/devices/usb_device.py#L62-L84 |
45,052 | nutechsoftware/alarmdecoder | alarmdecoder/devices/usb_device.py | USBDevice.start_detection | def start_detection(cls, on_attached=None, on_detached=None):
"""
Starts the device detection thread.
:param on_attached: function to be called when a device is attached **Callback definition:** *def callback(thread, device)*
:type on_attached: function
:param on_detached: func... | python | def start_detection(cls, on_attached=None, on_detached=None):
"""
Starts the device detection thread.
:param on_attached: function to be called when a device is attached **Callback definition:** *def callback(thread, device)*
:type on_attached: function
:param on_detached: func... | [
"def",
"start_detection",
"(",
"cls",
",",
"on_attached",
"=",
"None",
",",
"on_detached",
"=",
"None",
")",
":",
"if",
"not",
"have_pyftdi",
":",
"raise",
"ImportError",
"(",
"'The USBDevice class has been disabled due to missing requirement: pyftdi or pyusb.'",
")",
"... | Starts the device detection thread.
:param on_attached: function to be called when a device is attached **Callback definition:** *def callback(thread, device)*
:type on_attached: function
:param on_detached: function to be called when a device is detached **Callback definition:** *def callbac... | [
"Starts",
"the",
"device",
"detection",
"thread",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/devices/usb_device.py#L124-L144 |
45,053 | nutechsoftware/alarmdecoder | alarmdecoder/devices/usb_device.py | USBDevice.interface | def interface(self, value):
"""
Sets the interface used to connect to the device.
:param value: may specify either the serial number or the device index
:type value: string or int
"""
self._interface = value
if isinstance(value, int):
self._device_num... | python | def interface(self, value):
"""
Sets the interface used to connect to the device.
:param value: may specify either the serial number or the device index
:type value: string or int
"""
self._interface = value
if isinstance(value, int):
self._device_num... | [
"def",
"interface",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"_interface",
"=",
"value",
"if",
"isinstance",
"(",
"value",
",",
"int",
")",
":",
"self",
".",
"_device_number",
"=",
"value",
"else",
":",
"self",
".",
"_serial_number",
"=",
"val... | Sets the interface used to connect to the device.
:param value: may specify either the serial number or the device index
:type value: string or int | [
"Sets",
"the",
"interface",
"used",
"to",
"connect",
"to",
"the",
"device",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/devices/usb_device.py#L170-L181 |
45,054 | nutechsoftware/alarmdecoder | alarmdecoder/devices/usb_device.py | USBDevice._get_serial_number | def _get_serial_number(self):
"""
Retrieves the FTDI device serial number.
:returns: string containing the device serial number
"""
return usb.util.get_string(self._device.usb_dev, 64, self._device.usb_dev.iSerialNumber) | python | def _get_serial_number(self):
"""
Retrieves the FTDI device serial number.
:returns: string containing the device serial number
"""
return usb.util.get_string(self._device.usb_dev, 64, self._device.usb_dev.iSerialNumber) | [
"def",
"_get_serial_number",
"(",
"self",
")",
":",
"return",
"usb",
".",
"util",
".",
"get_string",
"(",
"self",
".",
"_device",
".",
"usb_dev",
",",
"64",
",",
"self",
".",
"_device",
".",
"usb_dev",
".",
"iSerialNumber",
")"
] | Retrieves the FTDI device serial number.
:returns: string containing the device serial number | [
"Retrieves",
"the",
"FTDI",
"device",
"serial",
"number",
"."
] | b0c014089e24455228cb4402cf30ba98157578cd | https://github.com/nutechsoftware/alarmdecoder/blob/b0c014089e24455228cb4402cf30ba98157578cd/alarmdecoder/devices/usb_device.py#L427-L433 |
45,055 | mgedmin/imgdiff | imgdiff.py | parse_color | def parse_color(color):
"""Parse a color value.
I've decided not to expect a leading '#' because it's a comment character
in some shells.
>>> parse_color('4bf') == (0x44, 0xbb, 0xff, 0xff)
True
>>> parse_color('ccce') == (0xcc, 0xcc, 0xcc, 0xee)
True
>>> parse_color... | python | def parse_color(color):
"""Parse a color value.
I've decided not to expect a leading '#' because it's a comment character
in some shells.
>>> parse_color('4bf') == (0x44, 0xbb, 0xff, 0xff)
True
>>> parse_color('ccce') == (0xcc, 0xcc, 0xcc, 0xee)
True
>>> parse_color... | [
"def",
"parse_color",
"(",
"color",
")",
":",
"if",
"len",
"(",
"color",
")",
"not",
"in",
"(",
"3",
",",
"4",
",",
"6",
",",
"8",
")",
":",
"raise",
"ValueError",
"(",
"'bad color %s'",
"%",
"repr",
"(",
"color",
")",
")",
"if",
"len",
"(",
"c... | Parse a color value.
I've decided not to expect a leading '#' because it's a comment character
in some shells.
>>> parse_color('4bf') == (0x44, 0xbb, 0xff, 0xff)
True
>>> parse_color('ccce') == (0xcc, 0xcc, 0xcc, 0xee)
True
>>> parse_color('d8b4a2') == (0xd8, 0xb4, 0xa2... | [
"Parse",
"a",
"color",
"value",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L25-L58 |
45,056 | mgedmin/imgdiff | imgdiff.py | check_color | def check_color(option, opt, value):
"""Validate and convert an option value of type 'color'.
``option`` is an optparse.Option instance.
``opt`` is a string with the user-supplied option name (e.g. '--bgcolor').
``value`` is the user-supplied value.
"""
try:
return parse_color(value)
... | python | def check_color(option, opt, value):
"""Validate and convert an option value of type 'color'.
``option`` is an optparse.Option instance.
``opt`` is a string with the user-supplied option name (e.g. '--bgcolor').
``value`` is the user-supplied value.
"""
try:
return parse_color(value)
... | [
"def",
"check_color",
"(",
"option",
",",
"opt",
",",
"value",
")",
":",
"try",
":",
"return",
"parse_color",
"(",
"value",
")",
"except",
"ValueError",
":",
"raise",
"optparse",
".",
"OptionValueError",
"(",
"\"option %s: invalid color value: %r\"",
"%",
"(",
... | Validate and convert an option value of type 'color'.
``option`` is an optparse.Option instance.
``opt`` is a string with the user-supplied option name (e.g. '--bgcolor').
``value`` is the user-supplied value. | [
"Validate",
"and",
"convert",
"an",
"option",
"value",
"of",
"type",
"color",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L61-L74 |
45,057 | mgedmin/imgdiff | imgdiff.py | pick_orientation | def pick_orientation(img1, img2, spacing, desired_aspect=1.618):
"""Pick a tiling orientation for two images.
Returns either 'lr' for left-and-right, or 'tb' for top-and-bottom.
Picks the one that makes the combined image have a better aspect
ratio, where 'better' is defined as 'closer to 1:1.618'.
... | python | def pick_orientation(img1, img2, spacing, desired_aspect=1.618):
"""Pick a tiling orientation for two images.
Returns either 'lr' for left-and-right, or 'tb' for top-and-bottom.
Picks the one that makes the combined image have a better aspect
ratio, where 'better' is defined as 'closer to 1:1.618'.
... | [
"def",
"pick_orientation",
"(",
"img1",
",",
"img2",
",",
"spacing",
",",
"desired_aspect",
"=",
"1.618",
")",
":",
"w1",
",",
"h1",
"=",
"img1",
".",
"size",
"w2",
",",
"h2",
"=",
"img2",
".",
"size",
"size_a",
"=",
"(",
"w1",
"+",
"spacing",
"+",... | Pick a tiling orientation for two images.
Returns either 'lr' for left-and-right, or 'tb' for top-and-bottom.
Picks the one that makes the combined image have a better aspect
ratio, where 'better' is defined as 'closer to 1:1.618'. | [
"Pick",
"a",
"tiling",
"orientation",
"for",
"two",
"images",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L169-L189 |
45,058 | mgedmin/imgdiff | imgdiff.py | tile_images | def tile_images(img1, img2, mask1, mask2, opts):
"""Combine two images into one by tiling them.
``mask1`` and ``mask2`` provide optional masks for alpha-blending;
pass None to avoid.
Fills unused areas with ``opts.bgcolor``.
Puts a ``opts.spacing``-wide bar with a thin line of ``opts.sepcolor``
... | python | def tile_images(img1, img2, mask1, mask2, opts):
"""Combine two images into one by tiling them.
``mask1`` and ``mask2`` provide optional masks for alpha-blending;
pass None to avoid.
Fills unused areas with ``opts.bgcolor``.
Puts a ``opts.spacing``-wide bar with a thin line of ``opts.sepcolor``
... | [
"def",
"tile_images",
"(",
"img1",
",",
"img2",
",",
"mask1",
",",
"mask2",
",",
"opts",
")",
":",
"w1",
",",
"h1",
"=",
"img1",
".",
"size",
"w2",
",",
"h2",
"=",
"img2",
".",
"size",
"if",
"opts",
".",
"orientation",
"==",
"'auto'",
":",
"opts"... | Combine two images into one by tiling them.
``mask1`` and ``mask2`` provide optional masks for alpha-blending;
pass None to avoid.
Fills unused areas with ``opts.bgcolor``.
Puts a ``opts.spacing``-wide bar with a thin line of ``opts.sepcolor``
color between them.
``opts.orientation`` can be ... | [
"Combine",
"two",
"images",
"into",
"one",
"by",
"tiling",
"them",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L192-L232 |
45,059 | mgedmin/imgdiff | imgdiff.py | spawn_viewer | def spawn_viewer(viewer, img, filename, grace):
"""Launch an external program to view an image.
``img`` is an Image object.
``viewer`` is a command name. Arguments are not allowed; exactly one
argument will be passed: the name of the image file.
``filename`` is the suggested filename for a tempo... | python | def spawn_viewer(viewer, img, filename, grace):
"""Launch an external program to view an image.
``img`` is an Image object.
``viewer`` is a command name. Arguments are not allowed; exactly one
argument will be passed: the name of the image file.
``filename`` is the suggested filename for a tempo... | [
"def",
"spawn_viewer",
"(",
"viewer",
",",
"img",
",",
"filename",
",",
"grace",
")",
":",
"tempdir",
"=",
"tempfile",
".",
"mkdtemp",
"(",
"prefix",
"=",
"'imgdiff-'",
")",
"try",
":",
"imgfile",
"=",
"os",
".",
"path",
".",
"join",
"(",
"tempdir",
... | Launch an external program to view an image.
``img`` is an Image object.
``viewer`` is a command name. Arguments are not allowed; exactly one
argument will be passed: the name of the image file.
``filename`` is the suggested filename for a temporary file.
``grace`` is the number of seconds to w... | [
"Launch",
"an",
"external",
"program",
"to",
"view",
"an",
"image",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L235-L262 |
45,060 | mgedmin/imgdiff | imgdiff.py | tweak_diff | def tweak_diff(diff, opacity):
"""Adjust a difference map into an opacity mask for a given lowest opacity.
Performs a linear map from [0; 255] to [opacity; 255].
The result is that similar areas will have a given opacity, while
dissimilar areas will be opaque.
"""
mask = diff.point(lambda i: o... | python | def tweak_diff(diff, opacity):
"""Adjust a difference map into an opacity mask for a given lowest opacity.
Performs a linear map from [0; 255] to [opacity; 255].
The result is that similar areas will have a given opacity, while
dissimilar areas will be opaque.
"""
mask = diff.point(lambda i: o... | [
"def",
"tweak_diff",
"(",
"diff",
",",
"opacity",
")",
":",
"mask",
"=",
"diff",
".",
"point",
"(",
"lambda",
"i",
":",
"opacity",
"+",
"i",
"*",
"(",
"255",
"-",
"opacity",
")",
"//",
"255",
")",
"return",
"mask"
] | Adjust a difference map into an opacity mask for a given lowest opacity.
Performs a linear map from [0; 255] to [opacity; 255].
The result is that similar areas will have a given opacity, while
dissimilar areas will be opaque. | [
"Adjust",
"a",
"difference",
"map",
"into",
"an",
"opacity",
"mask",
"for",
"a",
"given",
"lowest",
"opacity",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L265-L274 |
45,061 | mgedmin/imgdiff | imgdiff.py | diff | def diff(img1, img2, x1y1, x2y2):
"""Compare two images with given alignments.
Returns a difference map.
``x1y1``: a tuple ``(x1, y1)`` to specify the top-left corner of the
aligned area with respect to ``img1``.
``x2y2``: a tuple ``(x2, y2)`` to specify the top-left corner of
the aligned are... | python | def diff(img1, img2, x1y1, x2y2):
"""Compare two images with given alignments.
Returns a difference map.
``x1y1``: a tuple ``(x1, y1)`` to specify the top-left corner of the
aligned area with respect to ``img1``.
``x2y2``: a tuple ``(x2, y2)`` to specify the top-left corner of
the aligned are... | [
"def",
"diff",
"(",
"img1",
",",
"img2",
",",
"x1y1",
",",
"x2y2",
")",
":",
"x1",
",",
"y1",
"=",
"x1y1",
"x2",
",",
"y2",
"=",
"x2y2",
"w1",
",",
"h1",
"=",
"img1",
".",
"size",
"w2",
",",
"h2",
"=",
"img2",
".",
"size",
"w",
",",
"h",
... | Compare two images with given alignments.
Returns a difference map.
``x1y1``: a tuple ``(x1, y1)`` to specify the top-left corner of the
aligned area with respect to ``img1``.
``x2y2``: a tuple ``(x2, y2)`` to specify the top-left corner of
the aligned area with respect to ``img2``.
Either `... | [
"Compare",
"two",
"images",
"with",
"given",
"alignments",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L277-L346 |
45,062 | mgedmin/imgdiff | imgdiff.py | diff_badness | def diff_badness(diff):
"""Estimate the "badness" value of a difference map.
Returns 0 if the pictures are identical
Returns a large number if the pictures are completely different
(e.g. a black field and a white field). More specifically, returns
``255 * width * height`` where ``(width, height) ... | python | def diff_badness(diff):
"""Estimate the "badness" value of a difference map.
Returns 0 if the pictures are identical
Returns a large number if the pictures are completely different
(e.g. a black field and a white field). More specifically, returns
``255 * width * height`` where ``(width, height) ... | [
"def",
"diff_badness",
"(",
"diff",
")",
":",
"# identical pictures = black image = return 0",
"# completely different pictures = white image = return lots",
"return",
"sum",
"(",
"i",
"*",
"n",
"for",
"i",
",",
"n",
"in",
"enumerate",
"(",
"diff",
".",
"histogram",
"... | Estimate the "badness" value of a difference map.
Returns 0 if the pictures are identical
Returns a large number if the pictures are completely different
(e.g. a black field and a white field). More specifically, returns
``255 * width * height`` where ``(width, height) == diff.size``.
Returns so... | [
"Estimate",
"the",
"badness",
"value",
"of",
"a",
"difference",
"map",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L349-L362 |
45,063 | mgedmin/imgdiff | imgdiff.py | best_diff | def best_diff(img1, img2, opts):
"""Find the best alignment of two images that minimizes the differences.
Returns (diff, alignments) where ``diff`` is a difference map, and
``alignments`` is a tuple ((x1, y2), (x2, y2)).
See ``diff()`` for the description of the alignment numbers.
"""
w1, h1 =... | python | def best_diff(img1, img2, opts):
"""Find the best alignment of two images that minimizes the differences.
Returns (diff, alignments) where ``diff`` is a difference map, and
``alignments`` is a tuple ((x1, y2), (x2, y2)).
See ``diff()`` for the description of the alignment numbers.
"""
w1, h1 =... | [
"def",
"best_diff",
"(",
"img1",
",",
"img2",
",",
"opts",
")",
":",
"w1",
",",
"h1",
"=",
"img1",
".",
"size",
"w2",
",",
"h2",
"=",
"img2",
".",
"size",
"w",
",",
"h",
"=",
"min",
"(",
"w1",
",",
"w2",
")",
",",
"min",
"(",
"h1",
",",
"... | Find the best alignment of two images that minimizes the differences.
Returns (diff, alignments) where ``diff`` is a difference map, and
``alignments`` is a tuple ((x1, y2), (x2, y2)).
See ``diff()`` for the description of the alignment numbers. | [
"Find",
"the",
"best",
"alignment",
"of",
"two",
"images",
"that",
"minimizes",
"the",
"differences",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L415-L450 |
45,064 | mgedmin/imgdiff | imgdiff.py | simple_highlight | def simple_highlight(img1, img2, opts):
"""Try to align the two images to minimize pixel differences.
Produces two masks for img1 and img2.
The algorithm works by comparing every possible alignment of the images,
finding the aligment that minimzes the differences, and then smoothing
it a bit to re... | python | def simple_highlight(img1, img2, opts):
"""Try to align the two images to minimize pixel differences.
Produces two masks for img1 and img2.
The algorithm works by comparing every possible alignment of the images,
finding the aligment that minimzes the differences, and then smoothing
it a bit to re... | [
"def",
"simple_highlight",
"(",
"img1",
",",
"img2",
",",
"opts",
")",
":",
"try",
":",
"diff",
",",
"(",
"(",
"x1",
",",
"y1",
")",
",",
"(",
"x2",
",",
"y2",
")",
")",
"=",
"best_diff",
"(",
"img1",
",",
"img2",
",",
"opts",
")",
"except",
... | Try to align the two images to minimize pixel differences.
Produces two masks for img1 and img2.
The algorithm works by comparing every possible alignment of the images,
finding the aligment that minimzes the differences, and then smoothing
it a bit to reduce spurious matches in areas that are percept... | [
"Try",
"to",
"align",
"the",
"two",
"images",
"to",
"minimize",
"pixel",
"differences",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L453-L478 |
45,065 | mgedmin/imgdiff | imgdiff.py | slow_highlight | def slow_highlight(img1, img2, opts):
"""Try to find similar areas between two images.
Produces two masks for img1 and img2.
The algorithm works by comparing every possible alignment of the images,
smoothing it a bit to reduce spurious matches in areas that are
perceptibly different (e.g. text), a... | python | def slow_highlight(img1, img2, opts):
"""Try to find similar areas between two images.
Produces two masks for img1 and img2.
The algorithm works by comparing every possible alignment of the images,
smoothing it a bit to reduce spurious matches in areas that are
perceptibly different (e.g. text), a... | [
"def",
"slow_highlight",
"(",
"img1",
",",
"img2",
",",
"opts",
")",
":",
"w1",
",",
"h1",
"=",
"img1",
".",
"size",
"w2",
",",
"h2",
"=",
"img2",
".",
"size",
"W",
",",
"H",
"=",
"max",
"(",
"w1",
",",
"w2",
")",
",",
"max",
"(",
"h1",
","... | Try to find similar areas between two images.
Produces two masks for img1 and img2.
The algorithm works by comparing every possible alignment of the images,
smoothing it a bit to reduce spurious matches in areas that are
perceptibly different (e.g. text), and then taking the point-wise minimum
of ... | [
"Try",
"to",
"find",
"similar",
"areas",
"between",
"two",
"images",
"."
] | f80b173c6fb1f32f3e016d153b5b84a14d966e1a | https://github.com/mgedmin/imgdiff/blob/f80b173c6fb1f32f3e016d153b5b84a14d966e1a/imgdiff.py#L481-L552 |
45,066 | LinuxChristian/pyW215 | pyW215/pyW215.py | SmartPlug.SOAPAction | def SOAPAction(self, Action, responseElement, params = "", recursive = False):
"""Generate the SOAP action call.
:type Action: str
:type responseElement: str
:type params: str
:type recursive: bool
:param Action: The action to perform on the device
:param respons... | python | def SOAPAction(self, Action, responseElement, params = "", recursive = False):
"""Generate the SOAP action call.
:type Action: str
:type responseElement: str
:type params: str
:type recursive: bool
:param Action: The action to perform on the device
:param respons... | [
"def",
"SOAPAction",
"(",
"self",
",",
"Action",
",",
"responseElement",
",",
"params",
"=",
"\"\"",
",",
"recursive",
"=",
"False",
")",
":",
"# Authenticate client",
"if",
"self",
".",
"authenticated",
"is",
"None",
":",
"self",
".",
"authenticated",
"=",
... | Generate the SOAP action call.
:type Action: str
:type responseElement: str
:type params: str
:type recursive: bool
:param Action: The action to perform on the device
:param responseElement: The XML element that is returned upon success
:param params: Any additio... | [
"Generate",
"the",
"SOAP",
"action",
"call",
"."
] | 63e50b8ee11bc38ed66554f9b92429b552dda550 | https://github.com/LinuxChristian/pyW215/blob/63e50b8ee11bc38ed66554f9b92429b552dda550/pyW215/pyW215.py#L117-L184 |
45,067 | LinuxChristian/pyW215 | pyW215/pyW215.py | SmartPlug.fetchMyCgi | def fetchMyCgi(self):
"""Fetches statistics from my_cgi.cgi"""
try:
response = urlopen(Request('http://{}/my_cgi.cgi'.format(self.ip), b'request=create_chklst'));
except (HTTPError, URLError):
_LOGGER.warning("Failed to open url to {}".format(self.ip))
self._e... | python | def fetchMyCgi(self):
"""Fetches statistics from my_cgi.cgi"""
try:
response = urlopen(Request('http://{}/my_cgi.cgi'.format(self.ip), b'request=create_chklst'));
except (HTTPError, URLError):
_LOGGER.warning("Failed to open url to {}".format(self.ip))
self._e... | [
"def",
"fetchMyCgi",
"(",
"self",
")",
":",
"try",
":",
"response",
"=",
"urlopen",
"(",
"Request",
"(",
"'http://{}/my_cgi.cgi'",
".",
"format",
"(",
"self",
".",
"ip",
")",
",",
"b'request=create_chklst'",
")",
")",
"except",
"(",
"HTTPError",
",",
"URLE... | Fetches statistics from my_cgi.cgi | [
"Fetches",
"statistics",
"from",
"my_cgi",
".",
"cgi"
] | 63e50b8ee11bc38ed66554f9b92429b552dda550 | https://github.com/LinuxChristian/pyW215/blob/63e50b8ee11bc38ed66554f9b92429b552dda550/pyW215/pyW215.py#L186-L196 |
45,068 | LinuxChristian/pyW215 | pyW215/pyW215.py | SmartPlug.current_consumption | def current_consumption(self):
"""Get the current power consumption in Watt."""
res = 'N/A'
if self.use_legacy_protocol:
# Use /my_cgi.cgi to retrieve current consumption
try:
res = self.fetchMyCgi()['Meter Watt']
except:
return... | python | def current_consumption(self):
"""Get the current power consumption in Watt."""
res = 'N/A'
if self.use_legacy_protocol:
# Use /my_cgi.cgi to retrieve current consumption
try:
res = self.fetchMyCgi()['Meter Watt']
except:
return... | [
"def",
"current_consumption",
"(",
"self",
")",
":",
"res",
"=",
"'N/A'",
"if",
"self",
".",
"use_legacy_protocol",
":",
"# Use /my_cgi.cgi to retrieve current consumption",
"try",
":",
"res",
"=",
"self",
".",
"fetchMyCgi",
"(",
")",
"[",
"'Meter Watt'",
"]",
"... | Get the current power consumption in Watt. | [
"Get",
"the",
"current",
"power",
"consumption",
"in",
"Watt",
"."
] | 63e50b8ee11bc38ed66554f9b92429b552dda550 | https://github.com/LinuxChristian/pyW215/blob/63e50b8ee11bc38ed66554f9b92429b552dda550/pyW215/pyW215.py#L199-L222 |
45,069 | LinuxChristian/pyW215 | pyW215/pyW215.py | SmartPlug.total_consumption | def total_consumption(self):
"""Get the total power consumpuntion in the device lifetime."""
if self.use_legacy_protocol:
# TotalConsumption currently fails on the legacy protocol and
# creates a mess in the logs. Just return 'N/A' for now.
return 'N/A'
res =... | python | def total_consumption(self):
"""Get the total power consumpuntion in the device lifetime."""
if self.use_legacy_protocol:
# TotalConsumption currently fails on the legacy protocol and
# creates a mess in the logs. Just return 'N/A' for now.
return 'N/A'
res =... | [
"def",
"total_consumption",
"(",
"self",
")",
":",
"if",
"self",
".",
"use_legacy_protocol",
":",
"# TotalConsumption currently fails on the legacy protocol and",
"# creates a mess in the logs. Just return 'N/A' for now.",
"return",
"'N/A'",
"res",
"=",
"'N/A'",
"try",
":",
"... | Get the total power consumpuntion in the device lifetime. | [
"Get",
"the",
"total",
"power",
"consumpuntion",
"in",
"the",
"device",
"lifetime",
"."
] | 63e50b8ee11bc38ed66554f9b92429b552dda550 | https://github.com/LinuxChristian/pyW215/blob/63e50b8ee11bc38ed66554f9b92429b552dda550/pyW215/pyW215.py#L229-L250 |
45,070 | LinuxChristian/pyW215 | pyW215/pyW215.py | SmartPlug.state | def state(self, value):
"""Set device state.
:type value: str
:param value: Future state (either ON or OFF)
"""
if value.upper() == ON:
return self.SOAPAction('SetSocketSettings', 'SetSocketSettingsResult', self.controlParameters("1", "true"))
elif value.uppe... | python | def state(self, value):
"""Set device state.
:type value: str
:param value: Future state (either ON or OFF)
"""
if value.upper() == ON:
return self.SOAPAction('SetSocketSettings', 'SetSocketSettingsResult', self.controlParameters("1", "true"))
elif value.uppe... | [
"def",
"state",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
".",
"upper",
"(",
")",
"==",
"ON",
":",
"return",
"self",
".",
"SOAPAction",
"(",
"'SetSocketSettings'",
",",
"'SetSocketSettingsResult'",
",",
"self",
".",
"controlParameters",
"(",
"\"1... | Set device state.
:type value: str
:param value: Future state (either ON or OFF) | [
"Set",
"device",
"state",
"."
] | 63e50b8ee11bc38ed66554f9b92429b552dda550 | https://github.com/LinuxChristian/pyW215/blob/63e50b8ee11bc38ed66554f9b92429b552dda550/pyW215/pyW215.py#L285-L296 |
45,071 | LinuxChristian/pyW215 | pyW215/pyW215.py | SmartPlug.auth | def auth(self):
"""Authenticate using the SOAP interface.
Authentication is a two-step process. First a initial payload
is sent to the device requesting additional login information in the form
of a publickey, a challenge string and a cookie.
These values are then hashed by a MD... | python | def auth(self):
"""Authenticate using the SOAP interface.
Authentication is a two-step process. First a initial payload
is sent to the device requesting additional login information in the form
of a publickey, a challenge string and a cookie.
These values are then hashed by a MD... | [
"def",
"auth",
"(",
"self",
")",
":",
"payload",
"=",
"self",
".",
"initial_auth_payload",
"(",
")",
"# Build initial header",
"headers",
"=",
"{",
"'Content-Type'",
":",
"'\"text/xml; charset=utf-8\"'",
",",
"'SOAPAction'",
":",
"'\"http://purenetworks.com/HNAP1/Login\... | Authenticate using the SOAP interface.
Authentication is a two-step process. First a initial payload
is sent to the device requesting additional login information in the form
of a publickey, a challenge string and a cookie.
These values are then hashed by a MD5 algorithm producing a pri... | [
"Authenticate",
"using",
"the",
"SOAP",
"interface",
"."
] | 63e50b8ee11bc38ed66554f9b92429b552dda550 | https://github.com/LinuxChristian/pyW215/blob/63e50b8ee11bc38ed66554f9b92429b552dda550/pyW215/pyW215.py#L302-L374 |
45,072 | TeamHG-Memex/json-lines | json_lines/_gzip.py | get_known_read_position | def get_known_read_position(fp, buffered=True):
"""
Return a position in a file which is known to be read & handled.
It assumes a buffered file and streaming processing.
"""
buffer_size = io.DEFAULT_BUFFER_SIZE if buffered else 0
return max(fp.tell() - buffer_size, 0) | python | def get_known_read_position(fp, buffered=True):
"""
Return a position in a file which is known to be read & handled.
It assumes a buffered file and streaming processing.
"""
buffer_size = io.DEFAULT_BUFFER_SIZE if buffered else 0
return max(fp.tell() - buffer_size, 0) | [
"def",
"get_known_read_position",
"(",
"fp",
",",
"buffered",
"=",
"True",
")",
":",
"buffer_size",
"=",
"io",
".",
"DEFAULT_BUFFER_SIZE",
"if",
"buffered",
"else",
"0",
"return",
"max",
"(",
"fp",
".",
"tell",
"(",
")",
"-",
"buffer_size",
",",
"0",
")"... | Return a position in a file which is known to be read & handled.
It assumes a buffered file and streaming processing. | [
"Return",
"a",
"position",
"in",
"a",
"file",
"which",
"is",
"known",
"to",
"be",
"read",
"&",
"handled",
".",
"It",
"assumes",
"a",
"buffered",
"file",
"and",
"streaming",
"processing",
"."
] | b0488ac746c90065f1599e51b710205d9c2392ad | https://github.com/TeamHG-Memex/json-lines/blob/b0488ac746c90065f1599e51b710205d9c2392ad/json_lines/_gzip.py#L10-L16 |
45,073 | TeamHG-Memex/json-lines | json_lines/_gzip.py | recover | def recover(gzfile, last_good_position):
# type: (gzip.GzipFile, int) -> gzip.GzipFile
"""
Skip to the next possibly decompressable part of a gzip file.
Return a new GzipFile object if such part is found or None
if it is not found.
"""
pos = get_recover_position(gzfile, last_good_position=l... | python | def recover(gzfile, last_good_position):
# type: (gzip.GzipFile, int) -> gzip.GzipFile
"""
Skip to the next possibly decompressable part of a gzip file.
Return a new GzipFile object if such part is found or None
if it is not found.
"""
pos = get_recover_position(gzfile, last_good_position=l... | [
"def",
"recover",
"(",
"gzfile",
",",
"last_good_position",
")",
":",
"# type: (gzip.GzipFile, int) -> gzip.GzipFile",
"pos",
"=",
"get_recover_position",
"(",
"gzfile",
",",
"last_good_position",
"=",
"last_good_position",
")",
"if",
"pos",
"==",
"-",
"1",
":",
"re... | Skip to the next possibly decompressable part of a gzip file.
Return a new GzipFile object if such part is found or None
if it is not found. | [
"Skip",
"to",
"the",
"next",
"possibly",
"decompressable",
"part",
"of",
"a",
"gzip",
"file",
".",
"Return",
"a",
"new",
"GzipFile",
"object",
"if",
"such",
"part",
"is",
"found",
"or",
"None",
"if",
"it",
"is",
"not",
"found",
"."
] | b0488ac746c90065f1599e51b710205d9c2392ad | https://github.com/TeamHG-Memex/json-lines/blob/b0488ac746c90065f1599e51b710205d9c2392ad/json_lines/_gzip.py#L19-L32 |
45,074 | TeamHG-Memex/json-lines | json_lines/utils.py | maybe_gzip_open | def maybe_gzip_open(path, *args, **kwargs):
"""
Open file with either open or gzip.open, depending on file extension.
This function doesn't handle json lines format, just opens a file
in a way it is decoded transparently if needed.
"""
path = path_to_str(path)
if path.endswith('.gz') or pat... | python | def maybe_gzip_open(path, *args, **kwargs):
"""
Open file with either open or gzip.open, depending on file extension.
This function doesn't handle json lines format, just opens a file
in a way it is decoded transparently if needed.
"""
path = path_to_str(path)
if path.endswith('.gz') or pat... | [
"def",
"maybe_gzip_open",
"(",
"path",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"path",
"=",
"path_to_str",
"(",
"path",
")",
"if",
"path",
".",
"endswith",
"(",
"'.gz'",
")",
"or",
"path",
".",
"endswith",
"(",
"'.gzip'",
")",
":",
"_o... | Open file with either open or gzip.open, depending on file extension.
This function doesn't handle json lines format, just opens a file
in a way it is decoded transparently if needed. | [
"Open",
"file",
"with",
"either",
"open",
"or",
"gzip",
".",
"open",
"depending",
"on",
"file",
"extension",
"."
] | b0488ac746c90065f1599e51b710205d9c2392ad | https://github.com/TeamHG-Memex/json-lines/blob/b0488ac746c90065f1599e51b710205d9c2392ad/json_lines/utils.py#L7-L19 |
45,075 | TeamHG-Memex/json-lines | json_lines/utils.py | path_to_str | def path_to_str(path):
""" Convert pathlib.Path objects to str; return other objects as-is. """
try:
from pathlib import Path as _Path
except ImportError: # Python < 3.4
class _Path:
pass
if isinstance(path, _Path):
return str(path)
return path | python | def path_to_str(path):
""" Convert pathlib.Path objects to str; return other objects as-is. """
try:
from pathlib import Path as _Path
except ImportError: # Python < 3.4
class _Path:
pass
if isinstance(path, _Path):
return str(path)
return path | [
"def",
"path_to_str",
"(",
"path",
")",
":",
"try",
":",
"from",
"pathlib",
"import",
"Path",
"as",
"_Path",
"except",
"ImportError",
":",
"# Python < 3.4",
"class",
"_Path",
":",
"pass",
"if",
"isinstance",
"(",
"path",
",",
"_Path",
")",
":",
"return",
... | Convert pathlib.Path objects to str; return other objects as-is. | [
"Convert",
"pathlib",
".",
"Path",
"objects",
"to",
"str",
";",
"return",
"other",
"objects",
"as",
"-",
"is",
"."
] | b0488ac746c90065f1599e51b710205d9c2392ad | https://github.com/TeamHG-Memex/json-lines/blob/b0488ac746c90065f1599e51b710205d9c2392ad/json_lines/utils.py#L22-L31 |
45,076 | croach/django-simple-rest | simple_rest/auth/signature.py | calculate_signature | def calculate_signature(key, data, timestamp=None):
"""
Calculates the signature for the given request data.
"""
# Create a timestamp if one was not given
if timestamp is None:
timestamp = int(time.time())
# Construct the message from the timestamp and the data in the request
messag... | python | def calculate_signature(key, data, timestamp=None):
"""
Calculates the signature for the given request data.
"""
# Create a timestamp if one was not given
if timestamp is None:
timestamp = int(time.time())
# Construct the message from the timestamp and the data in the request
messag... | [
"def",
"calculate_signature",
"(",
"key",
",",
"data",
",",
"timestamp",
"=",
"None",
")",
":",
"# Create a timestamp if one was not given",
"if",
"timestamp",
"is",
"None",
":",
"timestamp",
"=",
"int",
"(",
"time",
".",
"time",
"(",
")",
")",
"# Construct th... | Calculates the signature for the given request data. | [
"Calculates",
"the",
"signature",
"for",
"the",
"given",
"request",
"data",
"."
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/auth/signature.py#L6-L20 |
45,077 | rs/eve-auth-jwt | eve_auth_jwt/auth.py | JWTAuth.authenticate | def authenticate(self):
"""
Indicate to the client that it needs to authenticate via a 401.
"""
if request.headers.get('Authorization') or request.args.get('access_token'):
realm = 'Bearer realm="%s", error="invalid_token"' % __package__
else:
realm = 'Bea... | python | def authenticate(self):
"""
Indicate to the client that it needs to authenticate via a 401.
"""
if request.headers.get('Authorization') or request.args.get('access_token'):
realm = 'Bearer realm="%s", error="invalid_token"' % __package__
else:
realm = 'Bea... | [
"def",
"authenticate",
"(",
"self",
")",
":",
"if",
"request",
".",
"headers",
".",
"get",
"(",
"'Authorization'",
")",
"or",
"request",
".",
"args",
".",
"get",
"(",
"'access_token'",
")",
":",
"realm",
"=",
"'Bearer realm=\"%s\", error=\"invalid_token\"'",
"... | Indicate to the client that it needs to authenticate via a 401. | [
"Indicate",
"to",
"the",
"client",
"that",
"it",
"needs",
"to",
"authenticate",
"via",
"a",
"401",
"."
] | 23c906433de80cf60cab93381a8996b17938651e | https://github.com/rs/eve-auth-jwt/blob/23c906433de80cf60cab93381a8996b17938651e/eve_auth_jwt/auth.py#L73-L82 |
45,078 | rs/eve-auth-jwt | eve_auth_jwt/auth.py | JWTAuth.check_token | def check_token(self, token, allowed_roles, resource, method):
"""
This function is called when a token is sent throught the access_token
parameter or the Authorization header as specified in the oAuth 2 specification.
The provided token is validated with the JWT_SECRET defined in the E... | python | def check_token(self, token, allowed_roles, resource, method):
"""
This function is called when a token is sent throught the access_token
parameter or the Authorization header as specified in the oAuth 2 specification.
The provided token is validated with the JWT_SECRET defined in the E... | [
"def",
"check_token",
"(",
"self",
",",
"token",
",",
"allowed_roles",
",",
"resource",
",",
"method",
")",
":",
"resource_conf",
"=",
"config",
".",
"DOMAIN",
"[",
"resource",
"]",
"audiences",
"=",
"resource_conf",
".",
"get",
"(",
"'audiences'",
",",
"c... | This function is called when a token is sent throught the access_token
parameter or the Authorization header as specified in the oAuth 2 specification.
The provided token is validated with the JWT_SECRET defined in the Eve configuration.
The token issuer (iss claim) must be the one specified by... | [
"This",
"function",
"is",
"called",
"when",
"a",
"token",
"is",
"sent",
"throught",
"the",
"access_token",
"parameter",
"or",
"the",
"Authorization",
"header",
"as",
"specified",
"in",
"the",
"oAuth",
"2",
"specification",
"."
] | 23c906433de80cf60cab93381a8996b17938651e | https://github.com/rs/eve-auth-jwt/blob/23c906433de80cf60cab93381a8996b17938651e/eve_auth_jwt/auth.py#L84-L106 |
45,079 | rs/eve-auth-jwt | eve_auth_jwt/auth.py | JWTAuth.requires_token | def requires_token(self, audiences=None, allowed_roles=None):
"""
Decorator for functions that will be protected with token authentication.
Token must be provvided either through access_token parameter or Authorization
header.
See check_token() method for further details.
... | python | def requires_token(self, audiences=None, allowed_roles=None):
"""
Decorator for functions that will be protected with token authentication.
Token must be provvided either through access_token parameter or Authorization
header.
See check_token() method for further details.
... | [
"def",
"requires_token",
"(",
"self",
",",
"audiences",
"=",
"None",
",",
"allowed_roles",
"=",
"None",
")",
":",
"def",
"requires_token_wrapper",
"(",
"f",
")",
":",
"@",
"wraps",
"(",
"f",
")",
"def",
"decorated",
"(",
"*",
"args",
",",
"*",
"*",
"... | Decorator for functions that will be protected with token authentication.
Token must be provvided either through access_token parameter or Authorization
header.
See check_token() method for further details. | [
"Decorator",
"for",
"functions",
"that",
"will",
"be",
"protected",
"with",
"token",
"authentication",
"."
] | 23c906433de80cf60cab93381a8996b17938651e | https://github.com/rs/eve-auth-jwt/blob/23c906433de80cf60cab93381a8996b17938651e/eve_auth_jwt/auth.py#L108-L130 |
45,080 | mherrmann/pypxlib | pypxlib/pxlib_ctypes/py2.py | LibraryLoader.load_library | def load_library(self,libname):
"""Given the name of a library, load it."""
paths = self.getpaths(libname)
for path in paths:
if os.path.exists(path):
return self.load(path)
raise ImportError("%s not found." % libname) | python | def load_library(self,libname):
"""Given the name of a library, load it."""
paths = self.getpaths(libname)
for path in paths:
if os.path.exists(path):
return self.load(path)
raise ImportError("%s not found." % libname) | [
"def",
"load_library",
"(",
"self",
",",
"libname",
")",
":",
"paths",
"=",
"self",
".",
"getpaths",
"(",
"libname",
")",
"for",
"path",
"in",
"paths",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"return",
"self",
".",
"load... | Given the name of a library, load it. | [
"Given",
"the",
"name",
"of",
"a",
"library",
"load",
"it",
"."
] | b2235383fe27f46a1f2e4c283403cc39f1b58a19 | https://github.com/mherrmann/pypxlib/blob/b2235383fe27f46a1f2e4c283403cc39f1b58a19/pypxlib/pxlib_ctypes/py2.py#L360-L368 |
45,081 | mherrmann/pypxlib | pypxlib/pxlib_ctypes/py2.py | LibraryLoader.getpaths | def getpaths(self,libname):
"""Return a list of paths where the library might be found."""
if os.path.isabs(libname):
yield libname
else:
# FIXME / TODO return '.' and os.path.dirname(__file__)
for path in self.getplatformpaths(libname):
yield ... | python | def getpaths(self,libname):
"""Return a list of paths where the library might be found."""
if os.path.isabs(libname):
yield libname
else:
# FIXME / TODO return '.' and os.path.dirname(__file__)
for path in self.getplatformpaths(libname):
yield ... | [
"def",
"getpaths",
"(",
"self",
",",
"libname",
")",
":",
"if",
"os",
".",
"path",
".",
"isabs",
"(",
"libname",
")",
":",
"yield",
"libname",
"else",
":",
"# FIXME / TODO return '.' and os.path.dirname(__file__)",
"for",
"path",
"in",
"self",
".",
"getplatfor... | Return a list of paths where the library might be found. | [
"Return",
"a",
"list",
"of",
"paths",
"where",
"the",
"library",
"might",
"be",
"found",
"."
] | b2235383fe27f46a1f2e4c283403cc39f1b58a19 | https://github.com/mherrmann/pypxlib/blob/b2235383fe27f46a1f2e4c283403cc39f1b58a19/pypxlib/pxlib_ctypes/py2.py#L384-L394 |
45,082 | croach/django-simple-rest | simple_rest/utils/serializers.py | to_json | def to_json(content, indent=None):
"""
Serializes a python object as JSON
This method uses the DJangoJSONEncoder to to ensure that python objects
such as Decimal objects are properly serialized. It can also serialize
Django QuerySet objects.
"""
if isinstance(content, QuerySet):
jso... | python | def to_json(content, indent=None):
"""
Serializes a python object as JSON
This method uses the DJangoJSONEncoder to to ensure that python objects
such as Decimal objects are properly serialized. It can also serialize
Django QuerySet objects.
"""
if isinstance(content, QuerySet):
jso... | [
"def",
"to_json",
"(",
"content",
",",
"indent",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"content",
",",
"QuerySet",
")",
":",
"json_serializer",
"=",
"serializers",
".",
"get_serializer",
"(",
"'json'",
")",
"(",
")",
"serialized_content",
"=",
"j... | Serializes a python object as JSON
This method uses the DJangoJSONEncoder to to ensure that python objects
such as Decimal objects are properly serialized. It can also serialize
Django QuerySet objects. | [
"Serializes",
"a",
"python",
"object",
"as",
"JSON"
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/utils/serializers.py#L33-L50 |
45,083 | croach/django-simple-rest | simple_rest/utils/serializers.py | to_html | def to_html(data):
"""
Serializes a python object as HTML
This method uses the to_json method to turn the given data object into
formatted JSON that is displayed in an HTML page. If pygments in installed,
syntax highlighting will also be applied to the JSON.
"""
base_html_template = Templat... | python | def to_html(data):
"""
Serializes a python object as HTML
This method uses the to_json method to turn the given data object into
formatted JSON that is displayed in an HTML page. If pygments in installed,
syntax highlighting will also be applied to the JSON.
"""
base_html_template = Templat... | [
"def",
"to_html",
"(",
"data",
")",
":",
"base_html_template",
"=",
"Template",
"(",
"'''\n <html>\n <head>\n {% if style %}\n <style type=\"text/css\">\n {{ style }}\n </style>\n {% endif %}\n ... | Serializes a python object as HTML
This method uses the to_json method to turn the given data object into
formatted JSON that is displayed in an HTML page. If pygments in installed,
syntax highlighting will also be applied to the JSON. | [
"Serializes",
"a",
"python",
"object",
"as",
"HTML"
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/utils/serializers.py#L53-L90 |
45,084 | croach/django-simple-rest | simple_rest/utils/serializers.py | to_text | def to_text(data):
"""
Serializes a python object as plain text
If the data can be serialized as JSON, this method will use the to_json
method to format the data, otherwise the data is returned as is.
"""
try:
serialized_content = to_json(data, indent=4)
except Exception, e:
... | python | def to_text(data):
"""
Serializes a python object as plain text
If the data can be serialized as JSON, this method will use the to_json
method to format the data, otherwise the data is returned as is.
"""
try:
serialized_content = to_json(data, indent=4)
except Exception, e:
... | [
"def",
"to_text",
"(",
"data",
")",
":",
"try",
":",
"serialized_content",
"=",
"to_json",
"(",
"data",
",",
"indent",
"=",
"4",
")",
"except",
"Exception",
",",
"e",
":",
"serialized_content",
"=",
"data",
"return",
"serialized_content"
] | Serializes a python object as plain text
If the data can be serialized as JSON, this method will use the to_json
method to format the data, otherwise the data is returned as is. | [
"Serializes",
"a",
"python",
"object",
"as",
"plain",
"text"
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/utils/serializers.py#L92-L103 |
45,085 | croach/django-simple-rest | simple_rest/auth/decorators.py | auth_required | def auth_required(secret_key_func):
"""
Requires that the user be authenticated either by a signature or by
being actively logged in.
"""
def actual_decorator(obj):
def test_func(request, *args, **kwargs):
secret_key = secret_key_func(request, *args, **kwargs)
return... | python | def auth_required(secret_key_func):
"""
Requires that the user be authenticated either by a signature or by
being actively logged in.
"""
def actual_decorator(obj):
def test_func(request, *args, **kwargs):
secret_key = secret_key_func(request, *args, **kwargs)
return... | [
"def",
"auth_required",
"(",
"secret_key_func",
")",
":",
"def",
"actual_decorator",
"(",
"obj",
")",
":",
"def",
"test_func",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"secret_key",
"=",
"secret_key_func",
"(",
"request",
",",
... | Requires that the user be authenticated either by a signature or by
being actively logged in. | [
"Requires",
"that",
"the",
"user",
"be",
"authenticated",
"either",
"by",
"a",
"signature",
"or",
"by",
"being",
"actively",
"logged",
"in",
"."
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/auth/decorators.py#L10-L24 |
45,086 | croach/django-simple-rest | simple_rest/auth/decorators.py | login_required | def login_required(obj):
"""
Requires that the user be logged in order to gain access to the resource
at the specified the URI.
"""
decorator = request_passes_test(lambda r, *args, **kwargs: r.user.is_authenticated())
return wrap_object(obj, decorator) | python | def login_required(obj):
"""
Requires that the user be logged in order to gain access to the resource
at the specified the URI.
"""
decorator = request_passes_test(lambda r, *args, **kwargs: r.user.is_authenticated())
return wrap_object(obj, decorator) | [
"def",
"login_required",
"(",
"obj",
")",
":",
"decorator",
"=",
"request_passes_test",
"(",
"lambda",
"r",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
":",
"r",
".",
"user",
".",
"is_authenticated",
"(",
")",
")",
"return",
"wrap_object",
"(",
"obj",
"... | Requires that the user be logged in order to gain access to the resource
at the specified the URI. | [
"Requires",
"that",
"the",
"user",
"be",
"logged",
"in",
"order",
"to",
"gain",
"access",
"to",
"the",
"resource",
"at",
"the",
"specified",
"the",
"URI",
"."
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/auth/decorators.py#L27-L33 |
45,087 | croach/django-simple-rest | simple_rest/auth/decorators.py | admin_required | def admin_required(obj):
"""
Requires that the user be logged AND be set as a superuser
"""
decorator = request_passes_test(lambda r, *args, **kwargs: r.user.is_superuser)
return wrap_object(obj, decorator) | python | def admin_required(obj):
"""
Requires that the user be logged AND be set as a superuser
"""
decorator = request_passes_test(lambda r, *args, **kwargs: r.user.is_superuser)
return wrap_object(obj, decorator) | [
"def",
"admin_required",
"(",
"obj",
")",
":",
"decorator",
"=",
"request_passes_test",
"(",
"lambda",
"r",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
":",
"r",
".",
"user",
".",
"is_superuser",
")",
"return",
"wrap_object",
"(",
"obj",
",",
"decorator",... | Requires that the user be logged AND be set as a superuser | [
"Requires",
"that",
"the",
"user",
"be",
"logged",
"AND",
"be",
"set",
"as",
"a",
"superuser"
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/auth/decorators.py#L36-L41 |
45,088 | croach/django-simple-rest | simple_rest/auth/decorators.py | signature_required | def signature_required(secret_key_func):
"""
Requires that the request contain a valid signature to gain access
to a specified resource.
"""
def actual_decorator(obj):
def test_func(request, *args, **kwargs):
secret_key = secret_key_func(request, *args, **kwargs)
ret... | python | def signature_required(secret_key_func):
"""
Requires that the request contain a valid signature to gain access
to a specified resource.
"""
def actual_decorator(obj):
def test_func(request, *args, **kwargs):
secret_key = secret_key_func(request, *args, **kwargs)
ret... | [
"def",
"signature_required",
"(",
"secret_key_func",
")",
":",
"def",
"actual_decorator",
"(",
"obj",
")",
":",
"def",
"test_func",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"secret_key",
"=",
"secret_key_func",
"(",
"request",
"... | Requires that the request contain a valid signature to gain access
to a specified resource. | [
"Requires",
"that",
"the",
"request",
"contain",
"a",
"valid",
"signature",
"to",
"gain",
"access",
"to",
"a",
"specified",
"resource",
"."
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/auth/decorators.py#L44-L58 |
45,089 | croach/django-simple-rest | simple_rest/auth/decorators.py | validate_signature | def validate_signature(request, secret_key):
"""
Validates the signature associated with the given request.
"""
# Extract the request parameters according to the HTTP method
data = request.GET.copy()
if request.method != 'GET':
message_body = getattr(request, request.method, {})
... | python | def validate_signature(request, secret_key):
"""
Validates the signature associated with the given request.
"""
# Extract the request parameters according to the HTTP method
data = request.GET.copy()
if request.method != 'GET':
message_body = getattr(request, request.method, {})
... | [
"def",
"validate_signature",
"(",
"request",
",",
"secret_key",
")",
":",
"# Extract the request parameters according to the HTTP method",
"data",
"=",
"request",
".",
"GET",
".",
"copy",
"(",
")",
"if",
"request",
".",
"method",
"!=",
"'GET'",
":",
"message_body",
... | Validates the signature associated with the given request. | [
"Validates",
"the",
"signature",
"associated",
"with",
"the",
"given",
"request",
"."
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/auth/decorators.py#L78-L119 |
45,090 | gtaylor/django-dynamodb-sessions | dynamodb_sessions/backends/dynamodb.py | SessionStore.exists | def exists(self, session_key):
"""
Checks to see if a session currently exists in DynamoDB.
:rtype: bool
:returns: ``True`` if a session with the given key exists in the DB,
``False`` if not.
"""
response = self.table.get_item(
Key={'session_key'... | python | def exists(self, session_key):
"""
Checks to see if a session currently exists in DynamoDB.
:rtype: bool
:returns: ``True`` if a session with the given key exists in the DB,
``False`` if not.
"""
response = self.table.get_item(
Key={'session_key'... | [
"def",
"exists",
"(",
"self",
",",
"session_key",
")",
":",
"response",
"=",
"self",
".",
"table",
".",
"get_item",
"(",
"Key",
"=",
"{",
"'session_key'",
":",
"session_key",
"}",
",",
"ConsistentRead",
"=",
"ALWAYS_CONSISTENT",
")",
"if",
"'Item'",
"in",
... | Checks to see if a session currently exists in DynamoDB.
:rtype: bool
:returns: ``True`` if a session with the given key exists in the DB,
``False`` if not. | [
"Checks",
"to",
"see",
"if",
"a",
"session",
"currently",
"exists",
"in",
"DynamoDB",
"."
] | 434031aa483b26b0b7b5acbdf683bbe1575956f1 | https://github.com/gtaylor/django-dynamodb-sessions/blob/434031aa483b26b0b7b5acbdf683bbe1575956f1/dynamodb_sessions/backends/dynamodb.py#L102-L117 |
45,091 | gtaylor/django-dynamodb-sessions | dynamodb_sessions/backends/dynamodb.py | SessionStore.save | def save(self, must_create=False):
"""
Saves the current session data to the database.
:keyword bool must_create: If ``True``, a ``CreateError`` exception
will be raised if the saving operation doesn't create a *new* entry
(as opposed to possibly updating an existing ent... | python | def save(self, must_create=False):
"""
Saves the current session data to the database.
:keyword bool must_create: If ``True``, a ``CreateError`` exception
will be raised if the saving operation doesn't create a *new* entry
(as opposed to possibly updating an existing ent... | [
"def",
"save",
"(",
"self",
",",
"must_create",
"=",
"False",
")",
":",
"# If the save method is called with must_create equal to True, I'm",
"# setting self._session_key equal to None and when",
"# self.get_or_create_session_key is called the new",
"# session_key will be created.",
"if"... | Saves the current session data to the database.
:keyword bool must_create: If ``True``, a ``CreateError`` exception
will be raised if the saving operation doesn't create a *new* entry
(as opposed to possibly updating an existing entry).
:raises: ``CreateError`` if ``must_create`... | [
"Saves",
"the",
"current",
"session",
"data",
"to",
"the",
"database",
"."
] | 434031aa483b26b0b7b5acbdf683bbe1575956f1 | https://github.com/gtaylor/django-dynamodb-sessions/blob/434031aa483b26b0b7b5acbdf683bbe1575956f1/dynamodb_sessions/backends/dynamodb.py#L136-L179 |
45,092 | gtaylor/django-dynamodb-sessions | dynamodb_sessions/backends/dynamodb.py | SessionStore.delete | def delete(self, session_key=None):
"""
Deletes the current session, or the one specified in ``session_key``.
:keyword str session_key: Optionally, override the session key
to delete.
"""
if session_key is None:
if self.session_key is None:
... | python | def delete(self, session_key=None):
"""
Deletes the current session, or the one specified in ``session_key``.
:keyword str session_key: Optionally, override the session key
to delete.
"""
if session_key is None:
if self.session_key is None:
... | [
"def",
"delete",
"(",
"self",
",",
"session_key",
"=",
"None",
")",
":",
"if",
"session_key",
"is",
"None",
":",
"if",
"self",
".",
"session_key",
"is",
"None",
":",
"return",
"session_key",
"=",
"self",
".",
"session_key",
"self",
".",
"table",
".",
"... | Deletes the current session, or the one specified in ``session_key``.
:keyword str session_key: Optionally, override the session key
to delete. | [
"Deletes",
"the",
"current",
"session",
"or",
"the",
"one",
"specified",
"in",
"session_key",
"."
] | 434031aa483b26b0b7b5acbdf683bbe1575956f1 | https://github.com/gtaylor/django-dynamodb-sessions/blob/434031aa483b26b0b7b5acbdf683bbe1575956f1/dynamodb_sessions/backends/dynamodb.py#L181-L194 |
45,093 | gtaylor/django-dynamodb-sessions | dynamodb_sessions/backends/cached_dynamodb.py | SessionStore.flush | def flush(self):
"""
Removes the current session data from the database and regenerates the
key.
"""
self.clear()
self.delete(self.session_key)
self.create() | python | def flush(self):
"""
Removes the current session data from the database and regenerates the
key.
"""
self.clear()
self.delete(self.session_key)
self.create() | [
"def",
"flush",
"(",
"self",
")",
":",
"self",
".",
"clear",
"(",
")",
"self",
".",
"delete",
"(",
"self",
".",
"session_key",
")",
"self",
".",
"create",
"(",
")"
] | Removes the current session data from the database and regenerates the
key. | [
"Removes",
"the",
"current",
"session",
"data",
"from",
"the",
"database",
"and",
"regenerates",
"the",
"key",
"."
] | 434031aa483b26b0b7b5acbdf683bbe1575956f1 | https://github.com/gtaylor/django-dynamodb-sessions/blob/434031aa483b26b0b7b5acbdf683bbe1575956f1/dynamodb_sessions/backends/cached_dynamodb.py#L49-L57 |
45,094 | croach/django-simple-rest | simple_rest/utils/decorators.py | wrap_object | def wrap_object(obj, decorator):
"""
Decorates the given object with the decorator function.
If obj is a method, the method is decorated with the decorator function
and returned. If obj is a class (i.e., a class based view), the methods
in the class corresponding to HTTP methods will be decorated a... | python | def wrap_object(obj, decorator):
"""
Decorates the given object with the decorator function.
If obj is a method, the method is decorated with the decorator function
and returned. If obj is a class (i.e., a class based view), the methods
in the class corresponding to HTTP methods will be decorated a... | [
"def",
"wrap_object",
"(",
"obj",
",",
"decorator",
")",
":",
"actual_decorator",
"=",
"method_decorator",
"(",
"decorator",
")",
"if",
"inspect",
".",
"isfunction",
"(",
"obj",
")",
":",
"wrapped_obj",
"=",
"actual_decorator",
"(",
"obj",
")",
"update_wrapper... | Decorates the given object with the decorator function.
If obj is a method, the method is decorated with the decorator function
and returned. If obj is a class (i.e., a class based view), the methods
in the class corresponding to HTTP methods will be decorated and the
resultant class object will be ret... | [
"Decorates",
"the",
"given",
"object",
"with",
"the",
"decorator",
"function",
"."
] | 5f5904969d170ef3803a9fb735f814ef76f79427 | https://github.com/croach/django-simple-rest/blob/5f5904969d170ef3803a9fb735f814ef76f79427/simple_rest/utils/decorators.py#L7-L32 |
45,095 | spyder-ide/conda-manager | conda_manager/models/packages.py | CondaPackagesModel.get_package_versions | def get_package_versions(self, name):
"""
Gives all the compatible package canonical name
name : str
Name of the package
"""
package_data = self._packages.get(name)
versions = []
if package_data:
versions = sort_versions(list(package_data... | python | def get_package_versions(self, name):
"""
Gives all the compatible package canonical name
name : str
Name of the package
"""
package_data = self._packages.get(name)
versions = []
if package_data:
versions = sort_versions(list(package_data... | [
"def",
"get_package_versions",
"(",
"self",
",",
"name",
")",
":",
"package_data",
"=",
"self",
".",
"_packages",
".",
"get",
"(",
"name",
")",
"versions",
"=",
"[",
"]",
"if",
"package_data",
":",
"versions",
"=",
"sort_versions",
"(",
"list",
"(",
"pac... | Gives all the compatible package canonical name
name : str
Name of the package | [
"Gives",
"all",
"the",
"compatible",
"package",
"canonical",
"name"
] | 89a2126cbecefc92185cf979347ccac1c5ee5d9d | https://github.com/spyder-ide/conda-manager/blob/89a2126cbecefc92185cf979347ccac1c5ee5d9d/conda_manager/models/packages.py#L416-L429 |
45,096 | spyder-ide/conda-manager | conda_manager/utils/__init__.py | get_conf_path | def get_conf_path(filename=None):
"""Return absolute path for configuration file with specified filename."""
conf_dir = osp.join(get_home_dir(), '.condamanager')
if not osp.isdir(conf_dir):
os.mkdir(conf_dir)
if filename is None:
return conf_dir
else:
return osp.j... | python | def get_conf_path(filename=None):
"""Return absolute path for configuration file with specified filename."""
conf_dir = osp.join(get_home_dir(), '.condamanager')
if not osp.isdir(conf_dir):
os.mkdir(conf_dir)
if filename is None:
return conf_dir
else:
return osp.j... | [
"def",
"get_conf_path",
"(",
"filename",
"=",
"None",
")",
":",
"conf_dir",
"=",
"osp",
".",
"join",
"(",
"get_home_dir",
"(",
")",
",",
"'.condamanager'",
")",
"if",
"not",
"osp",
".",
"isdir",
"(",
"conf_dir",
")",
":",
"os",
".",
"mkdir",
"(",
"co... | Return absolute path for configuration file with specified filename. | [
"Return",
"absolute",
"path",
"for",
"configuration",
"file",
"with",
"specified",
"filename",
"."
] | 89a2126cbecefc92185cf979347ccac1c5ee5d9d | https://github.com/spyder-ide/conda-manager/blob/89a2126cbecefc92185cf979347ccac1c5ee5d9d/conda_manager/utils/__init__.py#L68-L78 |
45,097 | spyder-ide/conda-manager | conda_manager/utils/__init__.py | sort_versions | def sort_versions(versions=(), reverse=False, sep=u'.'):
"""Sort a list of version number strings.
This function ensures that the package sorting based on number name is
performed correctly when including alpha, dev rc1 etc...
"""
if versions == []:
return []
digits = u'012345... | python | def sort_versions(versions=(), reverse=False, sep=u'.'):
"""Sort a list of version number strings.
This function ensures that the package sorting based on number name is
performed correctly when including alpha, dev rc1 etc...
"""
if versions == []:
return []
digits = u'012345... | [
"def",
"sort_versions",
"(",
"versions",
"=",
"(",
")",
",",
"reverse",
"=",
"False",
",",
"sep",
"=",
"u'.'",
")",
":",
"if",
"versions",
"==",
"[",
"]",
":",
"return",
"[",
"]",
"digits",
"=",
"u'0123456789'",
"def",
"toint",
"(",
"x",
")",
":",
... | Sort a list of version number strings.
This function ensures that the package sorting based on number name is
performed correctly when including alpha, dev rc1 etc... | [
"Sort",
"a",
"list",
"of",
"version",
"number",
"strings",
".",
"This",
"function",
"ensures",
"that",
"the",
"package",
"sorting",
"based",
"on",
"number",
"name",
"is",
"performed",
"correctly",
"when",
"including",
"alpha",
"dev",
"rc1",
"etc",
"..."
] | 89a2126cbecefc92185cf979347ccac1c5ee5d9d | https://github.com/spyder-ide/conda-manager/blob/89a2126cbecefc92185cf979347ccac1c5ee5d9d/conda_manager/utils/__init__.py#L86-L151 |
45,098 | berlincode/sjcl | examples/backup_cryptedblog.py | write_file | def write_file(fname_parts, content):
""" write a file and create all needed directories """
fname_parts = [str(part) for part in fname_parts]
# try to create the directory
if len(fname_parts) > 1:
try:
os.makedirs(os.path.join(*fname_parts[:-1]))
except OSError:
... | python | def write_file(fname_parts, content):
""" write a file and create all needed directories """
fname_parts = [str(part) for part in fname_parts]
# try to create the directory
if len(fname_parts) > 1:
try:
os.makedirs(os.path.join(*fname_parts[:-1]))
except OSError:
... | [
"def",
"write_file",
"(",
"fname_parts",
",",
"content",
")",
":",
"fname_parts",
"=",
"[",
"str",
"(",
"part",
")",
"for",
"part",
"in",
"fname_parts",
"]",
"# try to create the directory",
"if",
"len",
"(",
"fname_parts",
")",
">",
"1",
":",
"try",
":",
... | write a file and create all needed directories | [
"write",
"a",
"file",
"and",
"create",
"all",
"needed",
"directories"
] | e8bdad312fa99c89c74f8651a1240afba8a9f3bd | https://github.com/berlincode/sjcl/blob/e8bdad312fa99c89c74f8651a1240afba8a9f3bd/examples/backup_cryptedblog.py#L27-L40 |
45,099 | spyder-ide/conda-manager | conda_manager/models/filter.py | MultiColumnSortFilterProxy.remove_filter_function | def remove_filter_function(self, name):
"""Removes the filter function associated with name, if it exists.
name : hashable object
"""
if name in self._filter_functions.keys():
del self._filter_functions[name]
self.invalidateFilter() | python | def remove_filter_function(self, name):
"""Removes the filter function associated with name, if it exists.
name : hashable object
"""
if name in self._filter_functions.keys():
del self._filter_functions[name]
self.invalidateFilter() | [
"def",
"remove_filter_function",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"in",
"self",
".",
"_filter_functions",
".",
"keys",
"(",
")",
":",
"del",
"self",
".",
"_filter_functions",
"[",
"name",
"]",
"self",
".",
"invalidateFilter",
"(",
")"
] | Removes the filter function associated with name, if it exists.
name : hashable object | [
"Removes",
"the",
"filter",
"function",
"associated",
"with",
"name",
"if",
"it",
"exists",
"."
] | 89a2126cbecefc92185cf979347ccac1c5ee5d9d | https://github.com/spyder-ide/conda-manager/blob/89a2126cbecefc92185cf979347ccac1c5ee5d9d/conda_manager/models/filter.py#L78-L85 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.