partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | pcolor | r"""
Return a string that once printed is colorized.
:param text: Text to colorize
:type text: string
:param color: Color to use, one of :code:`'black'`, :code:`'red'`,
:code:`'green'`, :code:`'yellow'`, :code:`'blue'`,
:code:`'magenta'`, :code:`'cyan'`, :code:`... | pmisc/strings.py | def pcolor(text, color, indent=0):
r"""
Return a string that once printed is colorized.
:param text: Text to colorize
:type text: string
:param color: Color to use, one of :code:`'black'`, :code:`'red'`,
:code:`'green'`, :code:`'yellow'`, :code:`'blue'`,
:co... | def pcolor(text, color, indent=0):
r"""
Return a string that once printed is colorized.
:param text: Text to colorize
:type text: string
:param color: Color to use, one of :code:`'black'`, :code:`'red'`,
:code:`'green'`, :code:`'yellow'`, :code:`'blue'`,
:co... | [
"r",
"Return",
"a",
"string",
"that",
"once",
"printed",
"is",
"colorized",
"."
] | pmacosta/pmisc | python | https://github.com/pmacosta/pmisc/blob/dd2bb32e59eee872f1ef2db2d9921a396ab9f50b/pmisc/strings.py#L161-L212 | [
"def",
"pcolor",
"(",
"text",
",",
"color",
",",
"indent",
"=",
"0",
")",
":",
"esc_dict",
"=",
"{",
"\"black\"",
":",
"30",
",",
"\"red\"",
":",
"31",
",",
"\"green\"",
":",
"32",
",",
"\"yellow\"",
":",
"33",
",",
"\"blue\"",
":",
"34",
",",
"\... | dd2bb32e59eee872f1ef2db2d9921a396ab9f50b |
train | quote_str | r"""
Add extra quotes to a string.
If the argument is not a string it is returned unmodified.
:param obj: Object
:type obj: any
:rtype: Same as argument
For example:
>>> import pmisc
>>> pmisc.quote_str(5)
5
>>> pmisc.quote_str('Hello!')
'"Hello!"'
... | pmisc/strings.py | def quote_str(obj):
r"""
Add extra quotes to a string.
If the argument is not a string it is returned unmodified.
:param obj: Object
:type obj: any
:rtype: Same as argument
For example:
>>> import pmisc
>>> pmisc.quote_str(5)
5
>>> pmisc.quote_str('Hello... | def quote_str(obj):
r"""
Add extra quotes to a string.
If the argument is not a string it is returned unmodified.
:param obj: Object
:type obj: any
:rtype: Same as argument
For example:
>>> import pmisc
>>> pmisc.quote_str(5)
5
>>> pmisc.quote_str('Hello... | [
"r",
"Add",
"extra",
"quotes",
"to",
"a",
"string",
"."
] | pmacosta/pmisc | python | https://github.com/pmacosta/pmisc/blob/dd2bb32e59eee872f1ef2db2d9921a396ab9f50b/pmisc/strings.py#L215-L238 | [
"def",
"quote_str",
"(",
"obj",
")",
":",
"if",
"not",
"isinstance",
"(",
"obj",
",",
"str",
")",
":",
"return",
"obj",
"return",
"\"'{obj}'\"",
".",
"format",
"(",
"obj",
"=",
"obj",
")",
"if",
"'\"'",
"in",
"obj",
"else",
"'\"{obj}\"'",
".",
"forma... | dd2bb32e59eee872f1ef2db2d9921a396ab9f50b |
train | strframe | Return a string with a frame record pretty-formatted.
The record is typically an item in a list generated by `inspect.stack()
<https://docs.python.org/3/library/inspect.html#inspect.stack>`_).
:param obj: Frame record
:type obj: tuple
:param extended: Flag that indicates whether contents of the ... | pmisc/strings.py | def strframe(obj, extended=False):
"""
Return a string with a frame record pretty-formatted.
The record is typically an item in a list generated by `inspect.stack()
<https://docs.python.org/3/library/inspect.html#inspect.stack>`_).
:param obj: Frame record
:type obj: tuple
:param extende... | def strframe(obj, extended=False):
"""
Return a string with a frame record pretty-formatted.
The record is typically an item in a list generated by `inspect.stack()
<https://docs.python.org/3/library/inspect.html#inspect.stack>`_).
:param obj: Frame record
:type obj: tuple
:param extende... | [
"Return",
"a",
"string",
"with",
"a",
"frame",
"record",
"pretty",
"-",
"formatted",
"."
] | pmacosta/pmisc | python | https://github.com/pmacosta/pmisc/blob/dd2bb32e59eee872f1ef2db2d9921a396ab9f50b/pmisc/strings.py#L241-L279 | [
"def",
"strframe",
"(",
"obj",
",",
"extended",
"=",
"False",
")",
":",
"# Stack frame -> (frame object [0], filename [1], line number of current",
"# line [2], function name [3], list of lines of context from source",
"# code [4], index of current line within list [5])",
"fname",
"=",
... | dd2bb32e59eee872f1ef2db2d9921a396ab9f50b |
train | Variables.set | Set variable values via a dictionary mapping name to value. | optimix/_variables.py | def set(self, x):
"""
Set variable values via a dictionary mapping name to value.
"""
for name, value in iter(x.items()):
if hasattr(value, "ndim"):
if self[name].value.ndim < value.ndim:
self[name].value.itemset(value.squeeze())
... | def set(self, x):
"""
Set variable values via a dictionary mapping name to value.
"""
for name, value in iter(x.items()):
if hasattr(value, "ndim"):
if self[name].value.ndim < value.ndim:
self[name].value.itemset(value.squeeze())
... | [
"Set",
"variable",
"values",
"via",
"a",
"dictionary",
"mapping",
"name",
"to",
"value",
"."
] | limix/optimix | python | https://github.com/limix/optimix/blob/d7b1356df259c9f6ee0d658258fb47d0074fc416/optimix/_variables.py#L6-L17 | [
"def",
"set",
"(",
"self",
",",
"x",
")",
":",
"for",
"name",
",",
"value",
"in",
"iter",
"(",
"x",
".",
"items",
"(",
")",
")",
":",
"if",
"hasattr",
"(",
"value",
",",
"\"ndim\"",
")",
":",
"if",
"self",
"[",
"name",
"]",
".",
"value",
".",... | d7b1356df259c9f6ee0d658258fb47d0074fc416 |
train | Variables.select | Return a subset of variables according to ``fixed``. | optimix/_variables.py | def select(self, fixed):
"""
Return a subset of variables according to ``fixed``.
"""
names = [n for n in self.names() if self[n].isfixed == fixed]
return Variables({n: self[n] for n in names}) | def select(self, fixed):
"""
Return a subset of variables according to ``fixed``.
"""
names = [n for n in self.names() if self[n].isfixed == fixed]
return Variables({n: self[n] for n in names}) | [
"Return",
"a",
"subset",
"of",
"variables",
"according",
"to",
"fixed",
"."
] | limix/optimix | python | https://github.com/limix/optimix/blob/d7b1356df259c9f6ee0d658258fb47d0074fc416/optimix/_variables.py#L19-L24 | [
"def",
"select",
"(",
"self",
",",
"fixed",
")",
":",
"names",
"=",
"[",
"n",
"for",
"n",
"in",
"self",
".",
"names",
"(",
")",
"if",
"self",
"[",
"n",
"]",
".",
"isfixed",
"==",
"fixed",
"]",
"return",
"Variables",
"(",
"{",
"n",
":",
"self",
... | d7b1356df259c9f6ee0d658258fb47d0074fc416 |
train | USPSInterface.validate | Return True if this is a valid USPS tracking number. | packagetrack/usps.py | def validate(self, tracking_number):
"Return True if this is a valid USPS tracking number."
tracking_num = tracking_number[:-1].replace(' ', '')
odd_total = 0
even_total = 0
for ii, digit in enumerate(tracking_num):
if ii % 2:
odd_total += int(digit)
... | def validate(self, tracking_number):
"Return True if this is a valid USPS tracking number."
tracking_num = tracking_number[:-1].replace(' ', '')
odd_total = 0
even_total = 0
for ii, digit in enumerate(tracking_num):
if ii % 2:
odd_total += int(digit)
... | [
"Return",
"True",
"if",
"this",
"is",
"a",
"valid",
"USPS",
"tracking",
"number",
"."
] | storborg/packagetrack | python | https://github.com/storborg/packagetrack/blob/e1e5417565b8e2a919936713e1939db5aa895e56/packagetrack/usps.py#L11-L23 | [
"def",
"validate",
"(",
"self",
",",
"tracking_number",
")",
":",
"tracking_num",
"=",
"tracking_number",
"[",
":",
"-",
"1",
"]",
".",
"replace",
"(",
"' '",
",",
"''",
")",
"odd_total",
"=",
"0",
"even_total",
"=",
"0",
"for",
"ii",
",",
"digit",
"... | e1e5417565b8e2a919936713e1939db5aa895e56 |
train | UPSInterface.validate | Return True if this is a valid UPS tracking number. | packagetrack/ups.py | def validate(self, tracking_number):
"Return True if this is a valid UPS tracking number."
tracking_num = tracking_number[2:-1]
odd_total = 0
even_total = 0
for ii, digit in enumerate(tracking_num.upper()):
try:
value = int(digit)
except V... | def validate(self, tracking_number):
"Return True if this is a valid UPS tracking number."
tracking_num = tracking_number[2:-1]
odd_total = 0
even_total = 0
for ii, digit in enumerate(tracking_num.upper()):
try:
value = int(digit)
except V... | [
"Return",
"True",
"if",
"this",
"is",
"a",
"valid",
"UPS",
"tracking",
"number",
"."
] | storborg/packagetrack | python | https://github.com/storborg/packagetrack/blob/e1e5417565b8e2a919936713e1939db5aa895e56/packagetrack/ups.py#L18-L36 | [
"def",
"validate",
"(",
"self",
",",
"tracking_number",
")",
":",
"tracking_num",
"=",
"tracking_number",
"[",
"2",
":",
"-",
"1",
"]",
"odd_total",
"=",
"0",
"even_total",
"=",
"0",
"for",
"ii",
",",
"digit",
"in",
"enumerate",
"(",
"tracking_num",
".",... | e1e5417565b8e2a919936713e1939db5aa895e56 |
train | UPSInterface.track | Track a UPS package by number. Returns just a delivery date. | packagetrack/ups.py | def track(self, tracking_number):
"Track a UPS package by number. Returns just a delivery date."
resp = self.send_request(tracking_number)
return self.parse_response(resp) | def track(self, tracking_number):
"Track a UPS package by number. Returns just a delivery date."
resp = self.send_request(tracking_number)
return self.parse_response(resp) | [
"Track",
"a",
"UPS",
"package",
"by",
"number",
".",
"Returns",
"just",
"a",
"delivery",
"date",
"."
] | storborg/packagetrack | python | https://github.com/storborg/packagetrack/blob/e1e5417565b8e2a919936713e1939db5aa895e56/packagetrack/ups.py#L86-L89 | [
"def",
"track",
"(",
"self",
",",
"tracking_number",
")",
":",
"resp",
"=",
"self",
".",
"send_request",
"(",
"tracking_number",
")",
"return",
"self",
".",
"parse_response",
"(",
"resp",
")"
] | e1e5417565b8e2a919936713e1939db5aa895e56 |
train | Reach.load | r"""
Read a file in word2vec .txt format.
The load function will raise a ValueError when trying to load items
which do not conform to line lengths.
Parameters
----------
pathtovector : string
The path to the vector file.
header : bool
Whe... | reach/reach.py | def load(pathtovector,
wordlist=(),
num_to_load=None,
truncate_embeddings=None,
unk_word=None,
sep=" "):
r"""
Read a file in word2vec .txt format.
The load function will raise a ValueError when trying to load items
which d... | def load(pathtovector,
wordlist=(),
num_to_load=None,
truncate_embeddings=None,
unk_word=None,
sep=" "):
r"""
Read a file in word2vec .txt format.
The load function will raise a ValueError when trying to load items
which d... | [
"r",
"Read",
"a",
"file",
"in",
"word2vec",
".",
"txt",
"format",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L74-L133 | [
"def",
"load",
"(",
"pathtovector",
",",
"wordlist",
"=",
"(",
")",
",",
"num_to_load",
"=",
"None",
",",
"truncate_embeddings",
"=",
"None",
",",
"unk_word",
"=",
"None",
",",
"sep",
"=",
"\" \"",
")",
":",
"vectors",
",",
"items",
"=",
"Reach",
".",
... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach._load | Load a matrix and wordlist from a .vec file. | reach/reach.py | def _load(pathtovector,
wordlist,
num_to_load=None,
truncate_embeddings=None,
sep=" "):
"""Load a matrix and wordlist from a .vec file."""
vectors = []
addedwords = set()
words = []
try:
wordlist = set(wordlist)... | def _load(pathtovector,
wordlist,
num_to_load=None,
truncate_embeddings=None,
sep=" "):
"""Load a matrix and wordlist from a .vec file."""
vectors = []
addedwords = set()
words = []
try:
wordlist = set(wordlist)... | [
"Load",
"a",
"matrix",
"and",
"wordlist",
"from",
"a",
".",
"vec",
"file",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L136-L205 | [
"def",
"_load",
"(",
"pathtovector",
",",
"wordlist",
",",
"num_to_load",
"=",
"None",
",",
"truncate_embeddings",
"=",
"None",
",",
"sep",
"=",
"\" \"",
")",
":",
"vectors",
"=",
"[",
"]",
"addedwords",
"=",
"set",
"(",
")",
"words",
"=",
"[",
"]",
... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.vectorize | Vectorize a sentence by replacing all items with their vectors.
Parameters
----------
tokens : object or list of objects
The tokens to vectorize.
remove_oov : bool, optional, default False
Whether to remove OOV items. If False, OOV items are replaced by
... | reach/reach.py | def vectorize(self, tokens, remove_oov=False, norm=False):
"""
Vectorize a sentence by replacing all items with their vectors.
Parameters
----------
tokens : object or list of objects
The tokens to vectorize.
remove_oov : bool, optional, default False
... | def vectorize(self, tokens, remove_oov=False, norm=False):
"""
Vectorize a sentence by replacing all items with their vectors.
Parameters
----------
tokens : object or list of objects
The tokens to vectorize.
remove_oov : bool, optional, default False
... | [
"Vectorize",
"a",
"sentence",
"by",
"replacing",
"all",
"items",
"with",
"their",
"vectors",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L211-L245 | [
"def",
"vectorize",
"(",
"self",
",",
"tokens",
",",
"remove_oov",
"=",
"False",
",",
"norm",
"=",
"False",
")",
":",
"if",
"not",
"tokens",
":",
"raise",
"ValueError",
"(",
"\"You supplied an empty list.\"",
")",
"index",
"=",
"list",
"(",
"self",
".",
... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.bow | Create a bow representation of a list of tokens.
Parameters
----------
tokens : list.
The list of items to change into a bag of words representation.
remove_oov : bool.
Whether to remove OOV items from the input.
If this is True, the length of the ret... | reach/reach.py | def bow(self, tokens, remove_oov=False):
"""
Create a bow representation of a list of tokens.
Parameters
----------
tokens : list.
The list of items to change into a bag of words representation.
remove_oov : bool.
Whether to remove OOV items from ... | def bow(self, tokens, remove_oov=False):
"""
Create a bow representation of a list of tokens.
Parameters
----------
tokens : list.
The list of items to change into a bag of words representation.
remove_oov : bool.
Whether to remove OOV items from ... | [
"Create",
"a",
"bow",
"representation",
"of",
"a",
"list",
"of",
"tokens",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L247-L279 | [
"def",
"bow",
"(",
"self",
",",
"tokens",
",",
"remove_oov",
"=",
"False",
")",
":",
"if",
"remove_oov",
":",
"tokens",
"=",
"[",
"x",
"for",
"x",
"in",
"tokens",
"if",
"x",
"in",
"self",
".",
"items",
"]",
"for",
"t",
"in",
"tokens",
":",
"try",... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.transform | Transform a corpus by repeated calls to vectorize, defined above.
Parameters
----------
corpus : A list of strings, list of list of strings.
Represents a corpus as a list of sentences, where sentences
can either be strings or lists of tokens.
remove_oov : bool, o... | reach/reach.py | def transform(self, corpus, remove_oov=False, norm=False):
"""
Transform a corpus by repeated calls to vectorize, defined above.
Parameters
----------
corpus : A list of strings, list of list of strings.
Represents a corpus as a list of sentences, where sentences
... | def transform(self, corpus, remove_oov=False, norm=False):
"""
Transform a corpus by repeated calls to vectorize, defined above.
Parameters
----------
corpus : A list of strings, list of list of strings.
Represents a corpus as a list of sentences, where sentences
... | [
"Transform",
"a",
"corpus",
"by",
"repeated",
"calls",
"to",
"vectorize",
"defined",
"above",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L281-L303 | [
"def",
"transform",
"(",
"self",
",",
"corpus",
",",
"remove_oov",
"=",
"False",
",",
"norm",
"=",
"False",
")",
":",
"return",
"[",
"self",
".",
"vectorize",
"(",
"s",
",",
"remove_oov",
"=",
"remove_oov",
",",
"norm",
"=",
"norm",
")",
"for",
"s",
... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.most_similar | Return the num most similar items to a given list of items.
Parameters
----------
items : list of objects or a single object.
The items to get the most similar items to.
num : int, optional, default 10
The number of most similar items to retrieve.
batch_s... | reach/reach.py | def most_similar(self,
items,
num=10,
batch_size=100,
show_progressbar=False,
return_names=True):
"""
Return the num most similar items to a given list of items.
Parameters
---------... | def most_similar(self,
items,
num=10,
batch_size=100,
show_progressbar=False,
return_names=True):
"""
Return the num most similar items to a given list of items.
Parameters
---------... | [
"Return",
"the",
"num",
"most",
"similar",
"items",
"to",
"a",
"given",
"list",
"of",
"items",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L305-L356 | [
"def",
"most_similar",
"(",
"self",
",",
"items",
",",
"num",
"=",
"10",
",",
"batch_size",
"=",
"100",
",",
"show_progressbar",
"=",
"False",
",",
"return_names",
"=",
"True",
")",
":",
"# This line allows users to input single items.",
"# We used to rely on string... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.threshold | Return all items whose similarity is higher than threshold.
Parameters
----------
items : list of objects or a single object.
The items to get the most similar items to.
threshold : float, optional, default .5
The radius within which to retrieve items.
ba... | reach/reach.py | def threshold(self,
items,
threshold=.5,
batch_size=100,
show_progressbar=False,
return_names=True):
"""
Return all items whose similarity is higher than threshold.
Parameters
----------
it... | def threshold(self,
items,
threshold=.5,
batch_size=100,
show_progressbar=False,
return_names=True):
"""
Return all items whose similarity is higher than threshold.
Parameters
----------
it... | [
"Return",
"all",
"items",
"whose",
"similarity",
"is",
"higher",
"than",
"threshold",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L358-L409 | [
"def",
"threshold",
"(",
"self",
",",
"items",
",",
"threshold",
"=",
".5",
",",
"batch_size",
"=",
"100",
",",
"show_progressbar",
"=",
"False",
",",
"return_names",
"=",
"True",
")",
":",
"# This line allows users to input single items.",
"# We used to rely on str... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.nearest_neighbor | Find the nearest neighbors to some arbitrary vector.
This function is meant to be used in composition operations. The
most_similar function can only handle items that are in vocab, and
looks up their vector through a dictionary. Compositions, e.g.
"King - man + woman" are necessarily no... | reach/reach.py | def nearest_neighbor(self,
vectors,
num=10,
batch_size=100,
show_progressbar=False,
return_names=True):
"""
Find the nearest neighbors to some arbitrary vector.
This func... | def nearest_neighbor(self,
vectors,
num=10,
batch_size=100,
show_progressbar=False,
return_names=True):
"""
Find the nearest neighbors to some arbitrary vector.
This func... | [
"Find",
"the",
"nearest",
"neighbors",
"to",
"some",
"arbitrary",
"vector",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L411-L459 | [
"def",
"nearest_neighbor",
"(",
"self",
",",
"vectors",
",",
"num",
"=",
"10",
",",
"batch_size",
"=",
"100",
",",
"show_progressbar",
"=",
"False",
",",
"return_names",
"=",
"True",
")",
":",
"vectors",
"=",
"np",
".",
"array",
"(",
"vectors",
")",
"i... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.nearest_neighbor_threshold | Find the nearest neighbors to some arbitrary vector.
This function is meant to be used in composition operations. The
most_similar function can only handle items that are in vocab, and
looks up their vector through a dictionary. Compositions, e.g.
"King - man + woman" are necessarily no... | reach/reach.py | def nearest_neighbor_threshold(self,
vectors,
threshold=.5,
batch_size=100,
show_progressbar=False,
return_names=True):
"""
Find ... | def nearest_neighbor_threshold(self,
vectors,
threshold=.5,
batch_size=100,
show_progressbar=False,
return_names=True):
"""
Find ... | [
"Find",
"the",
"nearest",
"neighbors",
"to",
"some",
"arbitrary",
"vector",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L461-L509 | [
"def",
"nearest_neighbor_threshold",
"(",
"self",
",",
"vectors",
",",
"threshold",
"=",
".5",
",",
"batch_size",
"=",
"100",
",",
"show_progressbar",
"=",
"False",
",",
"return_names",
"=",
"True",
")",
":",
"vectors",
"=",
"np",
".",
"array",
"(",
"vecto... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach._threshold_batch | Batched cosine distance. | reach/reach.py | def _threshold_batch(self,
vectors,
batch_size,
threshold,
show_progressbar,
return_names):
"""Batched cosine distance."""
vectors = self.normalize(vectors)
# Single tran... | def _threshold_batch(self,
vectors,
batch_size,
threshold,
show_progressbar,
return_names):
"""Batched cosine distance."""
vectors = self.normalize(vectors)
# Single tran... | [
"Batched",
"cosine",
"distance",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L511-L536 | [
"def",
"_threshold_batch",
"(",
"self",
",",
"vectors",
",",
"batch_size",
",",
"threshold",
",",
"show_progressbar",
",",
"return_names",
")",
":",
"vectors",
"=",
"self",
".",
"normalize",
"(",
"vectors",
")",
"# Single transpose, makes things faster.",
"reference... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach._batch | Batched cosine distance. | reach/reach.py | def _batch(self,
vectors,
batch_size,
num,
show_progressbar,
return_names):
"""Batched cosine distance."""
vectors = self.normalize(vectors)
# Single transpose, makes things faster.
reference_transposed = self.no... | def _batch(self,
vectors,
batch_size,
num,
show_progressbar,
return_names):
"""Batched cosine distance."""
vectors = self.normalize(vectors)
# Single transpose, makes things faster.
reference_transposed = self.no... | [
"Batched",
"cosine",
"distance",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L538-L568 | [
"def",
"_batch",
"(",
"self",
",",
"vectors",
",",
"batch_size",
",",
"num",
",",
"show_progressbar",
",",
"return_names",
")",
":",
"vectors",
"=",
"self",
".",
"normalize",
"(",
"vectors",
")",
"# Single transpose, makes things faster.",
"reference_transposed",
... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.normalize | Normalize a matrix of row vectors to unit length.
Contains a shortcut if there are no zero vectors in the matrix.
If there are zero vectors, we do some indexing tricks to avoid
dividing by 0.
Parameters
----------
vectors : np.array
The vectors to normalize.... | reach/reach.py | def normalize(vectors):
"""
Normalize a matrix of row vectors to unit length.
Contains a shortcut if there are no zero vectors in the matrix.
If there are zero vectors, we do some indexing tricks to avoid
dividing by 0.
Parameters
----------
vectors : np... | def normalize(vectors):
"""
Normalize a matrix of row vectors to unit length.
Contains a shortcut if there are no zero vectors in the matrix.
If there are zero vectors, we do some indexing tricks to avoid
dividing by 0.
Parameters
----------
vectors : np... | [
"Normalize",
"a",
"matrix",
"of",
"row",
"vectors",
"to",
"unit",
"length",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L571-L610 | [
"def",
"normalize",
"(",
"vectors",
")",
":",
"if",
"np",
".",
"ndim",
"(",
"vectors",
")",
"==",
"1",
":",
"norm",
"=",
"np",
".",
"linalg",
".",
"norm",
"(",
"vectors",
")",
"if",
"norm",
"==",
"0",
":",
"return",
"np",
".",
"zeros_like",
"(",
... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.vector_similarity | Compute the similarity between a vector and a set of items. | reach/reach.py | def vector_similarity(self, vector, items):
"""Compute the similarity between a vector and a set of items."""
vector = self.normalize(vector)
items_vec = np.stack([self.norm_vectors[self.items[x]] for x in items])
return vector.dot(items_vec.T) | def vector_similarity(self, vector, items):
"""Compute the similarity between a vector and a set of items."""
vector = self.normalize(vector)
items_vec = np.stack([self.norm_vectors[self.items[x]] for x in items])
return vector.dot(items_vec.T) | [
"Compute",
"the",
"similarity",
"between",
"a",
"vector",
"and",
"a",
"set",
"of",
"items",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L612-L616 | [
"def",
"vector_similarity",
"(",
"self",
",",
"vector",
",",
"items",
")",
":",
"vector",
"=",
"self",
".",
"normalize",
"(",
"vector",
")",
"items_vec",
"=",
"np",
".",
"stack",
"(",
"[",
"self",
".",
"norm_vectors",
"[",
"self",
".",
"items",
"[",
... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.similarity | Compute the similarity between two sets of items.
Parameters
----------
i1 : object
The first set of items.
i2 : object
The second set of item.
Returns
-------
sim : array of floats
An array of similarity scores between 1 and ... | reach/reach.py | def similarity(self, i1, i2):
"""
Compute the similarity between two sets of items.
Parameters
----------
i1 : object
The first set of items.
i2 : object
The second set of item.
Returns
-------
sim : array of floats
... | def similarity(self, i1, i2):
"""
Compute the similarity between two sets of items.
Parameters
----------
i1 : object
The first set of items.
i2 : object
The second set of item.
Returns
-------
sim : array of floats
... | [
"Compute",
"the",
"similarity",
"between",
"two",
"sets",
"of",
"items",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L618-L647 | [
"def",
"similarity",
"(",
"self",
",",
"i1",
",",
"i2",
")",
":",
"try",
":",
"if",
"i1",
"in",
"self",
".",
"items",
":",
"i1",
"=",
"[",
"i1",
"]",
"except",
"TypeError",
":",
"pass",
"try",
":",
"if",
"i2",
"in",
"self",
".",
"items",
":",
... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.prune | Prune the current reach instance by removing items.
Parameters
----------
wordlist : list of str
A list of words to keep. Note that this wordlist need not include
all words in the Reach instance. Any words which are in the
wordlist, but not in the reach insta... | reach/reach.py | def prune(self, wordlist):
"""
Prune the current reach instance by removing items.
Parameters
----------
wordlist : list of str
A list of words to keep. Note that this wordlist need not include
all words in the Reach instance. Any words which are in the
... | def prune(self, wordlist):
"""
Prune the current reach instance by removing items.
Parameters
----------
wordlist : list of str
A list of words to keep. Note that this wordlist need not include
all words in the Reach instance. Any words which are in the
... | [
"Prune",
"the",
"current",
"reach",
"instance",
"by",
"removing",
"items",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L649-L673 | [
"def",
"prune",
"(",
"self",
",",
"wordlist",
")",
":",
"# Remove duplicates",
"wordlist",
"=",
"set",
"(",
"wordlist",
")",
".",
"intersection",
"(",
"set",
"(",
"self",
".",
"items",
".",
"keys",
"(",
")",
")",
")",
"indices",
"=",
"[",
"self",
"."... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.save | Save the current vector space in word2vec format.
Parameters
----------
path : str
The path to save the vector file to.
write_header : bool, optional, default True
Whether to write a word2vec-style header as the first line of the
file | reach/reach.py | def save(self, path, write_header=True):
"""
Save the current vector space in word2vec format.
Parameters
----------
path : str
The path to save the vector file to.
write_header : bool, optional, default True
Whether to write a word2vec-style head... | def save(self, path, write_header=True):
"""
Save the current vector space in word2vec format.
Parameters
----------
path : str
The path to save the vector file to.
write_header : bool, optional, default True
Whether to write a word2vec-style head... | [
"Save",
"the",
"current",
"vector",
"space",
"in",
"word2vec",
"format",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L675-L700 | [
"def",
"save",
"(",
"self",
",",
"path",
",",
"write_header",
"=",
"True",
")",
":",
"with",
"open",
"(",
"path",
",",
"'w'",
")",
"as",
"f",
":",
"if",
"write_header",
":",
"f",
".",
"write",
"(",
"u\"{0} {1}\\n\"",
".",
"format",
"(",
"str",
"(",... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.save_fast_format | Save a reach instance in a fast format.
The reach fast format stores the words and vectors of a Reach instance
separately in a JSON and numpy format, respectively.
Parameters
----------
filename : str
The prefix to add to the saved filename. Note that this is not th... | reach/reach.py | def save_fast_format(self, filename):
"""
Save a reach instance in a fast format.
The reach fast format stores the words and vectors of a Reach instance
separately in a JSON and numpy format, respectively.
Parameters
----------
filename : str
The pre... | def save_fast_format(self, filename):
"""
Save a reach instance in a fast format.
The reach fast format stores the words and vectors of a Reach instance
separately in a JSON and numpy format, respectively.
Parameters
----------
filename : str
The pre... | [
"Save",
"a",
"reach",
"instance",
"in",
"a",
"fast",
"format",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L702-L724 | [
"def",
"save_fast_format",
"(",
"self",
",",
"filename",
")",
":",
"items",
",",
"_",
"=",
"zip",
"(",
"*",
"sorted",
"(",
"self",
".",
"items",
".",
"items",
"(",
")",
",",
"key",
"=",
"lambda",
"x",
":",
"x",
"[",
"1",
"]",
")",
")",
"items",... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach.load_fast_format | Load a reach instance in fast format.
As described above, the fast format stores the words and vectors of the
Reach instance separately, and is drastically faster than loading from
.txt files.
Parameters
----------
filename : str
The filename prefix from whi... | reach/reach.py | def load_fast_format(filename):
"""
Load a reach instance in fast format.
As described above, the fast format stores the words and vectors of the
Reach instance separately, and is drastically faster than loading from
.txt files.
Parameters
----------
fil... | def load_fast_format(filename):
"""
Load a reach instance in fast format.
As described above, the fast format stores the words and vectors of the
Reach instance separately, and is drastically faster than loading from
.txt files.
Parameters
----------
fil... | [
"Load",
"a",
"reach",
"instance",
"in",
"fast",
"format",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L727-L745 | [
"def",
"load_fast_format",
"(",
"filename",
")",
":",
"words",
",",
"unk_index",
",",
"name",
",",
"vectors",
"=",
"Reach",
".",
"_load_fast",
"(",
"filename",
")",
"return",
"Reach",
"(",
"vectors",
",",
"words",
",",
"unk_index",
"=",
"unk_index",
",",
... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | Reach._load_fast | Sub for fast loader. | reach/reach.py | def _load_fast(filename):
"""Sub for fast loader."""
it = json.load(open("{}_items.json".format(filename)))
words, unk_index, name = it["items"], it["unk_index"], it["name"]
vectors = np.load(open("{}_vectors.npy".format(filename), 'rb'))
return words, unk_index, name, vectors | def _load_fast(filename):
"""Sub for fast loader."""
it = json.load(open("{}_items.json".format(filename)))
words, unk_index, name = it["items"], it["unk_index"], it["name"]
vectors = np.load(open("{}_vectors.npy".format(filename), 'rb'))
return words, unk_index, name, vectors | [
"Sub",
"for",
"fast",
"loader",
"."
] | stephantul/reach | python | https://github.com/stephantul/reach/blob/e5ed0cc895d17429e797c6d7dd57bce82ff00d5d/reach/reach.py#L748-L753 | [
"def",
"_load_fast",
"(",
"filename",
")",
":",
"it",
"=",
"json",
".",
"load",
"(",
"open",
"(",
"\"{}_items.json\"",
".",
"format",
"(",
"filename",
")",
")",
")",
"words",
",",
"unk_index",
",",
"name",
"=",
"it",
"[",
"\"items\"",
"]",
",",
"it",... | e5ed0cc895d17429e797c6d7dd57bce82ff00d5d |
train | demo_usage | Plots a noisy sine curve and the fitting to it.
Also presents the error and the error in the
approximation of its first derivative (cosine curve)
Usage example for benchmarking:
$ time python sine.py --nhead 3 --ntail 3 --n-fit 500000 --n-data 50000
Usage example for plotting:
$ python sine.... | examples/sine.py | def demo_usage(n_data=50, n_fit=537, nhead=5, ntail=5, plot=False, alt=0):
"""
Plots a noisy sine curve and the fitting to it.
Also presents the error and the error in the
approximation of its first derivative (cosine curve)
Usage example for benchmarking:
$ time python sine.py --nhead 3 --nta... | def demo_usage(n_data=50, n_fit=537, nhead=5, ntail=5, plot=False, alt=0):
"""
Plots a noisy sine curve and the fitting to it.
Also presents the error and the error in the
approximation of its first derivative (cosine curve)
Usage example for benchmarking:
$ time python sine.py --nhead 3 --nta... | [
"Plots",
"a",
"noisy",
"sine",
"curve",
"and",
"the",
"fitting",
"to",
"it",
".",
"Also",
"presents",
"the",
"error",
"and",
"the",
"error",
"in",
"the",
"approximation",
"of",
"its",
"first",
"derivative",
"(",
"cosine",
"curve",
")"
] | bjodah/finitediff | python | https://github.com/bjodah/finitediff/blob/c1b1c6840512d2206e2f97315d9bf1738c1ca3d3/examples/sine.py#L13-L83 | [
"def",
"demo_usage",
"(",
"n_data",
"=",
"50",
",",
"n_fit",
"=",
"537",
",",
"nhead",
"=",
"5",
",",
"ntail",
"=",
"5",
",",
"plot",
"=",
"False",
",",
"alt",
"=",
"0",
")",
":",
"x0",
",",
"xend",
"=",
"0",
",",
"5",
"# shaky linspace -5% to +5... | c1b1c6840512d2206e2f97315d9bf1738c1ca3d3 |
train | demo_err | This demo shows how the error in the estimate varies depending
on how many data points are included in the interpolation
(m parameter in this function). | examples/err.py | def demo_err():
"""
This demo shows how the error in the estimate varies depending
on how many data points are included in the interpolation
(m parameter in this function).
"""
max_order = 7
n = 20
l = 0.25
fmt1 = '{0: <5s}\t{1: <21s}\t{2: >21s}\t{3: >21s}\t{4: >21s}'
fmt2 = '{0:... | def demo_err():
"""
This demo shows how the error in the estimate varies depending
on how many data points are included in the interpolation
(m parameter in this function).
"""
max_order = 7
n = 20
l = 0.25
fmt1 = '{0: <5s}\t{1: <21s}\t{2: >21s}\t{3: >21s}\t{4: >21s}'
fmt2 = '{0:... | [
"This",
"demo",
"shows",
"how",
"the",
"error",
"in",
"the",
"estimate",
"varies",
"depending",
"on",
"how",
"many",
"data",
"points",
"are",
"included",
"in",
"the",
"interpolation",
"(",
"m",
"parameter",
"in",
"this",
"function",
")",
"."
] | bjodah/finitediff | python | https://github.com/bjodah/finitediff/blob/c1b1c6840512d2206e2f97315d9bf1738c1ca3d3/examples/err.py#L9-L37 | [
"def",
"demo_err",
"(",
")",
":",
"max_order",
"=",
"7",
"n",
"=",
"20",
"l",
"=",
"0.25",
"fmt1",
"=",
"'{0: <5s}\\t{1: <21s}\\t{2: >21s}\\t{3: >21s}\\t{4: >21s}'",
"fmt2",
"=",
"'{0: <5d}\\t{1:20.18f}\\t{2: >21.18f}\\t{3: >21.18f}\\t{4: >21.18f}'",
"x",
"=",
"np",
"."... | c1b1c6840512d2206e2f97315d9bf1738c1ca3d3 |
train | display_results | Fancy display. | octohatrack/helpers.py | def display_results(repo_name, contributors, api_len):
"""
Fancy display.
"""
print("\n")
print("All Contributors:")
# Sort and consolidate on Name
seen = []
for user in sorted(contributors, key=_sort_by_name):
if user.get("name"):
key = user["name"]
else:
... | def display_results(repo_name, contributors, api_len):
"""
Fancy display.
"""
print("\n")
print("All Contributors:")
# Sort and consolidate on Name
seen = []
for user in sorted(contributors, key=_sort_by_name):
if user.get("name"):
key = user["name"]
else:
... | [
"Fancy",
"display",
"."
] | LABHR/octohatrack | python | https://github.com/LABHR/octohatrack/blob/bf855a0190518a3b2c45304cbbac00e22086b6da/octohatrack/helpers.py#L13-L39 | [
"def",
"display_results",
"(",
"repo_name",
",",
"contributors",
",",
"api_len",
")",
":",
"print",
"(",
"\"\\n\"",
")",
"print",
"(",
"\"All Contributors:\"",
")",
"# Sort and consolidate on Name",
"seen",
"=",
"[",
"]",
"for",
"user",
"in",
"sorted",
"(",
"c... | bf855a0190518a3b2c45304cbbac00e22086b6da |
train | get_json | Handle headers and json for us :3 | octohatrack/api_helpers.py | def get_json(uri):
"""
Handle headers and json for us :3
"""
response = requests.get(API + uri, headers=HEADERS)
limit = int(response.headers.get("x-ratelimit-remaining"))
if limit == 0:
sys.stdout.write("\n")
message = "You have run out of GitHub request tokens. "
if i... | def get_json(uri):
"""
Handle headers and json for us :3
"""
response = requests.get(API + uri, headers=HEADERS)
limit = int(response.headers.get("x-ratelimit-remaining"))
if limit == 0:
sys.stdout.write("\n")
message = "You have run out of GitHub request tokens. "
if i... | [
"Handle",
"headers",
"and",
"json",
"for",
"us",
":",
"3"
] | LABHR/octohatrack | python | https://github.com/LABHR/octohatrack/blob/bf855a0190518a3b2c45304cbbac00e22086b6da/octohatrack/api_helpers.py#L24-L51 | [
"def",
"get_json",
"(",
"uri",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"API",
"+",
"uri",
",",
"headers",
"=",
"HEADERS",
")",
"limit",
"=",
"int",
"(",
"response",
".",
"headers",
".",
"get",
"(",
"\"x-ratelimit-remaining\"",
")",
")",... | bf855a0190518a3b2c45304cbbac00e22086b6da |
train | api_walk | For a GitHub URI, walk all the pages until there's no more content | octohatrack/api_helpers.py | def api_walk(uri, per_page=100, key="login"):
"""
For a GitHub URI, walk all the pages until there's no more content
"""
page = 1
result = []
while True:
response = get_json(uri + "?page=%d&per_page=%d" % (page, per_page))
if len(response) == 0:
break
else:
... | def api_walk(uri, per_page=100, key="login"):
"""
For a GitHub URI, walk all the pages until there's no more content
"""
page = 1
result = []
while True:
response = get_json(uri + "?page=%d&per_page=%d" % (page, per_page))
if len(response) == 0:
break
else:
... | [
"For",
"a",
"GitHub",
"URI",
"walk",
"all",
"the",
"pages",
"until",
"there",
"s",
"no",
"more",
"content"
] | LABHR/octohatrack | python | https://github.com/LABHR/octohatrack/blob/bf855a0190518a3b2c45304cbbac00e22086b6da/octohatrack/api_helpers.py#L54-L73 | [
"def",
"api_walk",
"(",
"uri",
",",
"per_page",
"=",
"100",
",",
"key",
"=",
"\"login\"",
")",
":",
"page",
"=",
"1",
"result",
"=",
"[",
"]",
"while",
"True",
":",
"response",
"=",
"get_json",
"(",
"uri",
"+",
"\"?page=%d&per_page=%d\"",
"%",
"(",
"... | bf855a0190518a3b2c45304cbbac00e22086b6da |
train | api_get | Simple API endpoint get, return only the keys we care about | octohatrack/api_helpers.py | def api_get(uri, key=None):
"""
Simple API endpoint get, return only the keys we care about
"""
response = get_json(uri)
if response:
if type(response) == list:
r = response[0]
elif type(response) == dict:
r = response
if type(r) == dict:
... | def api_get(uri, key=None):
"""
Simple API endpoint get, return only the keys we care about
"""
response = get_json(uri)
if response:
if type(response) == list:
r = response[0]
elif type(response) == dict:
r = response
if type(r) == dict:
... | [
"Simple",
"API",
"endpoint",
"get",
"return",
"only",
"the",
"keys",
"we",
"care",
"about"
] | LABHR/octohatrack | python | https://github.com/LABHR/octohatrack/blob/bf855a0190518a3b2c45304cbbac00e22086b6da/octohatrack/api_helpers.py#L86-L103 | [
"def",
"api_get",
"(",
"uri",
",",
"key",
"=",
"None",
")",
":",
"response",
"=",
"get_json",
"(",
"uri",
")",
"if",
"response",
":",
"if",
"type",
"(",
"response",
")",
"==",
"list",
":",
"r",
"=",
"response",
"[",
"0",
"]",
"elif",
"type",
"(",... | bf855a0190518a3b2c45304cbbac00e22086b6da |
train | reducejson | Not sure if there's a better way to walk the ... interesting result | octohatrack_graphql.py | def reducejson(j):
"""
Not sure if there's a better way to walk the ... interesting result
"""
authors = []
for key in j["data"]["repository"]["commitComments"]["edges"]:
authors.append(key["node"]["author"])
for key in j["data"]["repository"]["issues"]["nodes"]:
auth... | def reducejson(j):
"""
Not sure if there's a better way to walk the ... interesting result
"""
authors = []
for key in j["data"]["repository"]["commitComments"]["edges"]:
authors.append(key["node"]["author"])
for key in j["data"]["repository"]["issues"]["nodes"]:
auth... | [
"Not",
"sure",
"if",
"there",
"s",
"a",
"better",
"way",
"to",
"walk",
"the",
"...",
"interesting",
"result"
] | LABHR/octohatrack | python | https://github.com/LABHR/octohatrack/blob/bf855a0190518a3b2c45304cbbac00e22086b6da/octohatrack_graphql.py#L52-L73 | [
"def",
"reducejson",
"(",
"j",
")",
":",
"authors",
"=",
"[",
"]",
"for",
"key",
"in",
"j",
"[",
"\"data\"",
"]",
"[",
"\"repository\"",
"]",
"[",
"\"commitComments\"",
"]",
"[",
"\"edges\"",
"]",
":",
"authors",
".",
"append",
"(",
"key",
"[",
"\"no... | bf855a0190518a3b2c45304cbbac00e22086b6da |
train | stringify_with_dot_if_path | Pathlib never renders a leading './' in front of a local path. That's an
issue because on POSIX subprocess.py (like bash) won't execute scripts in
the current directory without it. In the same vein, we also don't want
Path('echo') to match '/usr/bin/echo' from the $PATH. To work around both
issues, we e... | duct.py | def stringify_with_dot_if_path(x):
'''Pathlib never renders a leading './' in front of a local path. That's an
issue because on POSIX subprocess.py (like bash) won't execute scripts in
the current directory without it. In the same vein, we also don't want
Path('echo') to match '/usr/bin/echo' from the $... | def stringify_with_dot_if_path(x):
'''Pathlib never renders a leading './' in front of a local path. That's an
issue because on POSIX subprocess.py (like bash) won't execute scripts in
the current directory without it. In the same vein, we also don't want
Path('echo') to match '/usr/bin/echo' from the $... | [
"Pathlib",
"never",
"renders",
"a",
"leading",
".",
"/",
"in",
"front",
"of",
"a",
"local",
"path",
".",
"That",
"s",
"an",
"issue",
"because",
"on",
"POSIX",
"subprocess",
".",
"py",
"(",
"like",
"bash",
")",
"won",
"t",
"execute",
"scripts",
"in",
... | oconnor663/duct.py | python | https://github.com/oconnor663/duct.py/blob/f10f1e9093a2913281294bb89a6e1744aa700e73/duct.py#L616-L625 | [
"def",
"stringify_with_dot_if_path",
"(",
"x",
")",
":",
"if",
"isinstance",
"(",
"x",
",",
"PurePath",
")",
":",
"# Note that join does nothing if the path is absolute.",
"return",
"os",
".",
"path",
".",
"join",
"(",
"'.'",
",",
"str",
"(",
"x",
")",
")",
... | f10f1e9093a2913281294bb89a6e1744aa700e73 |
train | maybe_canonicalize_exe_path | There's a tricky interaction between exe paths and `dir`. Exe paths can
be relative, and so we have to ask: Is an exe path interpreted relative to
the parent's cwd, or the child's? The answer is that it's platform
dependent! >.< (Windows uses the parent's cwd, but because of the
fork-chdir-exec pattern,... | duct.py | def maybe_canonicalize_exe_path(exe_name, iocontext):
'''There's a tricky interaction between exe paths and `dir`. Exe paths can
be relative, and so we have to ask: Is an exe path interpreted relative to
the parent's cwd, or the child's? The answer is that it's platform
dependent! >.< (Windows uses the ... | def maybe_canonicalize_exe_path(exe_name, iocontext):
'''There's a tricky interaction between exe paths and `dir`. Exe paths can
be relative, and so we have to ask: Is an exe path interpreted relative to
the parent's cwd, or the child's? The answer is that it's platform
dependent! >.< (Windows uses the ... | [
"There",
"s",
"a",
"tricky",
"interaction",
"between",
"exe",
"paths",
"and",
"dir",
".",
"Exe",
"paths",
"can",
"be",
"relative",
"and",
"so",
"we",
"have",
"to",
"ask",
":",
"Is",
"an",
"exe",
"path",
"interpreted",
"relative",
"to",
"the",
"parent",
... | oconnor663/duct.py | python | https://github.com/oconnor663/duct.py/blob/f10f1e9093a2913281294bb89a6e1744aa700e73/duct.py#L661-L694 | [
"def",
"maybe_canonicalize_exe_path",
"(",
"exe_name",
",",
"iocontext",
")",
":",
"has_sep",
"=",
"(",
"os",
".",
"path",
".",
"sep",
"in",
"exe_name",
"or",
"(",
"os",
".",
"path",
".",
"altsep",
"is",
"not",
"None",
"and",
"os",
".",
"path",
".",
... | f10f1e9093a2913281294bb89a6e1744aa700e73 |
train | safe_popen | This wrapper works around two major deadlock issues to do with pipes.
The first is that, before Python 3.2 on POSIX systems, os.pipe() creates
inheritable file descriptors, which leak to all child processes and prevent
reads from reaching EOF. The workaround for this is to set close_fds=True
on POSIX, w... | duct.py | def safe_popen(*args, **kwargs):
'''This wrapper works around two major deadlock issues to do with pipes.
The first is that, before Python 3.2 on POSIX systems, os.pipe() creates
inheritable file descriptors, which leak to all child processes and prevent
reads from reaching EOF. The workaround for this ... | def safe_popen(*args, **kwargs):
'''This wrapper works around two major deadlock issues to do with pipes.
The first is that, before Python 3.2 on POSIX systems, os.pipe() creates
inheritable file descriptors, which leak to all child processes and prevent
reads from reaching EOF. The workaround for this ... | [
"This",
"wrapper",
"works",
"around",
"two",
"major",
"deadlock",
"issues",
"to",
"do",
"with",
"pipes",
".",
"The",
"first",
"is",
"that",
"before",
"Python",
"3",
".",
"2",
"on",
"POSIX",
"systems",
"os",
".",
"pipe",
"()",
"creates",
"inheritable",
"f... | oconnor663/duct.py | python | https://github.com/oconnor663/duct.py/blob/f10f1e9093a2913281294bb89a6e1744aa700e73/duct.py#L700-L718 | [
"def",
"safe_popen",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"close_fds",
"=",
"(",
"os",
".",
"name",
"!=",
"'nt'",
")",
"with",
"popen_lock",
":",
"return",
"subprocess",
".",
"Popen",
"(",
"*",
"args",
",",
"close_fds",
"=",
"close_fd... | f10f1e9093a2913281294bb89a6e1744aa700e73 |
train | Expression.run | Execute the expression and return a Result, which includes the exit
status and any captured output. Raise an exception if the status is
non-zero. | duct.py | def run(self):
'''Execute the expression and return a Result, which includes the exit
status and any captured output. Raise an exception if the status is
non-zero.'''
with spawn_output_reader() as (stdout_capture, stdout_thread):
with spawn_output_reader() as (stderr_capture,... | def run(self):
'''Execute the expression and return a Result, which includes the exit
status and any captured output. Raise an exception if the status is
non-zero.'''
with spawn_output_reader() as (stdout_capture, stdout_thread):
with spawn_output_reader() as (stderr_capture,... | [
"Execute",
"the",
"expression",
"and",
"return",
"a",
"Result",
"which",
"includes",
"the",
"exit",
"status",
"and",
"any",
"captured",
"output",
".",
"Raise",
"an",
"exception",
"if",
"the",
"status",
"is",
"non",
"-",
"zero",
"."
] | oconnor663/duct.py | python | https://github.com/oconnor663/duct.py/blob/f10f1e9093a2913281294bb89a6e1744aa700e73/duct.py#L26-L39 | [
"def",
"run",
"(",
"self",
")",
":",
"with",
"spawn_output_reader",
"(",
")",
"as",
"(",
"stdout_capture",
",",
"stdout_thread",
")",
":",
"with",
"spawn_output_reader",
"(",
")",
"as",
"(",
"stderr_capture",
",",
"stderr_thread",
")",
":",
"context",
"=",
... | f10f1e9093a2913281294bb89a6e1744aa700e73 |
train | Expression.read | Execute the expression and capture its output, similar to backticks
or $() in the shell. This is a wrapper around run() which captures
stdout, decodes it, trims it, and returns it directly. | duct.py | def read(self):
'''Execute the expression and capture its output, similar to backticks
or $() in the shell. This is a wrapper around run() which captures
stdout, decodes it, trims it, and returns it directly.'''
result = self.stdout_capture().run()
stdout_str = decode_with_univer... | def read(self):
'''Execute the expression and capture its output, similar to backticks
or $() in the shell. This is a wrapper around run() which captures
stdout, decodes it, trims it, and returns it directly.'''
result = self.stdout_capture().run()
stdout_str = decode_with_univer... | [
"Execute",
"the",
"expression",
"and",
"capture",
"its",
"output",
"similar",
"to",
"backticks",
"or",
"$",
"()",
"in",
"the",
"shell",
".",
"This",
"is",
"a",
"wrapper",
"around",
"run",
"()",
"which",
"captures",
"stdout",
"decodes",
"it",
"trims",
"it",... | oconnor663/duct.py | python | https://github.com/oconnor663/duct.py/blob/f10f1e9093a2913281294bb89a6e1744aa700e73/duct.py#L41-L47 | [
"def",
"read",
"(",
"self",
")",
":",
"result",
"=",
"self",
".",
"stdout_capture",
"(",
")",
".",
"run",
"(",
")",
"stdout_str",
"=",
"decode_with_universal_newlines",
"(",
"result",
".",
"stdout",
")",
"return",
"stdout_str",
".",
"rstrip",
"(",
"'\\n'",... | f10f1e9093a2913281294bb89a6e1744aa700e73 |
train | Expression.start | Equivalent to `run`, but instead of blocking the current thread,
return a WaitHandle that doesn't block until `wait` is called. This is
currently implemented with a simple background thread, though in theory
it could avoid using threads in most cases. | duct.py | def start(self):
'''Equivalent to `run`, but instead of blocking the current thread,
return a WaitHandle that doesn't block until `wait` is called. This is
currently implemented with a simple background thread, though in theory
it could avoid using threads in most cases.'''
threa... | def start(self):
'''Equivalent to `run`, but instead of blocking the current thread,
return a WaitHandle that doesn't block until `wait` is called. This is
currently implemented with a simple background thread, though in theory
it could avoid using threads in most cases.'''
threa... | [
"Equivalent",
"to",
"run",
"but",
"instead",
"of",
"blocking",
"the",
"current",
"thread",
"return",
"a",
"WaitHandle",
"that",
"doesn",
"t",
"block",
"until",
"wait",
"is",
"called",
".",
"This",
"is",
"currently",
"implemented",
"with",
"a",
"simple",
"bac... | oconnor663/duct.py | python | https://github.com/oconnor663/duct.py/blob/f10f1e9093a2913281294bb89a6e1744aa700e73/duct.py#L49-L56 | [
"def",
"start",
"(",
"self",
")",
":",
"thread",
"=",
"ThreadWithReturn",
"(",
"self",
".",
"run",
")",
"thread",
".",
"start",
"(",
")",
"return",
"WaitHandle",
"(",
"thread",
")"
] | f10f1e9093a2913281294bb89a6e1744aa700e73 |
train | LaMetricManager._exec | execute a command at the device using the RESTful API
:param str cmd: one of the REST commands, e.g. GET or POST
:param str url: URL of the REST API the command should be applied to
:param dict json_data: json data that should be attached to the command | lmnotify/lmnotify.py | def _exec(self, cmd, url, json_data=None):
"""
execute a command at the device using the RESTful API
:param str cmd: one of the REST commands, e.g. GET or POST
:param str url: URL of the REST API the command should be applied to
:param dict json_data: json data that should be at... | def _exec(self, cmd, url, json_data=None):
"""
execute a command at the device using the RESTful API
:param str cmd: one of the REST commands, e.g. GET or POST
:param str url: URL of the REST API the command should be applied to
:param dict json_data: json data that should be at... | [
"execute",
"a",
"command",
"at",
"the",
"device",
"using",
"the",
"RESTful",
"API"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L90-L136 | [
"def",
"_exec",
"(",
"self",
",",
"cmd",
",",
"url",
",",
"json_data",
"=",
"None",
")",
":",
"assert",
"(",
"cmd",
"in",
"(",
"\"GET\"",
",",
"\"POST\"",
",",
"\"PUT\"",
",",
"\"DELETE\"",
")",
")",
"assert",
"(",
"self",
".",
"dev",
"is",
"not",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.set_device | set the current device (that will be used for following API calls)
:param dict dev: device that should be used for the API calls
(can be obtained via get_devices function) | lmnotify/lmnotify.py | def set_device(self, dev):
"""
set the current device (that will be used for following API calls)
:param dict dev: device that should be used for the API calls
(can be obtained via get_devices function)
"""
log.debug("setting device to '{}'".format(dev))... | def set_device(self, dev):
"""
set the current device (that will be used for following API calls)
:param dict dev: device that should be used for the API calls
(can be obtained via get_devices function)
"""
log.debug("setting device to '{}'".format(dev))... | [
"set",
"the",
"current",
"device",
"(",
"that",
"will",
"be",
"used",
"for",
"following",
"API",
"calls",
")"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L146-L155 | [
"def",
"set_device",
"(",
"self",
",",
"dev",
")",
":",
"log",
".",
"debug",
"(",
"\"setting device to '{}'\"",
".",
"format",
"(",
"dev",
")",
")",
"self",
".",
"dev",
"=",
"dev",
"self",
".",
"set_apps_list",
"(",
")"
] | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager._get_widget_id | returns widget_id for given package_name does not care
about multiple widget ids at the moment, just picks the first
:param str package_name: package to check for
:return: id of first widget which belongs to the given package_name
:rtype: str | lmnotify/lmnotify.py | def _get_widget_id(self, package_name):
"""
returns widget_id for given package_name does not care
about multiple widget ids at the moment, just picks the first
:param str package_name: package to check for
:return: id of first widget which belongs to the given package_name
... | def _get_widget_id(self, package_name):
"""
returns widget_id for given package_name does not care
about multiple widget ids at the moment, just picks the first
:param str package_name: package to check for
:return: id of first widget which belongs to the given package_name
... | [
"returns",
"widget_id",
"for",
"given",
"package_name",
"does",
"not",
"care",
"about",
"multiple",
"widget",
"ids",
"at",
"the",
"moment",
"just",
"picks",
"the",
"first"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L157-L171 | [
"def",
"_get_widget_id",
"(",
"self",
",",
"package_name",
")",
":",
"widget_id",
"=",
"\"\"",
"for",
"app",
"in",
"self",
".",
"get_apps_list",
"(",
")",
":",
"if",
"app",
".",
"package",
"==",
"package_name",
":",
"widget_id",
"=",
"list",
"(",
"app",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_user | get the user details via the cloud | lmnotify/lmnotify.py | def get_user(self):
"""
get the user details via the cloud
"""
log.debug("getting user information from LaMetric cloud...")
_, url = CLOUD_URLS["get_user"]
res = self._cloud_session.session.get(url)
if res is not None:
# raise an exception on error
... | def get_user(self):
"""
get the user details via the cloud
"""
log.debug("getting user information from LaMetric cloud...")
_, url = CLOUD_URLS["get_user"]
res = self._cloud_session.session.get(url)
if res is not None:
# raise an exception on error
... | [
"get",
"the",
"user",
"details",
"via",
"the",
"cloud"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L174-L185 | [
"def",
"get_user",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting user information from LaMetric cloud...\"",
")",
"_",
",",
"url",
"=",
"CLOUD_URLS",
"[",
"\"get_user\"",
"]",
"res",
"=",
"self",
".",
"_cloud_session",
".",
"session",
".",
"get",... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_devices | get all devices that are linked to the user, if the local device
file is not existing the devices will be obtained from the LaMetric
cloud, otherwise the local device file will be read.
:param bool force_reload: When True, devices are read again from cloud
:param bool save_devices: When... | lmnotify/lmnotify.py | def get_devices(self, force_reload=False, save_devices=True):
"""
get all devices that are linked to the user, if the local device
file is not existing the devices will be obtained from the LaMetric
cloud, otherwise the local device file will be read.
:param bool force_reload: W... | def get_devices(self, force_reload=False, save_devices=True):
"""
get all devices that are linked to the user, if the local device
file is not existing the devices will be obtained from the LaMetric
cloud, otherwise the local device file will be read.
:param bool force_reload: W... | [
"get",
"all",
"devices",
"that",
"are",
"linked",
"to",
"the",
"user",
"if",
"the",
"local",
"device",
"file",
"is",
"not",
"existing",
"the",
"devices",
"will",
"be",
"obtained",
"from",
"the",
"LaMetric",
"cloud",
"otherwise",
"the",
"local",
"device",
"... | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L187-L222 | [
"def",
"get_devices",
"(",
"self",
",",
"force_reload",
"=",
"False",
",",
"save_devices",
"=",
"True",
")",
":",
"if",
"(",
"(",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"_devices_filename",
")",
")",
"or",
"(",
"force_reload",
"is",... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.save_devices | save devices that have been obtained from LaMetric cloud
to a local file | lmnotify/lmnotify.py | def save_devices(self):
"""
save devices that have been obtained from LaMetric cloud
to a local file
"""
log.debug("saving devices to ''...".format(self._devices_filename))
if self._devices != []:
with codecs.open(self._devices_filename, "wb", "utf-8") as f:
... | def save_devices(self):
"""
save devices that have been obtained from LaMetric cloud
to a local file
"""
log.debug("saving devices to ''...".format(self._devices_filename))
if self._devices != []:
with codecs.open(self._devices_filename, "wb", "utf-8") as f:
... | [
"save",
"devices",
"that",
"have",
"been",
"obtained",
"from",
"LaMetric",
"cloud",
"to",
"a",
"local",
"file"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L224-L232 | [
"def",
"save_devices",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"saving devices to ''...\"",
".",
"format",
"(",
"self",
".",
"_devices_filename",
")",
")",
"if",
"self",
".",
"_devices",
"!=",
"[",
"]",
":",
"with",
"codecs",
".",
"open",
"(",... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_endpoint_map | returns API version and endpoint map | lmnotify/lmnotify.py | def get_endpoint_map(self):
"""
returns API version and endpoint map
"""
log.debug("getting end points...")
cmd, url = DEVICE_URLS["get_endpoint_map"]
return self._exec(cmd, url) | def get_endpoint_map(self):
"""
returns API version and endpoint map
"""
log.debug("getting end points...")
cmd, url = DEVICE_URLS["get_endpoint_map"]
return self._exec(cmd, url) | [
"returns",
"API",
"version",
"and",
"endpoint",
"map"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L235-L241 | [
"def",
"get_endpoint_map",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting end points...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_endpoint_map\"",
"]",
"return",
"self",
".",
"_exec",
"(",
"cmd",
",",
"url",
")"
] | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.load_devices | load stored devices from the local file | lmnotify/lmnotify.py | def load_devices(self):
"""
load stored devices from the local file
"""
self._devices = []
if os.path.exists(self._devices_filename):
log.debug(
"loading devices from '{}'...".format(self._devices_filename)
)
with codecs.open(se... | def load_devices(self):
"""
load stored devices from the local file
"""
self._devices = []
if os.path.exists(self._devices_filename):
log.debug(
"loading devices from '{}'...".format(self._devices_filename)
)
with codecs.open(se... | [
"load",
"stored",
"devices",
"from",
"the",
"local",
"file"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L252-L264 | [
"def",
"load_devices",
"(",
"self",
")",
":",
"self",
".",
"_devices",
"=",
"[",
"]",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"_devices_filename",
")",
":",
"log",
".",
"debug",
"(",
"\"loading devices from '{}'...\"",
".",
"format",
"(... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_device_state | returns the full device state | lmnotify/lmnotify.py | def get_device_state(self):
"""
returns the full device state
"""
log.debug("getting device state...")
cmd, url = DEVICE_URLS["get_device_state"]
return self._exec(cmd, url) | def get_device_state(self):
"""
returns the full device state
"""
log.debug("getting device state...")
cmd, url = DEVICE_URLS["get_device_state"]
return self._exec(cmd, url) | [
"returns",
"the",
"full",
"device",
"state"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L266-L272 | [
"def",
"get_device_state",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting device state...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_device_state\"",
"]",
"return",
"self",
".",
"_exec",
"(",
"cmd",
",",
"url",
")"
] | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.send_notification | sends new notification to the device
:param Model model: an instance of the Model class that should be used
:param str priority: the priority of the notification
[info, warning or critical] (default: warning)
:param str icon_type: the icon type of the notification
... | lmnotify/lmnotify.py | def send_notification(
self, model, priority="warning", icon_type=None, lifetime=None
):
"""
sends new notification to the device
:param Model model: an instance of the Model class that should be used
:param str priority: the priority of the notification
... | def send_notification(
self, model, priority="warning", icon_type=None, lifetime=None
):
"""
sends new notification to the device
:param Model model: an instance of the Model class that should be used
:param str priority: the priority of the notification
... | [
"sends",
"new",
"notification",
"to",
"the",
"device"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L274-L303 | [
"def",
"send_notification",
"(",
"self",
",",
"model",
",",
"priority",
"=",
"\"warning\"",
",",
"icon_type",
"=",
"None",
",",
"lifetime",
"=",
"None",
")",
":",
"assert",
"(",
"priority",
"in",
"(",
"\"info\"",
",",
"\"warning\"",
",",
"\"critical\"",
")... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_notifications | returns the list of all notifications in queue | lmnotify/lmnotify.py | def get_notifications(self):
"""
returns the list of all notifications in queue
"""
log.debug("getting notifications in queue...")
cmd, url = DEVICE_URLS["get_notifications_queue"]
return self._exec(cmd, url) | def get_notifications(self):
"""
returns the list of all notifications in queue
"""
log.debug("getting notifications in queue...")
cmd, url = DEVICE_URLS["get_notifications_queue"]
return self._exec(cmd, url) | [
"returns",
"the",
"list",
"of",
"all",
"notifications",
"in",
"queue"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L305-L311 | [
"def",
"get_notifications",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting notifications in queue...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_notifications_queue\"",
"]",
"return",
"self",
".",
"_exec",
"(",
"cmd",
",",
"url",
"... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_current_notification | returns the current notification (i.e. the one that is visible) | lmnotify/lmnotify.py | def get_current_notification(self):
"""
returns the current notification (i.e. the one that is visible)
"""
log.debug("getting visible notification...")
cmd, url = DEVICE_URLS["get_current_notification"]
return self._exec(cmd, url) | def get_current_notification(self):
"""
returns the current notification (i.e. the one that is visible)
"""
log.debug("getting visible notification...")
cmd, url = DEVICE_URLS["get_current_notification"]
return self._exec(cmd, url) | [
"returns",
"the",
"current",
"notification",
"(",
"i",
".",
"e",
".",
"the",
"one",
"that",
"is",
"visible",
")"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L313-L319 | [
"def",
"get_current_notification",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting visible notification...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_current_notification\"",
"]",
"return",
"self",
".",
"_exec",
"(",
"cmd",
",",
"url... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_notification | returns a specific notification by given id
:param str notification_id: the ID of the notification | lmnotify/lmnotify.py | def get_notification(self, notification_id):
"""
returns a specific notification by given id
:param str notification_id: the ID of the notification
"""
log.debug("getting notification '{}'...".format(notification_id))
cmd, url = DEVICE_URLS["get_notification"]
re... | def get_notification(self, notification_id):
"""
returns a specific notification by given id
:param str notification_id: the ID of the notification
"""
log.debug("getting notification '{}'...".format(notification_id))
cmd, url = DEVICE_URLS["get_notification"]
re... | [
"returns",
"a",
"specific",
"notification",
"by",
"given",
"id"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L321-L329 | [
"def",
"get_notification",
"(",
"self",
",",
"notification_id",
")",
":",
"log",
".",
"debug",
"(",
"\"getting notification '{}'...\"",
".",
"format",
"(",
"notification_id",
")",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_notification\"",
"]",
"ret... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_display | returns information about the display, including
brightness, screensaver etc. | lmnotify/lmnotify.py | def get_display(self):
"""
returns information about the display, including
brightness, screensaver etc.
"""
log.debug("getting display information...")
cmd, url = DEVICE_URLS["get_display"]
return self._exec(cmd, url) | def get_display(self):
"""
returns information about the display, including
brightness, screensaver etc.
"""
log.debug("getting display information...")
cmd, url = DEVICE_URLS["get_display"]
return self._exec(cmd, url) | [
"returns",
"information",
"about",
"the",
"display",
"including",
"brightness",
"screensaver",
"etc",
"."
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L341-L348 | [
"def",
"get_display",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting display information...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_display\"",
"]",
"return",
"self",
".",
"_exec",
"(",
"cmd",
",",
"url",
")"
] | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.set_display | allows to modify display state (change brightness)
:param int brightness: display brightness [0, 100] (default: 100)
:param str brightness_mode: the brightness mode of the display
[auto, manual] (default: auto) | lmnotify/lmnotify.py | def set_display(self, brightness=100, brightness_mode="auto"):
"""
allows to modify display state (change brightness)
:param int brightness: display brightness [0, 100] (default: 100)
:param str brightness_mode: the brightness mode of the display
[aut... | def set_display(self, brightness=100, brightness_mode="auto"):
"""
allows to modify display state (change brightness)
:param int brightness: display brightness [0, 100] (default: 100)
:param str brightness_mode: the brightness mode of the display
[aut... | [
"allows",
"to",
"modify",
"display",
"state",
"(",
"change",
"brightness",
")"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L350-L369 | [
"def",
"set_display",
"(",
"self",
",",
"brightness",
"=",
"100",
",",
"brightness_mode",
"=",
"\"auto\"",
")",
":",
"assert",
"(",
"brightness_mode",
"in",
"(",
"\"auto\"",
",",
"\"manual\"",
")",
")",
"assert",
"(",
"brightness",
"in",
"range",
"(",
"101... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.set_screensaver | set the display's screensaver mode
:param str mode: mode of the screensaver
[when_dark, time_based]
:param bool is_mode_enabled: specifies if mode is enabled or disabled
:param str start_time: start time, only used in time_based mode
(form... | lmnotify/lmnotify.py | def set_screensaver(
self, mode, is_mode_enabled, start_time=None, end_time=None,
is_screensaver_enabled=True
):
"""
set the display's screensaver mode
:param str mode: mode of the screensaver
[when_dark, time_based]
:param bool is_mode_enabl... | def set_screensaver(
self, mode, is_mode_enabled, start_time=None, end_time=None,
is_screensaver_enabled=True
):
"""
set the display's screensaver mode
:param str mode: mode of the screensaver
[when_dark, time_based]
:param bool is_mode_enabl... | [
"set",
"the",
"display",
"s",
"screensaver",
"mode"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L371-L408 | [
"def",
"set_screensaver",
"(",
"self",
",",
"mode",
",",
"is_mode_enabled",
",",
"start_time",
"=",
"None",
",",
"end_time",
"=",
"None",
",",
"is_screensaver_enabled",
"=",
"True",
")",
":",
"assert",
"(",
"mode",
"in",
"(",
"\"when_dark\"",
",",
"\"time_ba... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_volume | returns the current volume | lmnotify/lmnotify.py | def get_volume(self):
"""
returns the current volume
"""
log.debug("getting volumne...")
cmd, url = DEVICE_URLS["get_volume"]
return self._exec(cmd, url) | def get_volume(self):
"""
returns the current volume
"""
log.debug("getting volumne...")
cmd, url = DEVICE_URLS["get_volume"]
return self._exec(cmd, url) | [
"returns",
"the",
"current",
"volume"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L410-L416 | [
"def",
"get_volume",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting volumne...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_volume\"",
"]",
"return",
"self",
".",
"_exec",
"(",
"cmd",
",",
"url",
")"
] | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.set_volume | allows to change the volume
:param int volume: volume to be set for the current device
[0..100] (default: 50) | lmnotify/lmnotify.py | def set_volume(self, volume=50):
"""
allows to change the volume
:param int volume: volume to be set for the current device
[0..100] (default: 50)
"""
assert(volume in range(101))
log.debug("setting volume...")
cmd, url = DEVICE_URLS[... | def set_volume(self, volume=50):
"""
allows to change the volume
:param int volume: volume to be set for the current device
[0..100] (default: 50)
"""
assert(volume in range(101))
log.debug("setting volume...")
cmd, url = DEVICE_URLS[... | [
"allows",
"to",
"change",
"the",
"volume"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L418-L433 | [
"def",
"set_volume",
"(",
"self",
",",
"volume",
"=",
"50",
")",
":",
"assert",
"(",
"volume",
"in",
"range",
"(",
"101",
")",
")",
"log",
".",
"debug",
"(",
"\"setting volume...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"set_volume\"",
"]... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_bluetooth_state | returns the bluetooth state | lmnotify/lmnotify.py | def get_bluetooth_state(self):
"""
returns the bluetooth state
"""
log.debug("getting bluetooth state...")
cmd, url = DEVICE_URLS["get_bluetooth_state"]
return self._exec(cmd, url) | def get_bluetooth_state(self):
"""
returns the bluetooth state
"""
log.debug("getting bluetooth state...")
cmd, url = DEVICE_URLS["get_bluetooth_state"]
return self._exec(cmd, url) | [
"returns",
"the",
"bluetooth",
"state"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L435-L441 | [
"def",
"get_bluetooth_state",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting bluetooth state...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_bluetooth_state\"",
"]",
"return",
"self",
".",
"_exec",
"(",
"cmd",
",",
"url",
")"
] | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.set_bluetooth | allows to activate/deactivate bluetooth and change the name | lmnotify/lmnotify.py | def set_bluetooth(self, active=None, name=None):
"""
allows to activate/deactivate bluetooth and change the name
"""
assert(active is not None or name is not None)
log.debug("setting bluetooth state...")
cmd, url = DEVICE_URLS["set_bluetooth"]
json_data = {}
... | def set_bluetooth(self, active=None, name=None):
"""
allows to activate/deactivate bluetooth and change the name
"""
assert(active is not None or name is not None)
log.debug("setting bluetooth state...")
cmd, url = DEVICE_URLS["set_bluetooth"]
json_data = {}
... | [
"allows",
"to",
"activate",
"/",
"deactivate",
"bluetooth",
"and",
"change",
"the",
"name"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L443-L458 | [
"def",
"set_bluetooth",
"(",
"self",
",",
"active",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"assert",
"(",
"active",
"is",
"not",
"None",
"or",
"name",
"is",
"not",
"None",
")",
"log",
".",
"debug",
"(",
"\"setting bluetooth state...\"",
")",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.get_wifi_state | returns the current Wi-Fi state the device is connected to | lmnotify/lmnotify.py | def get_wifi_state(self):
"""
returns the current Wi-Fi state the device is connected to
"""
log.debug("getting wifi state...")
cmd, url = DEVICE_URLS["get_wifi_state"]
return self._exec(cmd, url) | def get_wifi_state(self):
"""
returns the current Wi-Fi state the device is connected to
"""
log.debug("getting wifi state...")
cmd, url = DEVICE_URLS["get_wifi_state"]
return self._exec(cmd, url) | [
"returns",
"the",
"current",
"Wi",
"-",
"Fi",
"state",
"the",
"device",
"is",
"connected",
"to"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L460-L466 | [
"def",
"get_wifi_state",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting wifi state...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_wifi_state\"",
"]",
"return",
"self",
".",
"_exec",
"(",
"cmd",
",",
"url",
")"
] | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.set_apps_list | gets installed apps and puts them into the available_apps list | lmnotify/lmnotify.py | def set_apps_list(self):
"""
gets installed apps and puts them into the available_apps list
"""
log.debug("getting apps and setting them in the internal app list...")
cmd, url = DEVICE_URLS["get_apps_list"]
result = self._exec(cmd, url)
self.available_apps = [
... | def set_apps_list(self):
"""
gets installed apps and puts them into the available_apps list
"""
log.debug("getting apps and setting them in the internal app list...")
cmd, url = DEVICE_URLS["get_apps_list"]
result = self._exec(cmd, url)
self.available_apps = [
... | [
"gets",
"installed",
"apps",
"and",
"puts",
"them",
"into",
"the",
"available_apps",
"list"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L469-L481 | [
"def",
"set_apps_list",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"getting apps and setting them in the internal app list...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"get_apps_list\"",
"]",
"result",
"=",
"self",
".",
"_exec",
"(",
"cmd",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.switch_to_app | activates an app that is specified by package. Selects the first
app it finds in the app list
:param package: name of package/app
:type package: str
:return: None
:rtype: None | lmnotify/lmnotify.py | def switch_to_app(self, package):
"""
activates an app that is specified by package. Selects the first
app it finds in the app list
:param package: name of package/app
:type package: str
:return: None
:rtype: None
"""
log.debug("switching to app '... | def switch_to_app(self, package):
"""
activates an app that is specified by package. Selects the first
app it finds in the app list
:param package: name of package/app
:type package: str
:return: None
:rtype: None
"""
log.debug("switching to app '... | [
"activates",
"an",
"app",
"that",
"is",
"specified",
"by",
"package",
".",
"Selects",
"the",
"first",
"app",
"it",
"finds",
"in",
"the",
"app",
"list"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L489-L505 | [
"def",
"switch_to_app",
"(",
"self",
",",
"package",
")",
":",
"log",
".",
"debug",
"(",
"\"switching to app '{}'...\"",
".",
"format",
"(",
"package",
")",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"switch_to_app\"",
"]",
"widget_id",
"=",
"self",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.switch_to_next_app | switches to the next app | lmnotify/lmnotify.py | def switch_to_next_app(self):
"""
switches to the next app
"""
log.debug("switching to next app...")
cmd, url = DEVICE_URLS["switch_to_next_app"]
self.result = self._exec(cmd, url) | def switch_to_next_app(self):
"""
switches to the next app
"""
log.debug("switching to next app...")
cmd, url = DEVICE_URLS["switch_to_next_app"]
self.result = self._exec(cmd, url) | [
"switches",
"to",
"the",
"next",
"app"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L507-L513 | [
"def",
"switch_to_next_app",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"switching to next app...\"",
")",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"switch_to_next_app\"",
"]",
"self",
".",
"result",
"=",
"self",
".",
"_exec",
"(",
"cmd",
",",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.activate_widget | activate the widget of the given package
:param str package: name of the package | lmnotify/lmnotify.py | def activate_widget(self, package):
"""
activate the widget of the given package
:param str package: name of the package
"""
cmd, url = DEVICE_URLS["activate_widget"]
# get widget id for the package
widget_id = self._get_widget_id(package)
url = url.form... | def activate_widget(self, package):
"""
activate the widget of the given package
:param str package: name of the package
"""
cmd, url = DEVICE_URLS["activate_widget"]
# get widget id for the package
widget_id = self._get_widget_id(package)
url = url.form... | [
"activate",
"the",
"widget",
"of",
"the",
"given",
"package"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L523-L535 | [
"def",
"activate_widget",
"(",
"self",
",",
"package",
")",
":",
"cmd",
",",
"url",
"=",
"DEVICE_URLS",
"[",
"\"activate_widget\"",
"]",
"# get widget id for the package",
"widget_id",
"=",
"self",
".",
"_get_widget_id",
"(",
"package",
")",
"url",
"=",
"url",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager._app_exec | meta method for all interactions with apps
:param package: name of package/app
:type package: str
:param action: the action to be executed
:type action: str
:param params: optional parameters for this action
:type params: dict
:return: None
:rtype: None | lmnotify/lmnotify.py | def _app_exec(self, package, action, params=None):
"""
meta method for all interactions with apps
:param package: name of package/app
:type package: str
:param action: the action to be executed
:type action: str
:param params: optional parameters for this action
... | def _app_exec(self, package, action, params=None):
"""
meta method for all interactions with apps
:param package: name of package/app
:type package: str
:param action: the action to be executed
:type action: str
:param params: optional parameters for this action
... | [
"meta",
"method",
"for",
"all",
"interactions",
"with",
"apps"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L537-L569 | [
"def",
"_app_exec",
"(",
"self",
",",
"package",
",",
"action",
",",
"params",
"=",
"None",
")",
":",
"# get list of possible commands from app.actions",
"allowed_commands",
"=",
"[",
"]",
"for",
"app",
"in",
"self",
".",
"get_apps_list",
"(",
")",
":",
"if",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.alarm_set | set the alarm clock
:param str time: time of the alarm (format: %H:%M:%S)
:param bool wake_with_radio: if True, radio will be used for the alarm
instead of beep sound | lmnotify/lmnotify.py | def alarm_set(self, time, wake_with_radio=False):
"""
set the alarm clock
:param str time: time of the alarm (format: %H:%M:%S)
:param bool wake_with_radio: if True, radio will be used for the alarm
instead of beep sound
"""
# TODO: c... | def alarm_set(self, time, wake_with_radio=False):
"""
set the alarm clock
:param str time: time of the alarm (format: %H:%M:%S)
:param bool wake_with_radio: if True, radio will be used for the alarm
instead of beep sound
"""
# TODO: c... | [
"set",
"the",
"alarm",
"clock"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L599-L614 | [
"def",
"alarm_set",
"(",
"self",
",",
"time",
",",
"wake_with_radio",
"=",
"False",
")",
":",
"# TODO: check for correct time format",
"log",
".",
"debug",
"(",
"\"alarm => set...\"",
")",
"params",
"=",
"{",
"\"enabled\"",
":",
"True",
",",
"\"time\"",
":",
"... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.alarm_disable | disable the alarm | lmnotify/lmnotify.py | def alarm_disable(self):
"""
disable the alarm
"""
log.debug("alarm => disable...")
params = {"enabled": False}
self._app_exec("com.lametric.clock", "clock.alarm", params=params) | def alarm_disable(self):
"""
disable the alarm
"""
log.debug("alarm => disable...")
params = {"enabled": False}
self._app_exec("com.lametric.clock", "clock.alarm", params=params) | [
"disable",
"the",
"alarm"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L616-L622 | [
"def",
"alarm_disable",
"(",
"self",
")",
":",
"log",
".",
"debug",
"(",
"\"alarm => disable...\"",
")",
"params",
"=",
"{",
"\"enabled\"",
":",
"False",
"}",
"self",
".",
"_app_exec",
"(",
"\"com.lametric.clock\"",
",",
"\"clock.alarm\"",
",",
"params",
"=",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | LaMetricManager.countdown_set | set the countdown
:param str duration:
:param str start_now: | lmnotify/lmnotify.py | def countdown_set(self, duration, start_now):
"""
set the countdown
:param str duration:
:param str start_now:
"""
log.debug("countdown => set...")
params = {'duration': duration, 'start_now': start_now}
self._app_exec(
"com.lametric.countdown... | def countdown_set(self, duration, start_now):
"""
set the countdown
:param str duration:
:param str start_now:
"""
log.debug("countdown => set...")
params = {'duration': duration, 'start_now': start_now}
self._app_exec(
"com.lametric.countdown... | [
"set",
"the",
"countdown"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/lmnotify.py#L645-L656 | [
"def",
"countdown_set",
"(",
"self",
",",
"duration",
",",
"start_now",
")",
":",
"log",
".",
"debug",
"(",
"\"countdown => set...\"",
")",
"params",
"=",
"{",
"'duration'",
":",
"duration",
",",
"'start_now'",
":",
"start_now",
"}",
"self",
".",
"_app_exec"... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | External.action | Call external script.
:param includes: testcase's includes
:param variables: variables
:return: script's output | catcher/steps/external.py | def action(self, includes: dict, variables: dict) -> tuple:
"""
Call external script.
:param includes: testcase's includes
:param variables: variables
:return: script's output
"""
json_args = fill_template_str(json.dumps(self.data), variables)
p = subproc... | def action(self, includes: dict, variables: dict) -> tuple:
"""
Call external script.
:param includes: testcase's includes
:param variables: variables
:return: script's output
"""
json_args = fill_template_str(json.dumps(self.data), variables)
p = subproc... | [
"Call",
"external",
"script",
"."
] | comtihon/catcher | python | https://github.com/comtihon/catcher/blob/5124e69d11cb6987daca595a61a4062d2b5f5ecc/catcher/steps/external.py#L17-L34 | [
"def",
"action",
"(",
"self",
",",
"includes",
":",
"dict",
",",
"variables",
":",
"dict",
")",
"->",
"tuple",
":",
"json_args",
"=",
"fill_template_str",
"(",
"json",
".",
"dumps",
"(",
"self",
".",
"data",
")",
",",
"variables",
")",
"p",
"=",
"sub... | 5124e69d11cb6987daca595a61a4062d2b5f5ecc |
train | CloudSession.set_credentials | set given credentials and reset the session | lmnotify/session.py | def set_credentials(self, client_id=None, client_secret=None):
"""
set given credentials and reset the session
"""
self._client_id = client_id
self._client_secret = client_secret
# make sure to reset session due to credential change
self._session = None | def set_credentials(self, client_id=None, client_secret=None):
"""
set given credentials and reset the session
"""
self._client_id = client_id
self._client_secret = client_secret
# make sure to reset session due to credential change
self._session = None | [
"set",
"given",
"credentials",
"and",
"reset",
"the",
"session"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/session.py#L82-L90 | [
"def",
"set_credentials",
"(",
"self",
",",
"client_id",
"=",
"None",
",",
"client_secret",
"=",
"None",
")",
":",
"self",
".",
"_client_id",
"=",
"client_id",
"self",
".",
"_client_secret",
"=",
"client_secret",
"# make sure to reset session due to credential change"... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | CloudSession.init_session | init a new oauth2 session that is required to access the cloud
:param bool get_token: if True, a token will be obtained, after
the session has been created | lmnotify/session.py | def init_session(self, get_token=True):
"""
init a new oauth2 session that is required to access the cloud
:param bool get_token: if True, a token will be obtained, after
the session has been created
"""
if (self._client_id is None) or (self._clien... | def init_session(self, get_token=True):
"""
init a new oauth2 session that is required to access the cloud
:param bool get_token: if True, a token will be obtained, after
the session has been created
"""
if (self._client_id is None) or (self._clien... | [
"init",
"a",
"new",
"oauth2",
"session",
"that",
"is",
"required",
"to",
"access",
"the",
"cloud"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/session.py#L98-L119 | [
"def",
"init_session",
"(",
"self",
",",
"get_token",
"=",
"True",
")",
":",
"if",
"(",
"self",
".",
"_client_id",
"is",
"None",
")",
"or",
"(",
"self",
".",
"_client_secret",
"is",
"None",
")",
":",
"sys",
".",
"exit",
"(",
"\"Please make sure to set th... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | CloudSession.get_token | get current oauth token | lmnotify/session.py | def get_token(self):
"""
get current oauth token
"""
self.token = self._session.fetch_token(
token_url=CLOUD_URLS["get_token"][1],
client_id=self._client_id,
client_secret=self._client_secret
) | def get_token(self):
"""
get current oauth token
"""
self.token = self._session.fetch_token(
token_url=CLOUD_URLS["get_token"][1],
client_id=self._client_id,
client_secret=self._client_secret
) | [
"get",
"current",
"oauth",
"token"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/session.py#L121-L129 | [
"def",
"get_token",
"(",
"self",
")",
":",
"self",
".",
"token",
"=",
"self",
".",
"_session",
".",
"fetch_token",
"(",
"token_url",
"=",
"CLOUD_URLS",
"[",
"\"get_token\"",
"]",
"[",
"1",
"]",
",",
"client_id",
"=",
"self",
".",
"_client_id",
",",
"cl... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | ExternalStep.simple_input | Use this method to get simple input as python object, with all
templates filled in
:param variables:
:return: python object | catcher/steps/external_step.py | def simple_input(self, variables):
"""
Use this method to get simple input as python object, with all
templates filled in
:param variables:
:return: python object
"""
json_args = fill_template_str(json.dumps(self.data), variables)
return try_get_objects(... | def simple_input(self, variables):
"""
Use this method to get simple input as python object, with all
templates filled in
:param variables:
:return: python object
"""
json_args = fill_template_str(json.dumps(self.data), variables)
return try_get_objects(... | [
"Use",
"this",
"method",
"to",
"get",
"simple",
"input",
"as",
"python",
"object",
"with",
"all",
"templates",
"filled",
"in"
] | comtihon/catcher | python | https://github.com/comtihon/catcher/blob/5124e69d11cb6987daca595a61a4062d2b5f5ecc/catcher/steps/external_step.py#L19-L29 | [
"def",
"simple_input",
"(",
"self",
",",
"variables",
")",
":",
"json_args",
"=",
"fill_template_str",
"(",
"json",
".",
"dumps",
"(",
"self",
".",
"data",
")",
",",
"variables",
")",
"return",
"try_get_objects",
"(",
"json_args",
")"
] | 5124e69d11cb6987daca595a61a4062d2b5f5ecc |
train | Config.create | creates an empty configuration file | lmnotify/config.py | def create(self):
"""
creates an empty configuration file
"""
if not self.exists():
# create new empyt config file based on template
self.config.add_section("lametric")
self.config.set("lametric", "client_id", "")
self.config.set("lametric"... | def create(self):
"""
creates an empty configuration file
"""
if not self.exists():
# create new empyt config file based on template
self.config.add_section("lametric")
self.config.set("lametric", "client_id", "")
self.config.set("lametric"... | [
"creates",
"an",
"empty",
"configuration",
"file"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/config.py#L61-L80 | [
"def",
"create",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"exists",
"(",
")",
":",
"# create new empyt config file based on template",
"self",
".",
"config",
".",
"add_section",
"(",
"\"lametric\"",
")",
"self",
".",
"config",
".",
"set",
"(",
"\"lam... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | Config.save | save current config to the file | lmnotify/config.py | def save(self):
"""
save current config to the file
"""
with open(self._filename, "w") as f:
self.config.write(f) | def save(self):
"""
save current config to the file
"""
with open(self._filename, "w") as f:
self.config.write(f) | [
"save",
"current",
"config",
"to",
"the",
"file"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/config.py#L88-L93 | [
"def",
"save",
"(",
"self",
")",
":",
"with",
"open",
"(",
"self",
".",
"_filename",
",",
"\"w\"",
")",
"as",
"f",
":",
"self",
".",
"config",
".",
"write",
"(",
"f",
")"
] | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | Router.rate_limit_wait | Sleep if rate limiting is required based on current time and last
query. | directions/base.py | def rate_limit_wait(self):
"""
Sleep if rate limiting is required based on current time and last
query.
"""
if self._rate_limit_dt and self._last_query is not None:
dt = time.time() - self._last_query
wait = self._rate_limit_dt - dt
if wait > ... | def rate_limit_wait(self):
"""
Sleep if rate limiting is required based on current time and last
query.
"""
if self._rate_limit_dt and self._last_query is not None:
dt = time.time() - self._last_query
wait = self._rate_limit_dt - dt
if wait > ... | [
"Sleep",
"if",
"rate",
"limiting",
"is",
"required",
"based",
"on",
"current",
"time",
"and",
"last",
"query",
"."
] | jwass/directions.py | python | https://github.com/jwass/directions.py/blob/c3734e4cb499fe80e27b2a26575a91ac4e834e95/directions/base.py#L22-L32 | [
"def",
"rate_limit_wait",
"(",
"self",
")",
":",
"if",
"self",
".",
"_rate_limit_dt",
"and",
"self",
".",
"_last_query",
"is",
"not",
"None",
":",
"dt",
"=",
"time",
".",
"time",
"(",
")",
"-",
"self",
".",
"_last_query",
"wait",
"=",
"self",
".",
"_... | c3734e4cb499fe80e27b2a26575a91ac4e834e95 |
train | Router.route | Query a route.
route(locations): points can be
- a sequence of locations
- a Shapely LineString
route(origin, destination, waypoints=None)
- origin and destination are a single destination
- waypoints are the points to be inserted between the
... | directions/base.py | def route(self, arg, destination=None, waypoints=None, raw=False, **kwargs):
"""
Query a route.
route(locations): points can be
- a sequence of locations
- a Shapely LineString
route(origin, destination, waypoints=None)
- origin and destination are a... | def route(self, arg, destination=None, waypoints=None, raw=False, **kwargs):
"""
Query a route.
route(locations): points can be
- a sequence of locations
- a Shapely LineString
route(origin, destination, waypoints=None)
- origin and destination are a... | [
"Query",
"a",
"route",
"."
] | jwass/directions.py | python | https://github.com/jwass/directions.py/blob/c3734e4cb499fe80e27b2a26575a91ac4e834e95/directions/base.py#L38-L99 | [
"def",
"route",
"(",
"self",
",",
"arg",
",",
"destination",
"=",
"None",
",",
"waypoints",
"=",
"None",
",",
"raw",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"points",
"=",
"_parse_points",
"(",
"arg",
",",
"destination",
",",
"waypoints",
")... | c3734e4cb499fe80e27b2a26575a91ac4e834e95 |
train | Route.from_geojson | Return a Route from a GeoJSON dictionary, as returned by Route.geojson() | directions/base.py | def from_geojson(cls, data):
"""
Return a Route from a GeoJSON dictionary, as returned by Route.geojson()
"""
properties = data['properties']
distance = properties.pop('distance')
duration = properties.pop('duration')
maneuvers = []
for feature in data['... | def from_geojson(cls, data):
"""
Return a Route from a GeoJSON dictionary, as returned by Route.geojson()
"""
properties = data['properties']
distance = properties.pop('distance')
duration = properties.pop('duration')
maneuvers = []
for feature in data['... | [
"Return",
"a",
"Route",
"from",
"a",
"GeoJSON",
"dictionary",
"as",
"returned",
"by",
"Route",
".",
"geojson",
"()"
] | jwass/directions.py | python | https://github.com/jwass/directions.py/blob/c3734e4cb499fe80e27b2a26575a91ac4e834e95/directions/base.py#L193-L210 | [
"def",
"from_geojson",
"(",
"cls",
",",
"data",
")",
":",
"properties",
"=",
"data",
"[",
"'properties'",
"]",
"distance",
"=",
"properties",
".",
"pop",
"(",
"'distance'",
")",
"duration",
"=",
"properties",
".",
"pop",
"(",
"'duration'",
")",
"maneuvers"... | c3734e4cb499fe80e27b2a26575a91ac4e834e95 |
train | prepare_modules | Scan all paths for external modules and form key-value dict.
:param module_paths: list of external modules (either python packages or third-party scripts)
:param available: dict of all registered python modules (can contain python modules from module_paths)
:return: dict of external modules, where keys are ... | catcher/utils/module_utils.py | def prepare_modules(module_paths: list, available: dict) -> dict:
"""
Scan all paths for external modules and form key-value dict.
:param module_paths: list of external modules (either python packages or third-party scripts)
:param available: dict of all registered python modules (can contain python mod... | def prepare_modules(module_paths: list, available: dict) -> dict:
"""
Scan all paths for external modules and form key-value dict.
:param module_paths: list of external modules (either python packages or third-party scripts)
:param available: dict of all registered python modules (can contain python mod... | [
"Scan",
"all",
"paths",
"for",
"external",
"modules",
"and",
"form",
"key",
"-",
"value",
"dict",
".",
":",
"param",
"module_paths",
":",
"list",
"of",
"external",
"modules",
"(",
"either",
"python",
"packages",
"or",
"third",
"-",
"party",
"scripts",
")",... | comtihon/catcher | python | https://github.com/comtihon/catcher/blob/5124e69d11cb6987daca595a61a4062d2b5f5ecc/catcher/utils/module_utils.py#L14-L32 | [
"def",
"prepare_modules",
"(",
"module_paths",
":",
"list",
",",
"available",
":",
"dict",
")",
"->",
"dict",
":",
"indexed",
"=",
"{",
"}",
"for",
"path",
"in",
"module_paths",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
"a... | 5124e69d11cb6987daca595a61a4062d2b5f5ecc |
train | SSDPManager.discover_upnp_devices | sends an SSDP discovery packet to the network and collects
the devices that replies to it. A dictionary is returned
using the devices unique usn as key | lmnotify/ssdp.py | def discover_upnp_devices(
self, st="upnp:rootdevice", timeout=2, mx=1, retries=1
):
"""
sends an SSDP discovery packet to the network and collects
the devices that replies to it. A dictionary is returned
using the devices unique usn as key
"""
# prepare UDP s... | def discover_upnp_devices(
self, st="upnp:rootdevice", timeout=2, mx=1, retries=1
):
"""
sends an SSDP discovery packet to the network and collects
the devices that replies to it. A dictionary is returned
using the devices unique usn as key
"""
# prepare UDP s... | [
"sends",
"an",
"SSDP",
"discovery",
"packet",
"to",
"the",
"network",
"and",
"collects",
"the",
"devices",
"that",
"replies",
"to",
"it",
".",
"A",
"dictionary",
"is",
"returned",
"using",
"the",
"devices",
"unique",
"usn",
"as",
"key"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/ssdp.py#L80-L115 | [
"def",
"discover_upnp_devices",
"(",
"self",
",",
"st",
"=",
"\"upnp:rootdevice\"",
",",
"timeout",
"=",
"2",
",",
"mx",
"=",
"1",
",",
"retries",
"=",
"1",
")",
":",
"# prepare UDP socket to transfer the SSDP packets",
"s",
"=",
"socket",
".",
"socket",
"(",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | SSDPManager.get_filtered_devices | returns a dict of devices that contain the given model name | lmnotify/ssdp.py | def get_filtered_devices(
self, model_name, device_types="upnp:rootdevice", timeout=2
):
"""
returns a dict of devices that contain the given model name
"""
# get list of all UPNP devices in the network
upnp_devices = self.discover_upnp_devices(st=device_types)
... | def get_filtered_devices(
self, model_name, device_types="upnp:rootdevice", timeout=2
):
"""
returns a dict of devices that contain the given model name
"""
# get list of all UPNP devices in the network
upnp_devices = self.discover_upnp_devices(st=device_types)
... | [
"returns",
"a",
"dict",
"of",
"devices",
"that",
"contain",
"the",
"given",
"model",
"name"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/ssdp.py#L117-L180 | [
"def",
"get_filtered_devices",
"(",
"self",
",",
"model_name",
",",
"device_types",
"=",
"\"upnp:rootdevice\"",
",",
"timeout",
"=",
"2",
")",
":",
"# get list of all UPNP devices in the network",
"upnp_devices",
"=",
"self",
".",
"discover_upnp_devices",
"(",
"st",
"... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | lazy_map | A variant of multiprocessing.Pool.map that supports lazy evaluation
As with the regular multiprocessing.Pool.map, the processes are spawned off
asynchronously while the results are returned in order. In contrast to
multiprocessing.Pool.map, the iterator (here: data_generator) is not
consumed at once bu... | mputil/map.py | def lazy_map(data_processor, data_generator, n_cpus=1, stepsize=None):
"""A variant of multiprocessing.Pool.map that supports lazy evaluation
As with the regular multiprocessing.Pool.map, the processes are spawned off
asynchronously while the results are returned in order. In contrast to
multiprocessin... | def lazy_map(data_processor, data_generator, n_cpus=1, stepsize=None):
"""A variant of multiprocessing.Pool.map that supports lazy evaluation
As with the regular multiprocessing.Pool.map, the processes are spawned off
asynchronously while the results are returned in order. In contrast to
multiprocessin... | [
"A",
"variant",
"of",
"multiprocessing",
".",
"Pool",
".",
"map",
"that",
"supports",
"lazy",
"evaluation"
] | rasbt/mputil | python | https://github.com/rasbt/mputil/blob/952844980d4083eabe7b387de69c3d50b04abb9a/mputil/map.py#L12-L68 | [
"def",
"lazy_map",
"(",
"data_processor",
",",
"data_generator",
",",
"n_cpus",
"=",
"1",
",",
"stepsize",
"=",
"None",
")",
":",
"if",
"not",
"n_cpus",
":",
"n_cpus",
"=",
"mp",
".",
"cpu_count",
"(",
")",
"elif",
"n_cpus",
"<",
"0",
":",
"n_cpus",
... | 952844980d4083eabe7b387de69c3d50b04abb9a |
train | lazy_imap | A variant of multiprocessing.Pool.imap that supports lazy evaluation
As with the regular multiprocessing.Pool.imap, the processes are spawned
off asynchronously while the results are returned in order. In contrast to
multiprocessing.Pool.imap, the iterator (here: data_generator) is not
consumed at once... | mputil/map.py | def lazy_imap(data_processor, data_generator, n_cpus=1, stepsize=None):
"""A variant of multiprocessing.Pool.imap that supports lazy evaluation
As with the regular multiprocessing.Pool.imap, the processes are spawned
off asynchronously while the results are returned in order. In contrast to
multiproces... | def lazy_imap(data_processor, data_generator, n_cpus=1, stepsize=None):
"""A variant of multiprocessing.Pool.imap that supports lazy evaluation
As with the regular multiprocessing.Pool.imap, the processes are spawned
off asynchronously while the results are returned in order. In contrast to
multiproces... | [
"A",
"variant",
"of",
"multiprocessing",
".",
"Pool",
".",
"imap",
"that",
"supports",
"lazy",
"evaluation"
] | rasbt/mputil | python | https://github.com/rasbt/mputil/blob/952844980d4083eabe7b387de69c3d50b04abb9a/mputil/map.py#L71-L123 | [
"def",
"lazy_imap",
"(",
"data_processor",
",",
"data_generator",
",",
"n_cpus",
"=",
"1",
",",
"stepsize",
"=",
"None",
")",
":",
"if",
"not",
"n_cpus",
":",
"n_cpus",
"=",
"mp",
".",
"cpu_count",
"(",
")",
"elif",
"n_cpus",
"<",
"0",
":",
"n_cpus",
... | 952844980d4083eabe7b387de69c3d50b04abb9a |
train | update_variables | Use this decorator on Step.action implementation.
Your action method should always return variables, or
both variables and output.
This decorator will update variables with output. | catcher/steps/step.py | def update_variables(func):
"""
Use this decorator on Step.action implementation.
Your action method should always return variables, or
both variables and output.
This decorator will update variables with output.
"""
@wraps(func)
def wrapper(self, *args, **kwargs):
result = f... | def update_variables(func):
"""
Use this decorator on Step.action implementation.
Your action method should always return variables, or
both variables and output.
This decorator will update variables with output.
"""
@wraps(func)
def wrapper(self, *args, **kwargs):
result = f... | [
"Use",
"this",
"decorator",
"on",
"Step",
".",
"action",
"implementation",
"."
] | comtihon/catcher | python | https://github.com/comtihon/catcher/blob/5124e69d11cb6987daca595a61a4062d2b5f5ecc/catcher/steps/step.py#L156-L175 | [
"def",
"update_variables",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"result",
"=",
"func",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
... | 5124e69d11cb6987daca595a61a4062d2b5f5ecc |
train | AppModel._set_properties | set the properties of the app model by the given data dict | lmnotify/models.py | def _set_properties(self, data):
"""
set the properties of the app model by the given data dict
"""
for property in data.keys():
if property in vars(self):
setattr(self, property, data[property]) | def _set_properties(self, data):
"""
set the properties of the app model by the given data dict
"""
for property in data.keys():
if property in vars(self):
setattr(self, property, data[property]) | [
"set",
"the",
"properties",
"of",
"the",
"app",
"model",
"by",
"the",
"given",
"data",
"dict"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/lmnotify/models.py#L18-L24 | [
"def",
"_set_properties",
"(",
"self",
",",
"data",
")",
":",
"for",
"property",
"in",
"data",
".",
"keys",
"(",
")",
":",
"if",
"property",
"in",
"vars",
"(",
"self",
")",
":",
"setattr",
"(",
"self",
",",
"property",
",",
"data",
"[",
"property",
... | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | get_long_description | get long description from README.rst file | setup.py | def get_long_description():
"""
get long description from README.rst file
"""
with codecs.open(os.path.join(here, "README.rst"), "r", "utf-8") as f:
return f.read() | def get_long_description():
"""
get long description from README.rst file
"""
with codecs.open(os.path.join(here, "README.rst"), "r", "utf-8") as f:
return f.read() | [
"get",
"long",
"description",
"from",
"README",
".",
"rst",
"file"
] | keans/lmnotify | python | https://github.com/keans/lmnotify/blob/b0a5282a582e5090852dc20fea8a135ca258d0d3/setup.py#L9-L14 | [
"def",
"get_long_description",
"(",
")",
":",
"with",
"codecs",
".",
"open",
"(",
"os",
".",
"path",
".",
"join",
"(",
"here",
",",
"\"README.rst\"",
")",
",",
"\"r\"",
",",
"\"utf-8\"",
")",
"as",
"f",
":",
"return",
"f",
".",
"read",
"(",
")"
] | b0a5282a582e5090852dc20fea8a135ca258d0d3 |
train | roll_call_handler | This action handler responds to the "roll call" emitted by the api
gateway when it is brought up with the normal summary produced by
the service. | nautilus/network/events/actionHandlers/rollCallHandler.py | async def roll_call_handler(service, action_type, payload, props, **kwds):
"""
This action handler responds to the "roll call" emitted by the api
gateway when it is brought up with the normal summary produced by
the service.
"""
# if the action type corresponds to a roll call
if ... | async def roll_call_handler(service, action_type, payload, props, **kwds):
"""
This action handler responds to the "roll call" emitted by the api
gateway when it is brought up with the normal summary produced by
the service.
"""
# if the action type corresponds to a roll call
if ... | [
"This",
"action",
"handler",
"responds",
"to",
"the",
"roll",
"call",
"emitted",
"by",
"the",
"api",
"gateway",
"when",
"it",
"is",
"brought",
"up",
"with",
"the",
"normal",
"summary",
"produced",
"by",
"the",
"service",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/network/events/actionHandlers/rollCallHandler.py#L3-L12 | [
"async",
"def",
"roll_call_handler",
"(",
"service",
",",
"action_type",
",",
"payload",
",",
"props",
",",
"*",
"*",
"kwds",
")",
":",
"# if the action type corresponds to a roll call",
"if",
"action_type",
"==",
"roll_call_type",
"(",
")",
":",
"# then announce th... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | flexible_api_handler | This query handler builds the dynamic picture of availible services. | nautilus/network/events/actionHandlers/flexibleAPIHandler.py | async def flexible_api_handler(service, action_type, payload, props, **kwds):
"""
This query handler builds the dynamic picture of availible services.
"""
# if the action represents a new service
if action_type == intialize_service_action():
# the treat the payload like json if its a str... | async def flexible_api_handler(service, action_type, payload, props, **kwds):
"""
This query handler builds the dynamic picture of availible services.
"""
# if the action represents a new service
if action_type == intialize_service_action():
# the treat the payload like json if its a str... | [
"This",
"query",
"handler",
"builds",
"the",
"dynamic",
"picture",
"of",
"availible",
"services",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/network/events/actionHandlers/flexibleAPIHandler.py#L7-L51 | [
"async",
"def",
"flexible_api_handler",
"(",
"service",
",",
"action_type",
",",
"payload",
",",
"props",
",",
"*",
"*",
"kwds",
")",
":",
"# if the action represents a new service",
"if",
"action_type",
"==",
"intialize_service_action",
"(",
")",
":",
"# the treat ... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | _parse_order_by | This function figures out the list of orderings for the given model and
argument.
Args:
model (nautilus.BaseModel): The model to compute ordering against
order_by (list of str): the list of fields to order_by. If the field
starts with a `+` then the order is acen... | nautilus/api/filter.py | def _parse_order_by(model, order_by):
"""
This function figures out the list of orderings for the given model and
argument.
Args:
model (nautilus.BaseModel): The model to compute ordering against
order_by (list of str): the list of fields to order_by. If the field
... | def _parse_order_by(model, order_by):
"""
This function figures out the list of orderings for the given model and
argument.
Args:
model (nautilus.BaseModel): The model to compute ordering against
order_by (list of str): the list of fields to order_by. If the field
... | [
"This",
"function",
"figures",
"out",
"the",
"list",
"of",
"orderings",
"for",
"the",
"given",
"model",
"and",
"argument",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/api/filter.py#L112-L147 | [
"def",
"_parse_order_by",
"(",
"model",
",",
"order_by",
")",
":",
"# the list of filters for the models",
"out",
"=",
"[",
"]",
"# for each attribute we have to order by",
"for",
"key",
"in",
"order_by",
":",
"# remove any whitespace",
"key",
"=",
"key",
".",
"strip"... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | model | Creates the example directory structure necessary for a model service. | nautilus/management/scripts/create.py | def model(model_names):
"""
Creates the example directory structure necessary for a model service.
"""
# for each model name we need to create
for model_name in model_names:
# the template context
context = {
'name': model_name,
}
# render the model t... | def model(model_names):
"""
Creates the example directory structure necessary for a model service.
"""
# for each model name we need to create
for model_name in model_names:
# the template context
context = {
'name': model_name,
}
# render the model t... | [
"Creates",
"the",
"example",
"directory",
"structure",
"necessary",
"for",
"a",
"model",
"service",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/management/scripts/create.py#L19-L32 | [
"def",
"model",
"(",
"model_names",
")",
":",
"# for each model name we need to create",
"for",
"model_name",
"in",
"model_names",
":",
"# the template context",
"context",
"=",
"{",
"'name'",
":",
"model_name",
",",
"}",
"# render the model template",
"render_template",
... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | api | Create the folder/directories for an ApiGateway service. | nautilus/management/scripts/create.py | def api():
"""
Create the folder/directories for an ApiGateway service.
"""
# the template context
context = {
'name': 'api',
'secret_key': random_string(32)
}
render_template(template='common', context=context)
render_template(template='api', context=context) | def api():
"""
Create the folder/directories for an ApiGateway service.
"""
# the template context
context = {
'name': 'api',
'secret_key': random_string(32)
}
render_template(template='common', context=context)
render_template(template='api', context=context) | [
"Create",
"the",
"folder",
"/",
"directories",
"for",
"an",
"ApiGateway",
"service",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/management/scripts/create.py#L36-L47 | [
"def",
"api",
"(",
")",
":",
"# the template context",
"context",
"=",
"{",
"'name'",
":",
"'api'",
",",
"'secret_key'",
":",
"random_string",
"(",
"32",
")",
"}",
"render_template",
"(",
"template",
"=",
"'common'",
",",
"context",
"=",
"context",
")",
"r... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | auth | Create the folder/directories for an Auth service. | nautilus/management/scripts/create.py | def auth():
"""
Create the folder/directories for an Auth service.
"""
# the template context
context = {
'name': 'auth',
}
render_template(template='common', context=context)
render_template(template='auth', context=context) | def auth():
"""
Create the folder/directories for an Auth service.
"""
# the template context
context = {
'name': 'auth',
}
render_template(template='common', context=context)
render_template(template='auth', context=context) | [
"Create",
"the",
"folder",
"/",
"directories",
"for",
"an",
"Auth",
"service",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/management/scripts/create.py#L51-L61 | [
"def",
"auth",
"(",
")",
":",
"# the template context",
"context",
"=",
"{",
"'name'",
":",
"'auth'",
",",
"}",
"render_template",
"(",
"template",
"=",
"'common'",
",",
"context",
"=",
"context",
")",
"render_template",
"(",
"template",
"=",
"'auth'",
",",
... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | connection | Creates the example directory structure necessary for a connection
service. | nautilus/management/scripts/create.py | def connection(model_connections):
"""
Creates the example directory structure necessary for a connection
service.
"""
# for each connection group
for connection_str in model_connections:
# the services to connect
services = connection_str.split(':')
services.so... | def connection(model_connections):
"""
Creates the example directory structure necessary for a connection
service.
"""
# for each connection group
for connection_str in model_connections:
# the services to connect
services = connection_str.split(':')
services.so... | [
"Creates",
"the",
"example",
"directory",
"structure",
"necessary",
"for",
"a",
"connection",
"service",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/management/scripts/create.py#L66-L89 | [
"def",
"connection",
"(",
"model_connections",
")",
":",
"# for each connection group",
"for",
"connection_str",
"in",
"model_connections",
":",
"# the services to connect",
"services",
"=",
"connection_str",
".",
"split",
"(",
"':'",
")",
"services",
".",
"sort",
"("... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | get_model_string | This function returns the conventional action designator for a given model. | nautilus/conventions/models.py | def get_model_string(model):
"""
This function returns the conventional action designator for a given model.
"""
name = model if isinstance(model, str) else model.__name__
return normalize_string(name) | def get_model_string(model):
"""
This function returns the conventional action designator for a given model.
"""
name = model if isinstance(model, str) else model.__name__
return normalize_string(name) | [
"This",
"function",
"returns",
"the",
"conventional",
"action",
"designator",
"for",
"a",
"given",
"model",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/conventions/models.py#L8-L13 | [
"def",
"get_model_string",
"(",
"model",
")",
":",
"name",
"=",
"model",
"if",
"isinstance",
"(",
"model",
",",
"str",
")",
"else",
"model",
".",
"__name__",
"return",
"normalize_string",
"(",
"name",
")"
] | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | build_native_type_dictionary | This function takes a list of type summaries and builds a dictionary
with native representations of each entry. Useful for dynamically
building native class records from summaries. | nautilus/api/util/build_native_type_dictionary.py | def build_native_type_dictionary(fields, respect_required=False, wrap_field=True, name=''):
"""
This function takes a list of type summaries and builds a dictionary
with native representations of each entry. Useful for dynamically
building native class records from summaries.
"""
# a... | def build_native_type_dictionary(fields, respect_required=False, wrap_field=True, name=''):
"""
This function takes a list of type summaries and builds a dictionary
with native representations of each entry. Useful for dynamically
building native class records from summaries.
"""
# a... | [
"This",
"function",
"takes",
"a",
"list",
"of",
"type",
"summaries",
"and",
"builds",
"a",
"dictionary",
"with",
"native",
"representations",
"of",
"each",
"entry",
".",
"Useful",
"for",
"dynamically",
"building",
"native",
"class",
"records",
"from",
"summaries... | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/api/util/build_native_type_dictionary.py#L7-L49 | [
"def",
"build_native_type_dictionary",
"(",
"fields",
",",
"respect_required",
"=",
"False",
",",
"wrap_field",
"=",
"True",
",",
"name",
"=",
"''",
")",
":",
"# a place to start when building the input field attributes",
"input_fields",
"=",
"{",
"}",
"# go over every ... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | summarize_crud_mutation | This function provides the standard form for crud mutations. | nautilus/api/util/summarize_crud_mutation.py | def summarize_crud_mutation(method, model, isAsync=False):
"""
This function provides the standard form for crud mutations.
"""
# create the approrpriate action type
action_type = get_crud_action(method=method, model=model)
# the name of the mutation
name = crud_mutation_name(model=mode... | def summarize_crud_mutation(method, model, isAsync=False):
"""
This function provides the standard form for crud mutations.
"""
# create the approrpriate action type
action_type = get_crud_action(method=method, model=model)
# the name of the mutation
name = crud_mutation_name(model=mode... | [
"This",
"function",
"provides",
"the",
"standard",
"form",
"for",
"crud",
"mutations",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/api/util/summarize_crud_mutation.py#L15-L48 | [
"def",
"summarize_crud_mutation",
"(",
"method",
",",
"model",
",",
"isAsync",
"=",
"False",
")",
":",
"# create the approrpriate action type",
"action_type",
"=",
"get_crud_action",
"(",
"method",
"=",
"method",
",",
"model",
"=",
"model",
")",
"# the name of the m... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | KafkaBroker.start | This function starts the brokers interaction with the kafka stream | nautilus/network/events/consumers/kafka.py | def start(self):
"""
This function starts the brokers interaction with the kafka stream
"""
self.loop.run_until_complete(self._consumer.start())
self.loop.run_until_complete(self._producer.start())
self._consumer_task = self.loop.create_task(self._consume_event_callba... | def start(self):
"""
This function starts the brokers interaction with the kafka stream
"""
self.loop.run_until_complete(self._consumer.start())
self.loop.run_until_complete(self._producer.start())
self._consumer_task = self.loop.create_task(self._consume_event_callba... | [
"This",
"function",
"starts",
"the",
"brokers",
"interaction",
"with",
"the",
"kafka",
"stream"
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/network/events/consumers/kafka.py#L88-L94 | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"loop",
".",
"run_until_complete",
"(",
"self",
".",
"_consumer",
".",
"start",
"(",
")",
")",
"self",
".",
"loop",
".",
"run_until_complete",
"(",
"self",
".",
"_producer",
".",
"start",
"(",
")",
... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | KafkaBroker.stop | This method stops the brokers interaction with the kafka stream | nautilus/network/events/consumers/kafka.py | def stop(self):
"""
This method stops the brokers interaction with the kafka stream
"""
self.loop.run_until_complete(self._consumer.stop())
self.loop.run_until_complete(self._producer.stop())
# attempt
try:
# to cancel the service
self... | def stop(self):
"""
This method stops the brokers interaction with the kafka stream
"""
self.loop.run_until_complete(self._consumer.stop())
self.loop.run_until_complete(self._producer.stop())
# attempt
try:
# to cancel the service
self... | [
"This",
"method",
"stops",
"the",
"brokers",
"interaction",
"with",
"the",
"kafka",
"stream"
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/network/events/consumers/kafka.py#L97-L111 | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"loop",
".",
"run_until_complete",
"(",
"self",
".",
"_consumer",
".",
"stop",
"(",
")",
")",
"self",
".",
"loop",
".",
"run_until_complete",
"(",
"self",
".",
"_producer",
".",
"stop",
"(",
")",
")"... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
train | KafkaBroker.send | This method sends a message over the kafka stream. | nautilus/network/events/consumers/kafka.py | async def send(self, payload='', action_type='', channel=None, **kwds):
"""
This method sends a message over the kafka stream.
"""
# use a custom channel if one was provided
channel = channel or self.producer_channel
# serialize the action type for the
messag... | async def send(self, payload='', action_type='', channel=None, **kwds):
"""
This method sends a message over the kafka stream.
"""
# use a custom channel if one was provided
channel = channel or self.producer_channel
# serialize the action type for the
messag... | [
"This",
"method",
"sends",
"a",
"message",
"over",
"the",
"kafka",
"stream",
"."
] | AlecAivazis/graphql-over-kafka | python | https://github.com/AlecAivazis/graphql-over-kafka/blob/70e2acef27a2f87355590be1a6ca60ce3ab4d09c/nautilus/network/events/consumers/kafka.py#L114-L124 | [
"async",
"def",
"send",
"(",
"self",
",",
"payload",
"=",
"''",
",",
"action_type",
"=",
"''",
",",
"channel",
"=",
"None",
",",
"*",
"*",
"kwds",
")",
":",
"# use a custom channel if one was provided",
"channel",
"=",
"channel",
"or",
"self",
".",
"produc... | 70e2acef27a2f87355590be1a6ca60ce3ab4d09c |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.