repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
cihai/cihai | cihai/conversion.py | euc_to_python | def euc_to_python(hexstr):
"""
Convert a EUC-CN (GB2312) hex to a Python unicode string.
"""
hi = hexstr[0:2]
lo = hexstr[2:4]
gb_enc = b'\\x' + hi + b'\\x' + lo
return gb_enc.decode("gb2312") | python | def euc_to_python(hexstr):
"""
Convert a EUC-CN (GB2312) hex to a Python unicode string.
"""
hi = hexstr[0:2]
lo = hexstr[2:4]
gb_enc = b'\\x' + hi + b'\\x' + lo
return gb_enc.decode("gb2312") | [
"def",
"euc_to_python",
"(",
"hexstr",
")",
":",
"hi",
"=",
"hexstr",
"[",
"0",
":",
"2",
"]",
"lo",
"=",
"hexstr",
"[",
"2",
":",
"4",
"]",
"gb_enc",
"=",
"b'\\\\x'",
"+",
"hi",
"+",
"b'\\\\x'",
"+",
"lo",
"return",
"gb_enc",
".",
"decode",
"(",... | Convert a EUC-CN (GB2312) hex to a Python unicode string. | [
"Convert",
"a",
"EUC",
"-",
"CN",
"(",
"GB2312",
")",
"hex",
"to",
"a",
"Python",
"unicode",
"string",
"."
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/conversion.py#L104-L111 |
cihai/cihai | cihai/conversion.py | euc_to_utf8 | def euc_to_utf8(euchex):
"""
Convert EUC hex (e.g. "d2bb") to UTF8 hex (e.g. "e4 b8 80").
"""
utf8 = euc_to_python(euchex).encode("utf-8")
uf8 = utf8.decode('unicode_escape')
uf8 = uf8.encode('latin1')
uf8 = uf8.decode('euc-jp')
return uf8 | python | def euc_to_utf8(euchex):
"""
Convert EUC hex (e.g. "d2bb") to UTF8 hex (e.g. "e4 b8 80").
"""
utf8 = euc_to_python(euchex).encode("utf-8")
uf8 = utf8.decode('unicode_escape')
uf8 = uf8.encode('latin1')
uf8 = uf8.decode('euc-jp')
return uf8 | [
"def",
"euc_to_utf8",
"(",
"euchex",
")",
":",
"utf8",
"=",
"euc_to_python",
"(",
"euchex",
")",
".",
"encode",
"(",
"\"utf-8\"",
")",
"uf8",
"=",
"utf8",
".",
"decode",
"(",
"'unicode_escape'",
")",
"uf8",
"=",
"uf8",
".",
"encode",
"(",
"'latin1'",
"... | Convert EUC hex (e.g. "d2bb") to UTF8 hex (e.g. "e4 b8 80"). | [
"Convert",
"EUC",
"hex",
"(",
"e",
".",
"g",
".",
"d2bb",
")",
"to",
"UTF8",
"hex",
"(",
"e",
".",
"g",
".",
"e4",
"b8",
"80",
")",
"."
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/conversion.py#L114-L124 |
cihai/cihai | cihai/conversion.py | ucn_to_unicode | def ucn_to_unicode(ucn):
"""
Convert a Unicode Universal Character Number (e.g. "U+4E00" or "4E00") to
Python unicode (u'\\u4e00')
"""
if isinstance(ucn, string_types):
ucn = ucn.strip("U+")
if len(ucn) > int(4):
char = b'\U' + format(int(ucn, 16), '08x').encode('latin1')... | python | def ucn_to_unicode(ucn):
"""
Convert a Unicode Universal Character Number (e.g. "U+4E00" or "4E00") to
Python unicode (u'\\u4e00')
"""
if isinstance(ucn, string_types):
ucn = ucn.strip("U+")
if len(ucn) > int(4):
char = b'\U' + format(int(ucn, 16), '08x').encode('latin1')... | [
"def",
"ucn_to_unicode",
"(",
"ucn",
")",
":",
"if",
"isinstance",
"(",
"ucn",
",",
"string_types",
")",
":",
"ucn",
"=",
"ucn",
".",
"strip",
"(",
"\"U+\"",
")",
"if",
"len",
"(",
"ucn",
")",
">",
"int",
"(",
"4",
")",
":",
"char",
"=",
"b'\\U'"... | Convert a Unicode Universal Character Number (e.g. "U+4E00" or "4E00") to
Python unicode (u'\\u4e00') | [
"Convert",
"a",
"Unicode",
"Universal",
"Character",
"Number",
"(",
"e",
".",
"g",
".",
"U",
"+",
"4E00",
"or",
"4E00",
")",
"to",
"Python",
"unicode",
"(",
"u",
"\\\\",
"u4e00",
")"
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/conversion.py#L127-L144 |
cihai/cihai | cihai/conversion.py | euc_to_unicode | def euc_to_unicode(hexstr):
"""
Return EUC-CN (GB2312) hex to a Python unicode.
Parameters
----------
hexstr : bytes
Returns
-------
unicode :
Python unicode e.g. ``u'\\u4e00'`` / '一'.
Examples
--------
>>> u'\u4e00'.encode('gb2312').decode('utf-8')
u'\u04bb'... | python | def euc_to_unicode(hexstr):
"""
Return EUC-CN (GB2312) hex to a Python unicode.
Parameters
----------
hexstr : bytes
Returns
-------
unicode :
Python unicode e.g. ``u'\\u4e00'`` / '一'.
Examples
--------
>>> u'\u4e00'.encode('gb2312').decode('utf-8')
u'\u04bb'... | [
"def",
"euc_to_unicode",
"(",
"hexstr",
")",
":",
"hi",
"=",
"hexstr",
"[",
"0",
":",
"2",
"]",
"lo",
"=",
"hexstr",
"[",
"2",
":",
"4",
"]",
"# hi and lo are only 2 characters long, no risk with eval-ing them",
"gb_enc",
"=",
"b'\\\\x'",
"+",
"hi",
"+",
"b'... | Return EUC-CN (GB2312) hex to a Python unicode.
Parameters
----------
hexstr : bytes
Returns
-------
unicode :
Python unicode e.g. ``u'\\u4e00'`` / '一'.
Examples
--------
>>> u'\u4e00'.encode('gb2312').decode('utf-8')
u'\u04bb'
>>> (b'\\x' + b'd2' + b'\\x' + b'b... | [
"Return",
"EUC",
"-",
"CN",
"(",
"GB2312",
")",
"hex",
"to",
"a",
"Python",
"unicode",
"."
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/conversion.py#L147-L190 |
cihai/cihai | cihai/conversion.py | python_to_ucn | def python_to_ucn(uni_char, as_bytes=False):
"""
Return UCN character from Python Unicode character.
Converts a one character Python unicode string (e.g. u'\\u4e00') to the
corresponding Unicode UCN ('U+4E00').
"""
ucn = uni_char.encode('unicode_escape').decode('latin1')
ucn = text_type(ucn... | python | def python_to_ucn(uni_char, as_bytes=False):
"""
Return UCN character from Python Unicode character.
Converts a one character Python unicode string (e.g. u'\\u4e00') to the
corresponding Unicode UCN ('U+4E00').
"""
ucn = uni_char.encode('unicode_escape').decode('latin1')
ucn = text_type(ucn... | [
"def",
"python_to_ucn",
"(",
"uni_char",
",",
"as_bytes",
"=",
"False",
")",
":",
"ucn",
"=",
"uni_char",
".",
"encode",
"(",
"'unicode_escape'",
")",
".",
"decode",
"(",
"'latin1'",
")",
"ucn",
"=",
"text_type",
"(",
"ucn",
")",
".",
"replace",
"(",
"... | Return UCN character from Python Unicode character.
Converts a one character Python unicode string (e.g. u'\\u4e00') to the
corresponding Unicode UCN ('U+4E00'). | [
"Return",
"UCN",
"character",
"from",
"Python",
"Unicode",
"character",
"."
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/conversion.py#L196-L213 |
cihai/cihai | cihai/conversion.py | python_to_euc | def python_to_euc(uni_char, as_bytes=False):
"""
Return EUC character from a Python Unicode character.
Converts a one character Python unicode string (e.g. u'\\u4e00') to the
corresponding EUC hex ('d2bb').
"""
euc = repr(uni_char.encode("gb2312"))[1:-1].replace("\\x", "").strip("'")
if as... | python | def python_to_euc(uni_char, as_bytes=False):
"""
Return EUC character from a Python Unicode character.
Converts a one character Python unicode string (e.g. u'\\u4e00') to the
corresponding EUC hex ('d2bb').
"""
euc = repr(uni_char.encode("gb2312"))[1:-1].replace("\\x", "").strip("'")
if as... | [
"def",
"python_to_euc",
"(",
"uni_char",
",",
"as_bytes",
"=",
"False",
")",
":",
"euc",
"=",
"repr",
"(",
"uni_char",
".",
"encode",
"(",
"\"gb2312\"",
")",
")",
"[",
"1",
":",
"-",
"1",
"]",
".",
"replace",
"(",
"\"\\\\x\"",
",",
"\"\"",
")",
"."... | Return EUC character from a Python Unicode character.
Converts a one character Python unicode string (e.g. u'\\u4e00') to the
corresponding EUC hex ('d2bb'). | [
"Return",
"EUC",
"character",
"from",
"a",
"Python",
"Unicode",
"character",
"."
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/conversion.py#L216-L229 |
cihai/cihai | cihai/conversion.py | ucnstring_to_unicode | def ucnstring_to_unicode(ucn_string):
"""Return ucnstring as Unicode."""
ucn_string = ucnstring_to_python(ucn_string).decode('utf-8')
assert isinstance(ucn_string, text_type)
return ucn_string | python | def ucnstring_to_unicode(ucn_string):
"""Return ucnstring as Unicode."""
ucn_string = ucnstring_to_python(ucn_string).decode('utf-8')
assert isinstance(ucn_string, text_type)
return ucn_string | [
"def",
"ucnstring_to_unicode",
"(",
"ucn_string",
")",
":",
"ucn_string",
"=",
"ucnstring_to_python",
"(",
"ucn_string",
")",
".",
"decode",
"(",
"'utf-8'",
")",
"assert",
"isinstance",
"(",
"ucn_string",
",",
"text_type",
")",
"return",
"ucn_string"
] | Return ucnstring as Unicode. | [
"Return",
"ucnstring",
"as",
"Unicode",
"."
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/conversion.py#L232-L237 |
cihai/cihai | cihai/conversion.py | ucnstring_to_python | def ucnstring_to_python(ucn_string):
"""
Return string with Unicode UCN (e.g. "U+4E00") to native Python Unicode
(u'\\u4e00').
"""
res = re.findall("U\+[0-9a-fA-F]*", ucn_string)
for r in res:
ucn_string = ucn_string.replace(text_type(r), text_type(ucn_to_unicode(r)))
ucn_string = u... | python | def ucnstring_to_python(ucn_string):
"""
Return string with Unicode UCN (e.g. "U+4E00") to native Python Unicode
(u'\\u4e00').
"""
res = re.findall("U\+[0-9a-fA-F]*", ucn_string)
for r in res:
ucn_string = ucn_string.replace(text_type(r), text_type(ucn_to_unicode(r)))
ucn_string = u... | [
"def",
"ucnstring_to_python",
"(",
"ucn_string",
")",
":",
"res",
"=",
"re",
".",
"findall",
"(",
"\"U\\+[0-9a-fA-F]*\"",
",",
"ucn_string",
")",
"for",
"r",
"in",
"res",
":",
"ucn_string",
"=",
"ucn_string",
".",
"replace",
"(",
"text_type",
"(",
"r",
")"... | Return string with Unicode UCN (e.g. "U+4E00") to native Python Unicode
(u'\\u4e00'). | [
"Return",
"string",
"with",
"Unicode",
"UCN",
"(",
"e",
".",
"g",
".",
"U",
"+",
"4E00",
")",
"to",
"native",
"Python",
"Unicode",
"(",
"u",
"\\\\",
"u4e00",
")",
"."
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/conversion.py#L240-L252 |
cihai/cihai | cihai/conversion.py | parse_var | def parse_var(var):
"""
Returns a tuple consisting of a string and a tag, or None, if none is
specified.
"""
bits = var.split("<", 1)
if len(bits) < 2:
tag = None
else:
tag = bits[1]
return ucn_to_unicode(bits[0]), tag | python | def parse_var(var):
"""
Returns a tuple consisting of a string and a tag, or None, if none is
specified.
"""
bits = var.split("<", 1)
if len(bits) < 2:
tag = None
else:
tag = bits[1]
return ucn_to_unicode(bits[0]), tag | [
"def",
"parse_var",
"(",
"var",
")",
":",
"bits",
"=",
"var",
".",
"split",
"(",
"\"<\"",
",",
"1",
")",
"if",
"len",
"(",
"bits",
")",
"<",
"2",
":",
"tag",
"=",
"None",
"else",
":",
"tag",
"=",
"bits",
"[",
"1",
"]",
"return",
"ucn_to_unicode... | Returns a tuple consisting of a string and a tag, or None, if none is
specified. | [
"Returns",
"a",
"tuple",
"consisting",
"of",
"a",
"string",
"and",
"a",
"tag",
"or",
"None",
"if",
"none",
"is",
"specified",
"."
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/conversion.py#L255-L265 |
cihai/cihai | cihai/core.py | Cihai.from_file | def from_file(cls, config_path=None, *args, **kwargs):
"""
Create a Cihai instance from a JSON or YAML config.
Parameters
----------
config_path : str, optional
path to custom config file
Returns
-------
:class:`Cihai` :
applicati... | python | def from_file(cls, config_path=None, *args, **kwargs):
"""
Create a Cihai instance from a JSON or YAML config.
Parameters
----------
config_path : str, optional
path to custom config file
Returns
-------
:class:`Cihai` :
applicati... | [
"def",
"from_file",
"(",
"cls",
",",
"config_path",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"config_reader",
"=",
"kaptan",
".",
"Kaptan",
"(",
")",
"config",
"=",
"{",
"}",
"if",
"config_path",
":",
"if",
"not",
"os",
"."... | Create a Cihai instance from a JSON or YAML config.
Parameters
----------
config_path : str, optional
path to custom config file
Returns
-------
:class:`Cihai` :
application object | [
"Create",
"a",
"Cihai",
"instance",
"from",
"a",
"JSON",
"or",
"YAML",
"config",
"."
] | train | https://github.com/cihai/cihai/blob/43b0c2931da18c1ef1ff1cdd71e4b1c5eca24a41/cihai/core.py#L114-L150 |
eventbrite/localization_shuttle | src/shuttle/sync.py | DeskTxSync._process_locale | def _process_locale(self, locale):
"""Return True if this locale should be processed."""
if locale.lower().startswith('en'):
return False
return (locale in self.enabled_locales or
self.reverse_locale_map.get(locale.lower(), None)
in self.enabled_loc... | python | def _process_locale(self, locale):
"""Return True if this locale should be processed."""
if locale.lower().startswith('en'):
return False
return (locale in self.enabled_locales or
self.reverse_locale_map.get(locale.lower(), None)
in self.enabled_loc... | [
"def",
"_process_locale",
"(",
"self",
",",
"locale",
")",
":",
"if",
"locale",
".",
"lower",
"(",
")",
".",
"startswith",
"(",
"'en'",
")",
":",
"return",
"False",
"return",
"(",
"locale",
"in",
"self",
".",
"enabled_locales",
"or",
"self",
".",
"reve... | Return True if this locale should be processed. | [
"Return",
"True",
"if",
"this",
"locale",
"should",
"be",
"processed",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/sync.py#L42-L57 |
eventbrite/localization_shuttle | src/shuttle/sync.py | DeskTxSync.desk_locale | def desk_locale(self, locale):
"""Return the Desk-style locale for locale."""
locale = locale.lower().replace('-', '_')
return self.vendor_locale_map.get(locale, locale) | python | def desk_locale(self, locale):
"""Return the Desk-style locale for locale."""
locale = locale.lower().replace('-', '_')
return self.vendor_locale_map.get(locale, locale) | [
"def",
"desk_locale",
"(",
"self",
",",
"locale",
")",
":",
"locale",
"=",
"locale",
".",
"lower",
"(",
")",
".",
"replace",
"(",
"'-'",
",",
"'_'",
")",
"return",
"self",
".",
"vendor_locale_map",
".",
"get",
"(",
"locale",
",",
"locale",
")"
] | Return the Desk-style locale for locale. | [
"Return",
"the",
"Desk",
"-",
"style",
"locale",
"for",
"locale",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/sync.py#L59-L63 |
eventbrite/localization_shuttle | src/shuttle/sync.py | DeskTopics.push | def push(self):
"""Push topics to Transifex."""
tx = Tx(self.tx_project_slug)
# asssemble the template catalog
template = babel.messages.catalog.Catalog()
for topic in self.desk.topics():
if topic.show_in_portal:
template.add(topic.name)
# s... | python | def push(self):
"""Push topics to Transifex."""
tx = Tx(self.tx_project_slug)
# asssemble the template catalog
template = babel.messages.catalog.Catalog()
for topic in self.desk.topics():
if topic.show_in_portal:
template.add(topic.name)
# s... | [
"def",
"push",
"(",
"self",
")",
":",
"tx",
"=",
"Tx",
"(",
"self",
".",
"tx_project_slug",
")",
"# asssemble the template catalog",
"template",
"=",
"babel",
".",
"messages",
".",
"catalog",
".",
"Catalog",
"(",
")",
"for",
"topic",
"in",
"self",
".",
"... | Push topics to Transifex. | [
"Push",
"topics",
"to",
"Transifex",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/sync.py#L191-L214 |
eventbrite/localization_shuttle | src/shuttle/sync.py | DeskTopics.pull | def pull(self):
"""Pull topics from Transifex."""
topic_stats = txlib.api.statistics.Statistics.get(
project_slug=self.tx_project_slug,
resource_slug=self.TOPIC_STRINGS_SLUG,
)
translated = {}
# for each language
for locale in self.enabled_local... | python | def pull(self):
"""Pull topics from Transifex."""
topic_stats = txlib.api.statistics.Statistics.get(
project_slug=self.tx_project_slug,
resource_slug=self.TOPIC_STRINGS_SLUG,
)
translated = {}
# for each language
for locale in self.enabled_local... | [
"def",
"pull",
"(",
"self",
")",
":",
"topic_stats",
"=",
"txlib",
".",
"api",
".",
"statistics",
".",
"Statistics",
".",
"get",
"(",
"project_slug",
"=",
"self",
".",
"tx_project_slug",
",",
"resource_slug",
"=",
"self",
".",
"TOPIC_STRINGS_SLUG",
",",
")... | Pull topics from Transifex. | [
"Pull",
"topics",
"from",
"Transifex",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/sync.py#L216-L276 |
eventbrite/localization_shuttle | src/shuttle/sync.py | DeskTutorials.make_resource_document | def make_resource_document(self, title, content, tags=[],):
"""Return a single HTML document containing the title and content."""
assert "<html>" not in content
assert "<body>" not in content
return """
<html>
<head><title>%(title)s</title></head>
<body>
... | python | def make_resource_document(self, title, content, tags=[],):
"""Return a single HTML document containing the title and content."""
assert "<html>" not in content
assert "<body>" not in content
return """
<html>
<head><title>%(title)s</title></head>
<body>
... | [
"def",
"make_resource_document",
"(",
"self",
",",
"title",
",",
"content",
",",
"tags",
"=",
"[",
"]",
",",
")",
":",
"assert",
"\"<html>\"",
"not",
"in",
"content",
"assert",
"\"<body>\"",
"not",
"in",
"content",
"return",
"\"\"\"\n <html>\n <hea... | Return a single HTML document containing the title and content. | [
"Return",
"a",
"single",
"HTML",
"document",
"containing",
"the",
"title",
"and",
"content",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/sync.py#L294-L309 |
eventbrite/localization_shuttle | src/shuttle/sync.py | DeskTutorials.parse_resource_document | def parse_resource_document(self, content):
"""Return a dict with the keys title, content, tags for content."""
content = content.strip()
if not content.startswith('<html>'):
# this is not a full HTML doc, probably content w/o title, tags, etc
return dict(body=content)
... | python | def parse_resource_document(self, content):
"""Return a dict with the keys title, content, tags for content."""
content = content.strip()
if not content.startswith('<html>'):
# this is not a full HTML doc, probably content w/o title, tags, etc
return dict(body=content)
... | [
"def",
"parse_resource_document",
"(",
"self",
",",
"content",
")",
":",
"content",
"=",
"content",
".",
"strip",
"(",
")",
"if",
"not",
"content",
".",
"startswith",
"(",
"'<html>'",
")",
":",
"# this is not a full HTML doc, probably content w/o title, tags, etc",
... | Return a dict with the keys title, content, tags for content. | [
"Return",
"a",
"dict",
"with",
"the",
"keys",
"title",
"content",
"tags",
"for",
"content",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/sync.py#L311-L325 |
eventbrite/localization_shuttle | src/shuttle/sync.py | DeskTutorials.push | def push(self):
"""Push tutorials to Transifex."""
tx = Tx(self.tx_project_slug)
if self.options.resources:
articles = [
self.desk.articles().by_id(r.strip())
for r in self.options.resources.split(',')
]
else:
articles... | python | def push(self):
"""Push tutorials to Transifex."""
tx = Tx(self.tx_project_slug)
if self.options.resources:
articles = [
self.desk.articles().by_id(r.strip())
for r in self.options.resources.split(',')
]
else:
articles... | [
"def",
"push",
"(",
"self",
")",
":",
"tx",
"=",
"Tx",
"(",
"self",
".",
"tx_project_slug",
")",
"if",
"self",
".",
"options",
".",
"resources",
":",
"articles",
"=",
"[",
"self",
".",
"desk",
".",
"articles",
"(",
")",
".",
"by_id",
"(",
"r",
".... | Push tutorials to Transifex. | [
"Push",
"tutorials",
"to",
"Transifex",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/sync.py#L338-L385 |
eventbrite/localization_shuttle | src/shuttle/transifex.py | Tx.get_project | def get_project(self, locale, source_language_code=DEFAULT_SOURCE_LANGUAGE, **kwargs):
"""
Gets or creates the Transifex project for the current project prefix and locale
:param locale: A locale to which content is to be translated
:type locale: string
:param source_language_cod... | python | def get_project(self, locale, source_language_code=DEFAULT_SOURCE_LANGUAGE, **kwargs):
"""
Gets or creates the Transifex project for the current project prefix and locale
:param locale: A locale to which content is to be translated
:type locale: string
:param source_language_cod... | [
"def",
"get_project",
"(",
"self",
",",
"locale",
",",
"source_language_code",
"=",
"DEFAULT_SOURCE_LANGUAGE",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"locale_project",
"=",
"project",
".",
"Project",
".",
"get",
"(",
"slug",
"=",
"self",
".",
"get_... | Gets or creates the Transifex project for the current project prefix and locale
:param locale: A locale to which content is to be translated
:type locale: string
:param source_language_code: The language of the original untranslated content (i.e. Spanish),
defaults to DEFAULT_SOURCE... | [
"Gets",
"or",
"creates",
"the",
"Transifex",
"project",
"for",
"the",
"current",
"project",
"prefix",
"and",
"locale"
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/transifex.py#L34-L75 |
eventbrite/localization_shuttle | src/shuttle/transifex.py | Tx.translation_exists | def translation_exists(self, slug, lang):
"""Return True if the translation exists for this slug."""
try:
return translations.Translation.get(
project_slug=self.get_project_slug(lang),
slug=slug,
lang=lang,
)
except (NotFo... | python | def translation_exists(self, slug, lang):
"""Return True if the translation exists for this slug."""
try:
return translations.Translation.get(
project_slug=self.get_project_slug(lang),
slug=slug,
lang=lang,
)
except (NotFo... | [
"def",
"translation_exists",
"(",
"self",
",",
"slug",
",",
"lang",
")",
":",
"try",
":",
"return",
"translations",
".",
"Translation",
".",
"get",
"(",
"project_slug",
"=",
"self",
".",
"get_project_slug",
"(",
"lang",
")",
",",
"slug",
"=",
"slug",
","... | Return True if the translation exists for this slug. | [
"Return",
"True",
"if",
"the",
"translation",
"exists",
"for",
"this",
"slug",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/transifex.py#L143-L156 |
eventbrite/localization_shuttle | src/shuttle/transifex.py | Tx.list_resources | def list_resources(self, lang):
"""Return a sequence of resources for a given lang.
Each Resource is a dict containing the slug, name, i18n_type,
source_language_code and the category.
"""
return registry.registry.http_handler.get(
'/api/2/project/%s/resources/' % (... | python | def list_resources(self, lang):
"""Return a sequence of resources for a given lang.
Each Resource is a dict containing the slug, name, i18n_type,
source_language_code and the category.
"""
return registry.registry.http_handler.get(
'/api/2/project/%s/resources/' % (... | [
"def",
"list_resources",
"(",
"self",
",",
"lang",
")",
":",
"return",
"registry",
".",
"registry",
".",
"http_handler",
".",
"get",
"(",
"'/api/2/project/%s/resources/'",
"%",
"(",
"self",
".",
"get_project_slug",
"(",
"lang",
")",
",",
")",
")"
] | Return a sequence of resources for a given lang.
Each Resource is a dict containing the slug, name, i18n_type,
source_language_code and the category. | [
"Return",
"a",
"sequence",
"of",
"resources",
"for",
"a",
"given",
"lang",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/transifex.py#L158-L168 |
eventbrite/localization_shuttle | src/shuttle/transifex.py | Tx.resources | def resources(self, lang, slug):
"""Generate a list of Resources in the Project.
Yields dicts from the Tx API, with keys including the slug,
name, i18n_type, source_language_code, and category.
"""
resource = resources.Resource.get(
project_slug=self.get_project_sl... | python | def resources(self, lang, slug):
"""Generate a list of Resources in the Project.
Yields dicts from the Tx API, with keys including the slug,
name, i18n_type, source_language_code, and category.
"""
resource = resources.Resource.get(
project_slug=self.get_project_sl... | [
"def",
"resources",
"(",
"self",
",",
"lang",
",",
"slug",
")",
":",
"resource",
"=",
"resources",
".",
"Resource",
".",
"get",
"(",
"project_slug",
"=",
"self",
".",
"get_project_slug",
"(",
"lang",
")",
",",
"slug",
"=",
"slug",
",",
")",
"return",
... | Generate a list of Resources in the Project.
Yields dicts from the Tx API, with keys including the slug,
name, i18n_type, source_language_code, and category. | [
"Generate",
"a",
"list",
"of",
"Resources",
"in",
"the",
"Project",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/transifex.py#L170-L183 |
eventbrite/localization_shuttle | src/shuttle/transifex.py | Tx.resource_exists | def resource_exists(self, slug, locale, project_slug=None):
"""Return True if a Resource with the given slug exists in locale."""
try:
resource = resources.Resource.get(
project_slug=project_slug or self.get_project_slug(locale),
slug=slug,
)
... | python | def resource_exists(self, slug, locale, project_slug=None):
"""Return True if a Resource with the given slug exists in locale."""
try:
resource = resources.Resource.get(
project_slug=project_slug or self.get_project_slug(locale),
slug=slug,
)
... | [
"def",
"resource_exists",
"(",
"self",
",",
"slug",
",",
"locale",
",",
"project_slug",
"=",
"None",
")",
":",
"try",
":",
"resource",
"=",
"resources",
".",
"Resource",
".",
"get",
"(",
"project_slug",
"=",
"project_slug",
"or",
"self",
".",
"get_project_... | Return True if a Resource with the given slug exists in locale. | [
"Return",
"True",
"if",
"a",
"Resource",
"with",
"the",
"given",
"slug",
"exists",
"in",
"locale",
"."
] | train | https://github.com/eventbrite/localization_shuttle/blob/1e97e313b0dd75244d84eaa6e7a5fa63ee375e68/src/shuttle/transifex.py#L185-L199 |
Kane610/axis | axis/utils.py | session_request | def session_request(session, url, **kwargs):
"""Do HTTP/S request and return response as a string."""
try:
response = session(url, **kwargs)
response.raise_for_status()
return response.text
except requests.exceptions.HTTPError as errh:
_LOGGER.debug("%s, %s", response, err... | python | def session_request(session, url, **kwargs):
"""Do HTTP/S request and return response as a string."""
try:
response = session(url, **kwargs)
response.raise_for_status()
return response.text
except requests.exceptions.HTTPError as errh:
_LOGGER.debug("%s, %s", response, err... | [
"def",
"session_request",
"(",
"session",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"response",
"=",
"session",
"(",
"url",
",",
"*",
"*",
"kwargs",
")",
"response",
".",
"raise_for_status",
"(",
")",
"return",
"response",
".",
"text",... | Do HTTP/S request and return response as a string. | [
"Do",
"HTTP",
"/",
"S",
"request",
"and",
"return",
"response",
"as",
"a",
"string",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/utils.py#L11-L34 |
Kane610/axis | axis/event_services.py | get_event_list | def get_event_list(config):
"""Get a dict of supported events from device."""
eventinstances = session_request(
config.session.post, device_event_url.format(
proto=config.web_proto, host=config.host, port=config.port),
auth=config.session.auth, headers=headers, data=request_xml)
... | python | def get_event_list(config):
"""Get a dict of supported events from device."""
eventinstances = session_request(
config.session.post, device_event_url.format(
proto=config.web_proto, host=config.host, port=config.port),
auth=config.session.auth, headers=headers, data=request_xml)
... | [
"def",
"get_event_list",
"(",
"config",
")",
":",
"eventinstances",
"=",
"session_request",
"(",
"config",
".",
"session",
".",
"post",
",",
"device_event_url",
".",
"format",
"(",
"proto",
"=",
"config",
".",
"web_proto",
",",
"host",
"=",
"config",
".",
... | Get a dict of supported events from device. | [
"Get",
"a",
"dict",
"of",
"supported",
"events",
"from",
"device",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/event_services.py#L93-L112 |
Kane610/axis | axis/event_services.py | _prepare_event | def _prepare_event(eventinstances):
"""Converts event instances to a relevant dictionary."""
import xml.etree.ElementTree as ET
def parse_event(events):
"""Find all events inside of an topicset list.
MessageInstance signals that subsequent children will
contain source and data desc... | python | def _prepare_event(eventinstances):
"""Converts event instances to a relevant dictionary."""
import xml.etree.ElementTree as ET
def parse_event(events):
"""Find all events inside of an topicset list.
MessageInstance signals that subsequent children will
contain source and data desc... | [
"def",
"_prepare_event",
"(",
"eventinstances",
")",
":",
"import",
"xml",
".",
"etree",
".",
"ElementTree",
"as",
"ET",
"def",
"parse_event",
"(",
"events",
")",
":",
"\"\"\"Find all events inside of an topicset list.\n\n MessageInstance signals that subsequent childr... | Converts event instances to a relevant dictionary. | [
"Converts",
"event",
"instances",
"to",
"a",
"relevant",
"dictionary",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/event_services.py#L150-L183 |
Kane610/axis | axis/configuration.py | Configuration.url | def url(self):
"""Represent device base url."""
return URL.format(http=self.web_proto, host=self.host, port=self.port) | python | def url(self):
"""Represent device base url."""
return URL.format(http=self.web_proto, host=self.host, port=self.port) | [
"def",
"url",
"(",
"self",
")",
":",
"return",
"URL",
".",
"format",
"(",
"http",
"=",
"self",
".",
"web_proto",
",",
"host",
"=",
"self",
".",
"host",
",",
"port",
"=",
"self",
".",
"port",
")"
] | Represent device base url. | [
"Represent",
"device",
"base",
"url",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/configuration.py#L28-L30 |
Kane610/axis | axis/port_cgi.py | Ports.process_raw | def process_raw(self, raw: dict) -> None:
"""Pre-process raw dict.
Prepare parameters to work with APIItems.
"""
raw_ports = {}
for param in raw:
port_index = REGEX_PORT_INDEX.search(param).group(0)
if port_index not in raw_ports:
raw_po... | python | def process_raw(self, raw: dict) -> None:
"""Pre-process raw dict.
Prepare parameters to work with APIItems.
"""
raw_ports = {}
for param in raw:
port_index = REGEX_PORT_INDEX.search(param).group(0)
if port_index not in raw_ports:
raw_po... | [
"def",
"process_raw",
"(",
"self",
",",
"raw",
":",
"dict",
")",
"->",
"None",
":",
"raw_ports",
"=",
"{",
"}",
"for",
"param",
"in",
"raw",
":",
"port_index",
"=",
"REGEX_PORT_INDEX",
".",
"search",
"(",
"param",
")",
".",
"group",
"(",
"0",
")",
... | Pre-process raw dict.
Prepare parameters to work with APIItems. | [
"Pre",
"-",
"process",
"raw",
"dict",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/port_cgi.py#L42-L58 |
Kane610/axis | axis/port_cgi.py | Port.name | def name(self) -> str:
"""Return name relevant to direction."""
if self.direction == DIRECTION_IN:
return self.raw.get('Input.Name', '')
return self.raw.get('Output.Name', '') | python | def name(self) -> str:
"""Return name relevant to direction."""
if self.direction == DIRECTION_IN:
return self.raw.get('Input.Name', '')
return self.raw.get('Output.Name', '') | [
"def",
"name",
"(",
"self",
")",
"->",
"str",
":",
"if",
"self",
".",
"direction",
"==",
"DIRECTION_IN",
":",
"return",
"self",
".",
"raw",
".",
"get",
"(",
"'Input.Name'",
",",
"''",
")",
"return",
"self",
".",
"raw",
".",
"get",
"(",
"'Output.Name'... | Return name relevant to direction. | [
"Return",
"name",
"relevant",
"to",
"direction",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/port_cgi.py#L92-L96 |
Kane610/axis | axis/port_cgi.py | Port.action | def action(self, action):
r"""Activate or deactivate an output.
Use the <wait> option to activate/deactivate the port for a
limited period of time.
<Port ID> = Port name. Default: Name from Output.Name
<a> = Action character. /=active, \=inactive
<wait> = Delay befor... | python | def action(self, action):
r"""Activate or deactivate an output.
Use the <wait> option to activate/deactivate the port for a
limited period of time.
<Port ID> = Port name. Default: Name from Output.Name
<a> = Action character. /=active, \=inactive
<wait> = Delay befor... | [
"def",
"action",
"(",
"self",
",",
"action",
")",
":",
"if",
"not",
"self",
".",
"direction",
"==",
"DIRECTION_OUT",
":",
"return",
"port_action",
"=",
"quote",
"(",
"'{port}:{action}'",
".",
"format",
"(",
"port",
"=",
"int",
"(",
"self",
".",
"id",
"... | r"""Activate or deactivate an output.
Use the <wait> option to activate/deactivate the port for a
limited period of time.
<Port ID> = Port name. Default: Name from Output.Name
<a> = Action character. /=active, \=inactive
<wait> = Delay before the next action. Unit: milliseco... | [
"r",
"Activate",
"or",
"deactivate",
"an",
"output",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/port_cgi.py#L107-L130 |
Kane610/axis | axis/vapix.py | Vapix.initialize_params | def initialize_params(self, preload_data=True) -> None:
"""Load device parameters and initialize parameter management.
Preload data can be disabled to selectively load params afterwards.
"""
params = ''
if preload_data:
params = self.request('get', param_url)
... | python | def initialize_params(self, preload_data=True) -> None:
"""Load device parameters and initialize parameter management.
Preload data can be disabled to selectively load params afterwards.
"""
params = ''
if preload_data:
params = self.request('get', param_url)
... | [
"def",
"initialize_params",
"(",
"self",
",",
"preload_data",
"=",
"True",
")",
"->",
"None",
":",
"params",
"=",
"''",
"if",
"preload_data",
":",
"params",
"=",
"self",
".",
"request",
"(",
"'get'",
",",
"param_url",
")",
"self",
".",
"params",
"=",
"... | Load device parameters and initialize parameter management.
Preload data can be disabled to selectively load params afterwards. | [
"Load",
"device",
"parameters",
"and",
"initialize",
"parameter",
"management",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/vapix.py#L25-L34 |
Kane610/axis | axis/vapix.py | Vapix.initialize_ports | def initialize_ports(self) -> None:
"""Load IO port parameters for device."""
if not self.params:
self.initialize_params(preload_data=False)
self.params.update_ports()
self.ports = Ports(self.params, self.request) | python | def initialize_ports(self) -> None:
"""Load IO port parameters for device."""
if not self.params:
self.initialize_params(preload_data=False)
self.params.update_ports()
self.ports = Ports(self.params, self.request) | [
"def",
"initialize_ports",
"(",
"self",
")",
"->",
"None",
":",
"if",
"not",
"self",
".",
"params",
":",
"self",
".",
"initialize_params",
"(",
"preload_data",
"=",
"False",
")",
"self",
".",
"params",
".",
"update_ports",
"(",
")",
"self",
".",
"ports",... | Load IO port parameters for device. | [
"Load",
"IO",
"port",
"parameters",
"for",
"device",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/vapix.py#L36-L42 |
Kane610/axis | axis/vapix.py | Vapix.initialize_users | def initialize_users(self) -> None:
"""Load device user data and initialize user management."""
users = self.request('get', pwdgrp_url)
self.users = Users(users, self.request) | python | def initialize_users(self) -> None:
"""Load device user data and initialize user management."""
users = self.request('get', pwdgrp_url)
self.users = Users(users, self.request) | [
"def",
"initialize_users",
"(",
"self",
")",
"->",
"None",
":",
"users",
"=",
"self",
".",
"request",
"(",
"'get'",
",",
"pwdgrp_url",
")",
"self",
".",
"users",
"=",
"Users",
"(",
"users",
",",
"self",
".",
"request",
")"
] | Load device user data and initialize user management. | [
"Load",
"device",
"user",
"data",
"and",
"initialize",
"user",
"management",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/vapix.py#L44-L47 |
Kane610/axis | axis/vapix.py | Vapix.request | def request(self, method, path, **kwargs):
"""Prepare HTTP request."""
if method == 'get':
session_method = self.config.session.get
elif method == 'post':
session_method = self.config.session.post
else:
raise AxisException
url = self.config.... | python | def request(self, method, path, **kwargs):
"""Prepare HTTP request."""
if method == 'get':
session_method = self.config.session.get
elif method == 'post':
session_method = self.config.session.post
else:
raise AxisException
url = self.config.... | [
"def",
"request",
"(",
"self",
",",
"method",
",",
"path",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"method",
"==",
"'get'",
":",
"session_method",
"=",
"self",
".",
"config",
".",
"session",
".",
"get",
"elif",
"method",
"==",
"'post'",
":",
"sessio... | Prepare HTTP request. | [
"Prepare",
"HTTP",
"request",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/vapix.py#L49-L65 |
Kane610/axis | axis/event_stream.py | EventManager.new_event | def new_event(self, event_data: str) -> None:
"""New event to process."""
event = self.parse_event_xml(event_data)
if EVENT_OPERATION in event:
self.manage_event(event) | python | def new_event(self, event_data: str) -> None:
"""New event to process."""
event = self.parse_event_xml(event_data)
if EVENT_OPERATION in event:
self.manage_event(event) | [
"def",
"new_event",
"(",
"self",
",",
"event_data",
":",
"str",
")",
"->",
"None",
":",
"event",
"=",
"self",
".",
"parse_event_xml",
"(",
"event_data",
")",
"if",
"EVENT_OPERATION",
"in",
"event",
":",
"self",
".",
"manage_event",
"(",
"event",
")"
] | New event to process. | [
"New",
"event",
"to",
"process",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/event_stream.py#L41-L46 |
Kane610/axis | axis/event_stream.py | EventManager.parse_event_xml | def parse_event_xml(self, event_data) -> dict:
"""Parse metadata xml."""
event = {}
event_xml = event_data.decode()
message = MESSAGE.search(event_xml)
if not message:
return {}
event[EVENT_OPERATION] = message.group(EVENT_OPERATION)
topic = TOPIC.s... | python | def parse_event_xml(self, event_data) -> dict:
"""Parse metadata xml."""
event = {}
event_xml = event_data.decode()
message = MESSAGE.search(event_xml)
if not message:
return {}
event[EVENT_OPERATION] = message.group(EVENT_OPERATION)
topic = TOPIC.s... | [
"def",
"parse_event_xml",
"(",
"self",
",",
"event_data",
")",
"->",
"dict",
":",
"event",
"=",
"{",
"}",
"event_xml",
"=",
"event_data",
".",
"decode",
"(",
")",
"message",
"=",
"MESSAGE",
".",
"search",
"(",
"event_xml",
")",
"if",
"not",
"message",
... | Parse metadata xml. | [
"Parse",
"metadata",
"xml",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/event_stream.py#L48-L75 |
Kane610/axis | axis/event_stream.py | EventManager.manage_event | def manage_event(self, event) -> None:
"""Received new metadata.
Operation initialized means new event, also happens if reconnecting.
Operation changed updates existing events state.
"""
name = EVENT_NAME.format(
topic=event[EVENT_TOPIC], source=event.get(EVENT_SOURC... | python | def manage_event(self, event) -> None:
"""Received new metadata.
Operation initialized means new event, also happens if reconnecting.
Operation changed updates existing events state.
"""
name = EVENT_NAME.format(
topic=event[EVENT_TOPIC], source=event.get(EVENT_SOURC... | [
"def",
"manage_event",
"(",
"self",
",",
"event",
")",
"->",
"None",
":",
"name",
"=",
"EVENT_NAME",
".",
"format",
"(",
"topic",
"=",
"event",
"[",
"EVENT_TOPIC",
"]",
",",
"source",
"=",
"event",
".",
"get",
"(",
"EVENT_SOURCE_IDX",
")",
")",
"if",
... | Received new metadata.
Operation initialized means new event, also happens if reconnecting.
Operation changed updates existing events state. | [
"Received",
"new",
"metadata",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/event_stream.py#L77-L97 |
Kane610/axis | axis/event_stream.py | AxisBinaryEvent.state | def state(self, state: str) -> None:
"""Update state of event."""
self._state = state
for callback in self._callbacks:
callback() | python | def state(self, state: str) -> None:
"""Update state of event."""
self._state = state
for callback in self._callbacks:
callback() | [
"def",
"state",
"(",
"self",
",",
"state",
":",
"str",
")",
"->",
"None",
":",
"self",
".",
"_state",
"=",
"state",
"for",
"callback",
"in",
"self",
".",
"_callbacks",
":",
"callback",
"(",
")"
] | Update state of event. | [
"Update",
"state",
"of",
"event",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/event_stream.py#L124-L128 |
Kane610/axis | axis/event_stream.py | AxisBinaryEvent.remove_callback | def remove_callback(self, callback) -> None:
"""Remove callback."""
if callback in self._callbacks:
self._callbacks.remove(callback) | python | def remove_callback(self, callback) -> None:
"""Remove callback."""
if callback in self._callbacks:
self._callbacks.remove(callback) | [
"def",
"remove_callback",
"(",
"self",
",",
"callback",
")",
"->",
"None",
":",
"if",
"callback",
"in",
"self",
".",
"_callbacks",
":",
"self",
".",
"_callbacks",
".",
"remove",
"(",
"callback",
")"
] | Remove callback. | [
"Remove",
"callback",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/event_stream.py#L139-L142 |
Kane610/axis | axis/device.py | AxisDevice.enable_events | def enable_events(self, event_callback=None) -> None:
"""Enable events for stream."""
self.event = EventManager(event_callback)
self.stream.event = self.event | python | def enable_events(self, event_callback=None) -> None:
"""Enable events for stream."""
self.event = EventManager(event_callback)
self.stream.event = self.event | [
"def",
"enable_events",
"(",
"self",
",",
"event_callback",
"=",
"None",
")",
"->",
"None",
":",
"self",
".",
"event",
"=",
"EventManager",
"(",
"event_callback",
")",
"self",
".",
"stream",
".",
"event",
"=",
"self",
".",
"event"
] | Enable events for stream. | [
"Enable",
"events",
"for",
"stream",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/device.py#L31-L34 |
Kane610/axis | axis/param_cgi.py | Brand.update_brand | def update_brand(self) -> None:
"""Update brand group of parameters."""
self.update(path=URL_GET + GROUP.format(group=BRAND)) | python | def update_brand(self) -> None:
"""Update brand group of parameters."""
self.update(path=URL_GET + GROUP.format(group=BRAND)) | [
"def",
"update_brand",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"update",
"(",
"path",
"=",
"URL_GET",
"+",
"GROUP",
".",
"format",
"(",
"group",
"=",
"BRAND",
")",
")"
] | Update brand group of parameters. | [
"Update",
"brand",
"group",
"of",
"parameters",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/param_cgi.py#L27-L29 |
Kane610/axis | axis/param_cgi.py | Ports.update_ports | def update_ports(self) -> None:
"""Update port groups of parameters."""
self.update(path=URL_GET + GROUP.format(group=INPUT))
self.update(path=URL_GET + GROUP.format(group=IOPORT))
self.update(path=URL_GET + GROUP.format(group=OUTPUT)) | python | def update_ports(self) -> None:
"""Update port groups of parameters."""
self.update(path=URL_GET + GROUP.format(group=INPUT))
self.update(path=URL_GET + GROUP.format(group=IOPORT))
self.update(path=URL_GET + GROUP.format(group=OUTPUT)) | [
"def",
"update_ports",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"update",
"(",
"path",
"=",
"URL_GET",
"+",
"GROUP",
".",
"format",
"(",
"group",
"=",
"INPUT",
")",
")",
"self",
".",
"update",
"(",
"path",
"=",
"URL_GET",
"+",
"GROUP",
"."... | Update port groups of parameters. | [
"Update",
"port",
"groups",
"of",
"parameters",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/param_cgi.py#L63-L67 |
Kane610/axis | axis/param_cgi.py | Ports.ports | def ports(self) -> dict:
"""Create a smaller dictionary containing all ports."""
return {
param: self[param].raw
for param in self
if param.startswith(IOPORT)
} | python | def ports(self) -> dict:
"""Create a smaller dictionary containing all ports."""
return {
param: self[param].raw
for param in self
if param.startswith(IOPORT)
} | [
"def",
"ports",
"(",
"self",
")",
"->",
"dict",
":",
"return",
"{",
"param",
":",
"self",
"[",
"param",
"]",
".",
"raw",
"for",
"param",
"in",
"self",
"if",
"param",
".",
"startswith",
"(",
"IOPORT",
")",
"}"
] | Create a smaller dictionary containing all ports. | [
"Create",
"a",
"smaller",
"dictionary",
"containing",
"all",
"ports",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/param_cgi.py#L80-L86 |
Kane610/axis | axis/param_cgi.py | Properties.update_properties | def update_properties(self) -> None:
"""Update properties group of parameters."""
self.update(path=URL_GET + GROUP.format(group=PROPERTIES)) | python | def update_properties(self) -> None:
"""Update properties group of parameters."""
self.update(path=URL_GET + GROUP.format(group=PROPERTIES)) | [
"def",
"update_properties",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"update",
"(",
"path",
"=",
"URL_GET",
"+",
"GROUP",
".",
"format",
"(",
"group",
"=",
"PROPERTIES",
")",
")"
] | Update properties group of parameters. | [
"Update",
"properties",
"group",
"of",
"parameters",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/param_cgi.py#L92-L94 |
Kane610/axis | axis/param_cgi.py | Params.process_raw | def process_raw(self, raw: str) -> None:
"""Pre-process raw string.
Prepare parameters to work with APIItems.
"""
raw_params = dict(group.split('=', 1) for group in raw.splitlines())
super().process_raw(raw_params) | python | def process_raw(self, raw: str) -> None:
"""Pre-process raw string.
Prepare parameters to work with APIItems.
"""
raw_params = dict(group.split('=', 1) for group in raw.splitlines())
super().process_raw(raw_params) | [
"def",
"process_raw",
"(",
"self",
",",
"raw",
":",
"str",
")",
"->",
"None",
":",
"raw_params",
"=",
"dict",
"(",
"group",
".",
"split",
"(",
"'='",
",",
"1",
")",
"for",
"group",
"in",
"raw",
".",
"splitlines",
"(",
")",
")",
"super",
"(",
")",... | Pre-process raw string.
Prepare parameters to work with APIItems. | [
"Pre",
"-",
"process",
"raw",
"string",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/param_cgi.py#L149-L156 |
Kane610/axis | axis/pwdgrp_cgi.py | Users.create | def create(self, user: str, *,
pwd: str, sgrp: str, comment: str=None) -> None:
"""Create new user."""
data = {
'action': 'add',
'user': user,
'pwd': pwd,
'grp': 'users',
'sgrp': sgrp
}
if comment:
da... | python | def create(self, user: str, *,
pwd: str, sgrp: str, comment: str=None) -> None:
"""Create new user."""
data = {
'action': 'add',
'user': user,
'pwd': pwd,
'grp': 'users',
'sgrp': sgrp
}
if comment:
da... | [
"def",
"create",
"(",
"self",
",",
"user",
":",
"str",
",",
"*",
",",
"pwd",
":",
"str",
",",
"sgrp",
":",
"str",
",",
"comment",
":",
"str",
"=",
"None",
")",
"->",
"None",
":",
"data",
"=",
"{",
"'action'",
":",
"'add'",
",",
"'user'",
":",
... | Create new user. | [
"Create",
"new",
"user",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/pwdgrp_cgi.py#L44-L58 |
Kane610/axis | axis/pwdgrp_cgi.py | Users.delete | def delete(self, user: str) -> None:
"""Remove user."""
data = {
'action': 'remove',
'user': user
}
self._request('post', URL, data=data) | python | def delete(self, user: str) -> None:
"""Remove user."""
data = {
'action': 'remove',
'user': user
}
self._request('post', URL, data=data) | [
"def",
"delete",
"(",
"self",
",",
"user",
":",
"str",
")",
"->",
"None",
":",
"data",
"=",
"{",
"'action'",
":",
"'remove'",
",",
"'user'",
":",
"user",
"}",
"self",
".",
"_request",
"(",
"'post'",
",",
"URL",
",",
"data",
"=",
"data",
")"
] | Remove user. | [
"Remove",
"user",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/pwdgrp_cgi.py#L79-L86 |
Kane610/axis | axis/pwdgrp_cgi.py | Users.process_raw | def process_raw(self, raw: str) -> None:
"""Pre-process raw string.
Prepare users to work with APIItems.
Create booleans with user levels.
"""
raw_dict = dict(group.split('=') for group in raw.splitlines())
raw_users = {
user: {
group: user i... | python | def process_raw(self, raw: str) -> None:
"""Pre-process raw string.
Prepare users to work with APIItems.
Create booleans with user levels.
"""
raw_dict = dict(group.split('=') for group in raw.splitlines())
raw_users = {
user: {
group: user i... | [
"def",
"process_raw",
"(",
"self",
",",
"raw",
":",
"str",
")",
"->",
"None",
":",
"raw_dict",
"=",
"dict",
"(",
"group",
".",
"split",
"(",
"'='",
")",
"for",
"group",
"in",
"raw",
".",
"splitlines",
"(",
")",
")",
"raw_users",
"=",
"{",
"user",
... | Pre-process raw string.
Prepare users to work with APIItems.
Create booleans with user levels. | [
"Pre",
"-",
"process",
"raw",
"string",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/pwdgrp_cgi.py#L88-L104 |
Kane610/axis | axis/rtsp.py | RTSPClient.start | def start(self):
"""Start session."""
conn = self.loop.create_connection(
lambda: self, self.session.host, self.session.port)
task = self.loop.create_task(conn)
task.add_done_callback(self.init_done) | python | def start(self):
"""Start session."""
conn = self.loop.create_connection(
lambda: self, self.session.host, self.session.port)
task = self.loop.create_task(conn)
task.add_done_callback(self.init_done) | [
"def",
"start",
"(",
"self",
")",
":",
"conn",
"=",
"self",
".",
"loop",
".",
"create_connection",
"(",
"lambda",
":",
"self",
",",
"self",
".",
"session",
".",
"host",
",",
"self",
".",
"session",
".",
"port",
")",
"task",
"=",
"self",
".",
"loop"... | Start session. | [
"Start",
"session",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L43-L48 |
Kane610/axis | axis/rtsp.py | RTSPClient.init_done | def init_done(self, fut):
"""Server ready.
If we get OSError during init the device is not available.
"""
try:
if fut.exception():
fut.result()
except OSError as err:
_LOGGER.debug('RTSP got exception %s', err)
self.stop()
... | python | def init_done(self, fut):
"""Server ready.
If we get OSError during init the device is not available.
"""
try:
if fut.exception():
fut.result()
except OSError as err:
_LOGGER.debug('RTSP got exception %s', err)
self.stop()
... | [
"def",
"init_done",
"(",
"self",
",",
"fut",
")",
":",
"try",
":",
"if",
"fut",
".",
"exception",
"(",
")",
":",
"fut",
".",
"result",
"(",
")",
"except",
"OSError",
"as",
"err",
":",
"_LOGGER",
".",
"debug",
"(",
"'RTSP got exception %s'",
",",
"err... | Server ready.
If we get OSError during init the device is not available. | [
"Server",
"ready",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L50-L61 |
Kane610/axis | axis/rtsp.py | RTSPClient.stop | def stop(self):
"""Stop session."""
if self.transport:
self.transport.write(self.method.TEARDOWN().encode())
self.transport.close()
self.rtp.stop() | python | def stop(self):
"""Stop session."""
if self.transport:
self.transport.write(self.method.TEARDOWN().encode())
self.transport.close()
self.rtp.stop() | [
"def",
"stop",
"(",
"self",
")",
":",
"if",
"self",
".",
"transport",
":",
"self",
".",
"transport",
".",
"write",
"(",
"self",
".",
"method",
".",
"TEARDOWN",
"(",
")",
".",
"encode",
"(",
")",
")",
"self",
".",
"transport",
".",
"close",
"(",
"... | Stop session. | [
"Stop",
"session",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L63-L68 |
Kane610/axis | axis/rtsp.py | RTSPClient.connection_made | def connection_made(self, transport):
"""Connect to device is successful.
Start configuring RTSP session.
Schedule time out handle in case device doesn't respond.
"""
self.transport = transport
self.transport.write(self.method.message.encode())
self.time_out_hand... | python | def connection_made(self, transport):
"""Connect to device is successful.
Start configuring RTSP session.
Schedule time out handle in case device doesn't respond.
"""
self.transport = transport
self.transport.write(self.method.message.encode())
self.time_out_hand... | [
"def",
"connection_made",
"(",
"self",
",",
"transport",
")",
":",
"self",
".",
"transport",
"=",
"transport",
"self",
".",
"transport",
".",
"write",
"(",
"self",
".",
"method",
".",
"message",
".",
"encode",
"(",
")",
")",
"self",
".",
"time_out_handle... | Connect to device is successful.
Start configuring RTSP session.
Schedule time out handle in case device doesn't respond. | [
"Connect",
"to",
"device",
"is",
"successful",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L70-L79 |
Kane610/axis | axis/rtsp.py | RTSPClient.data_received | def data_received(self, data):
"""Got response on RTSP session.
Manage time out handle since response came in a reasonable time.
Update session parameters with latest response.
If state is playing schedule keep-alive.
"""
self.time_out_handle.cancel()
self.sessio... | python | def data_received(self, data):
"""Got response on RTSP session.
Manage time out handle since response came in a reasonable time.
Update session parameters with latest response.
If state is playing schedule keep-alive.
"""
self.time_out_handle.cancel()
self.sessio... | [
"def",
"data_received",
"(",
"self",
",",
"data",
")",
":",
"self",
".",
"time_out_handle",
".",
"cancel",
"(",
")",
"self",
".",
"session",
".",
"update",
"(",
"data",
".",
"decode",
"(",
")",
")",
"if",
"self",
".",
"session",
".",
"state",
"==",
... | Got response on RTSP session.
Manage time out handle since response came in a reasonable time.
Update session parameters with latest response.
If state is playing schedule keep-alive. | [
"Got",
"response",
"on",
"RTSP",
"session",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L81-L104 |
Kane610/axis | axis/rtsp.py | RTSPClient.time_out | def time_out(self):
"""If we don't get a response within time the RTSP request time out.
This usually happens if device isn't available on specified IP.
"""
_LOGGER.warning('Response timed out %s', self.session.host)
self.stop()
self.callback(SIGNAL_FAILED) | python | def time_out(self):
"""If we don't get a response within time the RTSP request time out.
This usually happens if device isn't available on specified IP.
"""
_LOGGER.warning('Response timed out %s', self.session.host)
self.stop()
self.callback(SIGNAL_FAILED) | [
"def",
"time_out",
"(",
"self",
")",
":",
"_LOGGER",
".",
"warning",
"(",
"'Response timed out %s'",
",",
"self",
".",
"session",
".",
"host",
")",
"self",
".",
"stop",
"(",
")",
"self",
".",
"callback",
"(",
"SIGNAL_FAILED",
")"
] | If we don't get a response within time the RTSP request time out.
This usually happens if device isn't available on specified IP. | [
"If",
"we",
"don",
"t",
"get",
"a",
"response",
"within",
"time",
"the",
"RTSP",
"request",
"time",
"out",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L112-L119 |
Kane610/axis | axis/rtsp.py | RTSPMethods.message | def message(self):
"""Return RTSP method based on sequence number from session."""
message = self.message_methods[self.session.method]()
_LOGGER.debug(message)
return message | python | def message(self):
"""Return RTSP method based on sequence number from session."""
message = self.message_methods[self.session.method]()
_LOGGER.debug(message)
return message | [
"def",
"message",
"(",
"self",
")",
":",
"message",
"=",
"self",
".",
"message_methods",
"[",
"self",
".",
"session",
".",
"method",
"]",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"message",
")",
"return",
"message"
] | Return RTSP method based on sequence number from session. | [
"Return",
"RTSP",
"method",
"based",
"on",
"sequence",
"number",
"from",
"session",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L201-L205 |
Kane610/axis | axis/rtsp.py | RTSPMethods.OPTIONS | def OPTIONS(self, authenticate=True):
"""Request options device supports."""
message = "OPTIONS " + self.session.url + " RTSP/1.0\r\n"
message += self.sequence
message += self.authentication if authenticate else ''
message += self.user_agent
message += self.session_id
... | python | def OPTIONS(self, authenticate=True):
"""Request options device supports."""
message = "OPTIONS " + self.session.url + " RTSP/1.0\r\n"
message += self.sequence
message += self.authentication if authenticate else ''
message += self.user_agent
message += self.session_id
... | [
"def",
"OPTIONS",
"(",
"self",
",",
"authenticate",
"=",
"True",
")",
":",
"message",
"=",
"\"OPTIONS \"",
"+",
"self",
".",
"session",
".",
"url",
"+",
"\" RTSP/1.0\\r\\n\"",
"message",
"+=",
"self",
".",
"sequence",
"message",
"+=",
"self",
".",
"authent... | Request options device supports. | [
"Request",
"options",
"device",
"supports",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L211-L219 |
Kane610/axis | axis/rtsp.py | RTSPMethods.DESCRIBE | def DESCRIBE(self):
"""Request description of what services RTSP server make available."""
message = "DESCRIBE " + self.session.url + " RTSP/1.0\r\n"
message += self.sequence
message += self.authentication
message += self.user_agent
message += "Accept: application/sdp\r\n... | python | def DESCRIBE(self):
"""Request description of what services RTSP server make available."""
message = "DESCRIBE " + self.session.url + " RTSP/1.0\r\n"
message += self.sequence
message += self.authentication
message += self.user_agent
message += "Accept: application/sdp\r\n... | [
"def",
"DESCRIBE",
"(",
"self",
")",
":",
"message",
"=",
"\"DESCRIBE \"",
"+",
"self",
".",
"session",
".",
"url",
"+",
"\" RTSP/1.0\\r\\n\"",
"message",
"+=",
"self",
".",
"sequence",
"message",
"+=",
"self",
".",
"authentication",
"message",
"+=",
"self",... | Request description of what services RTSP server make available. | [
"Request",
"description",
"of",
"what",
"services",
"RTSP",
"server",
"make",
"available",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L221-L229 |
Kane610/axis | axis/rtsp.py | RTSPMethods.SETUP | def SETUP(self):
"""Set up stream transport."""
message = "SETUP " + self.session.control_url + " RTSP/1.0\r\n"
message += self.sequence
message += self.authentication
message += self.user_agent
message += self.transport
message += '\r\n'
return message | python | def SETUP(self):
"""Set up stream transport."""
message = "SETUP " + self.session.control_url + " RTSP/1.0\r\n"
message += self.sequence
message += self.authentication
message += self.user_agent
message += self.transport
message += '\r\n'
return message | [
"def",
"SETUP",
"(",
"self",
")",
":",
"message",
"=",
"\"SETUP \"",
"+",
"self",
".",
"session",
".",
"control_url",
"+",
"\" RTSP/1.0\\r\\n\"",
"message",
"+=",
"self",
".",
"sequence",
"message",
"+=",
"self",
".",
"authentication",
"message",
"+=",
"self... | Set up stream transport. | [
"Set",
"up",
"stream",
"transport",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L231-L239 |
Kane610/axis | axis/rtsp.py | RTSPMethods.PLAY | def PLAY(self):
"""RTSP session is ready to send data."""
message = "PLAY " + self.session.url + " RTSP/1.0\r\n"
message += self.sequence
message += self.authentication
message += self.user_agent
message += self.session_id
message += '\r\n'
return message | python | def PLAY(self):
"""RTSP session is ready to send data."""
message = "PLAY " + self.session.url + " RTSP/1.0\r\n"
message += self.sequence
message += self.authentication
message += self.user_agent
message += self.session_id
message += '\r\n'
return message | [
"def",
"PLAY",
"(",
"self",
")",
":",
"message",
"=",
"\"PLAY \"",
"+",
"self",
".",
"session",
".",
"url",
"+",
"\" RTSP/1.0\\r\\n\"",
"message",
"+=",
"self",
".",
"sequence",
"message",
"+=",
"self",
".",
"authentication",
"message",
"+=",
"self",
".",
... | RTSP session is ready to send data. | [
"RTSP",
"session",
"is",
"ready",
"to",
"send",
"data",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L241-L249 |
Kane610/axis | axis/rtsp.py | RTSPMethods.authentication | def authentication(self):
"""Generate authentication string."""
if self.session.digest:
authentication = self.session.generate_digest()
elif self.session.basic:
authentication = self.session.generate_basic()
else:
return ''
return "Authorizatio... | python | def authentication(self):
"""Generate authentication string."""
if self.session.digest:
authentication = self.session.generate_digest()
elif self.session.basic:
authentication = self.session.generate_basic()
else:
return ''
return "Authorizatio... | [
"def",
"authentication",
"(",
"self",
")",
":",
"if",
"self",
".",
"session",
".",
"digest",
":",
"authentication",
"=",
"self",
".",
"session",
".",
"generate_digest",
"(",
")",
"elif",
"self",
".",
"session",
".",
"basic",
":",
"authentication",
"=",
"... | Generate authentication string. | [
"Generate",
"authentication",
"string",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L267-L275 |
Kane610/axis | axis/rtsp.py | RTSPMethods.transport | def transport(self):
"""Generate transport string."""
transport = "Transport: RTP/AVP;unicast;client_port={}-{}\r\n"
return transport.format(
str(self.session.rtp_port), str(self.session.rtcp_port)) | python | def transport(self):
"""Generate transport string."""
transport = "Transport: RTP/AVP;unicast;client_port={}-{}\r\n"
return transport.format(
str(self.session.rtp_port), str(self.session.rtcp_port)) | [
"def",
"transport",
"(",
"self",
")",
":",
"transport",
"=",
"\"Transport: RTP/AVP;unicast;client_port={}-{}\\r\\n\"",
"return",
"transport",
".",
"format",
"(",
"str",
"(",
"self",
".",
"session",
".",
"rtp_port",
")",
",",
"str",
"(",
"self",
".",
"session",
... | Generate transport string. | [
"Generate",
"transport",
"string",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L290-L294 |
Kane610/axis | axis/rtsp.py | RTSPSession.state | def state(self):
"""Which state the session is in.
Starting - all messages needed to get stream started.
Playing - keep-alive messages every self.session_timeout.
"""
if self.method in ['OPTIONS', 'DESCRIBE', 'SETUP', 'PLAY']:
state = STATE_STARTING
elif self... | python | def state(self):
"""Which state the session is in.
Starting - all messages needed to get stream started.
Playing - keep-alive messages every self.session_timeout.
"""
if self.method in ['OPTIONS', 'DESCRIBE', 'SETUP', 'PLAY']:
state = STATE_STARTING
elif self... | [
"def",
"state",
"(",
"self",
")",
":",
"if",
"self",
".",
"method",
"in",
"[",
"'OPTIONS'",
",",
"'DESCRIBE'",
",",
"'SETUP'",
",",
"'PLAY'",
"]",
":",
"state",
"=",
"STATE_STARTING",
"elif",
"self",
".",
"method",
"in",
"[",
"'KEEP-ALIVE'",
"]",
":",
... | Which state the session is in.
Starting - all messages needed to get stream started.
Playing - keep-alive messages every self.session_timeout. | [
"Which",
"state",
"the",
"session",
"is",
"in",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L358-L371 |
Kane610/axis | axis/rtsp.py | RTSPSession.update | def update(self, response):
"""Update session information from device response.
Increment sequence number when starting stream, not when playing.
If device requires authentication resend previous message with auth.
"""
data = response.splitlines()
_LOGGER.debug('Received... | python | def update(self, response):
"""Update session information from device response.
Increment sequence number when starting stream, not when playing.
If device requires authentication resend previous message with auth.
"""
data = response.splitlines()
_LOGGER.debug('Received... | [
"def",
"update",
"(",
"self",
",",
"response",
")",
":",
"data",
"=",
"response",
".",
"splitlines",
"(",
")",
"_LOGGER",
".",
"debug",
"(",
"'Received data %s from %s'",
",",
"data",
",",
"self",
".",
"host",
")",
"while",
"data",
":",
"line",
"=",
"d... | Update session information from device response.
Increment sequence number when starting stream, not when playing.
If device requires authentication resend previous message with auth. | [
"Update",
"session",
"information",
"from",
"device",
"response",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L373-L439 |
Kane610/axis | axis/rtsp.py | RTSPSession.generate_digest | def generate_digest(self):
"""RFC 2617."""
from hashlib import md5
ha1 = self.username + ':' + self.realm + ':' + self.password
HA1 = md5(ha1.encode('UTF-8')).hexdigest()
ha2 = self.method + ':' + self.url
HA2 = md5(ha2.encode('UTF-8')).hexdigest()
encrypt_respons... | python | def generate_digest(self):
"""RFC 2617."""
from hashlib import md5
ha1 = self.username + ':' + self.realm + ':' + self.password
HA1 = md5(ha1.encode('UTF-8')).hexdigest()
ha2 = self.method + ':' + self.url
HA2 = md5(ha2.encode('UTF-8')).hexdigest()
encrypt_respons... | [
"def",
"generate_digest",
"(",
"self",
")",
":",
"from",
"hashlib",
"import",
"md5",
"ha1",
"=",
"self",
".",
"username",
"+",
"':'",
"+",
"self",
".",
"realm",
"+",
"':'",
"+",
"self",
".",
"password",
"HA1",
"=",
"md5",
"(",
"ha1",
".",
"encode",
... | RFC 2617. | [
"RFC",
"2617",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L441-L458 |
Kane610/axis | axis/rtsp.py | RTSPSession.generate_basic | def generate_basic(self):
"""RFC 2617."""
from base64 import b64encode
if not self.basic_auth:
creds = self.username + ':' + self.password
self.basic_auth = 'Basic '
self.basic_auth += b64encode(creds.encode('UTF-8')).decode('UTF-8')
return self.basic_... | python | def generate_basic(self):
"""RFC 2617."""
from base64 import b64encode
if not self.basic_auth:
creds = self.username + ':' + self.password
self.basic_auth = 'Basic '
self.basic_auth += b64encode(creds.encode('UTF-8')).decode('UTF-8')
return self.basic_... | [
"def",
"generate_basic",
"(",
"self",
")",
":",
"from",
"base64",
"import",
"b64encode",
"if",
"not",
"self",
".",
"basic_auth",
":",
"creds",
"=",
"self",
".",
"username",
"+",
"':'",
"+",
"self",
".",
"password",
"self",
".",
"basic_auth",
"=",
"'Basic... | RFC 2617. | [
"RFC",
"2617",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/rtsp.py#L460-L467 |
pnpnpn/retry-decorator | retry_decorator/retry_decorator.py | retry | def retry(ExceptionToCheck, tries=10, timeout_secs=1.0, logger=None, callback_by_exception=None):
"""
Retry calling the decorated function using an exponential backoff.
:param callback_by_exception: callback/method invocation on certain exceptions
:type callback_by_exception: None or dict
"""
de... | python | def retry(ExceptionToCheck, tries=10, timeout_secs=1.0, logger=None, callback_by_exception=None):
"""
Retry calling the decorated function using an exponential backoff.
:param callback_by_exception: callback/method invocation on certain exceptions
:type callback_by_exception: None or dict
"""
de... | [
"def",
"retry",
"(",
"ExceptionToCheck",
",",
"tries",
"=",
"10",
",",
"timeout_secs",
"=",
"1.0",
",",
"logger",
"=",
"None",
",",
"callback_by_exception",
"=",
"None",
")",
":",
"def",
"deco_retry",
"(",
"f",
")",
":",
"def",
"f_retry",
"(",
"*",
"ar... | Retry calling the decorated function using an exponential backoff.
:param callback_by_exception: callback/method invocation on certain exceptions
:type callback_by_exception: None or dict | [
"Retry",
"calling",
"the",
"decorated",
"function",
"using",
"an",
"exponential",
"backoff",
".",
":",
"param",
"callback_by_exception",
":",
"callback",
"/",
"method",
"invocation",
"on",
"certain",
"exceptions",
":",
"type",
"callback_by_exception",
":",
"None",
... | train | https://github.com/pnpnpn/retry-decorator/blob/8233db393e76b52fbf47fa608520f6e57098f566/retry_decorator/retry_decorator.py#L15-L56 |
Kane610/axis | axis/streammanager.py | StreamManager.stream_url | def stream_url(self):
"""Build url for stream."""
rtsp_url = RTSP_URL.format(
host=self.config.host, video=self.video_query,
audio=self.audio_query, event=self.event_query)
_LOGGER.debug(rtsp_url)
return rtsp_url | python | def stream_url(self):
"""Build url for stream."""
rtsp_url = RTSP_URL.format(
host=self.config.host, video=self.video_query,
audio=self.audio_query, event=self.event_query)
_LOGGER.debug(rtsp_url)
return rtsp_url | [
"def",
"stream_url",
"(",
"self",
")",
":",
"rtsp_url",
"=",
"RTSP_URL",
".",
"format",
"(",
"host",
"=",
"self",
".",
"config",
".",
"host",
",",
"video",
"=",
"self",
".",
"video_query",
",",
"audio",
"=",
"self",
".",
"audio_query",
",",
"event",
... | Build url for stream. | [
"Build",
"url",
"for",
"stream",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/streammanager.py#L29-L35 |
Kane610/axis | axis/streammanager.py | StreamManager.session_callback | def session_callback(self, signal):
"""Signalling from stream session.
Data - new data available for processing.
Playing - Connection is healthy.
Retry - if there is no connection to device.
"""
if signal == SIGNAL_DATA:
self.event.new_event(self.data)
... | python | def session_callback(self, signal):
"""Signalling from stream session.
Data - new data available for processing.
Playing - Connection is healthy.
Retry - if there is no connection to device.
"""
if signal == SIGNAL_DATA:
self.event.new_event(self.data)
... | [
"def",
"session_callback",
"(",
"self",
",",
"signal",
")",
":",
"if",
"signal",
"==",
"SIGNAL_DATA",
":",
"self",
".",
"event",
".",
"new_event",
"(",
"self",
".",
"data",
")",
"elif",
"signal",
"==",
"SIGNAL_FAILED",
":",
"self",
".",
"retry",
"(",
"... | Signalling from stream session.
Data - new data available for processing.
Playing - Connection is healthy.
Retry - if there is no connection to device. | [
"Signalling",
"from",
"stream",
"session",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/streammanager.py#L52-L67 |
Kane610/axis | axis/streammanager.py | StreamManager.start | def start(self):
"""Start stream."""
if not self.stream or self.stream.session.state == STATE_STOPPED:
self.stream = RTSPClient(
self.config.loop, self.stream_url, self.config.host,
self.config.username, self.config.password,
self.session_callb... | python | def start(self):
"""Start stream."""
if not self.stream or self.stream.session.state == STATE_STOPPED:
self.stream = RTSPClient(
self.config.loop, self.stream_url, self.config.host,
self.config.username, self.config.password,
self.session_callb... | [
"def",
"start",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"stream",
"or",
"self",
".",
"stream",
".",
"session",
".",
"state",
"==",
"STATE_STOPPED",
":",
"self",
".",
"stream",
"=",
"RTSPClient",
"(",
"self",
".",
"config",
".",
"loop",
",",
... | Start stream. | [
"Start",
"stream",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/streammanager.py#L74-L81 |
Kane610/axis | axis/streammanager.py | StreamManager.stop | def stop(self):
"""Stop stream."""
if self.stream and self.stream.session.state != STATE_STOPPED:
self.stream.stop() | python | def stop(self):
"""Stop stream."""
if self.stream and self.stream.session.state != STATE_STOPPED:
self.stream.stop() | [
"def",
"stop",
"(",
"self",
")",
":",
"if",
"self",
".",
"stream",
"and",
"self",
".",
"stream",
".",
"session",
".",
"state",
"!=",
"STATE_STOPPED",
":",
"self",
".",
"stream",
".",
"stop",
"(",
")"
] | Stop stream. | [
"Stop",
"stream",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/streammanager.py#L83-L86 |
Kane610/axis | axis/streammanager.py | StreamManager.retry | def retry(self):
"""No connection to device, retry connection after 15 seconds."""
self.stream = None
self.config.loop.call_later(RETRY_TIMER, self.start)
_LOGGER.debug('Reconnecting to %s', self.config.host) | python | def retry(self):
"""No connection to device, retry connection after 15 seconds."""
self.stream = None
self.config.loop.call_later(RETRY_TIMER, self.start)
_LOGGER.debug('Reconnecting to %s', self.config.host) | [
"def",
"retry",
"(",
"self",
")",
":",
"self",
".",
"stream",
"=",
"None",
"self",
".",
"config",
".",
"loop",
".",
"call_later",
"(",
"RETRY_TIMER",
",",
"self",
".",
"start",
")",
"_LOGGER",
".",
"debug",
"(",
"'Reconnecting to %s'",
",",
"self",
"."... | No connection to device, retry connection after 15 seconds. | [
"No",
"connection",
"to",
"device",
"retry",
"connection",
"after",
"15",
"seconds",
"."
] | train | https://github.com/Kane610/axis/blob/b2b44ce595c7b722b5e13eabcab7b91f048e1808/axis/streammanager.py#L88-L92 |
hydraplatform/hydra-base | hydra_base/db/truncate.py | connect_mysql | def connect_mysql():
"""
return an inspector object
"""
MySQLConnection.get_characterset_info = MySQLConnection.get_charset
db = create_engine(engine_name)
db.echo = True
db.connect()
return db | python | def connect_mysql():
"""
return an inspector object
"""
MySQLConnection.get_characterset_info = MySQLConnection.get_charset
db = create_engine(engine_name)
db.echo = True
db.connect()
return db | [
"def",
"connect_mysql",
"(",
")",
":",
"MySQLConnection",
".",
"get_characterset_info",
"=",
"MySQLConnection",
".",
"get_charset",
"db",
"=",
"create_engine",
"(",
"engine_name",
")",
"db",
".",
"echo",
"=",
"True",
"db",
".",
"connect",
"(",
")",
"return",
... | return an inspector object | [
"return",
"an",
"inspector",
"object"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/db/truncate.py#L40-L50 |
hydraplatform/hydra-base | hydra_base/util/permissions.py | check_perm | def check_perm(user_id, permission_code):
"""
Checks whether a user has permission to perform an action.
The permission_code parameter should be a permission contained in tPerm.
If the user does not have permission to perfom an action, a permission
error is thrown.
"""
try:
... | python | def check_perm(user_id, permission_code):
"""
Checks whether a user has permission to perform an action.
The permission_code parameter should be a permission contained in tPerm.
If the user does not have permission to perfom an action, a permission
error is thrown.
"""
try:
... | [
"def",
"check_perm",
"(",
"user_id",
",",
"permission_code",
")",
":",
"try",
":",
"perm",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Perm",
")",
".",
"filter",
"(",
"Perm",
".",
"code",
"==",
"permission_code",
")",
".",
"one",
"(",
")",
"exce... | Checks whether a user has permission to perform an action.
The permission_code parameter should be a permission contained in tPerm.
If the user does not have permission to perfom an action, a permission
error is thrown. | [
"Checks",
"whether",
"a",
"user",
"has",
"permission",
"to",
"perform",
"an",
"action",
".",
"The",
"permission_code",
"parameter",
"should",
"be",
"a",
"permission",
"contained",
"in",
"tPerm",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/permissions.py#L28-L48 |
hydraplatform/hydra-base | hydra_base/util/permissions.py | required_perms | def required_perms(*req_perms):
"""
Decorator applied to functions requiring caller to possess permission
Takes args tuple of required perms and raises PermissionsError
via check_perm if these are not a subset of user perms
"""
def dec_wrapper(wfunc):
@wraps(wfunc)
def w... | python | def required_perms(*req_perms):
"""
Decorator applied to functions requiring caller to possess permission
Takes args tuple of required perms and raises PermissionsError
via check_perm if these are not a subset of user perms
"""
def dec_wrapper(wfunc):
@wraps(wfunc)
def w... | [
"def",
"required_perms",
"(",
"*",
"req_perms",
")",
":",
"def",
"dec_wrapper",
"(",
"wfunc",
")",
":",
"@",
"wraps",
"(",
"wfunc",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"user_id",
"=",
"kwargs",
".",
"get",
"(... | Decorator applied to functions requiring caller to possess permission
Takes args tuple of required perms and raises PermissionsError
via check_perm if these are not a subset of user perms | [
"Decorator",
"applied",
"to",
"functions",
"requiring",
"caller",
"to",
"possess",
"permission",
"Takes",
"args",
"tuple",
"of",
"required",
"perms",
"and",
"raises",
"PermissionsError",
"via",
"check_perm",
"if",
"these",
"are",
"not",
"a",
"subset",
"of",
"use... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/permissions.py#L52-L68 |
hydraplatform/hydra-base | hydra_base/util/permissions.py | required_role | def required_role(req_role):
"""
Decorator applied to functions requiring caller to possess the specified role
"""
def dec_wrapper(wfunc):
@wraps(wfunc)
def wrapped(*args, **kwargs):
user_id = kwargs.get("user_id")
try:
res = db.DBSession.query... | python | def required_role(req_role):
"""
Decorator applied to functions requiring caller to possess the specified role
"""
def dec_wrapper(wfunc):
@wraps(wfunc)
def wrapped(*args, **kwargs):
user_id = kwargs.get("user_id")
try:
res = db.DBSession.query... | [
"def",
"required_role",
"(",
"req_role",
")",
":",
"def",
"dec_wrapper",
"(",
"wfunc",
")",
":",
"@",
"wraps",
"(",
"wfunc",
")",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"user_id",
"=",
"kwargs",
".",
"get",
"(",
"\"u... | Decorator applied to functions requiring caller to possess the specified role | [
"Decorator",
"applied",
"to",
"functions",
"requiring",
"caller",
"to",
"possess",
"the",
"specified",
"role"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/permissions.py#L70-L87 |
hydraplatform/hydra-base | hydra_base/util/hydra_dateutil.py | get_time_period | def get_time_period(period_name):
"""
Given a time period name, fetch the hydra-compatible time
abbreviation.
"""
time_abbreviation = time_map.get(period_name.lower())
if time_abbreviation is None:
raise Exception("Symbol %s not recognised as a time period"%period_name)
ret... | python | def get_time_period(period_name):
"""
Given a time period name, fetch the hydra-compatible time
abbreviation.
"""
time_abbreviation = time_map.get(period_name.lower())
if time_abbreviation is None:
raise Exception("Symbol %s not recognised as a time period"%period_name)
ret... | [
"def",
"get_time_period",
"(",
"period_name",
")",
":",
"time_abbreviation",
"=",
"time_map",
".",
"get",
"(",
"period_name",
".",
"lower",
"(",
")",
")",
"if",
"time_abbreviation",
"is",
"None",
":",
"raise",
"Exception",
"(",
"\"Symbol %s not recognised as a tim... | Given a time period name, fetch the hydra-compatible time
abbreviation. | [
"Given",
"a",
"time",
"period",
"name",
"fetch",
"the",
"hydra",
"-",
"compatible",
"time",
"abbreviation",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/hydra_dateutil.py#L42-L52 |
hydraplatform/hydra-base | hydra_base/util/hydra_dateutil.py | get_datetime | def get_datetime(timestamp):
"""
Turn a string timestamp into a date time. First tries to use dateutil.
Failing that it tries to guess the time format and converts it manually
using stfptime.
@returns: A timezone unaware timestamp.
"""
timestamp_is_float = False
try:
... | python | def get_datetime(timestamp):
"""
Turn a string timestamp into a date time. First tries to use dateutil.
Failing that it tries to guess the time format and converts it manually
using stfptime.
@returns: A timezone unaware timestamp.
"""
timestamp_is_float = False
try:
... | [
"def",
"get_datetime",
"(",
"timestamp",
")",
":",
"timestamp_is_float",
"=",
"False",
"try",
":",
"float",
"(",
"timestamp",
")",
"timestamp_is_float",
"=",
"True",
"except",
"(",
"ValueError",
",",
"TypeError",
")",
":",
"pass",
"if",
"timestamp_is_float",
"... | Turn a string timestamp into a date time. First tries to use dateutil.
Failing that it tries to guess the time format and converts it manually
using stfptime.
@returns: A timezone unaware timestamp. | [
"Turn",
"a",
"string",
"timestamp",
"into",
"a",
"date",
"time",
".",
"First",
"tries",
"to",
"use",
"dateutil",
".",
"Failing",
"that",
"it",
"tries",
"to",
"guess",
"the",
"time",
"format",
"and",
"converts",
"it",
"manually",
"using",
"stfptime",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/hydra_dateutil.py#L54-L105 |
hydraplatform/hydra-base | hydra_base/util/hydra_dateutil.py | timestamp_to_ordinal | def timestamp_to_ordinal(timestamp):
"""Convert a timestamp as defined in the soap interface to the time format
stored in the database.
"""
if timestamp is None:
return None
ts_time = get_datetime(timestamp)
# Convert time to Gregorian ordinal (1 = January 1st, year 1)
ordinal_ts_t... | python | def timestamp_to_ordinal(timestamp):
"""Convert a timestamp as defined in the soap interface to the time format
stored in the database.
"""
if timestamp is None:
return None
ts_time = get_datetime(timestamp)
# Convert time to Gregorian ordinal (1 = January 1st, year 1)
ordinal_ts_t... | [
"def",
"timestamp_to_ordinal",
"(",
"timestamp",
")",
":",
"if",
"timestamp",
"is",
"None",
":",
"return",
"None",
"ts_time",
"=",
"get_datetime",
"(",
"timestamp",
")",
"# Convert time to Gregorian ordinal (1 = January 1st, year 1)",
"ordinal_ts_time",
"=",
"Decimal",
... | Convert a timestamp as defined in the soap interface to the time format
stored in the database. | [
"Convert",
"a",
"timestamp",
"as",
"defined",
"in",
"the",
"soap",
"interface",
"to",
"the",
"time",
"format",
"stored",
"in",
"the",
"database",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/hydra_dateutil.py#L108-L129 |
hydraplatform/hydra-base | hydra_base/util/hydra_dateutil.py | date_to_string | def date_to_string(date, seasonal=False):
"""Convert a date to a standard string used by Hydra. The resulting string
looks like this::
'2013-10-03 00:49:17.568-0400'
Hydra also accepts seasonal time series (yearly recurring). If the flag
``seasonal`` is set to ``True``, this function will gene... | python | def date_to_string(date, seasonal=False):
"""Convert a date to a standard string used by Hydra. The resulting string
looks like this::
'2013-10-03 00:49:17.568-0400'
Hydra also accepts seasonal time series (yearly recurring). If the flag
``seasonal`` is set to ``True``, this function will gene... | [
"def",
"date_to_string",
"(",
"date",
",",
"seasonal",
"=",
"False",
")",
":",
"seasonal_key",
"=",
"config",
".",
"get",
"(",
"'DEFAULT'",
",",
"'seasonal_key'",
",",
"'9999'",
")",
"if",
"seasonal",
":",
"FORMAT",
"=",
"seasonal_key",
"+",
"'-%m-%dT%H:%M:%... | Convert a date to a standard string used by Hydra. The resulting string
looks like this::
'2013-10-03 00:49:17.568-0400'
Hydra also accepts seasonal time series (yearly recurring). If the flag
``seasonal`` is set to ``True``, this function will generate a string
recognised by Hydra as seasonal... | [
"Convert",
"a",
"date",
"to",
"a",
"standard",
"string",
"used",
"by",
"Hydra",
".",
"The",
"resulting",
"string",
"looks",
"like",
"this",
"::"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/hydra_dateutil.py#L157-L173 |
hydraplatform/hydra-base | hydra_base/util/hydra_dateutil.py | guess_timefmt | def guess_timefmt(datestr):
"""
Try to guess the format a date is written in.
The following formats are supported:
================= ============== ===============
Format Example Python format
----------------- -------------- ---------------
``YYYY-MM-DD`` 2002-04-21 ... | python | def guess_timefmt(datestr):
"""
Try to guess the format a date is written in.
The following formats are supported:
================= ============== ===============
Format Example Python format
----------------- -------------- ---------------
``YYYY-MM-DD`` 2002-04-21 ... | [
"def",
"guess_timefmt",
"(",
"datestr",
")",
":",
"if",
"isinstance",
"(",
"datestr",
",",
"float",
")",
"or",
"isinstance",
"(",
"datestr",
",",
"int",
")",
":",
"return",
"None",
"seasonal_key",
"=",
"str",
"(",
"config",
".",
"get",
"(",
"'DEFAULT'",
... | Try to guess the format a date is written in.
The following formats are supported:
================= ============== ===============
Format Example Python format
----------------- -------------- ---------------
``YYYY-MM-DD`` 2002-04-21 %Y-%m-%d
``YYYY.MM.DD`` 2002.0... | [
"Try",
"to",
"guess",
"the",
"format",
"a",
"date",
"is",
"written",
"in",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/hydra_dateutil.py#L176-L294 |
hydraplatform/hydra-base | hydra_base/util/hydra_dateutil.py | reindex_timeseries | def reindex_timeseries(ts_string, new_timestamps):
"""
get data for timesamp
:param a JSON string, in pandas-friendly format
:param a timestamp or list of timestamps (datetimes)
:returns a pandas data frame, reindexed with the supplied timestamos or None if no data is found
"""
... | python | def reindex_timeseries(ts_string, new_timestamps):
"""
get data for timesamp
:param a JSON string, in pandas-friendly format
:param a timestamp or list of timestamps (datetimes)
:returns a pandas data frame, reindexed with the supplied timestamos or None if no data is found
"""
... | [
"def",
"reindex_timeseries",
"(",
"ts_string",
",",
"new_timestamps",
")",
":",
"#If a single timestamp is passed in, turn it into a list",
"#Reindexing can't work if it's not a list",
"if",
"not",
"isinstance",
"(",
"new_timestamps",
",",
"list",
")",
":",
"new_timestamps",
... | get data for timesamp
:param a JSON string, in pandas-friendly format
:param a timestamp or list of timestamps (datetimes)
:returns a pandas data frame, reindexed with the supplied timestamos or None if no data is found | [
"get",
"data",
"for",
"timesamp"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/hydra_dateutil.py#L296-L352 |
hydraplatform/hydra-base | hydra_base/util/hydra_dateutil.py | parse_time_step | def parse_time_step(time_step, target='s', units_ref=None):
"""
Read in the time step and convert it to seconds.
"""
log.info("Parsing time step %s", time_step)
# export numerical value from string using regex
value = re.findall(r'\d+', time_step)[0]
valuelen = len(value)
try:
... | python | def parse_time_step(time_step, target='s', units_ref=None):
"""
Read in the time step and convert it to seconds.
"""
log.info("Parsing time step %s", time_step)
# export numerical value from string using regex
value = re.findall(r'\d+', time_step)[0]
valuelen = len(value)
try:
... | [
"def",
"parse_time_step",
"(",
"time_step",
",",
"target",
"=",
"'s'",
",",
"units_ref",
"=",
"None",
")",
":",
"log",
".",
"info",
"(",
"\"Parsing time step %s\"",
",",
"time_step",
")",
"# export numerical value from string using regex",
"value",
"=",
"re",
".",... | Read in the time step and convert it to seconds. | [
"Read",
"in",
"the",
"time",
"step",
"and",
"convert",
"it",
"to",
"seconds",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/hydra_dateutil.py#L354-L378 |
hydraplatform/hydra-base | hydra_base/util/hydra_dateutil.py | get_time_axis | def get_time_axis(start_time, end_time, time_step, time_axis=None):
"""
Create a list of datetimes based on an start time, end time and
time step. If such a list is already passed in, then this is not
necessary.
Often either the start_time, end_time, time_step is passed into an
... | python | def get_time_axis(start_time, end_time, time_step, time_axis=None):
"""
Create a list of datetimes based on an start time, end time and
time step. If such a list is already passed in, then this is not
necessary.
Often either the start_time, end_time, time_step is passed into an
... | [
"def",
"get_time_axis",
"(",
"start_time",
",",
"end_time",
",",
"time_step",
",",
"time_axis",
"=",
"None",
")",
":",
"#Do this import here to avoid a circular dependency",
"from",
".",
".",
"lib",
"import",
"units",
"if",
"time_axis",
"is",
"not",
"None",
":",
... | Create a list of datetimes based on an start time, end time and
time step. If such a list is already passed in, then this is not
necessary.
Often either the start_time, end_time, time_step is passed into an
app or the time_axis is passed in directly. This function returns a
tim... | [
"Create",
"a",
"list",
"of",
"datetimes",
"based",
"on",
"an",
"start",
"time",
"end",
"time",
"and",
"time",
"step",
".",
"If",
"such",
"a",
"list",
"is",
"already",
"passed",
"in",
"then",
"this",
"is",
"not",
"necessary",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/util/hydra_dateutil.py#L380-L428 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_all_attributes | def _get_all_attributes(network):
"""
Get all the complex mode attributes in the network so that they
can be used for mapping to resource scenarios later.
"""
attrs = network.attributes
for n in network.nodes:
attrs.extend(n.attributes)
for l in network.links:
attrs.e... | python | def _get_all_attributes(network):
"""
Get all the complex mode attributes in the network so that they
can be used for mapping to resource scenarios later.
"""
attrs = network.attributes
for n in network.nodes:
attrs.extend(n.attributes)
for l in network.links:
attrs.e... | [
"def",
"_get_all_attributes",
"(",
"network",
")",
":",
"attrs",
"=",
"network",
".",
"attributes",
"for",
"n",
"in",
"network",
".",
"nodes",
":",
"attrs",
".",
"extend",
"(",
"n",
".",
"attributes",
")",
"for",
"l",
"in",
"network",
".",
"links",
":"... | Get all the complex mode attributes in the network so that they
can be used for mapping to resource scenarios later. | [
"Get",
"all",
"the",
"complex",
"mode",
"attributes",
"in",
"the",
"network",
"so",
"that",
"they",
"can",
"be",
"used",
"for",
"mapping",
"to",
"resource",
"scenarios",
"later",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L103-L116 |
hydraplatform/hydra-base | hydra_base/lib/network.py | add_network | def add_network(network,**kwargs):
"""
Takes an entire network complex model and saves it to the DB. This
complex model includes links & scenarios (with resource data). Returns
the network's complex model.
As links connect two nodes using the node_ids, if the nodes are new
they will not yet h... | python | def add_network(network,**kwargs):
"""
Takes an entire network complex model and saves it to the DB. This
complex model includes links & scenarios (with resource data). Returns
the network's complex model.
As links connect two nodes using the node_ids, if the nodes are new
they will not yet h... | [
"def",
"add_network",
"(",
"network",
",",
"*",
"*",
"kwargs",
")",
":",
"db",
".",
"DBSession",
".",
"autoflush",
"=",
"False",
"start_time",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"log",
".",
"debug",
"(",
"\"Adding network\"",
")",
... | Takes an entire network complex model and saves it to the DB. This
complex model includes links & scenarios (with resource data). Returns
the network's complex model.
As links connect two nodes using the node_ids, if the nodes are new
they will not yet have node_ids. In this case, use negative ids as... | [
"Takes",
"an",
"entire",
"network",
"complex",
"model",
"and",
"saves",
"it",
"to",
"the",
"DB",
".",
"This",
"complex",
"model",
"includes",
"links",
"&",
"scenarios",
"(",
"with",
"resource",
"data",
")",
".",
"Returns",
"the",
"network",
"s",
"complex",... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L427-L575 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_all_resource_attributes | def _get_all_resource_attributes(network_id, template_id=None):
"""
Get all the attributes for the nodes, links and groups of a network.
Return these attributes as a dictionary, keyed on type (NODE, LINK, GROUP)
then by ID of the node or link.
"""
base_qry = db.DBSession.query(
... | python | def _get_all_resource_attributes(network_id, template_id=None):
"""
Get all the attributes for the nodes, links and groups of a network.
Return these attributes as a dictionary, keyed on type (NODE, LINK, GROUP)
then by ID of the node or link.
"""
base_qry = db.DBSession.query(
... | [
"def",
"_get_all_resource_attributes",
"(",
"network_id",
",",
"template_id",
"=",
"None",
")",
":",
"base_qry",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"ResourceAttr",
".",
"id",
".",
"label",
"(",
"'id'",
")",
",",
"ResourceAttr",
".",
"ref_key",
... | Get all the attributes for the nodes, links and groups of a network.
Return these attributes as a dictionary, keyed on type (NODE, LINK, GROUP)
then by ID of the node or link. | [
"Get",
"all",
"the",
"attributes",
"for",
"the",
"nodes",
"links",
"and",
"groups",
"of",
"a",
"network",
".",
"Return",
"these",
"attributes",
"as",
"a",
"dictionary",
"keyed",
"on",
"type",
"(",
"NODE",
"LINK",
"GROUP",
")",
"then",
"by",
"ID",
"of",
... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L577-L652 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_all_templates | def _get_all_templates(network_id, template_id):
"""
Get all the templates for the nodes, links and groups of a network.
Return these templates as a dictionary, keyed on type (NODE, LINK, GROUP)
then by ID of the node or link.
"""
base_qry = db.DBSession.query(
... | python | def _get_all_templates(network_id, template_id):
"""
Get all the templates for the nodes, links and groups of a network.
Return these templates as a dictionary, keyed on type (NODE, LINK, GROUP)
then by ID of the node or link.
"""
base_qry = db.DBSession.query(
... | [
"def",
"_get_all_templates",
"(",
"network_id",
",",
"template_id",
")",
":",
"base_qry",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"ResourceType",
".",
"ref_key",
".",
"label",
"(",
"'ref_key'",
")",
",",
"ResourceType",
".",
"node_id",
".",
"label",
... | Get all the templates for the nodes, links and groups of a network.
Return these templates as a dictionary, keyed on type (NODE, LINK, GROUP)
then by ID of the node or link. | [
"Get",
"all",
"the",
"templates",
"for",
"the",
"nodes",
"links",
"and",
"groups",
"of",
"a",
"network",
".",
"Return",
"these",
"templates",
"as",
"a",
"dictionary",
"keyed",
"on",
"type",
"(",
"NODE",
"LINK",
"GROUP",
")",
"then",
"by",
"ID",
"of",
"... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L654-L740 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_all_group_items | def _get_all_group_items(network_id):
"""
Get all the resource group items in the network, across all scenarios
returns a dictionary of dict objects, keyed on scenario_id
"""
base_qry = db.DBSession.query(ResourceGroupItem)
item_qry = base_qry.join(Scenario).filter(Scenario.network_id==... | python | def _get_all_group_items(network_id):
"""
Get all the resource group items in the network, across all scenarios
returns a dictionary of dict objects, keyed on scenario_id
"""
base_qry = db.DBSession.query(ResourceGroupItem)
item_qry = base_qry.join(Scenario).filter(Scenario.network_id==... | [
"def",
"_get_all_group_items",
"(",
"network_id",
")",
":",
"base_qry",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"ResourceGroupItem",
")",
"item_qry",
"=",
"base_qry",
".",
"join",
"(",
"Scenario",
")",
".",
"filter",
"(",
"Scenario",
".",
"network_id... | Get all the resource group items in the network, across all scenarios
returns a dictionary of dict objects, keyed on scenario_id | [
"Get",
"all",
"the",
"resource",
"group",
"items",
"in",
"the",
"network",
"across",
"all",
"scenarios",
"returns",
"a",
"dictionary",
"of",
"dict",
"objects",
"keyed",
"on",
"scenario_id"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L743-L769 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_all_resourcescenarios | def _get_all_resourcescenarios(network_id, user_id):
"""
Get all the resource scenarios in a network, across all scenarios
returns a dictionary of dict objects, keyed on scenario_id
"""
rs_qry = db.DBSession.query(
Dataset.type,
Dataset.unit_id,
... | python | def _get_all_resourcescenarios(network_id, user_id):
"""
Get all the resource scenarios in a network, across all scenarios
returns a dictionary of dict objects, keyed on scenario_id
"""
rs_qry = db.DBSession.query(
Dataset.type,
Dataset.unit_id,
... | [
"def",
"_get_all_resourcescenarios",
"(",
"network_id",
",",
"user_id",
")",
":",
"rs_qry",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Dataset",
".",
"type",
",",
"Dataset",
".",
"unit_id",
",",
"Dataset",
".",
"name",
",",
"Dataset",
".",
"hash",
... | Get all the resource scenarios in a network, across all scenarios
returns a dictionary of dict objects, keyed on scenario_id | [
"Get",
"all",
"the",
"resource",
"scenarios",
"in",
"a",
"network",
"across",
"all",
"scenarios",
"returns",
"a",
"dictionary",
"of",
"dict",
"objects",
"keyed",
"on",
"scenario_id"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L771-L835 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_metadata | def _get_metadata(network_id, user_id):
"""
Get all the metadata in a network, across all scenarios
returns a dictionary of dict objects, keyed on dataset ID
"""
log.info("Getting Metadata")
dataset_qry = db.DBSession.query(
Dataset
).outerjoin(DatasetOwner, and_(Data... | python | def _get_metadata(network_id, user_id):
"""
Get all the metadata in a network, across all scenarios
returns a dictionary of dict objects, keyed on dataset ID
"""
log.info("Getting Metadata")
dataset_qry = db.DBSession.query(
Dataset
).outerjoin(DatasetOwner, and_(Data... | [
"def",
"_get_metadata",
"(",
"network_id",
",",
"user_id",
")",
":",
"log",
".",
"info",
"(",
"\"Getting Metadata\"",
")",
"dataset_qry",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Dataset",
")",
".",
"outerjoin",
"(",
"DatasetOwner",
",",
"and_",
"(... | Get all the metadata in a network, across all scenarios
returns a dictionary of dict objects, keyed on dataset ID | [
"Get",
"all",
"the",
"metadata",
"in",
"a",
"network",
"across",
"all",
"scenarios",
"returns",
"a",
"dictionary",
"of",
"dict",
"objects",
"keyed",
"on",
"dataset",
"ID"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L838-L872 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_network_owners | def _get_network_owners(network_id):
"""
Get all the nodes in a network
"""
owners_i = db.DBSession.query(NetworkOwner).filter(
NetworkOwner.network_id==network_id).options(noload('network')).options(joinedload_all('user')).all()
owners = [JSONObject(owner_i) for owner_i... | python | def _get_network_owners(network_id):
"""
Get all the nodes in a network
"""
owners_i = db.DBSession.query(NetworkOwner).filter(
NetworkOwner.network_id==network_id).options(noload('network')).options(joinedload_all('user')).all()
owners = [JSONObject(owner_i) for owner_i... | [
"def",
"_get_network_owners",
"(",
"network_id",
")",
":",
"owners_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"NetworkOwner",
")",
".",
"filter",
"(",
"NetworkOwner",
".",
"network_id",
"==",
"network_id",
")",
".",
"options",
"(",
"noload",
"(",
... | Get all the nodes in a network | [
"Get",
"all",
"the",
"nodes",
"in",
"a",
"network"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L874-L883 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_nodes | def _get_nodes(network_id, template_id=None):
"""
Get all the nodes in a network
"""
extras = {'types':[], 'attributes':[]}
node_qry = db.DBSession.query(Node).filter(
Node.network_id==network_id,
Node.status=='A').options(
... | python | def _get_nodes(network_id, template_id=None):
"""
Get all the nodes in a network
"""
extras = {'types':[], 'attributes':[]}
node_qry = db.DBSession.query(Node).filter(
Node.network_id==network_id,
Node.status=='A').options(
... | [
"def",
"_get_nodes",
"(",
"network_id",
",",
"template_id",
"=",
"None",
")",
":",
"extras",
"=",
"{",
"'types'",
":",
"[",
"]",
",",
"'attributes'",
":",
"[",
"]",
"}",
"node_qry",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Node",
")",
".",
... | Get all the nodes in a network | [
"Get",
"all",
"the",
"nodes",
"in",
"a",
"network"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L885-L906 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_links | def _get_links(network_id, template_id=None):
"""
Get all the links in a network
"""
extras = {'types':[], 'attributes':[]}
link_qry = db.DBSession.query(Link).filter(
Link.network_id==network_id,
Link.status=='A').o... | python | def _get_links(network_id, template_id=None):
"""
Get all the links in a network
"""
extras = {'types':[], 'attributes':[]}
link_qry = db.DBSession.query(Link).filter(
Link.network_id==network_id,
Link.status=='A').o... | [
"def",
"_get_links",
"(",
"network_id",
",",
"template_id",
"=",
"None",
")",
":",
"extras",
"=",
"{",
"'types'",
":",
"[",
"]",
",",
"'attributes'",
":",
"[",
"]",
"}",
"link_qry",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Link",
")",
".",
... | Get all the links in a network | [
"Get",
"all",
"the",
"links",
"in",
"a",
"network"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L908-L929 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_groups | def _get_groups(network_id, template_id=None):
"""
Get all the resource groups in a network
"""
extras = {'types':[], 'attributes':[]}
group_qry = db.DBSession.query(ResourceGroup).filter(
ResourceGroup.network_id==network_id,
... | python | def _get_groups(network_id, template_id=None):
"""
Get all the resource groups in a network
"""
extras = {'types':[], 'attributes':[]}
group_qry = db.DBSession.query(ResourceGroup).filter(
ResourceGroup.network_id==network_id,
... | [
"def",
"_get_groups",
"(",
"network_id",
",",
"template_id",
"=",
"None",
")",
":",
"extras",
"=",
"{",
"'types'",
":",
"[",
"]",
",",
"'attributes'",
":",
"[",
"]",
"}",
"group_qry",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"ResourceGroup",
")"... | Get all the resource groups in a network | [
"Get",
"all",
"the",
"resource",
"groups",
"in",
"a",
"network"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L931-L952 |
hydraplatform/hydra-base | hydra_base/lib/network.py | _get_scenarios | def _get_scenarios(network_id, include_data, user_id, scenario_ids=None):
"""
Get all the scenarios in a network
"""
scen_qry = db.DBSession.query(Scenario).filter(
Scenario.network_id == network_id).options(
noload('network')).filter(
... | python | def _get_scenarios(network_id, include_data, user_id, scenario_ids=None):
"""
Get all the scenarios in a network
"""
scen_qry = db.DBSession.query(Scenario).filter(
Scenario.network_id == network_id).options(
noload('network')).filter(
... | [
"def",
"_get_scenarios",
"(",
"network_id",
",",
"include_data",
",",
"user_id",
",",
"scenario_ids",
"=",
"None",
")",
":",
"scen_qry",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Scenario",
")",
".",
"filter",
"(",
"Scenario",
".",
"network_id",
"==... | Get all the scenarios in a network | [
"Get",
"all",
"the",
"scenarios",
"in",
"a",
"network"
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L954-L984 |
hydraplatform/hydra-base | hydra_base/lib/network.py | get_network | def get_network(network_id, summary=False, include_data='N', scenario_ids=None, template_id=None, **kwargs):
"""
Return a whole network as a dictionary.
network_id: ID of the network to retrieve
include_data: 'Y' or 'N'. Indicate whether scenario data is to be returned.
... | python | def get_network(network_id, summary=False, include_data='N', scenario_ids=None, template_id=None, **kwargs):
"""
Return a whole network as a dictionary.
network_id: ID of the network to retrieve
include_data: 'Y' or 'N'. Indicate whether scenario data is to be returned.
... | [
"def",
"get_network",
"(",
"network_id",
",",
"summary",
"=",
"False",
",",
"include_data",
"=",
"'N'",
",",
"scenario_ids",
"=",
"None",
",",
"template_id",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"log",
".",
"debug",
"(",
"\"getting network %s\""... | Return a whole network as a dictionary.
network_id: ID of the network to retrieve
include_data: 'Y' or 'N'. Indicate whether scenario data is to be returned.
This has a significant speed impact as retrieving large amounts
of data can be expensive.
scen... | [
"Return",
"a",
"whole",
"network",
"as",
"a",
"dictionary",
".",
"network_id",
":",
"ID",
"of",
"the",
"network",
"to",
"retrieve",
"include_data",
":",
"Y",
"or",
"N",
".",
"Indicate",
"whether",
"scenario",
"data",
"is",
"to",
"be",
"returned",
".",
"T... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L986-L1057 |
hydraplatform/hydra-base | hydra_base/lib/network.py | get_nodes | def get_nodes(network_id, template_id=None, **kwargs):
"""
Get all the nodes in a network.
args:
network_id (int): The network in which to search
template_id (int): Only return nodes whose type is in this template.
"""
user_id = kwargs.get('user_id')
try:
... | python | def get_nodes(network_id, template_id=None, **kwargs):
"""
Get all the nodes in a network.
args:
network_id (int): The network in which to search
template_id (int): Only return nodes whose type is in this template.
"""
user_id = kwargs.get('user_id')
try:
... | [
"def",
"get_nodes",
"(",
"network_id",
",",
"template_id",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"user_id",
"=",
"kwargs",
".",
"get",
"(",
"'user_id'",
")",
"try",
":",
"net_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
")... | Get all the nodes in a network.
args:
network_id (int): The network in which to search
template_id (int): Only return nodes whose type is in this template. | [
"Get",
"all",
"the",
"nodes",
"in",
"a",
"network",
".",
"args",
":",
"network_id",
"(",
"int",
")",
":",
"The",
"network",
"in",
"which",
"to",
"search",
"template_id",
"(",
"int",
")",
":",
"Only",
"return",
"nodes",
"whose",
"type",
"is",
"in",
"t... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L1059-L1088 |
hydraplatform/hydra-base | hydra_base/lib/network.py | get_links | def get_links(network_id, template_id=None, **kwargs):
"""
Get all the links in a network.
args:
network_id (int): The network in which to search
template_id (int): Only return links whose type is in this template.
"""
user_id = kwargs.get('user_id')
try:
... | python | def get_links(network_id, template_id=None, **kwargs):
"""
Get all the links in a network.
args:
network_id (int): The network in which to search
template_id (int): Only return links whose type is in this template.
"""
user_id = kwargs.get('user_id')
try:
... | [
"def",
"get_links",
"(",
"network_id",
",",
"template_id",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"user_id",
"=",
"kwargs",
".",
"get",
"(",
"'user_id'",
")",
"try",
":",
"net_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
")... | Get all the links in a network.
args:
network_id (int): The network in which to search
template_id (int): Only return links whose type is in this template. | [
"Get",
"all",
"the",
"links",
"in",
"a",
"network",
".",
"args",
":",
"network_id",
"(",
"int",
")",
":",
"The",
"network",
"in",
"which",
"to",
"search",
"template_id",
"(",
"int",
")",
":",
"Only",
"return",
"links",
"whose",
"type",
"is",
"in",
"t... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L1090-L1120 |
hydraplatform/hydra-base | hydra_base/lib/network.py | get_groups | def get_groups(network_id, template_id=None, **kwargs):
"""
Get all the resource groups in a network.
args:
network_id (int): The network in which to search
template_id (int): Only return resource groups whose type is in this template.
"""
user_id = kwargs.get('user_i... | python | def get_groups(network_id, template_id=None, **kwargs):
"""
Get all the resource groups in a network.
args:
network_id (int): The network in which to search
template_id (int): Only return resource groups whose type is in this template.
"""
user_id = kwargs.get('user_i... | [
"def",
"get_groups",
"(",
"network_id",
",",
"template_id",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"user_id",
"=",
"kwargs",
".",
"get",
"(",
"'user_id'",
")",
"try",
":",
"net_i",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
"... | Get all the resource groups in a network.
args:
network_id (int): The network in which to search
template_id (int): Only return resource groups whose type is in this template. | [
"Get",
"all",
"the",
"resource",
"groups",
"in",
"a",
"network",
".",
"args",
":",
"network_id",
"(",
"int",
")",
":",
"The",
"network",
"in",
"which",
"to",
"search",
"template_id",
"(",
"int",
")",
":",
"Only",
"return",
"resource",
"groups",
"whose",
... | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L1123-L1153 |
hydraplatform/hydra-base | hydra_base/lib/network.py | get_network_by_name | def get_network_by_name(project_id, network_name,**kwargs):
"""
Return a whole network as a complex model.
"""
try:
res = db.DBSession.query(Network.id).filter(func.lower(Network.name).like(network_name.lower()), Network.project_id == project_id).one()
net = get_network(res.id, 'Y', Non... | python | def get_network_by_name(project_id, network_name,**kwargs):
"""
Return a whole network as a complex model.
"""
try:
res = db.DBSession.query(Network.id).filter(func.lower(Network.name).like(network_name.lower()), Network.project_id == project_id).one()
net = get_network(res.id, 'Y', Non... | [
"def",
"get_network_by_name",
"(",
"project_id",
",",
"network_name",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"res",
"=",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
".",
"id",
")",
".",
"filter",
"(",
"func",
".",
"lower",
"(",
"Net... | Return a whole network as a complex model. | [
"Return",
"a",
"whole",
"network",
"as",
"a",
"complex",
"model",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L1275-L1285 |
hydraplatform/hydra-base | hydra_base/lib/network.py | network_exists | def network_exists(project_id, network_name,**kwargs):
"""
Return a whole network as a complex model.
"""
try:
db.DBSession.query(Network.id).filter(func.lower(Network.name).like(network_name.lower()), Network.project_id == project_id).one()
return 'Y'
except NoResultFound:
r... | python | def network_exists(project_id, network_name,**kwargs):
"""
Return a whole network as a complex model.
"""
try:
db.DBSession.query(Network.id).filter(func.lower(Network.name).like(network_name.lower()), Network.project_id == project_id).one()
return 'Y'
except NoResultFound:
r... | [
"def",
"network_exists",
"(",
"project_id",
",",
"network_name",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"db",
".",
"DBSession",
".",
"query",
"(",
"Network",
".",
"id",
")",
".",
"filter",
"(",
"func",
".",
"lower",
"(",
"Network",
".",
"name... | Return a whole network as a complex model. | [
"Return",
"a",
"whole",
"network",
"as",
"a",
"complex",
"model",
"."
] | train | https://github.com/hydraplatform/hydra-base/blob/9251ff7946505f7a272c87837390acd1c435bc6e/hydra_base/lib/network.py#L1288-L1296 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.