partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | LanguageTool._get_languages | Get supported languages (by querying the server). | grammar_check/__init__.py | def _get_languages(cls) -> set:
"""Get supported languages (by querying the server)."""
if not cls._server_is_alive():
cls._start_server_on_free_port()
url = urllib.parse.urljoin(cls._url, 'Languages')
languages = set()
for e in cls._get_root(url, num_tries=1):
... | def _get_languages(cls) -> set:
"""Get supported languages (by querying the server)."""
if not cls._server_is_alive():
cls._start_server_on_free_port()
url = urllib.parse.urljoin(cls._url, 'Languages')
languages = set()
for e in cls._get_root(url, num_tries=1):
... | [
"Get",
"supported",
"languages",
"(",
"by",
"querying",
"the",
"server",
")",
"."
] | viraja1/grammar-check | python | https://github.com/viraja1/grammar-check/blob/103bf27119b85b4ef26c8f8d4089b6c882cabe5c/grammar_check/__init__.py#L277-L286 | [
"def",
"_get_languages",
"(",
"cls",
")",
"->",
"set",
":",
"if",
"not",
"cls",
".",
"_server_is_alive",
"(",
")",
":",
"cls",
".",
"_start_server_on_free_port",
"(",
")",
"url",
"=",
"urllib",
".",
"parse",
".",
"urljoin",
"(",
"cls",
".",
"_url",
","... | 103bf27119b85b4ef26c8f8d4089b6c882cabe5c |
train | LanguageTool._get_attrib | Get matches element attributes. | grammar_check/__init__.py | def _get_attrib(cls):
"""Get matches element attributes."""
if not cls._server_is_alive():
cls._start_server_on_free_port()
params = {'language': FAILSAFE_LANGUAGE, 'text': ''}
data = urllib.parse.urlencode(params).encode()
root = cls._get_root(cls._url, data, num_tri... | def _get_attrib(cls):
"""Get matches element attributes."""
if not cls._server_is_alive():
cls._start_server_on_free_port()
params = {'language': FAILSAFE_LANGUAGE, 'text': ''}
data = urllib.parse.urlencode(params).encode()
root = cls._get_root(cls._url, data, num_tri... | [
"Get",
"matches",
"element",
"attributes",
"."
] | viraja1/grammar-check | python | https://github.com/viraja1/grammar-check/blob/103bf27119b85b4ef26c8f8d4089b6c882cabe5c/grammar_check/__init__.py#L289-L296 | [
"def",
"_get_attrib",
"(",
"cls",
")",
":",
"if",
"not",
"cls",
".",
"_server_is_alive",
"(",
")",
":",
"cls",
".",
"_start_server_on_free_port",
"(",
")",
"params",
"=",
"{",
"'language'",
":",
"FAILSAFE_LANGUAGE",
",",
"'text'",
":",
"''",
"}",
"data",
... | 103bf27119b85b4ef26c8f8d4089b6c882cabe5c |
train | get_form | Patched method for PageAdmin.get_form.
Returns a page form without the base field 'meta_description' which is
overridden in djangocms-page-meta.
This is triggered in the page add view and in the change view if
the meta description of the page is empty. | djangocms_page_meta/admin.py | def get_form(self, request, obj=None, **kwargs):
"""
Patched method for PageAdmin.get_form.
Returns a page form without the base field 'meta_description' which is
overridden in djangocms-page-meta.
This is triggered in the page add view and in the change view if
the meta description of the pag... | def get_form(self, request, obj=None, **kwargs):
"""
Patched method for PageAdmin.get_form.
Returns a page form without the base field 'meta_description' which is
overridden in djangocms-page-meta.
This is triggered in the page add view and in the change view if
the meta description of the pag... | [
"Patched",
"method",
"for",
"PageAdmin",
".",
"get_form",
"."
] | nephila/djangocms-page-meta | python | https://github.com/nephila/djangocms-page-meta/blob/a38efe3fe3a717d9ad91bfc6aacab90989cd04a4/djangocms_page_meta/admin.py#L91-L106 | [
"def",
"get_form",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"language",
"=",
"get_language_from_request",
"(",
"request",
",",
"obj",
")",
"form",
"=",
"_BASE_PAGEADMIN__GET_FORM",
"(",
"self",
",",
"request"... | a38efe3fe3a717d9ad91bfc6aacab90989cd04a4 |
train | get_cache_key | Create the cache key for the current page and language | djangocms_page_meta/utils.py | def get_cache_key(page, language):
"""
Create the cache key for the current page and language
"""
from cms.cache import _get_cache_key
try:
site_id = page.node.site_id
except AttributeError: # CMS_3_4
site_id = page.site_id
return _get_cache_key('page_meta', page, language, ... | def get_cache_key(page, language):
"""
Create the cache key for the current page and language
"""
from cms.cache import _get_cache_key
try:
site_id = page.node.site_id
except AttributeError: # CMS_3_4
site_id = page.site_id
return _get_cache_key('page_meta', page, language, ... | [
"Create",
"the",
"cache",
"key",
"for",
"the",
"current",
"page",
"and",
"language"
] | nephila/djangocms-page-meta | python | https://github.com/nephila/djangocms-page-meta/blob/a38efe3fe3a717d9ad91bfc6aacab90989cd04a4/djangocms_page_meta/utils.py#L10-L19 | [
"def",
"get_cache_key",
"(",
"page",
",",
"language",
")",
":",
"from",
"cms",
".",
"cache",
"import",
"_get_cache_key",
"try",
":",
"site_id",
"=",
"page",
".",
"node",
".",
"site_id",
"except",
"AttributeError",
":",
"# CMS_3_4",
"site_id",
"=",
"page",
... | a38efe3fe3a717d9ad91bfc6aacab90989cd04a4 |
train | get_page_meta | Retrieves all the meta information for the page in the given language
:param page: a Page instance
:param lang: a language code
:return: Meta instance
:type: object | djangocms_page_meta/utils.py | def get_page_meta(page, language):
"""
Retrieves all the meta information for the page in the given language
:param page: a Page instance
:param lang: a language code
:return: Meta instance
:type: object
"""
from django.core.cache import cache
from meta.views import Meta
from .... | def get_page_meta(page, language):
"""
Retrieves all the meta information for the page in the given language
:param page: a Page instance
:param lang: a language code
:return: Meta instance
:type: object
"""
from django.core.cache import cache
from meta.views import Meta
from .... | [
"Retrieves",
"all",
"the",
"meta",
"information",
"for",
"the",
"page",
"in",
"the",
"given",
"language"
] | nephila/djangocms-page-meta | python | https://github.com/nephila/djangocms-page-meta/blob/a38efe3fe3a717d9ad91bfc6aacab90989cd04a4/djangocms_page_meta/utils.py#L22-L143 | [
"def",
"get_page_meta",
"(",
"page",
",",
"language",
")",
":",
"from",
"django",
".",
"core",
".",
"cache",
"import",
"cache",
"from",
"meta",
".",
"views",
"import",
"Meta",
"from",
".",
"models",
"import",
"PageMeta",
",",
"TitleMeta",
"try",
":",
"me... | a38efe3fe3a717d9ad91bfc6aacab90989cd04a4 |
train | MPR121.begin | Initialize communication with the MPR121.
Can specify a custom I2C address for the device using the address
parameter (defaults to 0x5A). Optional i2c parameter allows specifying a
custom I2C bus source (defaults to platform's I2C bus).
Returns True if communication with the MPR121 ... | Adafruit_MPR121/MPR121.py | def begin(self, address=MPR121_I2CADDR_DEFAULT, i2c=None, **kwargs):
"""Initialize communication with the MPR121.
Can specify a custom I2C address for the device using the address
parameter (defaults to 0x5A). Optional i2c parameter allows specifying a
custom I2C bus source (defaults... | def begin(self, address=MPR121_I2CADDR_DEFAULT, i2c=None, **kwargs):
"""Initialize communication with the MPR121.
Can specify a custom I2C address for the device using the address
parameter (defaults to 0x5A). Optional i2c parameter allows specifying a
custom I2C bus source (defaults... | [
"Initialize",
"communication",
"with",
"the",
"MPR121",
"."
] | adafruit/Adafruit_Python_MPR121 | python | https://github.com/adafruit/Adafruit_Python_MPR121/blob/86360b80186617e0056d5bd5279bda000978d92c/Adafruit_MPR121/MPR121.py#L73-L93 | [
"def",
"begin",
"(",
"self",
",",
"address",
"=",
"MPR121_I2CADDR_DEFAULT",
",",
"i2c",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# Assume we're using platform's default I2C bus if none is specified.",
"if",
"i2c",
"is",
"None",
":",
"import",
"Adafruit_GPIO"... | 86360b80186617e0056d5bd5279bda000978d92c |
train | MPR121.set_thresholds | Set the touch and release threshold for all inputs to the provided
values. Both touch and release should be a value between 0 to 255
(inclusive). | Adafruit_MPR121/MPR121.py | def set_thresholds(self, touch, release):
"""Set the touch and release threshold for all inputs to the provided
values. Both touch and release should be a value between 0 to 255
(inclusive).
"""
assert touch >= 0 and touch <= 255, 'touch must be between 0-255 (inclusive)'
... | def set_thresholds(self, touch, release):
"""Set the touch and release threshold for all inputs to the provided
values. Both touch and release should be a value between 0 to 255
(inclusive).
"""
assert touch >= 0 and touch <= 255, 'touch must be between 0-255 (inclusive)'
... | [
"Set",
"the",
"touch",
"and",
"release",
"threshold",
"for",
"all",
"inputs",
"to",
"the",
"provided",
"values",
".",
"Both",
"touch",
"and",
"release",
"should",
"be",
"a",
"value",
"between",
"0",
"to",
"255",
"(",
"inclusive",
")",
"."
] | adafruit/Adafruit_Python_MPR121 | python | https://github.com/adafruit/Adafruit_Python_MPR121/blob/86360b80186617e0056d5bd5279bda000978d92c/Adafruit_MPR121/MPR121.py#L148-L158 | [
"def",
"set_thresholds",
"(",
"self",
",",
"touch",
",",
"release",
")",
":",
"assert",
"touch",
">=",
"0",
"and",
"touch",
"<=",
"255",
",",
"'touch must be between 0-255 (inclusive)'",
"assert",
"release",
">=",
"0",
"and",
"release",
"<=",
"255",
",",
"'r... | 86360b80186617e0056d5bd5279bda000978d92c |
train | MPR121.filtered_data | Return filtered data register value for the provided pin (0-11).
Useful for debugging. | Adafruit_MPR121/MPR121.py | def filtered_data(self, pin):
"""Return filtered data register value for the provided pin (0-11).
Useful for debugging.
"""
assert pin >= 0 and pin < 12, 'pin must be between 0-11 (inclusive)'
return self._i2c_retry(self._device.readU16LE, MPR121_FILTDATA_0L + pin*2) | def filtered_data(self, pin):
"""Return filtered data register value for the provided pin (0-11).
Useful for debugging.
"""
assert pin >= 0 and pin < 12, 'pin must be between 0-11 (inclusive)'
return self._i2c_retry(self._device.readU16LE, MPR121_FILTDATA_0L + pin*2) | [
"Return",
"filtered",
"data",
"register",
"value",
"for",
"the",
"provided",
"pin",
"(",
"0",
"-",
"11",
")",
".",
"Useful",
"for",
"debugging",
"."
] | adafruit/Adafruit_Python_MPR121 | python | https://github.com/adafruit/Adafruit_Python_MPR121/blob/86360b80186617e0056d5bd5279bda000978d92c/Adafruit_MPR121/MPR121.py#L160-L165 | [
"def",
"filtered_data",
"(",
"self",
",",
"pin",
")",
":",
"assert",
"pin",
">=",
"0",
"and",
"pin",
"<",
"12",
",",
"'pin must be between 0-11 (inclusive)'",
"return",
"self",
".",
"_i2c_retry",
"(",
"self",
".",
"_device",
".",
"readU16LE",
",",
"MPR121_FI... | 86360b80186617e0056d5bd5279bda000978d92c |
train | MPR121.baseline_data | Return baseline data register value for the provided pin (0-11).
Useful for debugging. | Adafruit_MPR121/MPR121.py | def baseline_data(self, pin):
"""Return baseline data register value for the provided pin (0-11).
Useful for debugging.
"""
assert pin >= 0 and pin < 12, 'pin must be between 0-11 (inclusive)'
bl = self._i2c_retry(self._device.readU8, MPR121_BASELINE_0 + pin)
return bl <<... | def baseline_data(self, pin):
"""Return baseline data register value for the provided pin (0-11).
Useful for debugging.
"""
assert pin >= 0 and pin < 12, 'pin must be between 0-11 (inclusive)'
bl = self._i2c_retry(self._device.readU8, MPR121_BASELINE_0 + pin)
return bl <<... | [
"Return",
"baseline",
"data",
"register",
"value",
"for",
"the",
"provided",
"pin",
"(",
"0",
"-",
"11",
")",
".",
"Useful",
"for",
"debugging",
"."
] | adafruit/Adafruit_Python_MPR121 | python | https://github.com/adafruit/Adafruit_Python_MPR121/blob/86360b80186617e0056d5bd5279bda000978d92c/Adafruit_MPR121/MPR121.py#L167-L173 | [
"def",
"baseline_data",
"(",
"self",
",",
"pin",
")",
":",
"assert",
"pin",
">=",
"0",
"and",
"pin",
"<",
"12",
",",
"'pin must be between 0-11 (inclusive)'",
"bl",
"=",
"self",
".",
"_i2c_retry",
"(",
"self",
".",
"_device",
".",
"readU8",
",",
"MPR121_BA... | 86360b80186617e0056d5bd5279bda000978d92c |
train | MPR121.touched | Return touch state of all pins as a 12-bit value where each bit
represents a pin, with a value of 1 being touched and 0 not being touched. | Adafruit_MPR121/MPR121.py | def touched(self):
"""Return touch state of all pins as a 12-bit value where each bit
represents a pin, with a value of 1 being touched and 0 not being touched.
"""
t = self._i2c_retry(self._device.readU16LE, MPR121_TOUCHSTATUS_L)
return t & 0x0FFF | def touched(self):
"""Return touch state of all pins as a 12-bit value where each bit
represents a pin, with a value of 1 being touched and 0 not being touched.
"""
t = self._i2c_retry(self._device.readU16LE, MPR121_TOUCHSTATUS_L)
return t & 0x0FFF | [
"Return",
"touch",
"state",
"of",
"all",
"pins",
"as",
"a",
"12",
"-",
"bit",
"value",
"where",
"each",
"bit",
"represents",
"a",
"pin",
"with",
"a",
"value",
"of",
"1",
"being",
"touched",
"and",
"0",
"not",
"being",
"touched",
"."
] | adafruit/Adafruit_Python_MPR121 | python | https://github.com/adafruit/Adafruit_Python_MPR121/blob/86360b80186617e0056d5bd5279bda000978d92c/Adafruit_MPR121/MPR121.py#L175-L180 | [
"def",
"touched",
"(",
"self",
")",
":",
"t",
"=",
"self",
".",
"_i2c_retry",
"(",
"self",
".",
"_device",
".",
"readU16LE",
",",
"MPR121_TOUCHSTATUS_L",
")",
"return",
"t",
"&",
"0x0FFF"
] | 86360b80186617e0056d5bd5279bda000978d92c |
train | MPR121.is_touched | Return True if the specified pin is being touched, otherwise returns
False. | Adafruit_MPR121/MPR121.py | def is_touched(self, pin):
"""Return True if the specified pin is being touched, otherwise returns
False.
"""
assert pin >= 0 and pin < 12, 'pin must be between 0-11 (inclusive)'
t = self.touched()
return (t & (1 << pin)) > 0 | def is_touched(self, pin):
"""Return True if the specified pin is being touched, otherwise returns
False.
"""
assert pin >= 0 and pin < 12, 'pin must be between 0-11 (inclusive)'
t = self.touched()
return (t & (1 << pin)) > 0 | [
"Return",
"True",
"if",
"the",
"specified",
"pin",
"is",
"being",
"touched",
"otherwise",
"returns",
"False",
"."
] | adafruit/Adafruit_Python_MPR121 | python | https://github.com/adafruit/Adafruit_Python_MPR121/blob/86360b80186617e0056d5bd5279bda000978d92c/Adafruit_MPR121/MPR121.py#L182-L188 | [
"def",
"is_touched",
"(",
"self",
",",
"pin",
")",
":",
"assert",
"pin",
">=",
"0",
"and",
"pin",
"<",
"12",
",",
"'pin must be between 0-11 (inclusive)'",
"t",
"=",
"self",
".",
"touched",
"(",
")",
"return",
"(",
"t",
"&",
"(",
"1",
"<<",
"pin",
")... | 86360b80186617e0056d5bd5279bda000978d92c |
train | profileit | Decorator straight up stolen from stackoverflow | profiling/profile.py | def profileit(func):
"""
Decorator straight up stolen from stackoverflow
"""
def wrapper(*args, **kwargs):
datafn = func.__name__ + ".profile" # Name the data file sensibly
prof = cProfile.Profile()
prof.enable()
retval = prof.runcall(func, *args, **kwargs)
prof.d... | def profileit(func):
"""
Decorator straight up stolen from stackoverflow
"""
def wrapper(*args, **kwargs):
datafn = func.__name__ + ".profile" # Name the data file sensibly
prof = cProfile.Profile()
prof.enable()
retval = prof.runcall(func, *args, **kwargs)
prof.d... | [
"Decorator",
"straight",
"up",
"stolen",
"from",
"stackoverflow"
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/profiling/profile.py#L29-L46 | [
"def",
"profileit",
"(",
"func",
")",
":",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"datafn",
"=",
"func",
".",
"__name__",
"+",
"\".profile\"",
"# Name the data file sensibly",
"prof",
"=",
"cProfile",
".",
"Profile",
"(",
... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | filter_ip_range | Filter :class:`.Line` objects by IP range.
Both *192.168.1.203* and *192.168.1.10* are valid if the provided ip
range is ``192.168.1`` whereas *192.168.2.103* is not valid (note the
*.2.*).
:param ip_range: IP range that you want to filter to.
:type ip_range: string
:returns: a function that f... | haproxy/filters.py | def filter_ip_range(ip_range):
"""Filter :class:`.Line` objects by IP range.
Both *192.168.1.203* and *192.168.1.10* are valid if the provided ip
range is ``192.168.1`` whereas *192.168.2.103* is not valid (note the
*.2.*).
:param ip_range: IP range that you want to filter to.
:type ip_range: ... | def filter_ip_range(ip_range):
"""Filter :class:`.Line` objects by IP range.
Both *192.168.1.203* and *192.168.1.10* are valid if the provided ip
range is ``192.168.1`` whereas *192.168.2.103* is not valid (note the
*.2.*).
:param ip_range: IP range that you want to filter to.
:type ip_range: ... | [
"Filter",
":",
"class",
":",
".",
"Line",
"objects",
"by",
"IP",
"range",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/filters.py#L22-L39 | [
"def",
"filter_ip_range",
"(",
"ip_range",
")",
":",
"def",
"filter_func",
"(",
"log_line",
")",
":",
"ip",
"=",
"log_line",
".",
"get_ip",
"(",
")",
"if",
"ip",
":",
"return",
"ip",
".",
"startswith",
"(",
"ip_range",
")",
"return",
"filter_func"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | filter_slow_requests | Filter :class:`.Line` objects by their response time.
:param slowness: minimum time, in milliseconds, a server needs to answer
a request. If the server takes more time than that the log line is
accepted.
:type slowness: string
:returns: a function that filters by the server response time.
:... | haproxy/filters.py | def filter_slow_requests(slowness):
"""Filter :class:`.Line` objects by their response time.
:param slowness: minimum time, in milliseconds, a server needs to answer
a request. If the server takes more time than that the log line is
accepted.
:type slowness: string
:returns: a function that... | def filter_slow_requests(slowness):
"""Filter :class:`.Line` objects by their response time.
:param slowness: minimum time, in milliseconds, a server needs to answer
a request. If the server takes more time than that the log line is
accepted.
:type slowness: string
:returns: a function that... | [
"Filter",
":",
"class",
":",
".",
"Line",
"objects",
"by",
"their",
"response",
"time",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/filters.py#L71-L85 | [
"def",
"filter_slow_requests",
"(",
"slowness",
")",
":",
"def",
"filter_func",
"(",
"log_line",
")",
":",
"slowness_int",
"=",
"int",
"(",
"slowness",
")",
"return",
"slowness_int",
"<=",
"log_line",
".",
"time_wait_response",
"return",
"filter_func"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | filter_wait_on_queues | Filter :class:`.Line` objects by their queueing time in
HAProxy.
:param max_waiting: maximum time, in milliseconds, a request is waiting on
HAProxy prior to be delivered to a backend server. If HAProxy takes less
than that time the log line is counted.
:type max_waiting: string
:returns: a ... | haproxy/filters.py | def filter_wait_on_queues(max_waiting):
"""Filter :class:`.Line` objects by their queueing time in
HAProxy.
:param max_waiting: maximum time, in milliseconds, a request is waiting on
HAProxy prior to be delivered to a backend server. If HAProxy takes less
than that time the log line is counted.... | def filter_wait_on_queues(max_waiting):
"""Filter :class:`.Line` objects by their queueing time in
HAProxy.
:param max_waiting: maximum time, in milliseconds, a request is waiting on
HAProxy prior to be delivered to a backend server. If HAProxy takes less
than that time the log line is counted.... | [
"Filter",
":",
"class",
":",
".",
"Line",
"objects",
"by",
"their",
"queueing",
"time",
"in",
"HAProxy",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/filters.py#L88-L103 | [
"def",
"filter_wait_on_queues",
"(",
"max_waiting",
")",
":",
"def",
"filter_func",
"(",
"log_line",
")",
":",
"waiting",
"=",
"int",
"(",
"max_waiting",
")",
"return",
"waiting",
">=",
"log_line",
".",
"time_wait_queues",
"return",
"filter_func"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | filter_time_frame | Filter :class:`.Line` objects by their connection time.
:param start: a time expression (see -s argument on --help for its format)
to filter log lines that are before this time.
:type start: string
:param delta: a relative time expression (see -s argument on --help for
its format) to limit the ... | haproxy/filters.py | def filter_time_frame(start, delta):
"""Filter :class:`.Line` objects by their connection time.
:param start: a time expression (see -s argument on --help for its format)
to filter log lines that are before this time.
:type start: string
:param delta: a relative time expression (see -s argument o... | def filter_time_frame(start, delta):
"""Filter :class:`.Line` objects by their connection time.
:param start: a time expression (see -s argument on --help for its format)
to filter log lines that are before this time.
:type start: string
:param delta: a relative time expression (see -s argument o... | [
"Filter",
":",
"class",
":",
".",
"Line",
"objects",
"by",
"their",
"connection",
"time",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/filters.py#L106-L144 | [
"def",
"filter_time_frame",
"(",
"start",
",",
"delta",
")",
":",
"start_value",
"=",
"start",
"delta_value",
"=",
"delta",
"end_value",
"=",
"None",
"if",
"start_value",
"is",
"not",
"''",
":",
"start_value",
"=",
"_date_str_to_datetime",
"(",
"start_value",
... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | filter_response_size | Filter :class:`.Line` objects by the response size (in bytes).
Specially useful when looking for big file downloads.
:param size: Minimum amount of bytes a response body weighted.
:type size: string
:returns: a function that filters by the response size.
:rtype: function | haproxy/filters.py | def filter_response_size(size):
"""Filter :class:`.Line` objects by the response size (in bytes).
Specially useful when looking for big file downloads.
:param size: Minimum amount of bytes a response body weighted.
:type size: string
:returns: a function that filters by the response size.
:rty... | def filter_response_size(size):
"""Filter :class:`.Line` objects by the response size (in bytes).
Specially useful when looking for big file downloads.
:param size: Minimum amount of bytes a response body weighted.
:type size: string
:returns: a function that filters by the response size.
:rty... | [
"Filter",
":",
"class",
":",
".",
"Line",
"objects",
"by",
"the",
"response",
"size",
"(",
"in",
"bytes",
")",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/filters.py#L238-L262 | [
"def",
"filter_response_size",
"(",
"size",
")",
":",
"if",
"size",
".",
"startswith",
"(",
"'+'",
")",
":",
"size_value",
"=",
"int",
"(",
"size",
"[",
"1",
":",
"]",
")",
"else",
":",
"size_value",
"=",
"int",
"(",
"size",
")",
"def",
"filter_func"... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | _get_fields_for_model | Gets all of the fields on the model.
:param DeclarativeModel model: A SQLAlchemy ORM Model
:return: A tuple of the fields on the Model corresponding
to the columns on the Model.
:rtype: tuple | ripozo_sqlalchemy/easy_resource.py | def _get_fields_for_model(model):
"""
Gets all of the fields on the model.
:param DeclarativeModel model: A SQLAlchemy ORM Model
:return: A tuple of the fields on the Model corresponding
to the columns on the Model.
:rtype: tuple
"""
fields = []
for name in model._sa_class_manag... | def _get_fields_for_model(model):
"""
Gets all of the fields on the model.
:param DeclarativeModel model: A SQLAlchemy ORM Model
:return: A tuple of the fields on the Model corresponding
to the columns on the Model.
:rtype: tuple
"""
fields = []
for name in model._sa_class_manag... | [
"Gets",
"all",
"of",
"the",
"fields",
"on",
"the",
"model",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/easy_resource.py#L16-L33 | [
"def",
"_get_fields_for_model",
"(",
"model",
")",
":",
"fields",
"=",
"[",
"]",
"for",
"name",
"in",
"model",
".",
"_sa_class_manager",
":",
"prop",
"=",
"getattr",
"(",
"model",
",",
"name",
")",
"if",
"isinstance",
"(",
"prop",
".",
"property",
",",
... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | _get_relationships | Gets the necessary relationships for the resource
by inspecting the sqlalchemy model for relationships.
:param DeclarativeMeta model: The SQLAlchemy ORM model.
:return: A tuple of Relationship/ListRelationship instances
corresponding to the relationships on the Model.
:rtype: tuple | ripozo_sqlalchemy/easy_resource.py | def _get_relationships(model):
"""
Gets the necessary relationships for the resource
by inspecting the sqlalchemy model for relationships.
:param DeclarativeMeta model: The SQLAlchemy ORM model.
:return: A tuple of Relationship/ListRelationship instances
corresponding to the relationships o... | def _get_relationships(model):
"""
Gets the necessary relationships for the resource
by inspecting the sqlalchemy model for relationships.
:param DeclarativeMeta model: The SQLAlchemy ORM model.
:return: A tuple of Relationship/ListRelationship instances
corresponding to the relationships o... | [
"Gets",
"the",
"necessary",
"relationships",
"for",
"the",
"resource",
"by",
"inspecting",
"the",
"sqlalchemy",
"model",
"for",
"relationships",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/easy_resource.py#L48-L66 | [
"def",
"_get_relationships",
"(",
"model",
")",
":",
"relationships",
"=",
"[",
"]",
"for",
"name",
",",
"relationship",
"in",
"inspect",
"(",
"model",
")",
".",
"relationships",
".",
"items",
"(",
")",
":",
"class_",
"=",
"relationship",
".",
"mapper",
... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | create_resource | Creates a ResourceBase subclass by inspecting a SQLAlchemy
Model. This is somewhat more restrictive than explicitly
creating managers and resources. However, if you only need
any of the basic CRUD+L operations,
:param sqlalchemy.Model model: This is the model that
will be ... | ripozo_sqlalchemy/easy_resource.py | def create_resource(model, session_handler, resource_bases=(CRUDL,),
relationships=None, links=None, preprocessors=None,
postprocessors=None, fields=None, paginate_by=100,
auto_relationships=True, pks=None, create_fields=None,
update_fields... | def create_resource(model, session_handler, resource_bases=(CRUDL,),
relationships=None, links=None, preprocessors=None,
postprocessors=None, fields=None, paginate_by=100,
auto_relationships=True, pks=None, create_fields=None,
update_fields... | [
"Creates",
"a",
"ResourceBase",
"subclass",
"by",
"inspecting",
"a",
"SQLAlchemy",
"Model",
".",
"This",
"is",
"somewhat",
"more",
"restrictive",
"than",
"explicitly",
"creating",
"managers",
"and",
"resources",
".",
"However",
"if",
"you",
"only",
"need",
"any"... | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/easy_resource.py#L69-L145 | [
"def",
"create_resource",
"(",
"model",
",",
"session_handler",
",",
"resource_bases",
"=",
"(",
"CRUDL",
",",
")",
",",
"relationships",
"=",
"None",
",",
"links",
"=",
"None",
",",
"preprocessors",
"=",
"None",
",",
"postprocessors",
"=",
"None",
",",
"f... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | Log._is_pickle_valid | Logic to decide if the file should be processed or just needs to
be loaded from its pickle data. | haproxy/logfile.py | def _is_pickle_valid(self):
"""Logic to decide if the file should be processed or just needs to
be loaded from its pickle data.
"""
if not os.path.exists(self._pickle_file):
return False
else:
file_mtime = os.path.getmtime(self.logfile)
pickle_... | def _is_pickle_valid(self):
"""Logic to decide if the file should be processed or just needs to
be loaded from its pickle data.
"""
if not os.path.exists(self._pickle_file):
return False
else:
file_mtime = os.path.getmtime(self.logfile)
pickle_... | [
"Logic",
"to",
"decide",
"if",
"the",
"file",
"should",
"be",
"processed",
"or",
"just",
"needs",
"to",
"be",
"loaded",
"from",
"its",
"pickle",
"data",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L44-L55 | [
"def",
"_is_pickle_valid",
"(",
"self",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"_pickle_file",
")",
":",
"return",
"False",
"else",
":",
"file_mtime",
"=",
"os",
".",
"path",
".",
"getmtime",
"(",
"self",
".",
"log... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log._load | Load data from a pickle file. | haproxy/logfile.py | def _load(self):
"""Load data from a pickle file. """
with open(self._pickle_file, 'rb') as source:
pickler = pickle.Unpickler(source)
for attribute in self._pickle_attributes:
pickle_data = pickler.load()
setattr(self, attribute, pickle_data) | def _load(self):
"""Load data from a pickle file. """
with open(self._pickle_file, 'rb') as source:
pickler = pickle.Unpickler(source)
for attribute in self._pickle_attributes:
pickle_data = pickler.load()
setattr(self, attribute, pickle_data) | [
"Load",
"data",
"from",
"a",
"pickle",
"file",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L57-L64 | [
"def",
"_load",
"(",
"self",
")",
":",
"with",
"open",
"(",
"self",
".",
"_pickle_file",
",",
"'rb'",
")",
"as",
"source",
":",
"pickler",
"=",
"pickle",
".",
"Unpickler",
"(",
"source",
")",
"for",
"attribute",
"in",
"self",
".",
"_pickle_attributes",
... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log._save | Save the attributes defined on _pickle_attributes in a pickle file.
This improves a lot the nth run as the log file does not need to be
processed every time. | haproxy/logfile.py | def _save(self):
"""Save the attributes defined on _pickle_attributes in a pickle file.
This improves a lot the nth run as the log file does not need to be
processed every time.
"""
with open(self._pickle_file, 'wb') as source:
pickler = pickle.Pickler(source, pickle... | def _save(self):
"""Save the attributes defined on _pickle_attributes in a pickle file.
This improves a lot the nth run as the log file does not need to be
processed every time.
"""
with open(self._pickle_file, 'wb') as source:
pickler = pickle.Pickler(source, pickle... | [
"Save",
"the",
"attributes",
"defined",
"on",
"_pickle_attributes",
"in",
"a",
"pickle",
"file",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L66-L77 | [
"def",
"_save",
"(",
"self",
")",
":",
"with",
"open",
"(",
"self",
".",
"_pickle_file",
",",
"'wb'",
")",
"as",
"source",
":",
"pickler",
"=",
"pickle",
".",
"Pickler",
"(",
"source",
",",
"pickle",
".",
"HIGHEST_PROTOCOL",
")",
"for",
"attribute",
"i... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.parse_data | Parse data from data stream and replace object lines.
:param logfile: [required] Log file data stream.
:type logfile: str | haproxy/logfile.py | def parse_data(self, logfile):
"""Parse data from data stream and replace object lines.
:param logfile: [required] Log file data stream.
:type logfile: str
"""
for line in logfile:
stripped_line = line.strip()
parsed_line = Line(stripped_line)
... | def parse_data(self, logfile):
"""Parse data from data stream and replace object lines.
:param logfile: [required] Log file data stream.
:type logfile: str
"""
for line in logfile:
stripped_line = line.strip()
parsed_line = Line(stripped_line)
... | [
"Parse",
"data",
"from",
"data",
"stream",
"and",
"replace",
"object",
"lines",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L79-L94 | [
"def",
"parse_data",
"(",
"self",
",",
"logfile",
")",
":",
"for",
"line",
"in",
"logfile",
":",
"stripped_line",
"=",
"line",
".",
"strip",
"(",
")",
"parsed_line",
"=",
"Line",
"(",
"stripped_line",
")",
"if",
"parsed_line",
".",
"valid",
":",
"self",
... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.filter | Filter current log lines by a given filter function.
This allows to drill down data out of the log file by filtering the
relevant log lines to analyze.
For example, filter by a given IP so only log lines for that IP are
further processed with commands (top paths, http status counter...... | haproxy/logfile.py | def filter(self, filter_func, reverse=False):
"""Filter current log lines by a given filter function.
This allows to drill down data out of the log file by filtering the
relevant log lines to analyze.
For example, filter by a given IP so only log lines for that IP are
further p... | def filter(self, filter_func, reverse=False):
"""Filter current log lines by a given filter function.
This allows to drill down data out of the log file by filtering the
relevant log lines to analyze.
For example, filter by a given IP so only log lines for that IP are
further p... | [
"Filter",
"current",
"log",
"lines",
"by",
"a",
"given",
"filter",
"function",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L96-L136 | [
"def",
"filter",
"(",
"self",
",",
"filter_func",
",",
"reverse",
"=",
"False",
")",
":",
"new_log_file",
"=",
"Log",
"(",
")",
"new_log_file",
".",
"logfile",
"=",
"self",
".",
"logfile",
"new_log_file",
".",
"total_lines",
"=",
"0",
"new_log_file",
".",
... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.commands | Returns a list of all methods that start with ``cmd_``. | haproxy/logfile.py | def commands(cls):
"""Returns a list of all methods that start with ``cmd_``."""
cmds = [cmd[4:] for cmd in dir(cls) if cmd.startswith('cmd_')]
return cmds | def commands(cls):
"""Returns a list of all methods that start with ``cmd_``."""
cmds = [cmd[4:] for cmd in dir(cls) if cmd.startswith('cmd_')]
return cmds | [
"Returns",
"a",
"list",
"of",
"all",
"methods",
"that",
"start",
"with",
"cmd_",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L139-L142 | [
"def",
"commands",
"(",
"cls",
")",
":",
"cmds",
"=",
"[",
"cmd",
"[",
"4",
":",
"]",
"for",
"cmd",
"in",
"dir",
"(",
"cls",
")",
"if",
"cmd",
".",
"startswith",
"(",
"'cmd_'",
")",
"]",
"return",
"cmds"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_http_methods | Reports a breakdown of how many requests have been made per HTTP
method (GET, POST...). | haproxy/logfile.py | def cmd_http_methods(self):
"""Reports a breakdown of how many requests have been made per HTTP
method (GET, POST...).
"""
methods = defaultdict(int)
for line in self._valid_lines:
methods[line.http_request_method] += 1
return methods | def cmd_http_methods(self):
"""Reports a breakdown of how many requests have been made per HTTP
method (GET, POST...).
"""
methods = defaultdict(int)
for line in self._valid_lines:
methods[line.http_request_method] += 1
return methods | [
"Reports",
"a",
"breakdown",
"of",
"how",
"many",
"requests",
"have",
"been",
"made",
"per",
"HTTP",
"method",
"(",
"GET",
"POST",
"...",
")",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L152-L159 | [
"def",
"cmd_http_methods",
"(",
"self",
")",
":",
"methods",
"=",
"defaultdict",
"(",
"int",
")",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
":",
"methods",
"[",
"line",
".",
"http_request_method",
"]",
"+=",
"1",
"return",
"methods"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_ip_counter | Reports a breakdown of how many requests have been made per IP.
.. note::
To enable this command requests need to provide a header with the
forwarded IP (usually X-Forwarded-For) and be it the only header
being captured. | haproxy/logfile.py | def cmd_ip_counter(self):
"""Reports a breakdown of how many requests have been made per IP.
.. note::
To enable this command requests need to provide a header with the
forwarded IP (usually X-Forwarded-For) and be it the only header
being captured.
"""
ip_... | def cmd_ip_counter(self):
"""Reports a breakdown of how many requests have been made per IP.
.. note::
To enable this command requests need to provide a header with the
forwarded IP (usually X-Forwarded-For) and be it the only header
being captured.
"""
ip_... | [
"Reports",
"a",
"breakdown",
"of",
"how",
"many",
"requests",
"have",
"been",
"made",
"per",
"IP",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L161-L174 | [
"def",
"cmd_ip_counter",
"(",
"self",
")",
":",
"ip_counter",
"=",
"defaultdict",
"(",
"int",
")",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
":",
"ip",
"=",
"line",
".",
"get_ip",
"(",
")",
"if",
"ip",
"is",
"not",
"None",
":",
"ip_counter",
... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_status_codes_counter | Generate statistics about HTTP status codes. 404, 500 and so on. | haproxy/logfile.py | def cmd_status_codes_counter(self):
"""Generate statistics about HTTP status codes. 404, 500 and so on.
"""
status_codes = defaultdict(int)
for line in self._valid_lines:
status_codes[line.status_code] += 1
return status_codes | def cmd_status_codes_counter(self):
"""Generate statistics about HTTP status codes. 404, 500 and so on.
"""
status_codes = defaultdict(int)
for line in self._valid_lines:
status_codes[line.status_code] += 1
return status_codes | [
"Generate",
"statistics",
"about",
"HTTP",
"status",
"codes",
".",
"404",
"500",
"and",
"so",
"on",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L188-L194 | [
"def",
"cmd_status_codes_counter",
"(",
"self",
")",
":",
"status_codes",
"=",
"defaultdict",
"(",
"int",
")",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
":",
"status_codes",
"[",
"line",
".",
"status_code",
"]",
"+=",
"1",
"return",
"status_codes"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_request_path_counter | Generate statistics about HTTP requests' path. | haproxy/logfile.py | def cmd_request_path_counter(self):
"""Generate statistics about HTTP requests' path."""
paths = defaultdict(int)
for line in self._valid_lines:
paths[line.http_request_path] += 1
return paths | def cmd_request_path_counter(self):
"""Generate statistics about HTTP requests' path."""
paths = defaultdict(int)
for line in self._valid_lines:
paths[line.http_request_path] += 1
return paths | [
"Generate",
"statistics",
"about",
"HTTP",
"requests",
"path",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L196-L201 | [
"def",
"cmd_request_path_counter",
"(",
"self",
")",
":",
"paths",
"=",
"defaultdict",
"(",
"int",
")",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
":",
"paths",
"[",
"line",
".",
"http_request_path",
"]",
"+=",
"1",
"return",
"paths"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_slow_requests | List all requests that took a certain amount of time to be
processed.
.. warning::
By now hardcoded to 1 second (1000 milliseconds), improve the
command line interface to allow to send parameters to each command
or globally. | haproxy/logfile.py | def cmd_slow_requests(self):
"""List all requests that took a certain amount of time to be
processed.
.. warning::
By now hardcoded to 1 second (1000 milliseconds), improve the
command line interface to allow to send parameters to each command
or globally.
... | def cmd_slow_requests(self):
"""List all requests that took a certain amount of time to be
processed.
.. warning::
By now hardcoded to 1 second (1000 milliseconds), improve the
command line interface to allow to send parameters to each command
or globally.
... | [
"List",
"all",
"requests",
"that",
"took",
"a",
"certain",
"amount",
"of",
"time",
"to",
"be",
"processed",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L215-L229 | [
"def",
"cmd_slow_requests",
"(",
"self",
")",
":",
"slow_requests",
"=",
"[",
"line",
".",
"time_wait_response",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
"if",
"line",
".",
"time_wait_response",
">",
"1000",
"]",
"return",
"slow_requests"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_average_response_time | Returns the average response time of all, non aborted, requests. | haproxy/logfile.py | def cmd_average_response_time(self):
"""Returns the average response time of all, non aborted, requests."""
average = [
line.time_wait_response
for line in self._valid_lines
if line.time_wait_response >= 0
]
divisor = float(len(average))
if di... | def cmd_average_response_time(self):
"""Returns the average response time of all, non aborted, requests."""
average = [
line.time_wait_response
for line in self._valid_lines
if line.time_wait_response >= 0
]
divisor = float(len(average))
if di... | [
"Returns",
"the",
"average",
"response",
"time",
"of",
"all",
"non",
"aborted",
"requests",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L231-L242 | [
"def",
"cmd_average_response_time",
"(",
"self",
")",
":",
"average",
"=",
"[",
"line",
".",
"time_wait_response",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
"if",
"line",
".",
"time_wait_response",
">=",
"0",
"]",
"divisor",
"=",
"float",
"(",
"len",... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_average_waiting_time | Returns the average queue time of all, non aborted, requests. | haproxy/logfile.py | def cmd_average_waiting_time(self):
"""Returns the average queue time of all, non aborted, requests."""
average = [
line.time_wait_queues
for line in self._valid_lines
if line.time_wait_queues >= 0
]
divisor = float(len(average))
if divisor > ... | def cmd_average_waiting_time(self):
"""Returns the average queue time of all, non aborted, requests."""
average = [
line.time_wait_queues
for line in self._valid_lines
if line.time_wait_queues >= 0
]
divisor = float(len(average))
if divisor > ... | [
"Returns",
"the",
"average",
"queue",
"time",
"of",
"all",
"non",
"aborted",
"requests",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L244-L255 | [
"def",
"cmd_average_waiting_time",
"(",
"self",
")",
":",
"average",
"=",
"[",
"line",
".",
"time_wait_queues",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
"if",
"line",
".",
"time_wait_queues",
">=",
"0",
"]",
"divisor",
"=",
"float",
"(",
"len",
"(... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_server_load | Generate statistics regarding how many requests were processed by
each downstream server. | haproxy/logfile.py | def cmd_server_load(self):
"""Generate statistics regarding how many requests were processed by
each downstream server.
"""
servers = defaultdict(int)
for line in self._valid_lines:
servers[line.server_name] += 1
return servers | def cmd_server_load(self):
"""Generate statistics regarding how many requests were processed by
each downstream server.
"""
servers = defaultdict(int)
for line in self._valid_lines:
servers[line.server_name] += 1
return servers | [
"Generate",
"statistics",
"regarding",
"how",
"many",
"requests",
"were",
"processed",
"by",
"each",
"downstream",
"server",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L268-L275 | [
"def",
"cmd_server_load",
"(",
"self",
")",
":",
"servers",
"=",
"defaultdict",
"(",
"int",
")",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
":",
"servers",
"[",
"line",
".",
"server_name",
"]",
"+=",
"1",
"return",
"servers"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_queue_peaks | Generate a list of the requests peaks on the queue.
A queue peak is defined by the biggest value on the backend queue
on a series of log lines that are between log lines without being
queued.
.. warning::
Allow to configure up to which peak can be ignored. Currently
... | haproxy/logfile.py | def cmd_queue_peaks(self):
"""Generate a list of the requests peaks on the queue.
A queue peak is defined by the biggest value on the backend queue
on a series of log lines that are between log lines without being
queued.
.. warning::
Allow to configure up to which pe... | def cmd_queue_peaks(self):
"""Generate a list of the requests peaks on the queue.
A queue peak is defined by the biggest value on the backend queue
on a series of log lines that are between log lines without being
queued.
.. warning::
Allow to configure up to which pe... | [
"Generate",
"a",
"list",
"of",
"the",
"requests",
"peaks",
"on",
"the",
"queue",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L277-L330 | [
"def",
"cmd_queue_peaks",
"(",
"self",
")",
":",
"threshold",
"=",
"1",
"peaks",
"=",
"[",
"]",
"current_peak",
"=",
"0",
"current_queue",
"=",
"0",
"current_span",
"=",
"0",
"first_on_queue",
"=",
"None",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_connection_type | Generates statistics on how many requests are made via HTTP and how
many are made via SSL.
.. note::
This only works if the request path contains the default port for
SSL (443).
.. warning::
The ports are hardcoded, they should be configurable. | haproxy/logfile.py | def cmd_connection_type(self):
"""Generates statistics on how many requests are made via HTTP and how
many are made via SSL.
.. note::
This only works if the request path contains the default port for
SSL (443).
.. warning::
The ports are hardcoded, they s... | def cmd_connection_type(self):
"""Generates statistics on how many requests are made via HTTP and how
many are made via SSL.
.. note::
This only works if the request path contains the default port for
SSL (443).
.. warning::
The ports are hardcoded, they s... | [
"Generates",
"statistics",
"on",
"how",
"many",
"requests",
"are",
"made",
"via",
"HTTP",
"and",
"how",
"many",
"are",
"made",
"via",
"SSL",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L332-L350 | [
"def",
"cmd_connection_type",
"(",
"self",
")",
":",
"https",
"=",
"0",
"non_https",
"=",
"0",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
":",
"if",
"line",
".",
"is_https",
"(",
")",
":",
"https",
"+=",
"1",
"else",
":",
"non_https",
"+=",
"1... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_requests_per_minute | Generates statistics on how many requests were made per minute.
.. note::
Try to combine it with time constrains (``-s`` and ``-d``) as this
command output can be huge otherwise. | haproxy/logfile.py | def cmd_requests_per_minute(self):
"""Generates statistics on how many requests were made per minute.
.. note::
Try to combine it with time constrains (``-s`` and ``-d``) as this
command output can be huge otherwise.
"""
if len(self._valid_lines) == 0:
re... | def cmd_requests_per_minute(self):
"""Generates statistics on how many requests were made per minute.
.. note::
Try to combine it with time constrains (``-s`` and ``-d``) as this
command output can be huge otherwise.
"""
if len(self._valid_lines) == 0:
re... | [
"Generates",
"statistics",
"on",
"how",
"many",
"requests",
"were",
"made",
"per",
"minute",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L352-L398 | [
"def",
"cmd_requests_per_minute",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"_valid_lines",
")",
"==",
"0",
":",
"return",
"current_minute",
"=",
"self",
".",
"_valid_lines",
"[",
"0",
"]",
".",
"accept_date",
"current_minute_counter",
"=",
"0",
... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log.cmd_print | Returns the raw lines to be printed. | haproxy/logfile.py | def cmd_print(self):
"""Returns the raw lines to be printed."""
if not self._valid_lines:
return ''
return '\n'.join([line.raw_line for line in self._valid_lines]) + '\n' | def cmd_print(self):
"""Returns the raw lines to be printed."""
if not self._valid_lines:
return ''
return '\n'.join([line.raw_line for line in self._valid_lines]) + '\n' | [
"Returns",
"the",
"raw",
"lines",
"to",
"be",
"printed",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L400-L404 | [
"def",
"cmd_print",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_valid_lines",
":",
"return",
"''",
"return",
"'\\n'",
".",
"join",
"(",
"[",
"line",
".",
"raw_line",
"for",
"line",
"in",
"self",
".",
"_valid_lines",
"]",
")",
"+",
"'\\n'"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log._sort_lines | Haproxy writes its logs after having gathered all information
related to each specific connection. A simple request can be
really quick but others can be really slow, thus even if one connection
is logged later, it could have been accepted before others that are
already processed and log... | haproxy/logfile.py | def _sort_lines(self):
"""Haproxy writes its logs after having gathered all information
related to each specific connection. A simple request can be
really quick but others can be really slow, thus even if one connection
is logged later, it could have been accepted before others that are... | def _sort_lines(self):
"""Haproxy writes its logs after having gathered all information
related to each specific connection. A simple request can be
really quick but others can be really slow, thus even if one connection
is logged later, it could have been accepted before others that are... | [
"Haproxy",
"writes",
"its",
"logs",
"after",
"having",
"gathered",
"all",
"information",
"related",
"to",
"each",
"specific",
"connection",
".",
"A",
"simple",
"request",
"can",
"be",
"really",
"quick",
"but",
"others",
"can",
"be",
"really",
"slow",
"thus",
... | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L406-L419 | [
"def",
"_sort_lines",
"(",
"self",
")",
":",
"self",
".",
"_valid_lines",
"=",
"sorted",
"(",
"self",
".",
"_valid_lines",
",",
"key",
"=",
"lambda",
"line",
":",
"line",
".",
"accept_date",
",",
")"
] | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | Log._sort_and_trim | Sorts a dictionary with at least two fields on each of them sorting
by the second element.
.. warning::
Right now is hardcoded to 10 elements, improve the command line
interface to allow to send parameters to each command or globally. | haproxy/logfile.py | def _sort_and_trim(data, reverse=False):
"""Sorts a dictionary with at least two fields on each of them sorting
by the second element.
.. warning::
Right now is hardcoded to 10 elements, improve the command line
interface to allow to send parameters to each command or global... | def _sort_and_trim(data, reverse=False):
"""Sorts a dictionary with at least two fields on each of them sorting
by the second element.
.. warning::
Right now is hardcoded to 10 elements, improve the command line
interface to allow to send parameters to each command or global... | [
"Sorts",
"a",
"dictionary",
"with",
"at",
"least",
"two",
"fields",
"on",
"each",
"of",
"them",
"sorting",
"by",
"the",
"second",
"element",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/logfile.py#L422-L437 | [
"def",
"_sort_and_trim",
"(",
"data",
",",
"reverse",
"=",
"False",
")",
":",
"threshold",
"=",
"10",
"data_list",
"=",
"data",
".",
"items",
"(",
")",
"data_list",
"=",
"sorted",
"(",
"data_list",
",",
"key",
"=",
"lambda",
"data_info",
":",
"data_info"... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | db_access_point | Wraps a function that actually accesses the database.
It injects a session into the method and attempts to handle
it after the function has run.
:param method func: The method that is interacting with the database. | ripozo_sqlalchemy/alchemymanager.py | def db_access_point(func):
"""
Wraps a function that actually accesses the database.
It injects a session into the method and attempts to handle
it after the function has run.
:param method func: The method that is interacting with the database.
"""
@wraps(func)
def wrapper(self, *args,... | def db_access_point(func):
"""
Wraps a function that actually accesses the database.
It injects a session into the method and attempts to handle
it after the function has run.
:param method func: The method that is interacting with the database.
"""
@wraps(func)
def wrapper(self, *args,... | [
"Wraps",
"a",
"function",
"that",
"actually",
"accesses",
"the",
"database",
".",
"It",
"injects",
"a",
"session",
"into",
"the",
"method",
"and",
"attempts",
"to",
"handle",
"it",
"after",
"the",
"function",
"has",
"run",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L42-L65 | [
"def",
"db_access_point",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"\"\"\"\n Wrapper responsible for handling\n sessions\n \"\"\"",
"session",
"=... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager._get_field_python_type | Gets the python type for the attribute on the model
with the name provided.
:param Model model: The SqlAlchemy model class.
:param unicode name: The column name on the model
that you are attempting to get the python type.
:return: The python type of the column
:rtype... | ripozo_sqlalchemy/alchemymanager.py | def _get_field_python_type(model, name):
"""
Gets the python type for the attribute on the model
with the name provided.
:param Model model: The SqlAlchemy model class.
:param unicode name: The column name on the model
that you are attempting to get the python type.
... | def _get_field_python_type(model, name):
"""
Gets the python type for the attribute on the model
with the name provided.
:param Model model: The SqlAlchemy model class.
:param unicode name: The column name on the model
that you are attempting to get the python type.
... | [
"Gets",
"the",
"python",
"type",
"for",
"the",
"attribute",
"on",
"the",
"model",
"with",
"the",
"name",
"provided",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L90-L109 | [
"def",
"_get_field_python_type",
"(",
"model",
",",
"name",
")",
":",
"try",
":",
"return",
"getattr",
"(",
"model",
",",
"name",
")",
".",
"property",
".",
"columns",
"[",
"0",
"]",
".",
"type",
".",
"python_type",
"except",
"AttributeError",
":",
"# It... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager.get_field_type | Takes a field name and gets an appropriate BaseField instance
for that column. It inspects the Model that is set on the manager
to determine what the BaseField subclass should be.
:param unicode name:
:return: A BaseField subclass that is appropriate for
translating a strin... | ripozo_sqlalchemy/alchemymanager.py | def get_field_type(cls, name):
"""
Takes a field name and gets an appropriate BaseField instance
for that column. It inspects the Model that is set on the manager
to determine what the BaseField subclass should be.
:param unicode name:
:return: A BaseField subclass that... | def get_field_type(cls, name):
"""
Takes a field name and gets an appropriate BaseField instance
for that column. It inspects the Model that is set on the manager
to determine what the BaseField subclass should be.
:param unicode name:
:return: A BaseField subclass that... | [
"Takes",
"a",
"field",
"name",
"and",
"gets",
"an",
"appropriate",
"BaseField",
"instance",
"for",
"that",
"column",
".",
"It",
"inspects",
"the",
"Model",
"that",
"is",
"set",
"on",
"the",
"manager",
"to",
"determine",
"what",
"the",
"BaseField",
"subclass"... | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L112-L127 | [
"def",
"get_field_type",
"(",
"cls",
",",
"name",
")",
":",
"python_type",
"=",
"cls",
".",
"_get_field_python_type",
"(",
"cls",
".",
"model",
",",
"name",
")",
"if",
"python_type",
"in",
"_COLUMN_FIELD_MAP",
":",
"field_class",
"=",
"_COLUMN_FIELD_MAP",
"[",... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager.create | Creates a new instance of the self.model
and persists it to the database.
:param dict values: The dictionary of values to
set on the model. The key is the column name
and the value is what it will be set to. If
the cls._create_fields is defined then it will
... | ripozo_sqlalchemy/alchemymanager.py | def create(self, session, values, *args, **kwargs):
"""
Creates a new instance of the self.model
and persists it to the database.
:param dict values: The dictionary of values to
set on the model. The key is the column name
and the value is what it will be set to... | def create(self, session, values, *args, **kwargs):
"""
Creates a new instance of the self.model
and persists it to the database.
:param dict values: The dictionary of values to
set on the model. The key is the column name
and the value is what it will be set to... | [
"Creates",
"a",
"new",
"instance",
"of",
"the",
"self",
".",
"model",
"and",
"persists",
"it",
"to",
"the",
"database",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L130-L150 | [
"def",
"create",
"(",
"self",
",",
"session",
",",
"values",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"model",
"=",
"self",
".",
"model",
"(",
")",
"model",
"=",
"self",
".",
"_set_values_on_model",
"(",
"model",
",",
"values",
",",
"fi... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager.retrieve | Retrieves a model using the lookup keys provided.
Only one model should be returned by the lookup_keys
or else the manager will fail.
:param Session session: The SQLAlchemy session to use
:param dict lookup_keys: A dictionary mapping the fields
and their expected values
... | ripozo_sqlalchemy/alchemymanager.py | def retrieve(self, session, lookup_keys, *args, **kwargs):
"""
Retrieves a model using the lookup keys provided.
Only one model should be returned by the lookup_keys
or else the manager will fail.
:param Session session: The SQLAlchemy session to use
:param dict lookup_k... | def retrieve(self, session, lookup_keys, *args, **kwargs):
"""
Retrieves a model using the lookup keys provided.
Only one model should be returned by the lookup_keys
or else the manager will fail.
:param Session session: The SQLAlchemy session to use
:param dict lookup_k... | [
"Retrieves",
"a",
"model",
"using",
"the",
"lookup",
"keys",
"provided",
".",
"Only",
"one",
"model",
"should",
"be",
"returned",
"by",
"the",
"lookup_keys",
"or",
"else",
"the",
"manager",
"will",
"fail",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L153-L169 | [
"def",
"retrieve",
"(",
"self",
",",
"session",
",",
"lookup_keys",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"model",
"=",
"self",
".",
"_get_model",
"(",
"lookup_keys",
",",
"session",
")",
"return",
"self",
".",
"serialize_model",
"(",
"m... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager.retrieve_list | Retrieves a list of the model for this manager.
It is restricted by the filters provided.
:param Session session: The SQLAlchemy session to use
:param dict filters: The filters to restrict the returned
models on
:return: A tuple of the list of dictionary representation
... | ripozo_sqlalchemy/alchemymanager.py | def retrieve_list(self, session, filters, *args, **kwargs):
"""
Retrieves a list of the model for this manager.
It is restricted by the filters provided.
:param Session session: The SQLAlchemy session to use
:param dict filters: The filters to restrict the returned
m... | def retrieve_list(self, session, filters, *args, **kwargs):
"""
Retrieves a list of the model for this manager.
It is restricted by the filters provided.
:param Session session: The SQLAlchemy session to use
:param dict filters: The filters to restrict the returned
m... | [
"Retrieves",
"a",
"list",
"of",
"the",
"model",
"for",
"this",
"manager",
".",
"It",
"is",
"restricted",
"by",
"the",
"filters",
"provided",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L172-L214 | [
"def",
"retrieve_list",
"(",
"self",
",",
"session",
",",
"filters",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"query",
"=",
"self",
".",
"queryset",
"(",
"session",
")",
"translator",
"=",
"IntegerField",
"(",
"'tmp'",
")",
"pagination_count"... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager.update | Updates the model with the specified lookup_keys and returns
the dictified object.
:param Session session: The SQLAlchemy session to use
:param dict lookup_keys: A dictionary mapping the fields
and their expected values
:param dict updates: The columns and the values to upda... | ripozo_sqlalchemy/alchemymanager.py | def update(self, session, lookup_keys, updates, *args, **kwargs):
"""
Updates the model with the specified lookup_keys and returns
the dictified object.
:param Session session: The SQLAlchemy session to use
:param dict lookup_keys: A dictionary mapping the fields
and... | def update(self, session, lookup_keys, updates, *args, **kwargs):
"""
Updates the model with the specified lookup_keys and returns
the dictified object.
:param Session session: The SQLAlchemy session to use
:param dict lookup_keys: A dictionary mapping the fields
and... | [
"Updates",
"the",
"model",
"with",
"the",
"specified",
"lookup_keys",
"and",
"returns",
"the",
"dictified",
"object",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L217-L236 | [
"def",
"update",
"(",
"self",
",",
"session",
",",
"lookup_keys",
",",
"updates",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"model",
"=",
"self",
".",
"_get_model",
"(",
"lookup_keys",
",",
"session",
")",
"model",
"=",
"self",
".",
"_set_... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager.delete | Deletes the model found using the lookup_keys
:param Session session: The SQLAlchemy session to use
:param dict lookup_keys: A dictionary mapping the fields
and their expected values
:return: An empty dictionary
:rtype: dict
:raises: NotFoundException | ripozo_sqlalchemy/alchemymanager.py | def delete(self, session, lookup_keys, *args, **kwargs):
"""
Deletes the model found using the lookup_keys
:param Session session: The SQLAlchemy session to use
:param dict lookup_keys: A dictionary mapping the fields
and their expected values
:return: An empty dicti... | def delete(self, session, lookup_keys, *args, **kwargs):
"""
Deletes the model found using the lookup_keys
:param Session session: The SQLAlchemy session to use
:param dict lookup_keys: A dictionary mapping the fields
and their expected values
:return: An empty dicti... | [
"Deletes",
"the",
"model",
"found",
"using",
"the",
"lookup_keys"
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L239-L253 | [
"def",
"delete",
"(",
"self",
",",
"session",
",",
"lookup_keys",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"model",
"=",
"self",
".",
"_get_model",
"(",
"lookup_keys",
",",
"session",
")",
"session",
".",
"delete",
"(",
"model",
")",
"ses... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager.serialize_model | Takes a model and serializes the fields provided into
a dictionary.
:param Model model: The Sqlalchemy model instance to serialize
:param dict field_dict: The dictionary of fields to return.
:return: The serialized model.
:rtype: dict | ripozo_sqlalchemy/alchemymanager.py | def serialize_model(self, model, field_dict=None):
"""
Takes a model and serializes the fields provided into
a dictionary.
:param Model model: The Sqlalchemy model instance to serialize
:param dict field_dict: The dictionary of fields to return.
:return: The serialized m... | def serialize_model(self, model, field_dict=None):
"""
Takes a model and serializes the fields provided into
a dictionary.
:param Model model: The Sqlalchemy model instance to serialize
:param dict field_dict: The dictionary of fields to return.
:return: The serialized m... | [
"Takes",
"a",
"model",
"and",
"serializes",
"the",
"fields",
"provided",
"into",
"a",
"dictionary",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L264-L275 | [
"def",
"serialize_model",
"(",
"self",
",",
"model",
",",
"field_dict",
"=",
"None",
")",
":",
"response",
"=",
"self",
".",
"_serialize_model_helper",
"(",
"model",
",",
"field_dict",
"=",
"field_dict",
")",
"return",
"make_json_safe",
"(",
"response",
")"
] | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager._serialize_model_helper | A recursive function for serializing a model
into a json ready format. | ripozo_sqlalchemy/alchemymanager.py | def _serialize_model_helper(self, model, field_dict=None):
"""
A recursive function for serializing a model
into a json ready format.
"""
field_dict = field_dict or self.dot_field_list_to_dict()
if model is None:
return None
if isinstance(model, Query... | def _serialize_model_helper(self, model, field_dict=None):
"""
A recursive function for serializing a model
into a json ready format.
"""
field_dict = field_dict or self.dot_field_list_to_dict()
if model is None:
return None
if isinstance(model, Query... | [
"A",
"recursive",
"function",
"for",
"serializing",
"a",
"model",
"into",
"a",
"json",
"ready",
"format",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L277-L298 | [
"def",
"_serialize_model_helper",
"(",
"self",
",",
"model",
",",
"field_dict",
"=",
"None",
")",
":",
"field_dict",
"=",
"field_dict",
"or",
"self",
".",
"dot_field_list_to_dict",
"(",
")",
"if",
"model",
"is",
"None",
":",
"return",
"None",
"if",
"isinstan... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager._get_model | Gets the sqlalchemy Model instance associated with
the lookup keys.
:param dict lookup_keys: A dictionary of the keys
and their associated values.
:param Session session: The sqlalchemy session
:return: The sqlalchemy orm model instance. | ripozo_sqlalchemy/alchemymanager.py | def _get_model(self, lookup_keys, session):
"""
Gets the sqlalchemy Model instance associated with
the lookup keys.
:param dict lookup_keys: A dictionary of the keys
and their associated values.
:param Session session: The sqlalchemy session
:return: The sqla... | def _get_model(self, lookup_keys, session):
"""
Gets the sqlalchemy Model instance associated with
the lookup keys.
:param dict lookup_keys: A dictionary of the keys
and their associated values.
:param Session session: The sqlalchemy session
:return: The sqla... | [
"Gets",
"the",
"sqlalchemy",
"Model",
"instance",
"associated",
"with",
"the",
"lookup",
"keys",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L300-L314 | [
"def",
"_get_model",
"(",
"self",
",",
"lookup_keys",
",",
"session",
")",
":",
"try",
":",
"return",
"self",
".",
"queryset",
"(",
"session",
")",
".",
"filter_by",
"(",
"*",
"*",
"lookup_keys",
")",
".",
"one",
"(",
")",
"except",
"NoResultFound",
":... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | AlchemyManager._set_values_on_model | Updates the values with the specified values.
:param Model model: The sqlalchemy model instance
:param dict values: The dictionary of attributes and
the values to set.
:param list fields: A list of strings indicating
the valid fields. Defaults to self.fields.
:re... | ripozo_sqlalchemy/alchemymanager.py | def _set_values_on_model(self, model, values, fields=None):
"""
Updates the values with the specified values.
:param Model model: The sqlalchemy model instance
:param dict values: The dictionary of attributes and
the values to set.
:param list fields: A list of strin... | def _set_values_on_model(self, model, values, fields=None):
"""
Updates the values with the specified values.
:param Model model: The sqlalchemy model instance
:param dict values: The dictionary of attributes and
the values to set.
:param list fields: A list of strin... | [
"Updates",
"the",
"values",
"with",
"the",
"specified",
"values",
"."
] | vertical-knowledge/ripozo-sqlalchemy | python | https://github.com/vertical-knowledge/ripozo-sqlalchemy/blob/4bcc57ec6db1b39b84b50553bb264e4950ce4ec2/ripozo_sqlalchemy/alchemymanager.py#L316-L333 | [
"def",
"_set_values_on_model",
"(",
"self",
",",
"model",
",",
"values",
",",
"fields",
"=",
"None",
")",
":",
"fields",
"=",
"fields",
"or",
"self",
".",
"fields",
"for",
"name",
",",
"val",
"in",
"six",
".",
"iteritems",
"(",
"values",
")",
":",
"i... | 4bcc57ec6db1b39b84b50553bb264e4950ce4ec2 |
train | print_commands | Prints all commands available from Log with their
description. | haproxy/main.py | def print_commands():
"""Prints all commands available from Log with their
description.
"""
dummy_log_file = Log()
commands = Log.commands()
commands.sort()
for cmd in commands:
cmd = getattr(dummy_log_file, 'cmd_{0}'.format(cmd))
description = cmd.__doc__
if descrip... | def print_commands():
"""Prints all commands available from Log with their
description.
"""
dummy_log_file = Log()
commands = Log.commands()
commands.sort()
for cmd in commands:
cmd = getattr(dummy_log_file, 'cmd_{0}'.format(cmd))
description = cmd.__doc__
if descrip... | [
"Prints",
"all",
"commands",
"available",
"from",
"Log",
"with",
"their",
"description",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/main.py#L191-L206 | [
"def",
"print_commands",
"(",
")",
":",
"dummy_log_file",
"=",
"Log",
"(",
")",
"commands",
"=",
"Log",
".",
"commands",
"(",
")",
"commands",
".",
"sort",
"(",
")",
"for",
"cmd",
"in",
"commands",
":",
"cmd",
"=",
"getattr",
"(",
"dummy_log_file",
","... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | print_filters | Prints all filters available with their description. | haproxy/main.py | def print_filters():
"""Prints all filters available with their description."""
for filter_name in VALID_FILTERS:
filter_func = getattr(filters, 'filter_{0}'.format(filter_name))
description = filter_func.__doc__
if description:
description = re.sub(r'\n\s+', ' ', description... | def print_filters():
"""Prints all filters available with their description."""
for filter_name in VALID_FILTERS:
filter_func = getattr(filters, 'filter_{0}'.format(filter_name))
description = filter_func.__doc__
if description:
description = re.sub(r'\n\s+', ' ', description... | [
"Prints",
"all",
"filters",
"available",
"with",
"their",
"description",
"."
] | gforcada/haproxy_log_analysis | python | https://github.com/gforcada/haproxy_log_analysis/blob/a899895359bd4df6f35e279ad75c32c5afcfe916/haproxy/main.py#L209-L218 | [
"def",
"print_filters",
"(",
")",
":",
"for",
"filter_name",
"in",
"VALID_FILTERS",
":",
"filter_func",
"=",
"getattr",
"(",
"filters",
",",
"'filter_{0}'",
".",
"format",
"(",
"filter_name",
")",
")",
"description",
"=",
"filter_func",
".",
"__doc__",
"if",
... | a899895359bd4df6f35e279ad75c32c5afcfe916 |
train | PowerManagementBase.add_observer | Adds weak ref to an observer.
@param observer: Instance of class registered with PowerManagementObserver
@raise TypeError: If observer is not registered with PowerManagementObserver abstract class | power/common.py | def add_observer(self, observer):
"""
Adds weak ref to an observer.
@param observer: Instance of class registered with PowerManagementObserver
@raise TypeError: If observer is not registered with PowerManagementObserver abstract class
"""
if not isinstance(observer, Powe... | def add_observer(self, observer):
"""
Adds weak ref to an observer.
@param observer: Instance of class registered with PowerManagementObserver
@raise TypeError: If observer is not registered with PowerManagementObserver abstract class
"""
if not isinstance(observer, Powe... | [
"Adds",
"weak",
"ref",
"to",
"an",
"observer",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/common.py#L115-L124 | [
"def",
"add_observer",
"(",
"self",
",",
"observer",
")",
":",
"if",
"not",
"isinstance",
"(",
"observer",
",",
"PowerManagementObserver",
")",
":",
"raise",
"TypeError",
"(",
"\"observer MUST conform to power.PowerManagementObserver\"",
")",
"self",
".",
"_weak_obser... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagementBase.remove_all_observers | Removes all registered observers. | power/common.py | def remove_all_observers(self):
"""
Removes all registered observers.
"""
for weak_observer in self._weak_observers:
observer = weak_observer()
if observer:
self.remove_observer(observer) | def remove_all_observers(self):
"""
Removes all registered observers.
"""
for weak_observer in self._weak_observers:
observer = weak_observer()
if observer:
self.remove_observer(observer) | [
"Removes",
"all",
"registered",
"observers",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/common.py#L135-L142 | [
"def",
"remove_all_observers",
"(",
"self",
")",
":",
"for",
"weak_observer",
"in",
"self",
".",
"_weak_observers",
":",
"observer",
"=",
"weak_observer",
"(",
")",
"if",
"observer",
":",
"self",
".",
"remove_observer",
"(",
"observer",
")"
] | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerSourcesNotificationsObserver.startThread | Spawns new NSThread to handle notifications. | power/darwin.py | def startThread(self):
"""Spawns new NSThread to handle notifications."""
if self._thread is not None:
return
self._thread = NSThread.alloc().initWithTarget_selector_object_(self, 'runPowerNotificationsThread', None)
self._thread.start() | def startThread(self):
"""Spawns new NSThread to handle notifications."""
if self._thread is not None:
return
self._thread = NSThread.alloc().initWithTarget_selector_object_(self, 'runPowerNotificationsThread', None)
self._thread.start() | [
"Spawns",
"new",
"NSThread",
"to",
"handle",
"notifications",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L177-L182 | [
"def",
"startThread",
"(",
"self",
")",
":",
"if",
"self",
".",
"_thread",
"is",
"not",
"None",
":",
"return",
"self",
".",
"_thread",
"=",
"NSThread",
".",
"alloc",
"(",
")",
".",
"initWithTarget_selector_object_",
"(",
"self",
",",
"'runPowerNotificationsT... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerSourcesNotificationsObserver.stopThread | Stops spawned NSThread. | power/darwin.py | def stopThread(self):
"""Stops spawned NSThread."""
if self._thread is not None:
self.performSelector_onThread_withObject_waitUntilDone_('stopPowerNotificationsThread', self._thread, None, objc.YES)
self._thread = None | def stopThread(self):
"""Stops spawned NSThread."""
if self._thread is not None:
self.performSelector_onThread_withObject_waitUntilDone_('stopPowerNotificationsThread', self._thread, None, objc.YES)
self._thread = None | [
"Stops",
"spawned",
"NSThread",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L184-L188 | [
"def",
"stopThread",
"(",
"self",
")",
":",
"if",
"self",
".",
"_thread",
"is",
"not",
"None",
":",
"self",
".",
"performSelector_onThread_withObject_waitUntilDone_",
"(",
"'stopPowerNotificationsThread'",
",",
"self",
".",
"_thread",
",",
"None",
",",
"objc",
"... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerSourcesNotificationsObserver.runPowerNotificationsThread | Main method of the spawned NSThread. Registers run loop source and runs current NSRunLoop. | power/darwin.py | def runPowerNotificationsThread(self):
"""Main method of the spawned NSThread. Registers run loop source and runs current NSRunLoop."""
pool = NSAutoreleasePool.alloc().init()
@objc.callbackFor(IOPSNotificationCreateRunLoopSource)
def on_power_source_notification(context):
w... | def runPowerNotificationsThread(self):
"""Main method of the spawned NSThread. Registers run loop source and runs current NSRunLoop."""
pool = NSAutoreleasePool.alloc().init()
@objc.callbackFor(IOPSNotificationCreateRunLoopSource)
def on_power_source_notification(context):
w... | [
"Main",
"method",
"of",
"the",
"spawned",
"NSThread",
".",
"Registers",
"run",
"loop",
"source",
"and",
"runs",
"current",
"NSRunLoop",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L190-L206 | [
"def",
"runPowerNotificationsThread",
"(",
"self",
")",
":",
"pool",
"=",
"NSAutoreleasePool",
".",
"alloc",
"(",
")",
".",
"init",
"(",
")",
"@",
"objc",
".",
"callbackFor",
"(",
"IOPSNotificationCreateRunLoopSource",
")",
"def",
"on_power_source_notification",
"... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerSourcesNotificationsObserver.stopPowerNotificationsThread | Removes the only source from NSRunLoop and cancels thread. | power/darwin.py | def stopPowerNotificationsThread(self):
"""Removes the only source from NSRunLoop and cancels thread."""
assert NSThread.currentThread() == self._thread
CFRunLoopSourceInvalidate(self._source)
self._source = None
NSThread.currentThread().cancel() | def stopPowerNotificationsThread(self):
"""Removes the only source from NSRunLoop and cancels thread."""
assert NSThread.currentThread() == self._thread
CFRunLoopSourceInvalidate(self._source)
self._source = None
NSThread.currentThread().cancel() | [
"Removes",
"the",
"only",
"source",
"from",
"NSRunLoop",
"and",
"cancels",
"thread",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L209-L215 | [
"def",
"stopPowerNotificationsThread",
"(",
"self",
")",
":",
"assert",
"NSThread",
".",
"currentThread",
"(",
")",
"==",
"self",
".",
"_thread",
"CFRunLoopSourceInvalidate",
"(",
"self",
".",
"_source",
")",
"self",
".",
"_source",
"=",
"None",
"NSThread",
".... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerSourcesNotificationsObserver.addObserver | Adds weak ref to an observer.
@param observer: Instance of class that implements on_power_source_notification() | power/darwin.py | def addObserver(self, observer):
"""
Adds weak ref to an observer.
@param observer: Instance of class that implements on_power_source_notification()
"""
with self._lock:
self._weak_observers.append(weakref.ref(observer))
if len(self._weak_observers) == 1:... | def addObserver(self, observer):
"""
Adds weak ref to an observer.
@param observer: Instance of class that implements on_power_source_notification()
"""
with self._lock:
self._weak_observers.append(weakref.ref(observer))
if len(self._weak_observers) == 1:... | [
"Adds",
"weak",
"ref",
"to",
"an",
"observer",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L217-L226 | [
"def",
"addObserver",
"(",
"self",
",",
"observer",
")",
":",
"with",
"self",
".",
"_lock",
":",
"self",
".",
"_weak_observers",
".",
"append",
"(",
"weakref",
".",
"ref",
"(",
"observer",
")",
")",
"if",
"len",
"(",
"self",
".",
"_weak_observers",
")"... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerSourcesNotificationsObserver.removeObserver | Removes an observer.
@param observer: Previously added observer | power/darwin.py | def removeObserver(self, observer):
"""
Removes an observer.
@param observer: Previously added observer
"""
with self._lock:
self._weak_observers.remove(weakref.ref(observer))
if len(self._weak_observers) == 0:
self.stopThread() | def removeObserver(self, observer):
"""
Removes an observer.
@param observer: Previously added observer
"""
with self._lock:
self._weak_observers.remove(weakref.ref(observer))
if len(self._weak_observers) == 0:
self.stopThread() | [
"Removes",
"an",
"observer",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L228-L237 | [
"def",
"removeObserver",
"(",
"self",
",",
"observer",
")",
":",
"with",
"self",
".",
"_lock",
":",
"self",
".",
"_weak_observers",
".",
"remove",
"(",
"weakref",
".",
"ref",
"(",
"observer",
")",
")",
"if",
"len",
"(",
"self",
".",
"_weak_observers",
... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.on_power_source_notification | Called in response to IOPSNotificationCreateRunLoopSource() event. | power/darwin.py | def on_power_source_notification(self):
"""
Called in response to IOPSNotificationCreateRunLoopSource() event.
"""
for weak_observer in self._weak_observers:
observer = weak_observer()
if observer:
observer.on_power_sources_change(self)
... | def on_power_source_notification(self):
"""
Called in response to IOPSNotificationCreateRunLoopSource() event.
"""
for weak_observer in self._weak_observers:
observer = weak_observer()
if observer:
observer.on_power_sources_change(self)
... | [
"Called",
"in",
"response",
"to",
"IOPSNotificationCreateRunLoopSource",
"()",
"event",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L250-L258 | [
"def",
"on_power_source_notification",
"(",
"self",
")",
":",
"for",
"weak_observer",
"in",
"self",
".",
"_weak_observers",
":",
"observer",
"=",
"weak_observer",
"(",
")",
"if",
"observer",
":",
"observer",
".",
"on_power_sources_change",
"(",
"self",
")",
"obs... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_time_remaining_estimate | In Mac OS X 10.7+
Uses IOPSGetTimeRemainingEstimate to get time remaining estimate.
In Mac OS X 10.6
IOPSGetTimeRemainingEstimate is not available.
If providing power source type is AC, returns TIME_REMAINING_UNLIMITED.
Otherwise looks through all power sources returned by IOPSG... | power/darwin.py | def get_time_remaining_estimate(self):
"""
In Mac OS X 10.7+
Uses IOPSGetTimeRemainingEstimate to get time remaining estimate.
In Mac OS X 10.6
IOPSGetTimeRemainingEstimate is not available.
If providing power source type is AC, returns TIME_REMAINING_UNLIMITED.
... | def get_time_remaining_estimate(self):
"""
In Mac OS X 10.7+
Uses IOPSGetTimeRemainingEstimate to get time remaining estimate.
In Mac OS X 10.6
IOPSGetTimeRemainingEstimate is not available.
If providing power source type is AC, returns TIME_REMAINING_UNLIMITED.
... | [
"In",
"Mac",
"OS",
"X",
"10",
".",
"7",
"+",
"Uses",
"IOPSGetTimeRemainingEstimate",
"to",
"get",
"time",
"remaining",
"estimate",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L276-L310 | [
"def",
"get_time_remaining_estimate",
"(",
"self",
")",
":",
"if",
"IOPSGetTimeRemainingEstimate",
"is",
"not",
"None",
":",
"# Mac OS X 10.7+",
"estimate",
"=",
"float",
"(",
"IOPSGetTimeRemainingEstimate",
"(",
")",
")",
"if",
"estimate",
"==",
"-",
"1.0",
":",
... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.add_observer | Spawns thread or adds IOPSNotificationCreateRunLoopSource directly to provided cf_run_loop
@see: __init__ | power/darwin.py | def add_observer(self, observer):
"""
Spawns thread or adds IOPSNotificationCreateRunLoopSource directly to provided cf_run_loop
@see: __init__
"""
super(PowerManagement, self).add_observer(observer)
if len(self._weak_observers) == 1:
if not self._cf_run_loop:... | def add_observer(self, observer):
"""
Spawns thread or adds IOPSNotificationCreateRunLoopSource directly to provided cf_run_loop
@see: __init__
"""
super(PowerManagement, self).add_observer(observer)
if len(self._weak_observers) == 1:
if not self._cf_run_loop:... | [
"Spawns",
"thread",
"or",
"adds",
"IOPSNotificationCreateRunLoopSource",
"directly",
"to",
"provided",
"cf_run_loop"
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L312-L327 | [
"def",
"add_observer",
"(",
"self",
",",
"observer",
")",
":",
"super",
"(",
"PowerManagement",
",",
"self",
")",
".",
"add_observer",
"(",
"observer",
")",
"if",
"len",
"(",
"self",
".",
"_weak_observers",
")",
"==",
"1",
":",
"if",
"not",
"self",
"."... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.remove_observer | Stops thread and invalidates source. | power/darwin.py | def remove_observer(self, observer):
"""
Stops thread and invalidates source.
"""
super(PowerManagement, self).remove_observer(observer)
if len(self._weak_observers) == 0:
if not self._cf_run_loop:
PowerManagement.notifications_observer.removeObserver(... | def remove_observer(self, observer):
"""
Stops thread and invalidates source.
"""
super(PowerManagement, self).remove_observer(observer)
if len(self._weak_observers) == 0:
if not self._cf_run_loop:
PowerManagement.notifications_observer.removeObserver(... | [
"Stops",
"thread",
"and",
"invalidates",
"source",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/darwin.py#L329-L339 | [
"def",
"remove_observer",
"(",
"self",
",",
"observer",
")",
":",
"super",
"(",
"PowerManagement",
",",
"self",
")",
".",
"remove_observer",
"(",
"observer",
")",
"if",
"len",
"(",
"self",
".",
"_weak_observers",
")",
"==",
"0",
":",
"if",
"not",
"self",... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_providing_power_source_type | Returns GetSystemPowerStatus().ACLineStatus
@raise: WindowsError if any underlying error occures. | power/win32.py | def get_providing_power_source_type(self):
"""
Returns GetSystemPowerStatus().ACLineStatus
@raise: WindowsError if any underlying error occures.
"""
power_status = SYSTEM_POWER_STATUS()
if not GetSystemPowerStatus(pointer(power_status)):
raise WinError()
... | def get_providing_power_source_type(self):
"""
Returns GetSystemPowerStatus().ACLineStatus
@raise: WindowsError if any underlying error occures.
"""
power_status = SYSTEM_POWER_STATUS()
if not GetSystemPowerStatus(pointer(power_status)):
raise WinError()
... | [
"Returns",
"GetSystemPowerStatus",
"()",
".",
"ACLineStatus"
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/win32.py#L45-L54 | [
"def",
"get_providing_power_source_type",
"(",
"self",
")",
":",
"power_status",
"=",
"SYSTEM_POWER_STATUS",
"(",
")",
"if",
"not",
"GetSystemPowerStatus",
"(",
"pointer",
"(",
"power_status",
")",
")",
":",
"raise",
"WinError",
"(",
")",
"return",
"POWER_TYPE_MAP... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_low_battery_warning_level | Returns warning according to GetSystemPowerStatus().BatteryLifeTime/BatteryLifePercent
@raise WindowsError if any underlying error occures. | power/win32.py | def get_low_battery_warning_level(self):
"""
Returns warning according to GetSystemPowerStatus().BatteryLifeTime/BatteryLifePercent
@raise WindowsError if any underlying error occures.
"""
power_status = SYSTEM_POWER_STATUS()
if not GetSystemPowerStatus(pointer(power_sta... | def get_low_battery_warning_level(self):
"""
Returns warning according to GetSystemPowerStatus().BatteryLifeTime/BatteryLifePercent
@raise WindowsError if any underlying error occures.
"""
power_status = SYSTEM_POWER_STATUS()
if not GetSystemPowerStatus(pointer(power_sta... | [
"Returns",
"warning",
"according",
"to",
"GetSystemPowerStatus",
"()",
".",
"BatteryLifeTime",
"/",
"BatteryLifePercent"
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/win32.py#L56-L74 | [
"def",
"get_low_battery_warning_level",
"(",
"self",
")",
":",
"power_status",
"=",
"SYSTEM_POWER_STATUS",
"(",
")",
"if",
"not",
"GetSystemPowerStatus",
"(",
"pointer",
"(",
"power_status",
")",
")",
":",
"raise",
"WinError",
"(",
")",
"if",
"POWER_TYPE_MAP",
"... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_time_remaining_estimate | Returns time remaining estimate according to GetSystemPowerStatus().BatteryLifeTime | power/win32.py | def get_time_remaining_estimate(self):
"""
Returns time remaining estimate according to GetSystemPowerStatus().BatteryLifeTime
"""
power_status = SYSTEM_POWER_STATUS()
if not GetSystemPowerStatus(pointer(power_status)):
raise WinError()
if POWER_TYPE_MAP[powe... | def get_time_remaining_estimate(self):
"""
Returns time remaining estimate according to GetSystemPowerStatus().BatteryLifeTime
"""
power_status = SYSTEM_POWER_STATUS()
if not GetSystemPowerStatus(pointer(power_status)):
raise WinError()
if POWER_TYPE_MAP[powe... | [
"Returns",
"time",
"remaining",
"estimate",
"according",
"to",
"GetSystemPowerStatus",
"()",
".",
"BatteryLifeTime"
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/win32.py#L76-L89 | [
"def",
"get_time_remaining_estimate",
"(",
"self",
")",
":",
"power_status",
"=",
"SYSTEM_POWER_STATUS",
"(",
")",
"if",
"not",
"GetSystemPowerStatus",
"(",
"pointer",
"(",
"power_status",
")",
")",
":",
"raise",
"WinError",
"(",
")",
"if",
"POWER_TYPE_MAP",
"["... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.power_source_type | FreeBSD use sysctl hw.acpi.acline to tell if Mains (1) is used or Battery (0).
Beware, that on a Desktop machines this hw.acpi.acline oid may not exist.
@return: One of common.POWER_TYPE_*
@raise: Runtime error if type of power source is not supported | power/freebsd.py | def power_source_type():
"""
FreeBSD use sysctl hw.acpi.acline to tell if Mains (1) is used or Battery (0).
Beware, that on a Desktop machines this hw.acpi.acline oid may not exist.
@return: One of common.POWER_TYPE_*
@raise: Runtime error if type of power source is not supported... | def power_source_type():
"""
FreeBSD use sysctl hw.acpi.acline to tell if Mains (1) is used or Battery (0).
Beware, that on a Desktop machines this hw.acpi.acline oid may not exist.
@return: One of common.POWER_TYPE_*
@raise: Runtime error if type of power source is not supported... | [
"FreeBSD",
"use",
"sysctl",
"hw",
".",
"acpi",
".",
"acline",
"to",
"tell",
"if",
"Mains",
"(",
"1",
")",
"is",
"used",
"or",
"Battery",
"(",
"0",
")",
".",
"Beware",
"that",
"on",
"a",
"Desktop",
"machines",
"this",
"hw",
".",
"acpi",
".",
"acline... | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/freebsd.py#L13-L30 | [
"def",
"power_source_type",
"(",
")",
":",
"try",
":",
"supply",
"=",
"int",
"(",
"subprocess",
".",
"check_output",
"(",
"[",
"\"sysctl\"",
",",
"\"-n\"",
",",
"\"hw.acpi.acline\"",
"]",
")",
")",
"except",
":",
"return",
"common",
".",
"POWER_TYPE_AC",
"... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_battery_state | TODO
@return: Tuple (energy_full, energy_now, power_now) | power/freebsd.py | def get_battery_state():
"""
TODO
@return: Tuple (energy_full, energy_now, power_now)
"""
energy_now = float(100.0)
power_now = float(100.0)
energy_full = float(100.0)
return energy_full, energy_now, power_now | def get_battery_state():
"""
TODO
@return: Tuple (energy_full, energy_now, power_now)
"""
energy_now = float(100.0)
power_now = float(100.0)
energy_full = float(100.0)
return energy_full, energy_now, power_now | [
"TODO"
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/freebsd.py#L64-L72 | [
"def",
"get_battery_state",
"(",
")",
":",
"energy_now",
"=",
"float",
"(",
"100.0",
")",
"power_now",
"=",
"float",
"(",
"100.0",
")",
"energy_full",
"=",
"float",
"(",
"100.0",
")",
"return",
"energy_full",
",",
"energy_now",
",",
"power_now"
] | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_providing_power_source_type | Looks through all power supplies in POWER_SUPPLY_PATH.
If there is an AC adapter online returns POWER_TYPE_AC.
If there is a discharging battery, returns POWER_TYPE_BATTERY.
Since the order of supplies is arbitrary, whatever found first is returned. | power/freebsd.py | def get_providing_power_source_type(self):
"""
Looks through all power supplies in POWER_SUPPLY_PATH.
If there is an AC adapter online returns POWER_TYPE_AC.
If there is a discharging battery, returns POWER_TYPE_BATTERY.
Since the order of supplies is arbitrary, whatever found fi... | def get_providing_power_source_type(self):
"""
Looks through all power supplies in POWER_SUPPLY_PATH.
If there is an AC adapter online returns POWER_TYPE_AC.
If there is a discharging battery, returns POWER_TYPE_BATTERY.
Since the order of supplies is arbitrary, whatever found fi... | [
"Looks",
"through",
"all",
"power",
"supplies",
"in",
"POWER_SUPPLY_PATH",
".",
"If",
"there",
"is",
"an",
"AC",
"adapter",
"online",
"returns",
"POWER_TYPE_AC",
".",
"If",
"there",
"is",
"a",
"discharging",
"battery",
"returns",
"POWER_TYPE_BATTERY",
".",
"Sinc... | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/freebsd.py#L75-L91 | [
"def",
"get_providing_power_source_type",
"(",
"self",
")",
":",
"type",
"=",
"self",
".",
"power_source_type",
"(",
")",
"if",
"type",
"==",
"common",
".",
"POWER_TYPE_AC",
":",
"if",
"self",
".",
"is_ac_online",
"(",
")",
":",
"return",
"common",
".",
"P... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_low_battery_warning_level | Looks through all power supplies in POWER_SUPPLY_PATH.
If there is an AC adapter online returns POWER_TYPE_AC returns LOW_BATTERY_WARNING_NONE.
Otherwise determines total percentage and time remaining across all attached batteries. | power/freebsd.py | def get_low_battery_warning_level(self):
"""
Looks through all power supplies in POWER_SUPPLY_PATH.
If there is an AC adapter online returns POWER_TYPE_AC returns LOW_BATTERY_WARNING_NONE.
Otherwise determines total percentage and time remaining across all attached batteries.
"""... | def get_low_battery_warning_level(self):
"""
Looks through all power supplies in POWER_SUPPLY_PATH.
If there is an AC adapter online returns POWER_TYPE_AC returns LOW_BATTERY_WARNING_NONE.
Otherwise determines total percentage and time remaining across all attached batteries.
"""... | [
"Looks",
"through",
"all",
"power",
"supplies",
"in",
"POWER_SUPPLY_PATH",
".",
"If",
"there",
"is",
"an",
"AC",
"adapter",
"online",
"returns",
"POWER_TYPE_AC",
"returns",
"LOW_BATTERY_WARNING_NONE",
".",
"Otherwise",
"determines",
"total",
"percentage",
"and",
"ti... | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/freebsd.py#L94-L130 | [
"def",
"get_low_battery_warning_level",
"(",
"self",
")",
":",
"all_energy_full",
"=",
"[",
"]",
"all_energy_now",
"=",
"[",
"]",
"all_power_now",
"=",
"[",
"]",
"try",
":",
"type",
"=",
"self",
".",
"power_source_type",
"(",
")",
"if",
"type",
"==",
"comm... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_time_remaining_estimate | Looks through all power sources and returns total time remaining estimate
or TIME_REMAINING_UNLIMITED if ac power supply is online. | power/freebsd.py | def get_time_remaining_estimate(self):
"""
Looks through all power sources and returns total time remaining estimate
or TIME_REMAINING_UNLIMITED if ac power supply is online.
"""
all_energy_now = []
all_power_now = []
try:
type = self.power_source_type... | def get_time_remaining_estimate(self):
"""
Looks through all power sources and returns total time remaining estimate
or TIME_REMAINING_UNLIMITED if ac power supply is online.
"""
all_energy_now = []
all_power_now = []
try:
type = self.power_source_type... | [
"Looks",
"through",
"all",
"power",
"sources",
"and",
"returns",
"total",
"time",
"remaining",
"estimate",
"or",
"TIME_REMAINING_UNLIMITED",
"if",
"ac",
"power",
"supply",
"is",
"online",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/freebsd.py#L133-L162 | [
"def",
"get_time_remaining_estimate",
"(",
"self",
")",
":",
"all_energy_now",
"=",
"[",
"]",
"all_power_now",
"=",
"[",
"]",
"try",
":",
"type",
"=",
"self",
".",
"power_source_type",
"(",
")",
"if",
"type",
"==",
"common",
".",
"POWER_TYPE_AC",
":",
"if"... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_providing_power_source_type | Looks through all power supplies in POWER_SUPPLY_PATH.
If there is an AC adapter online returns POWER_TYPE_AC.
If there is a discharging battery, returns POWER_TYPE_BATTERY.
Since the order of supplies is arbitrary, whatever found first is returned. | power/linux.py | def get_providing_power_source_type(self):
"""
Looks through all power supplies in POWER_SUPPLY_PATH.
If there is an AC adapter online returns POWER_TYPE_AC.
If there is a discharging battery, returns POWER_TYPE_BATTERY.
Since the order of supplies is arbitrary, whatever found fi... | def get_providing_power_source_type(self):
"""
Looks through all power supplies in POWER_SUPPLY_PATH.
If there is an AC adapter online returns POWER_TYPE_AC.
If there is a discharging battery, returns POWER_TYPE_BATTERY.
Since the order of supplies is arbitrary, whatever found fi... | [
"Looks",
"through",
"all",
"power",
"supplies",
"in",
"POWER_SUPPLY_PATH",
".",
"If",
"there",
"is",
"an",
"AC",
"adapter",
"online",
"returns",
"POWER_TYPE_AC",
".",
"If",
"there",
"is",
"a",
"discharging",
"battery",
"returns",
"POWER_TYPE_BATTERY",
".",
"Sinc... | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/linux.py#L88-L110 | [
"def",
"get_providing_power_source_type",
"(",
"self",
")",
":",
"for",
"supply",
"in",
"os",
".",
"listdir",
"(",
"POWER_SUPPLY_PATH",
")",
":",
"supply_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"POWER_SUPPLY_PATH",
",",
"supply",
")",
"try",
":",
... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | PowerManagement.get_time_remaining_estimate | Looks through all power sources and returns total time remaining estimate
or TIME_REMAINING_UNLIMITED if ac power supply is online. | power/linux.py | def get_time_remaining_estimate(self):
"""
Looks through all power sources and returns total time remaining estimate
or TIME_REMAINING_UNLIMITED if ac power supply is online.
"""
all_energy_now = []
all_energy_not_discharging = []
all_power_now = []
for su... | def get_time_remaining_estimate(self):
"""
Looks through all power sources and returns total time remaining estimate
or TIME_REMAINING_UNLIMITED if ac power supply is online.
"""
all_energy_now = []
all_energy_not_discharging = []
all_power_now = []
for su... | [
"Looks",
"through",
"all",
"power",
"sources",
"and",
"returns",
"total",
"time",
"remaining",
"estimate",
"or",
"TIME_REMAINING_UNLIMITED",
"if",
"ac",
"power",
"supply",
"is",
"online",
"."
] | Kentzo/Power | python | https://github.com/Kentzo/Power/blob/2c99b156546225e448f7030681af3df5cd345e4b/power/linux.py#L152-L188 | [
"def",
"get_time_remaining_estimate",
"(",
"self",
")",
":",
"all_energy_now",
"=",
"[",
"]",
"all_energy_not_discharging",
"=",
"[",
"]",
"all_power_now",
"=",
"[",
"]",
"for",
"supply",
"in",
"os",
".",
"listdir",
"(",
"POWER_SUPPLY_PATH",
")",
":",
"supply_... | 2c99b156546225e448f7030681af3df5cd345e4b |
train | Scratch._pack | Packages msg according to Scratch message specification (encodes and
appends length prefix to msg). Credit to chalkmarrow from the
scratch.mit.edu forums for the prefix encoding code. | scratch/scratch.py | def _pack(self, msg):
"""
Packages msg according to Scratch message specification (encodes and
appends length prefix to msg). Credit to chalkmarrow from the
scratch.mit.edu forums for the prefix encoding code.
"""
n = len(msg)
a = array.array('c')
a.app... | def _pack(self, msg):
"""
Packages msg according to Scratch message specification (encodes and
appends length prefix to msg). Credit to chalkmarrow from the
scratch.mit.edu forums for the prefix encoding code.
"""
n = len(msg)
a = array.array('c')
a.app... | [
"Packages",
"msg",
"according",
"to",
"Scratch",
"message",
"specification",
"(",
"encodes",
"and",
"appends",
"length",
"prefix",
"to",
"msg",
")",
".",
"Credit",
"to",
"chalkmarrow",
"from",
"the",
"scratch",
".",
"mit",
".",
"edu",
"forums",
"for",
"the",... | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L27-L39 | [
"def",
"_pack",
"(",
"self",
",",
"msg",
")",
":",
"n",
"=",
"len",
"(",
"msg",
")",
"a",
"=",
"array",
".",
"array",
"(",
"'c'",
")",
"a",
".",
"append",
"(",
"chr",
"(",
"(",
"n",
">>",
"24",
")",
"&",
"0xFF",
")",
")",
"a",
".",
"appen... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._get_type | Converts a string from Scratch to its proper type in Python. Expects a
string with its delimiting quotes in place. Returns either a string,
int or float. | scratch/scratch.py | def _get_type(self, s):
"""
Converts a string from Scratch to its proper type in Python. Expects a
string with its delimiting quotes in place. Returns either a string,
int or float.
"""
# TODO: what if the number is bigger than an int or float?
if s.startswith('... | def _get_type(self, s):
"""
Converts a string from Scratch to its proper type in Python. Expects a
string with its delimiting quotes in place. Returns either a string,
int or float.
"""
# TODO: what if the number is bigger than an int or float?
if s.startswith('... | [
"Converts",
"a",
"string",
"from",
"Scratch",
"to",
"its",
"proper",
"type",
"in",
"Python",
".",
"Expects",
"a",
"string",
"with",
"its",
"delimiting",
"quotes",
"in",
"place",
".",
"Returns",
"either",
"a",
"string",
"int",
"or",
"float",
"."
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L47-L59 | [
"def",
"_get_type",
"(",
"self",
",",
"s",
")",
":",
"# TODO: what if the number is bigger than an int or float?",
"if",
"s",
".",
"startswith",
"(",
"'\"'",
")",
"and",
"s",
".",
"endswith",
"(",
"'\"'",
")",
":",
"return",
"s",
"[",
"1",
":",
"-",
"1",
... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._escape | Escapes double quotes by adding another double quote as per the Scratch
protocol. Expects a string without its delimiting quotes. Returns a new
escaped string. | scratch/scratch.py | def _escape(self, msg):
"""
Escapes double quotes by adding another double quote as per the Scratch
protocol. Expects a string without its delimiting quotes. Returns a new
escaped string.
"""
escaped = ''
for c in msg:
escaped += c
if c ... | def _escape(self, msg):
"""
Escapes double quotes by adding another double quote as per the Scratch
protocol. Expects a string without its delimiting quotes. Returns a new
escaped string.
"""
escaped = ''
for c in msg:
escaped += c
if c ... | [
"Escapes",
"double",
"quotes",
"by",
"adding",
"another",
"double",
"quote",
"as",
"per",
"the",
"Scratch",
"protocol",
".",
"Expects",
"a",
"string",
"without",
"its",
"delimiting",
"quotes",
".",
"Returns",
"a",
"new",
"escaped",
"string",
"."
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L61-L72 | [
"def",
"_escape",
"(",
"self",
",",
"msg",
")",
":",
"escaped",
"=",
"''",
"for",
"c",
"in",
"msg",
":",
"escaped",
"+=",
"c",
"if",
"c",
"==",
"'\"'",
":",
"escaped",
"+=",
"'\"'",
"return",
"escaped"
] | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._unescape | Removes double quotes that were used to escape double quotes. Expects
a string without its delimiting quotes, or a number. Returns a new
unescaped string. | scratch/scratch.py | def _unescape(self, msg):
"""
Removes double quotes that were used to escape double quotes. Expects
a string without its delimiting quotes, or a number. Returns a new
unescaped string.
"""
if isinstance(msg, (int, float, long)):
return msg
unescaped =... | def _unescape(self, msg):
"""
Removes double quotes that were used to escape double quotes. Expects
a string without its delimiting quotes, or a number. Returns a new
unescaped string.
"""
if isinstance(msg, (int, float, long)):
return msg
unescaped =... | [
"Removes",
"double",
"quotes",
"that",
"were",
"used",
"to",
"escape",
"double",
"quotes",
".",
"Expects",
"a",
"string",
"without",
"its",
"delimiting",
"quotes",
"or",
"a",
"number",
".",
"Returns",
"a",
"new",
"unescaped",
"string",
"."
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L74-L90 | [
"def",
"_unescape",
"(",
"self",
",",
"msg",
")",
":",
"if",
"isinstance",
"(",
"msg",
",",
"(",
"int",
",",
"float",
",",
"long",
")",
")",
":",
"return",
"msg",
"unescaped",
"=",
"''",
"i",
"=",
"0",
"while",
"i",
"<",
"len",
"(",
"msg",
")",... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._is_msg | Returns True if message is a proper Scratch message, else return False. | scratch/scratch.py | def _is_msg(self, msg):
"""
Returns True if message is a proper Scratch message, else return False.
"""
if not msg or len(msg) < self.prefix_len:
return False
length = self._extract_len(msg[:self.prefix_len])
msg_type = msg[self.prefix_len:].split(' ', 1)[0]
... | def _is_msg(self, msg):
"""
Returns True if message is a proper Scratch message, else return False.
"""
if not msg or len(msg) < self.prefix_len:
return False
length = self._extract_len(msg[:self.prefix_len])
msg_type = msg[self.prefix_len:].split(' ', 1)[0]
... | [
"Returns",
"True",
"if",
"message",
"is",
"a",
"proper",
"Scratch",
"message",
"else",
"return",
"False",
"."
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L92-L102 | [
"def",
"_is_msg",
"(",
"self",
",",
"msg",
")",
":",
"if",
"not",
"msg",
"or",
"len",
"(",
"msg",
")",
"<",
"self",
".",
"prefix_len",
":",
"return",
"False",
"length",
"=",
"self",
".",
"_extract_len",
"(",
"msg",
"[",
":",
"self",
".",
"prefix_le... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._parse_broadcast | Given a broacast message, returns the message that was broadcast. | scratch/scratch.py | def _parse_broadcast(self, msg):
"""
Given a broacast message, returns the message that was broadcast.
"""
# get message, remove surrounding quotes, and unescape
return self._unescape(self._get_type(msg[self.broadcast_prefix_len:])) | def _parse_broadcast(self, msg):
"""
Given a broacast message, returns the message that was broadcast.
"""
# get message, remove surrounding quotes, and unescape
return self._unescape(self._get_type(msg[self.broadcast_prefix_len:])) | [
"Given",
"a",
"broacast",
"message",
"returns",
"the",
"message",
"that",
"was",
"broadcast",
"."
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L104-L109 | [
"def",
"_parse_broadcast",
"(",
"self",
",",
"msg",
")",
":",
"# get message, remove surrounding quotes, and unescape",
"return",
"self",
".",
"_unescape",
"(",
"self",
".",
"_get_type",
"(",
"msg",
"[",
"self",
".",
"broadcast_prefix_len",
":",
"]",
")",
")"
] | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._parse_sensorupdate | Given a sensor-update message, returns the sensors/variables that were
updated as a dict that maps sensors/variables to their updated values. | scratch/scratch.py | def _parse_sensorupdate(self, msg):
"""
Given a sensor-update message, returns the sensors/variables that were
updated as a dict that maps sensors/variables to their updated values.
"""
update = msg[self.sensorupdate_prefix_len:]
parsed = [] # each element is either a sen... | def _parse_sensorupdate(self, msg):
"""
Given a sensor-update message, returns the sensors/variables that were
updated as a dict that maps sensors/variables to their updated values.
"""
update = msg[self.sensorupdate_prefix_len:]
parsed = [] # each element is either a sen... | [
"Given",
"a",
"sensor",
"-",
"update",
"message",
"returns",
"the",
"sensors",
"/",
"variables",
"that",
"were",
"updated",
"as",
"a",
"dict",
"that",
"maps",
"sensors",
"/",
"variables",
"to",
"their",
"updated",
"values",
"."
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L111-L134 | [
"def",
"_parse_sensorupdate",
"(",
"self",
",",
"msg",
")",
":",
"update",
"=",
"msg",
"[",
"self",
".",
"sensorupdate_prefix_len",
":",
"]",
"parsed",
"=",
"[",
"]",
"# each element is either a sensor (key) or a sensor value",
"curr_seg",
"=",
"''",
"# current segm... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._parse | Parses a Scratch message and returns a tuple with the first element
as the message type, and the second element as the message payload. The
payload for a 'broadcast' message is a string, and the payload for a
'sensor-update' message is a dict whose keys are variables, and values
are up... | scratch/scratch.py | def _parse(self, msg):
"""
Parses a Scratch message and returns a tuple with the first element
as the message type, and the second element as the message payload. The
payload for a 'broadcast' message is a string, and the payload for a
'sensor-update' message is a dict whose ke... | def _parse(self, msg):
"""
Parses a Scratch message and returns a tuple with the first element
as the message type, and the second element as the message payload. The
payload for a 'broadcast' message is a string, and the payload for a
'sensor-update' message is a dict whose ke... | [
"Parses",
"a",
"Scratch",
"message",
"and",
"returns",
"a",
"tuple",
"with",
"the",
"first",
"element",
"as",
"the",
"message",
"type",
"and",
"the",
"second",
"element",
"as",
"the",
"message",
"payload",
".",
"The",
"payload",
"for",
"a",
"broadcast",
"m... | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L136-L150 | [
"def",
"_parse",
"(",
"self",
",",
"msg",
")",
":",
"if",
"not",
"self",
".",
"_is_msg",
"(",
"msg",
")",
":",
"return",
"None",
"msg_type",
"=",
"msg",
"[",
"self",
".",
"prefix_len",
":",
"]",
".",
"split",
"(",
"' '",
")",
"[",
"0",
"]",
"if... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._write | Writes string data out to Scratch | scratch/scratch.py | def _write(self, data):
"""
Writes string data out to Scratch
"""
total_sent = 0
length = len(data)
while total_sent < length:
try:
sent = self.socket.send(data[total_sent:])
except socket.error as (err, msg):
self.c... | def _write(self, data):
"""
Writes string data out to Scratch
"""
total_sent = 0
length = len(data)
while total_sent < length:
try:
sent = self.socket.send(data[total_sent:])
except socket.error as (err, msg):
self.c... | [
"Writes",
"string",
"data",
"out",
"to",
"Scratch"
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L152-L167 | [
"def",
"_write",
"(",
"self",
",",
"data",
")",
":",
"total_sent",
"=",
"0",
"length",
"=",
"len",
"(",
"data",
")",
"while",
"total_sent",
"<",
"length",
":",
"try",
":",
"sent",
"=",
"self",
".",
"socket",
".",
"send",
"(",
"data",
"[",
"total_se... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._read | Reads size number of bytes from Scratch and returns data as a string | scratch/scratch.py | def _read(self, size):
"""
Reads size number of bytes from Scratch and returns data as a string
"""
data = ''
while len(data) < size:
try:
chunk = self.socket.recv(size-len(data))
except socket.error as (err, msg):
self.conn... | def _read(self, size):
"""
Reads size number of bytes from Scratch and returns data as a string
"""
data = ''
while len(data) < size:
try:
chunk = self.socket.recv(size-len(data))
except socket.error as (err, msg):
self.conn... | [
"Reads",
"size",
"number",
"of",
"bytes",
"from",
"Scratch",
"and",
"returns",
"data",
"as",
"a",
"string"
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L175-L190 | [
"def",
"_read",
"(",
"self",
",",
"size",
")",
":",
"data",
"=",
"''",
"while",
"len",
"(",
"data",
")",
"<",
"size",
":",
"try",
":",
"chunk",
"=",
"self",
".",
"socket",
".",
"recv",
"(",
"size",
"-",
"len",
"(",
"data",
")",
")",
"except",
... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch._recv | Receives and returns a message from Scratch | scratch/scratch.py | def _recv(self):
"""
Receives and returns a message from Scratch
"""
prefix = self._read(self.prefix_len)
msg = self._read(self._extract_len(prefix))
return prefix + msg | def _recv(self):
"""
Receives and returns a message from Scratch
"""
prefix = self._read(self.prefix_len)
msg = self._read(self._extract_len(prefix))
return prefix + msg | [
"Receives",
"and",
"returns",
"a",
"message",
"from",
"Scratch"
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L192-L198 | [
"def",
"_recv",
"(",
"self",
")",
":",
"prefix",
"=",
"self",
".",
"_read",
"(",
"self",
".",
"prefix_len",
")",
"msg",
"=",
"self",
".",
"_read",
"(",
"self",
".",
"_extract_len",
"(",
"prefix",
")",
")",
"return",
"prefix",
"+",
"msg"
] | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch.connect | Connects to Scratch. | scratch/scratch.py | def connect(self):
"""
Connects to Scratch.
"""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.socket.connect((self.host, self.port))
except socket.error as (err, msg):
self.connected = False
raise ScratchErro... | def connect(self):
"""
Connects to Scratch.
"""
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
self.socket.connect((self.host, self.port))
except socket.error as (err, msg):
self.connected = False
raise ScratchErro... | [
"Connects",
"to",
"Scratch",
"."
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L200-L210 | [
"def",
"connect",
"(",
"self",
")",
":",
"self",
".",
"socket",
"=",
"socket",
".",
"socket",
"(",
"socket",
".",
"AF_INET",
",",
"socket",
".",
"SOCK_STREAM",
")",
"try",
":",
"self",
".",
"socket",
".",
"connect",
"(",
"(",
"self",
".",
"host",
"... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch.disconnect | Closes connection to Scratch | scratch/scratch.py | def disconnect(self):
"""
Closes connection to Scratch
"""
try: # connection may already be disconnected, so catch exceptions
self.socket.shutdown(socket.SHUT_RDWR) # a proper disconnect
except socket.error:
pass
self.socket.close()
self.co... | def disconnect(self):
"""
Closes connection to Scratch
"""
try: # connection may already be disconnected, so catch exceptions
self.socket.shutdown(socket.SHUT_RDWR) # a proper disconnect
except socket.error:
pass
self.socket.close()
self.co... | [
"Closes",
"connection",
"to",
"Scratch"
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L212-L221 | [
"def",
"disconnect",
"(",
"self",
")",
":",
"try",
":",
"# connection may already be disconnected, so catch exceptions",
"self",
".",
"socket",
".",
"shutdown",
"(",
"socket",
".",
"SHUT_RDWR",
")",
"# a proper disconnect",
"except",
"socket",
".",
"error",
":",
"pa... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch.sensorupdate | Given a dict of sensors and values, updates those sensors with the
values in Scratch. | scratch/scratch.py | def sensorupdate(self, data):
"""
Given a dict of sensors and values, updates those sensors with the
values in Scratch.
"""
if not isinstance(data, dict):
raise TypeError('Expected a dict')
msg = 'sensor-update '
for key in data.keys():
ms... | def sensorupdate(self, data):
"""
Given a dict of sensors and values, updates those sensors with the
values in Scratch.
"""
if not isinstance(data, dict):
raise TypeError('Expected a dict')
msg = 'sensor-update '
for key in data.keys():
ms... | [
"Given",
"a",
"dict",
"of",
"sensors",
"and",
"values",
"updates",
"those",
"sensors",
"with",
"the",
"values",
"in",
"Scratch",
"."
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L223-L234 | [
"def",
"sensorupdate",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"dict",
")",
":",
"raise",
"TypeError",
"(",
"'Expected a dict'",
")",
"msg",
"=",
"'sensor-update '",
"for",
"key",
"in",
"data",
".",
"keys",
"(",
... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Scratch.broadcast | Broadcasts msg to Scratch. msg can be a single message or an iterable
(list, tuple, set, generator, etc.) of messages. | scratch/scratch.py | def broadcast(self, msg):
"""
Broadcasts msg to Scratch. msg can be a single message or an iterable
(list, tuple, set, generator, etc.) of messages.
"""
if getattr(msg, '__iter__', False): # iterable
for m in msg:
self._send('broadcast "%s"' % self._e... | def broadcast(self, msg):
"""
Broadcasts msg to Scratch. msg can be a single message or an iterable
(list, tuple, set, generator, etc.) of messages.
"""
if getattr(msg, '__iter__', False): # iterable
for m in msg:
self._send('broadcast "%s"' % self._e... | [
"Broadcasts",
"msg",
"to",
"Scratch",
".",
"msg",
"can",
"be",
"a",
"single",
"message",
"or",
"an",
"iterable",
"(",
"list",
"tuple",
"set",
"generator",
"etc",
".",
")",
"of",
"messages",
"."
] | pilliq/scratchpy | python | https://github.com/pilliq/scratchpy/blob/a594561c147b1cf6696231c26a0475c7d52b8039/scratch/scratch.py#L236-L245 | [
"def",
"broadcast",
"(",
"self",
",",
"msg",
")",
":",
"if",
"getattr",
"(",
"msg",
",",
"'__iter__'",
",",
"False",
")",
":",
"# iterable",
"for",
"m",
"in",
"msg",
":",
"self",
".",
"_send",
"(",
"'broadcast \"%s\"'",
"%",
"self",
".",
"_escape",
"... | a594561c147b1cf6696231c26a0475c7d52b8039 |
train | Mock.run_simple_topology | Tests a simple topology. "Simple" means there it has no branches
or cycles. "emitters" is a list of emitters, starting with a spout
followed by 0 or more bolts that run in a chain. | petrel/petrel/mock.py | def run_simple_topology(cls, config, emitters, result_type=NAMEDTUPLE, max_spout_emits=None):
"""Tests a simple topology. "Simple" means there it has no branches
or cycles. "emitters" is a list of emitters, starting with a spout
followed by 0 or more bolts that run in a chain."""
... | def run_simple_topology(cls, config, emitters, result_type=NAMEDTUPLE, max_spout_emits=None):
"""Tests a simple topology. "Simple" means there it has no branches
or cycles. "emitters" is a list of emitters, starting with a spout
followed by 0 or more bolts that run in a chain."""
... | [
"Tests",
"a",
"simple",
"topology",
".",
"Simple",
"means",
"there",
"it",
"has",
"no",
"branches",
"or",
"cycles",
".",
"emitters",
"is",
"a",
"list",
"of",
"emitters",
"starting",
"with",
"a",
"spout",
"followed",
"by",
"0",
"or",
"more",
"bolts",
"tha... | AirSage/Petrel | python | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/mock.py#L108-L164 | [
"def",
"run_simple_topology",
"(",
"cls",
",",
"config",
",",
"emitters",
",",
"result_type",
"=",
"NAMEDTUPLE",
",",
"max_spout_emits",
"=",
"None",
")",
":",
"# The config is almost always required. The only known reason to pass",
"# None is when calling run_simple_topology()... | c4be9b7da5916dcc028ddb88850e7703203eeb79 |
train | TopologyBuilder.write | Writes the topology to a stream or file. | petrel/petrel/topologybuilder.py | def write(self, stream):
"""Writes the topology to a stream or file."""
topology = self.createTopology()
def write_it(stream):
transportOut = TMemoryBuffer()
protocolOut = TBinaryProtocol.TBinaryProtocol(transportOut)
topology.write(protocolOut)
by... | def write(self, stream):
"""Writes the topology to a stream or file."""
topology = self.createTopology()
def write_it(stream):
transportOut = TMemoryBuffer()
protocolOut = TBinaryProtocol.TBinaryProtocol(transportOut)
topology.write(protocolOut)
by... | [
"Writes",
"the",
"topology",
"to",
"a",
"stream",
"or",
"file",
"."
] | AirSage/Petrel | python | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/topologybuilder.py#L110-L126 | [
"def",
"write",
"(",
"self",
",",
"stream",
")",
":",
"topology",
"=",
"self",
".",
"createTopology",
"(",
")",
"def",
"write_it",
"(",
"stream",
")",
":",
"transportOut",
"=",
"TMemoryBuffer",
"(",
")",
"protocolOut",
"=",
"TBinaryProtocol",
".",
"TBinary... | c4be9b7da5916dcc028ddb88850e7703203eeb79 |
train | TopologyBuilder.read | Reads the topology from a stream or file. | petrel/petrel/topologybuilder.py | def read(self, stream):
"""Reads the topology from a stream or file."""
def read_it(stream):
bytes = stream.read()
transportIn = TMemoryBuffer(bytes)
protocolIn = TBinaryProtocol.TBinaryProtocol(transportIn)
topology = StormTopology()
topology.... | def read(self, stream):
"""Reads the topology from a stream or file."""
def read_it(stream):
bytes = stream.read()
transportIn = TMemoryBuffer(bytes)
protocolIn = TBinaryProtocol.TBinaryProtocol(transportIn)
topology = StormTopology()
topology.... | [
"Reads",
"the",
"topology",
"from",
"a",
"stream",
"or",
"file",
"."
] | AirSage/Petrel | python | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/topologybuilder.py#L128-L142 | [
"def",
"read",
"(",
"self",
",",
"stream",
")",
":",
"def",
"read_it",
"(",
"stream",
")",
":",
"bytes",
"=",
"stream",
".",
"read",
"(",
")",
"transportIn",
"=",
"TMemoryBuffer",
"(",
"bytes",
")",
"protocolIn",
"=",
"TBinaryProtocol",
".",
"TBinaryProt... | c4be9b7da5916dcc028ddb88850e7703203eeb79 |
train | build_jar | Build a StormTopology .jar which encapsulates the topology defined in
topology_dir. Optionally override the module and function names. This
feature supports the definition of multiple topologies in a single
directory. | petrel/petrel/package.py | def build_jar(source_jar_path, dest_jar_path, config, venv=None, definition=None, logdir=None):
"""Build a StormTopology .jar which encapsulates the topology defined in
topology_dir. Optionally override the module and function names. This
feature supports the definition of multiple topologies in a single
... | def build_jar(source_jar_path, dest_jar_path, config, venv=None, definition=None, logdir=None):
"""Build a StormTopology .jar which encapsulates the topology defined in
topology_dir. Optionally override the module and function names. This
feature supports the definition of multiple topologies in a single
... | [
"Build",
"a",
"StormTopology",
".",
"jar",
"which",
"encapsulates",
"the",
"topology",
"defined",
"in",
"topology_dir",
".",
"Optionally",
"override",
"the",
"module",
"and",
"function",
"names",
".",
"This",
"feature",
"supports",
"the",
"definition",
"of",
"mu... | AirSage/Petrel | python | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/package.py#L74-L172 | [
"def",
"build_jar",
"(",
"source_jar_path",
",",
"dest_jar_path",
",",
"config",
",",
"venv",
"=",
"None",
",",
"definition",
"=",
"None",
",",
"logdir",
"=",
"None",
")",
":",
"if",
"definition",
"is",
"None",
":",
"definition",
"=",
"'create.create'",
"#... | c4be9b7da5916dcc028ddb88850e7703203eeb79 |
train | sendFailureMsgToParent | This function is kind of a hack, but useful when a Python task
encounters a fatal exception. "msg" should be a simple string like
"E_SPOUTFAILED". This function sends "msg" as-is to the Storm worker,
which tries to parse it as JSON. The hacky aspect is that we
*deliberately* make it fail by sending it n... | petrel/petrel/storm.py | def sendFailureMsgToParent(msg):
"""This function is kind of a hack, but useful when a Python task
encounters a fatal exception. "msg" should be a simple string like
"E_SPOUTFAILED". This function sends "msg" as-is to the Storm worker,
which tries to parse it as JSON. The hacky aspect is that we
*de... | def sendFailureMsgToParent(msg):
"""This function is kind of a hack, but useful when a Python task
encounters a fatal exception. "msg" should be a simple string like
"E_SPOUTFAILED". This function sends "msg" as-is to the Storm worker,
which tries to parse it as JSON. The hacky aspect is that we
*de... | [
"This",
"function",
"is",
"kind",
"of",
"a",
"hack",
"but",
"useful",
"when",
"a",
"Python",
"task",
"encounters",
"a",
"fatal",
"exception",
".",
"msg",
"should",
"be",
"a",
"simple",
"string",
"like",
"E_SPOUTFAILED",
".",
"This",
"function",
"sends",
"m... | AirSage/Petrel | python | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/storm.py#L101-L113 | [
"def",
"sendFailureMsgToParent",
"(",
"msg",
")",
":",
"assert",
"isinstance",
"(",
"msg",
",",
"six",
".",
"string_types",
")",
"print",
"(",
"msg",
",",
"file",
"=",
"old_stdout",
")",
"print",
"(",
"'end'",
",",
"file",
"=",
"old_stdout",
")",
"storm_... | c4be9b7da5916dcc028ddb88850e7703203eeb79 |
train | emitMany | A more efficient way to emit a number of tuples at once. | petrel/petrel/storm.py | def emitMany(*args, **kwargs):
"""A more efficient way to emit a number of tuples at once."""
global MODE
if MODE == Bolt:
emitManyBolt(*args, **kwargs)
elif MODE == Spout:
emitManySpout(*args, **kwargs) | def emitMany(*args, **kwargs):
"""A more efficient way to emit a number of tuples at once."""
global MODE
if MODE == Bolt:
emitManyBolt(*args, **kwargs)
elif MODE == Spout:
emitManySpout(*args, **kwargs) | [
"A",
"more",
"efficient",
"way",
"to",
"emit",
"a",
"number",
"of",
"tuples",
"at",
"once",
"."
] | AirSage/Petrel | python | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/storm.py#L132-L138 | [
"def",
"emitMany",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"MODE",
"if",
"MODE",
"==",
"Bolt",
":",
"emitManyBolt",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"elif",
"MODE",
"==",
"Spout",
":",
"emitManySpout",
"(",
"*"... | c4be9b7da5916dcc028ddb88850e7703203eeb79 |
train | remote_debug | Handler to allow process to be remotely debugged. | petrel/petrel/rdebug.py | def remote_debug(sig,frame):
"""Handler to allow process to be remotely debugged."""
def _raiseEx(ex):
"""Raise specified exception in the remote process"""
_raiseEx.ex = ex
_raiseEx.ex = None
try:
# Provide some useful functions.
locs = {'_raiseEx' : _raiseEx}
... | def remote_debug(sig,frame):
"""Handler to allow process to be remotely debugged."""
def _raiseEx(ex):
"""Raise specified exception in the remote process"""
_raiseEx.ex = ex
_raiseEx.ex = None
try:
# Provide some useful functions.
locs = {'_raiseEx' : _raiseEx}
... | [
"Handler",
"to",
"allow",
"process",
"to",
"be",
"remotely",
"debugged",
"."
] | AirSage/Petrel | python | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/rdebug.py#L72-L122 | [
"def",
"remote_debug",
"(",
"sig",
",",
"frame",
")",
":",
"def",
"_raiseEx",
"(",
"ex",
")",
":",
"\"\"\"Raise specified exception in the remote process\"\"\"",
"_raiseEx",
".",
"ex",
"=",
"ex",
"_raiseEx",
".",
"ex",
"=",
"None",
"try",
":",
"# Provide some us... | c4be9b7da5916dcc028ddb88850e7703203eeb79 |
train | debug_process | Interrupt a running process and debug it. | petrel/petrel/rdebug.py | def debug_process(pid):
"""Interrupt a running process and debug it."""
os.kill(pid, signal.SIGUSR1) # Signal process.
pipe = NamedPipe(pipename(pid), 1)
try:
while pipe.is_open():
txt=raw_input(pipe.get()) + '\n'
pipe.put(txt)
except EOFError:
pass # Exit.
... | def debug_process(pid):
"""Interrupt a running process and debug it."""
os.kill(pid, signal.SIGUSR1) # Signal process.
pipe = NamedPipe(pipename(pid), 1)
try:
while pipe.is_open():
txt=raw_input(pipe.get()) + '\n'
pipe.put(txt)
except EOFError:
pass # Exit.
... | [
"Interrupt",
"a",
"running",
"process",
"and",
"debug",
"it",
"."
] | AirSage/Petrel | python | https://github.com/AirSage/Petrel/blob/c4be9b7da5916dcc028ddb88850e7703203eeb79/petrel/petrel/rdebug.py#L125-L135 | [
"def",
"debug_process",
"(",
"pid",
")",
":",
"os",
".",
"kill",
"(",
"pid",
",",
"signal",
".",
"SIGUSR1",
")",
"# Signal process.",
"pipe",
"=",
"NamedPipe",
"(",
"pipename",
"(",
"pid",
")",
",",
"1",
")",
"try",
":",
"while",
"pipe",
".",
"is_ope... | c4be9b7da5916dcc028ddb88850e7703203eeb79 |
train | PayPalInterface._encode_utf8 | UTF8 encodes all of the NVP values. | paypal/interface.py | def _encode_utf8(self, **kwargs):
"""
UTF8 encodes all of the NVP values.
"""
if is_py3:
# This is only valid for Python 2. In Python 3, unicode is
# everywhere (yay).
return kwargs
unencoded_pairs = kwargs
for i in unencoded_pairs.key... | def _encode_utf8(self, **kwargs):
"""
UTF8 encodes all of the NVP values.
"""
if is_py3:
# This is only valid for Python 2. In Python 3, unicode is
# everywhere (yay).
return kwargs
unencoded_pairs = kwargs
for i in unencoded_pairs.key... | [
"UTF8",
"encodes",
"all",
"of",
"the",
"NVP",
"values",
"."
] | gtaylor/paypal-python | python | https://github.com/gtaylor/paypal-python/blob/aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1/paypal/interface.py#L58-L72 | [
"def",
"_encode_utf8",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"is_py3",
":",
"# This is only valid for Python 2. In Python 3, unicode is",
"# everywhere (yay).",
"return",
"kwargs",
"unencoded_pairs",
"=",
"kwargs",
"for",
"i",
"in",
"unencoded_pairs",
... | aa7a987ea9e9b7f37bcd8a8b54a440aad6c871b1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.