repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
listlengths
20
707
docstring
stringlengths
3
17.3k
docstring_tokens
listlengths
3
222
sha
stringlengths
40
40
url
stringlengths
87
242
partition
stringclasses
1 value
idx
int64
0
252k
h2non/paco
paco/every.py
every
def every(coro, iterable, limit=1, loop=None): """ Returns `True` if every element in a given iterable satisfies the coroutine asynchronous test. If any iteratee coroutine call returns `False`, the process is inmediately stopped, and `False` will be returned. You can increase the concurrency l...
python
def every(coro, iterable, limit=1, loop=None): """ Returns `True` if every element in a given iterable satisfies the coroutine asynchronous test. If any iteratee coroutine call returns `False`, the process is inmediately stopped, and `False` will be returned. You can increase the concurrency l...
[ "def", "every", "(", "coro", ",", "iterable", ",", "limit", "=", "1", ",", "loop", "=", "None", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "assert_iter", "(", "iterable", "=", "iterable", ")", "# Reduced accumulator value", "passes", "...
Returns `True` if every element in a given iterable satisfies the coroutine asynchronous test. If any iteratee coroutine call returns `False`, the process is inmediately stopped, and `False` will be returned. You can increase the concurrency limit for a fast race condition scenario. This function...
[ "Returns", "True", "if", "every", "element", "in", "a", "given", "iterable", "satisfies", "the", "coroutine", "asynchronous", "test", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/every.py#L11-L84
train
63,000
h2non/paco
paco/gather.py
gather
def gather(*coros_or_futures, limit=0, loop=None, timeout=None, preserve_order=False, return_exceptions=False): """ Return a future aggregating results from the given coroutine objects with a concurrency execution limit. If all the tasks are done successfully, the returned future’s result is...
python
def gather(*coros_or_futures, limit=0, loop=None, timeout=None, preserve_order=False, return_exceptions=False): """ Return a future aggregating results from the given coroutine objects with a concurrency execution limit. If all the tasks are done successfully, the returned future’s result is...
[ "def", "gather", "(", "*", "coros_or_futures", ",", "limit", "=", "0", ",", "loop", "=", "None", ",", "timeout", "=", "None", ",", "preserve_order", "=", "False", ",", "return_exceptions", "=", "False", ")", ":", "# If no coroutines to schedule, return empty lis...
Return a future aggregating results from the given coroutine objects with a concurrency execution limit. If all the tasks are done successfully, the returned future’s result is the list of results (in the order of the original sequence, not necessarily the order of results arrival). If return_exce...
[ "Return", "a", "future", "aggregating", "results", "from", "the", "given", "coroutine", "objects", "with", "a", "concurrency", "execution", "limit", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/gather.py#L8-L90
train
63,001
h2non/paco
paco/timeout.py
timeout
def timeout(coro, timeout=None, loop=None): """ Wraps a given coroutine function, that when executed, if it takes more than the given timeout in seconds to execute, it will be canceled and raise an `asyncio.TimeoutError`. This function is equivalent to Python standard `asyncio.wait_for()` funct...
python
def timeout(coro, timeout=None, loop=None): """ Wraps a given coroutine function, that when executed, if it takes more than the given timeout in seconds to execute, it will be canceled and raise an `asyncio.TimeoutError`. This function is equivalent to Python standard `asyncio.wait_for()` funct...
[ "def", "timeout", "(", "coro", ",", "timeout", "=", "None", ",", "loop", "=", "None", ")", ":", "@", "asyncio", ".", "coroutine", "def", "_timeout", "(", "coro", ")", ":", "return", "(", "yield", "from", "asyncio", ".", "wait_for", "(", "coro", ",", ...
Wraps a given coroutine function, that when executed, if it takes more than the given timeout in seconds to execute, it will be canceled and raise an `asyncio.TimeoutError`. This function is equivalent to Python standard `asyncio.wait_for()` function. This function can be used as decorator. A...
[ "Wraps", "a", "given", "coroutine", "function", "that", "when", "executed", "if", "it", "takes", "more", "than", "the", "given", "timeout", "in", "seconds", "to", "execute", "it", "will", "be", "canceled", "and", "raise", "an", "asyncio", ".", "TimeoutError"...
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/timeout.py#L7-L42
train
63,002
h2non/paco
paco/race.py
race
def race(iterable, loop=None, timeout=None, *args, **kw): """ Runs coroutines from a given iterable concurrently without waiting until the previous one has completed. Once any of the tasks completes, the main coroutine is immediately resolved, yielding the first resolved value. All coroutines ...
python
def race(iterable, loop=None, timeout=None, *args, **kw): """ Runs coroutines from a given iterable concurrently without waiting until the previous one has completed. Once any of the tasks completes, the main coroutine is immediately resolved, yielding the first resolved value. All coroutines ...
[ "def", "race", "(", "iterable", ",", "loop", "=", "None", ",", "timeout", "=", "None", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "assert_iter", "(", "iterable", "=", "iterable", ")", "# Store coros and internal state", "coros", "=", "[", "]", "r...
Runs coroutines from a given iterable concurrently without waiting until the previous one has completed. Once any of the tasks completes, the main coroutine is immediately resolved, yielding the first resolved value. All coroutines will be executed in the same loop. This function is a coroutine. ...
[ "Runs", "coroutines", "from", "a", "given", "iterable", "concurrently", "without", "waiting", "until", "the", "previous", "one", "has", "completed", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/race.py#L12-L103
train
63,003
h2non/paco
paco/pipe.py
overload
def overload(fn): """ Overload a given callable object to be used with ``|`` operator overloading. This is especially used for composing a pipeline of transformation over a single data set. Arguments: fn (function): target function to decorate. Raises: TypeError: if functi...
python
def overload(fn): """ Overload a given callable object to be used with ``|`` operator overloading. This is especially used for composing a pipeline of transformation over a single data set. Arguments: fn (function): target function to decorate. Raises: TypeError: if functi...
[ "def", "overload", "(", "fn", ")", ":", "if", "not", "isfunction", "(", "fn", ")", ":", "raise", "TypeError", "(", "'paco: fn must be a callable object'", ")", "spec", "=", "getargspec", "(", "fn", ")", "args", "=", "spec", ".", "args", "if", "not", "spe...
Overload a given callable object to be used with ``|`` operator overloading. This is especially used for composing a pipeline of transformation over a single data set. Arguments: fn (function): target function to decorate. Raises: TypeError: if function or coroutine function is no...
[ "Overload", "a", "given", "callable", "object", "to", "be", "used", "with", "|", "operator", "overloading", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/pipe.py#L75-L108
train
63,004
h2non/paco
paco/generator.py
consume
def consume(generator): # pragma: no cover """ Helper function to consume a synchronous or asynchronous generator. Arguments: generator (generator|asyncgenerator): generator to consume. Returns: list """ # If synchronous generator, just consume and return as list if hasatt...
python
def consume(generator): # pragma: no cover """ Helper function to consume a synchronous or asynchronous generator. Arguments: generator (generator|asyncgenerator): generator to consume. Returns: list """ # If synchronous generator, just consume and return as list if hasatt...
[ "def", "consume", "(", "generator", ")", ":", "# pragma: no cover", "# If synchronous generator, just consume and return as list", "if", "hasattr", "(", "generator", ",", "'__next__'", ")", ":", "return", "list", "(", "generator", ")", "if", "not", "PY_35", ":", "ra...
Helper function to consume a synchronous or asynchronous generator. Arguments: generator (generator|asyncgenerator): generator to consume. Returns: list
[ "Helper", "function", "to", "consume", "a", "synchronous", "or", "asynchronous", "generator", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/generator.py#L8-L34
train
63,005
h2non/paco
paco/assertions.py
isfunc
def isfunc(x): """ Returns `True` if the given value is a function or method object. Arguments: x (mixed): value to check. Returns: bool """ return any([ inspect.isfunction(x) and not asyncio.iscoroutinefunction(x), inspect.ismethod(x) and not asyncio.iscoroutin...
python
def isfunc(x): """ Returns `True` if the given value is a function or method object. Arguments: x (mixed): value to check. Returns: bool """ return any([ inspect.isfunction(x) and not asyncio.iscoroutinefunction(x), inspect.ismethod(x) and not asyncio.iscoroutin...
[ "def", "isfunc", "(", "x", ")", ":", "return", "any", "(", "[", "inspect", ".", "isfunction", "(", "x", ")", "and", "not", "asyncio", ".", "iscoroutinefunction", "(", "x", ")", ",", "inspect", ".", "ismethod", "(", "x", ")", "and", "not", "asyncio", ...
Returns `True` if the given value is a function or method object. Arguments: x (mixed): value to check. Returns: bool
[ "Returns", "True", "if", "the", "given", "value", "is", "a", "function", "or", "method", "object", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/assertions.py#L54-L67
train
63,006
h2non/paco
paco/assertions.py
assert_corofunction
def assert_corofunction(**kw): """ Asserts if a given values are a coroutine function. Arguments: **kw (mixed): value to check if it is an iterable. Raises: TypeError: if assertion fails. """ for name, value in kw.items(): if not asyncio.iscoroutinefunction(value): ...
python
def assert_corofunction(**kw): """ Asserts if a given values are a coroutine function. Arguments: **kw (mixed): value to check if it is an iterable. Raises: TypeError: if assertion fails. """ for name, value in kw.items(): if not asyncio.iscoroutinefunction(value): ...
[ "def", "assert_corofunction", "(", "*", "*", "kw", ")", ":", "for", "name", ",", "value", "in", "kw", ".", "items", "(", ")", ":", "if", "not", "asyncio", ".", "iscoroutinefunction", "(", "value", ")", ":", "raise", "TypeError", "(", "'paco: {} must be a...
Asserts if a given values are a coroutine function. Arguments: **kw (mixed): value to check if it is an iterable. Raises: TypeError: if assertion fails.
[ "Asserts", "if", "a", "given", "values", "are", "a", "coroutine", "function", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/assertions.py#L83-L96
train
63,007
h2non/paco
paco/assertions.py
assert_iter
def assert_iter(**kw): """ Asserts if a given values implements a valid iterable interface. Arguments: **kw (mixed): value to check if it is an iterable. Raises: TypeError: if assertion fails. """ for name, value in kw.items(): if not isiter(value): raise Ty...
python
def assert_iter(**kw): """ Asserts if a given values implements a valid iterable interface. Arguments: **kw (mixed): value to check if it is an iterable. Raises: TypeError: if assertion fails. """ for name, value in kw.items(): if not isiter(value): raise Ty...
[ "def", "assert_iter", "(", "*", "*", "kw", ")", ":", "for", "name", ",", "value", "in", "kw", ".", "items", "(", ")", ":", "if", "not", "isiter", "(", "value", ")", ":", "raise", "TypeError", "(", "'paco: {} must be an iterable object'", ".", "format", ...
Asserts if a given values implements a valid iterable interface. Arguments: **kw (mixed): value to check if it is an iterable. Raises: TypeError: if assertion fails.
[ "Asserts", "if", "a", "given", "values", "implements", "a", "valid", "iterable", "interface", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/assertions.py#L99-L112
train
63,008
h2non/paco
paco/interval.py
interval
def interval(coro, interval=1, times=None, loop=None): """ Schedules the execution of a coroutine function every `x` amount of seconds. The function returns an `asyncio.Task`, which implements also an `asyncio.Future` interface, allowing the user to cancel the execution cycle. This functio...
python
def interval(coro, interval=1, times=None, loop=None): """ Schedules the execution of a coroutine function every `x` amount of seconds. The function returns an `asyncio.Task`, which implements also an `asyncio.Future` interface, allowing the user to cancel the execution cycle. This functio...
[ "def", "interval", "(", "coro", ",", "interval", "=", "1", ",", "times", "=", "None", ",", "loop", "=", "None", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "# Store maximum allowed number of calls", "times", "=", "int", "(", "times", "o...
Schedules the execution of a coroutine function every `x` amount of seconds. The function returns an `asyncio.Task`, which implements also an `asyncio.Future` interface, allowing the user to cancel the execution cycle. This function can be used as decorator. Arguments: coro (coroutine...
[ "Schedules", "the", "execution", "of", "a", "coroutine", "function", "every", "x", "amount", "of", "seconds", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/interval.py#L13-L74
train
63,009
rocky/python-spark
spark_parser/spark.py
GenericParser.addRule
def addRule(self, doc, func, _preprocess=True): """Add a grammar rules to _self.rules_, _self.rule2func_, and _self.rule2name_ Comments, lines starting with # and blank lines are stripped from doc. We also allow limited form of * and + when there it is of the RHS has a singl...
python
def addRule(self, doc, func, _preprocess=True): """Add a grammar rules to _self.rules_, _self.rule2func_, and _self.rule2name_ Comments, lines starting with # and blank lines are stripped from doc. We also allow limited form of * and + when there it is of the RHS has a singl...
[ "def", "addRule", "(", "self", ",", "doc", ",", "func", ",", "_preprocess", "=", "True", ")", ":", "fn", "=", "func", "# remove blanks lines and comment lines, e.g. lines starting with \"#\"", "doc", "=", "os", ".", "linesep", ".", "join", "(", "[", "s", "for"...
Add a grammar rules to _self.rules_, _self.rule2func_, and _self.rule2name_ Comments, lines starting with # and blank lines are stripped from doc. We also allow limited form of * and + when there it is of the RHS has a single item, e.g. stmts ::= stmt+
[ "Add", "a", "grammar", "rules", "to", "_self", ".", "rules_", "_self", ".", "rule2func_", "and", "_self", ".", "rule2name_" ]
8899954bcf0e166726841a43e87c23790eb3441f
https://github.com/rocky/python-spark/blob/8899954bcf0e166726841a43e87c23790eb3441f/spark_parser/spark.py#L188-L265
train
63,010
rocky/python-spark
spark_parser/spark.py
GenericParser.remove_rules
def remove_rules(self, doc): """Remove a grammar rules from _self.rules_, _self.rule2func_, and _self.rule2name_ """ # remove blanks lines and comment lines, e.g. lines starting with "#" doc = os.linesep.join([s for s in doc.splitlines() if s and not re.match("^\s*#", s)]) ...
python
def remove_rules(self, doc): """Remove a grammar rules from _self.rules_, _self.rule2func_, and _self.rule2name_ """ # remove blanks lines and comment lines, e.g. lines starting with "#" doc = os.linesep.join([s for s in doc.splitlines() if s and not re.match("^\s*#", s)]) ...
[ "def", "remove_rules", "(", "self", ",", "doc", ")", ":", "# remove blanks lines and comment lines, e.g. lines starting with \"#\"", "doc", "=", "os", ".", "linesep", ".", "join", "(", "[", "s", "for", "s", "in", "doc", ".", "splitlines", "(", ")", "if", "s", ...
Remove a grammar rules from _self.rules_, _self.rule2func_, and _self.rule2name_
[ "Remove", "a", "grammar", "rules", "from", "_self", ".", "rules_", "_self", ".", "rule2func_", "and", "_self", ".", "rule2name_" ]
8899954bcf0e166726841a43e87c23790eb3441f
https://github.com/rocky/python-spark/blob/8899954bcf0e166726841a43e87c23790eb3441f/spark_parser/spark.py#L267-L303
train
63,011
rocky/python-spark
spark_parser/spark.py
GenericParser.errorstack
def errorstack(self, tokens, i, full=False): """Show the stacks of completed symbols. We get this by inspecting the current transitions possible and from that extracting the set of states we are in, and from there we look at the set of symbols before the "dot". If full is True, w...
python
def errorstack(self, tokens, i, full=False): """Show the stacks of completed symbols. We get this by inspecting the current transitions possible and from that extracting the set of states we are in, and from there we look at the set of symbols before the "dot". If full is True, w...
[ "def", "errorstack", "(", "self", ",", "tokens", ",", "i", ",", "full", "=", "False", ")", ":", "print", "(", "\"\\n-- Stacks of completed symbols:\"", ")", "states", "=", "[", "s", "for", "s", "in", "self", ".", "edges", ".", "values", "(", ")", "if",...
Show the stacks of completed symbols. We get this by inspecting the current transitions possible and from that extracting the set of states we are in, and from there we look at the set of symbols before the "dot". If full is True, we show the entire rule with the dot placement. ...
[ "Show", "the", "stacks", "of", "completed", "symbols", ".", "We", "get", "this", "by", "inspecting", "the", "current", "transitions", "possible", "and", "from", "that", "extracting", "the", "set", "of", "states", "we", "are", "in", "and", "from", "there", ...
8899954bcf0e166726841a43e87c23790eb3441f
https://github.com/rocky/python-spark/blob/8899954bcf0e166726841a43e87c23790eb3441f/spark_parser/spark.py#L425-L459
train
63,012
rocky/python-spark
spark_parser/spark.py
GenericParser.parse
def parse(self, tokens, debug=None): """This is the main entry point from outside. Passing in a debug dictionary changes the default debug setting. """ self.tokens = tokens if debug: self.debug = debug sets = [ [(1, 0), (2, 0)] ] self.links...
python
def parse(self, tokens, debug=None): """This is the main entry point from outside. Passing in a debug dictionary changes the default debug setting. """ self.tokens = tokens if debug: self.debug = debug sets = [ [(1, 0), (2, 0)] ] self.links...
[ "def", "parse", "(", "self", ",", "tokens", ",", "debug", "=", "None", ")", ":", "self", ".", "tokens", "=", "tokens", "if", "debug", ":", "self", ".", "debug", "=", "debug", "sets", "=", "[", "[", "(", "1", ",", "0", ")", ",", "(", "2", ",",...
This is the main entry point from outside. Passing in a debug dictionary changes the default debug setting.
[ "This", "is", "the", "main", "entry", "point", "from", "outside", "." ]
8899954bcf0e166726841a43e87c23790eb3441f
https://github.com/rocky/python-spark/blob/8899954bcf0e166726841a43e87c23790eb3441f/spark_parser/spark.py#L461-L509
train
63,013
rocky/python-spark
spark_parser/spark.py
GenericParser.dump_grammar
def dump_grammar(self, out=sys.stdout): """ Print grammar rules """ for rule in sorted(self.rule2name.items()): out.write("%s\n" % rule2str(rule[0])) return
python
def dump_grammar(self, out=sys.stdout): """ Print grammar rules """ for rule in sorted(self.rule2name.items()): out.write("%s\n" % rule2str(rule[0])) return
[ "def", "dump_grammar", "(", "self", ",", "out", "=", "sys", ".", "stdout", ")", ":", "for", "rule", "in", "sorted", "(", "self", ".", "rule2name", ".", "items", "(", ")", ")", ":", "out", ".", "write", "(", "\"%s\\n\"", "%", "rule2str", "(", "rule"...
Print grammar rules
[ "Print", "grammar", "rules" ]
8899954bcf0e166726841a43e87c23790eb3441f
https://github.com/rocky/python-spark/blob/8899954bcf0e166726841a43e87c23790eb3441f/spark_parser/spark.py#L874-L880
train
63,014
rocky/python-spark
spark_parser/spark.py
GenericParser.profile_rule
def profile_rule(self, rule): """Bump count of the number of times _rule_ was used""" rule_str = self.reduce_string(rule) if rule_str not in self.profile_info: self.profile_info[rule_str] = 1 else: self.profile_info[rule_str] += 1
python
def profile_rule(self, rule): """Bump count of the number of times _rule_ was used""" rule_str = self.reduce_string(rule) if rule_str not in self.profile_info: self.profile_info[rule_str] = 1 else: self.profile_info[rule_str] += 1
[ "def", "profile_rule", "(", "self", ",", "rule", ")", ":", "rule_str", "=", "self", ".", "reduce_string", "(", "rule", ")", "if", "rule_str", "not", "in", "self", ".", "profile_info", ":", "self", ".", "profile_info", "[", "rule_str", "]", "=", "1", "e...
Bump count of the number of times _rule_ was used
[ "Bump", "count", "of", "the", "number", "of", "times", "_rule_", "was", "used" ]
8899954bcf0e166726841a43e87c23790eb3441f
https://github.com/rocky/python-spark/blob/8899954bcf0e166726841a43e87c23790eb3441f/spark_parser/spark.py#L975-L981
train
63,015
rocky/python-spark
spark_parser/spark.py
GenericParser.get_profile_info
def get_profile_info(self): """Show the accumulated results of how many times each rule was used""" return sorted(self.profile_info.items(), key=lambda kv: kv[1], reverse=False) return
python
def get_profile_info(self): """Show the accumulated results of how many times each rule was used""" return sorted(self.profile_info.items(), key=lambda kv: kv[1], reverse=False) return
[ "def", "get_profile_info", "(", "self", ")", ":", "return", "sorted", "(", "self", ".", "profile_info", ".", "items", "(", ")", ",", "key", "=", "lambda", "kv", ":", "kv", "[", "1", "]", ",", "reverse", "=", "False", ")", "return" ]
Show the accumulated results of how many times each rule was used
[ "Show", "the", "accumulated", "results", "of", "how", "many", "times", "each", "rule", "was", "used" ]
8899954bcf0e166726841a43e87c23790eb3441f
https://github.com/rocky/python-spark/blob/8899954bcf0e166726841a43e87c23790eb3441f/spark_parser/spark.py#L983-L988
train
63,016
h2non/paco
paco/partial.py
partial
def partial(coro, *args, **kw): """ Partial function implementation designed for coroutines, allowing variadic input arguments. This function can be used as decorator. arguments: coro (coroutinefunction): coroutine function to wrap. *args (mixed): mixed variadic arguments for parti...
python
def partial(coro, *args, **kw): """ Partial function implementation designed for coroutines, allowing variadic input arguments. This function can be used as decorator. arguments: coro (coroutinefunction): coroutine function to wrap. *args (mixed): mixed variadic arguments for parti...
[ "def", "partial", "(", "coro", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "@", "asyncio", ".", "coroutine", "def", "wrapper", "(", "*", "_args", ",", "*", "*", "_kw", ")", ":", "call_args"...
Partial function implementation designed for coroutines, allowing variadic input arguments. This function can be used as decorator. arguments: coro (coroutinefunction): coroutine function to wrap. *args (mixed): mixed variadic arguments for partial application. Raises: TypeErr...
[ "Partial", "function", "implementation", "designed", "for", "coroutines", "allowing", "variadic", "input", "arguments", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/partial.py#L8-L43
train
63,017
rocky/python-spark
example/expr2/eval.py
eval_expr
def eval_expr(expr_str, show_tokens=False, showast=False, showgrammar=False, compile_mode='exec'): """ evaluate simple expression """ parser_debug = {'rules': False, 'transition': False, 'reduce': showgrammar, 'errorstack': True, 'context': True } ...
python
def eval_expr(expr_str, show_tokens=False, showast=False, showgrammar=False, compile_mode='exec'): """ evaluate simple expression """ parser_debug = {'rules': False, 'transition': False, 'reduce': showgrammar, 'errorstack': True, 'context': True } ...
[ "def", "eval_expr", "(", "expr_str", ",", "show_tokens", "=", "False", ",", "showast", "=", "False", ",", "showgrammar", "=", "False", ",", "compile_mode", "=", "'exec'", ")", ":", "parser_debug", "=", "{", "'rules'", ":", "False", ",", "'transition'", ":"...
evaluate simple expression
[ "evaluate", "simple", "expression" ]
8899954bcf0e166726841a43e87c23790eb3441f
https://github.com/rocky/python-spark/blob/8899954bcf0e166726841a43e87c23790eb3441f/example/expr2/eval.py#L82-L101
train
63,018
kalbhor/MusicNow
musicnow/repair.py
setup
def setup(): """ Gathers all configs """ global CONFIG, BING_KEY, GENIUS_KEY, config_path, LOG_FILENAME, LOG_LINE_SEPERATOR LOG_FILENAME = 'musicrepair_log.txt' LOG_LINE_SEPERATOR = '........................\n' CONFIG = configparser.ConfigParser() config_path = realpath(__file__).rep...
python
def setup(): """ Gathers all configs """ global CONFIG, BING_KEY, GENIUS_KEY, config_path, LOG_FILENAME, LOG_LINE_SEPERATOR LOG_FILENAME = 'musicrepair_log.txt' LOG_LINE_SEPERATOR = '........................\n' CONFIG = configparser.ConfigParser() config_path = realpath(__file__).rep...
[ "def", "setup", "(", ")", ":", "global", "CONFIG", ",", "BING_KEY", ",", "GENIUS_KEY", ",", "config_path", ",", "LOG_FILENAME", ",", "LOG_LINE_SEPERATOR", "LOG_FILENAME", "=", "'musicrepair_log.txt'", "LOG_LINE_SEPERATOR", "=", "'........................\\n'", "CONFIG",...
Gathers all configs
[ "Gathers", "all", "configs" ]
12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291
https://github.com/kalbhor/MusicNow/blob/12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291/musicnow/repair.py#L42-L57
train
63,019
kalbhor/MusicNow
musicnow/repair.py
matching_details
def matching_details(song_name, song_title, artist): ''' Provides a score out of 10 that determines the relevance of the search result ''' match_name = difflib.SequenceMatcher(None, song_name, song_title).ratio() match_title = difflib.SequenceMatcher(None, song_name, artist + song_title).ratio(...
python
def matching_details(song_name, song_title, artist): ''' Provides a score out of 10 that determines the relevance of the search result ''' match_name = difflib.SequenceMatcher(None, song_name, song_title).ratio() match_title = difflib.SequenceMatcher(None, song_name, artist + song_title).ratio(...
[ "def", "matching_details", "(", "song_name", ",", "song_title", ",", "artist", ")", ":", "match_name", "=", "difflib", ".", "SequenceMatcher", "(", "None", ",", "song_name", ",", "song_title", ")", ".", "ratio", "(", ")", "match_title", "=", "difflib", ".", ...
Provides a score out of 10 that determines the relevance of the search result
[ "Provides", "a", "score", "out", "of", "10", "that", "determines", "the", "relevance", "of", "the", "search", "result" ]
12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291
https://github.com/kalbhor/MusicNow/blob/12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291/musicnow/repair.py#L60-L73
train
63,020
kalbhor/MusicNow
musicnow/repair.py
get_lyrics_letssingit
def get_lyrics_letssingit(song_name): ''' Scrapes the lyrics of a song since spotify does not provide lyrics takes song title as arguement ''' lyrics = "" url = "http://search.letssingit.com/cgi-exe/am.cgi?a=search&artist_id=&l=archive&s=" + \ quote(song_name.encode('utf-8')) html =...
python
def get_lyrics_letssingit(song_name): ''' Scrapes the lyrics of a song since spotify does not provide lyrics takes song title as arguement ''' lyrics = "" url = "http://search.letssingit.com/cgi-exe/am.cgi?a=search&artist_id=&l=archive&s=" + \ quote(song_name.encode('utf-8')) html =...
[ "def", "get_lyrics_letssingit", "(", "song_name", ")", ":", "lyrics", "=", "\"\"", "url", "=", "\"http://search.letssingit.com/cgi-exe/am.cgi?a=search&artist_id=&l=archive&s=\"", "+", "quote", "(", "song_name", ".", "encode", "(", "'utf-8'", ")", ")", "html", "=", "ur...
Scrapes the lyrics of a song since spotify does not provide lyrics takes song title as arguement
[ "Scrapes", "the", "lyrics", "of", "a", "song", "since", "spotify", "does", "not", "provide", "lyrics", "takes", "song", "title", "as", "arguement" ]
12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291
https://github.com/kalbhor/MusicNow/blob/12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291/musicnow/repair.py#L76-L104
train
63,021
kalbhor/MusicNow
musicnow/repair.py
get_details_letssingit
def get_details_letssingit(song_name): ''' Gets the song details if song details not found through spotify ''' song_name = improvename.songname(song_name) url = "http://search.letssingit.com/cgi-exe/am.cgi?a=search&artist_id=&l=archive&s=" + \ quote(song_name.encode('utf-8')) html = ur...
python
def get_details_letssingit(song_name): ''' Gets the song details if song details not found through spotify ''' song_name = improvename.songname(song_name) url = "http://search.letssingit.com/cgi-exe/am.cgi?a=search&artist_id=&l=archive&s=" + \ quote(song_name.encode('utf-8')) html = ur...
[ "def", "get_details_letssingit", "(", "song_name", ")", ":", "song_name", "=", "improvename", ".", "songname", "(", "song_name", ")", "url", "=", "\"http://search.letssingit.com/cgi-exe/am.cgi?a=search&artist_id=&l=archive&s=\"", "+", "quote", "(", "song_name", ".", "enco...
Gets the song details if song details not found through spotify
[ "Gets", "the", "song", "details", "if", "song", "details", "not", "found", "through", "spotify" ]
12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291
https://github.com/kalbhor/MusicNow/blob/12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291/musicnow/repair.py#L169-L227
train
63,022
kalbhor/MusicNow
musicnow/repair.py
add_albumart
def add_albumart(albumart, song_title): ''' Adds the album art to the song ''' try: img = urlopen(albumart) # Gets album art from url except Exception: log.log_error("* Could not add album art", indented=True) return None audio = EasyMP3(song_title, ID3=ID3) try: ...
python
def add_albumart(albumart, song_title): ''' Adds the album art to the song ''' try: img = urlopen(albumart) # Gets album art from url except Exception: log.log_error("* Could not add album art", indented=True) return None audio = EasyMP3(song_title, ID3=ID3) try: ...
[ "def", "add_albumart", "(", "albumart", ",", "song_title", ")", ":", "try", ":", "img", "=", "urlopen", "(", "albumart", ")", "# Gets album art from url", "except", "Exception", ":", "log", ".", "log_error", "(", "\"* Could not add album art\"", ",", "indented", ...
Adds the album art to the song
[ "Adds", "the", "album", "art", "to", "the", "song" ]
12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291
https://github.com/kalbhor/MusicNow/blob/12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291/musicnow/repair.py#L230-L258
train
63,023
kalbhor/MusicNow
musicnow/repair.py
add_details
def add_details(file_name, title, artist, album, lyrics=""): ''' Adds the details to song ''' tags = EasyMP3(file_name) tags["title"] = title tags["artist"] = artist tags["album"] = album tags.save() tags = ID3(file_name) uslt_output = USLT(encoding=3, lang=u'eng', desc=u'desc'...
python
def add_details(file_name, title, artist, album, lyrics=""): ''' Adds the details to song ''' tags = EasyMP3(file_name) tags["title"] = title tags["artist"] = artist tags["album"] = album tags.save() tags = ID3(file_name) uslt_output = USLT(encoding=3, lang=u'eng', desc=u'desc'...
[ "def", "add_details", "(", "file_name", ",", "title", ",", "artist", ",", "album", ",", "lyrics", "=", "\"\"", ")", ":", "tags", "=", "EasyMP3", "(", "file_name", ")", "tags", "[", "\"title\"", "]", "=", "title", "tags", "[", "\"artist\"", "]", "=", ...
Adds the details to song
[ "Adds", "the", "details", "to", "song" ]
12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291
https://github.com/kalbhor/MusicNow/blob/12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291/musicnow/repair.py#L261-L281
train
63,024
h2non/paco
paco/map.py
map
def map(coro, iterable, limit=0, loop=None, timeout=None, return_exceptions=False, *args, **kw): """ Concurrently maps values yielded from an iterable, passing then into an asynchronous coroutine function. Mapped values will be returned as list. Items order will be preserved based on origin...
python
def map(coro, iterable, limit=0, loop=None, timeout=None, return_exceptions=False, *args, **kw): """ Concurrently maps values yielded from an iterable, passing then into an asynchronous coroutine function. Mapped values will be returned as list. Items order will be preserved based on origin...
[ "def", "map", "(", "coro", ",", "iterable", ",", "limit", "=", "0", ",", "loop", "=", "None", ",", "timeout", "=", "None", ",", "return_exceptions", "=", "False", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "# Call each iterable but collecting yield...
Concurrently maps values yielded from an iterable, passing then into an asynchronous coroutine function. Mapped values will be returned as list. Items order will be preserved based on origin iterable order. Concurrency level can be configurable via ``limit`` param. This function is the asynchrono...
[ "Concurrently", "maps", "values", "yielded", "from", "an", "iterable", "passing", "then", "into", "an", "asynchronous", "coroutine", "function", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/map.py#L9-L57
train
63,025
kalbhor/MusicNow
musicnow/albumsearch.py
img_search_bing
def img_search_bing(album): ''' Bing image search ''' setup() album = album + " Album Art" api_key = "Key" endpoint = "https://api.cognitive.microsoft.com/bing/v5.0/images/search" links_dict = {} headers = {'Ocp-Apim-Subscription-Key': str(BING_KEY)} param = {'q': album, 'count': '1'...
python
def img_search_bing(album): ''' Bing image search ''' setup() album = album + " Album Art" api_key = "Key" endpoint = "https://api.cognitive.microsoft.com/bing/v5.0/images/search" links_dict = {} headers = {'Ocp-Apim-Subscription-Key': str(BING_KEY)} param = {'q': album, 'count': '1'...
[ "def", "img_search_bing", "(", "album", ")", ":", "setup", "(", ")", "album", "=", "album", "+", "\" Album Art\"", "api_key", "=", "\"Key\"", "endpoint", "=", "\"https://api.cognitive.microsoft.com/bing/v5.0/images/search\"", "links_dict", "=", "{", "}", "headers", ...
Bing image search
[ "Bing", "image", "search" ]
12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291
https://github.com/kalbhor/MusicNow/blob/12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291/musicnow/albumsearch.py#L42-L68
train
63,026
h2non/paco
paco/decorator.py
decorate
def decorate(fn): """ Generic decorator for coroutines helper functions allowing multiple variadic initialization arguments. This function is intended to be used internally. Arguments: fn (function): target function to decorate. Raises: TypeError: if function or coroutine func...
python
def decorate(fn): """ Generic decorator for coroutines helper functions allowing multiple variadic initialization arguments. This function is intended to be used internally. Arguments: fn (function): target function to decorate. Raises: TypeError: if function or coroutine func...
[ "def", "decorate", "(", "fn", ")", ":", "if", "not", "isfunction", "(", "fn", ")", ":", "raise", "TypeError", "(", "'paco: fn must be a callable object'", ")", "@", "functools", ".", "wraps", "(", "fn", ")", "def", "decorator", "(", "*", "args", ",", "*"...
Generic decorator for coroutines helper functions allowing multiple variadic initialization arguments. This function is intended to be used internally. Arguments: fn (function): target function to decorate. Raises: TypeError: if function or coroutine function is not provided. Ret...
[ "Generic", "decorator", "for", "coroutines", "helper", "functions", "allowing", "multiple", "variadic", "initialization", "arguments", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/decorator.py#L42-L85
train
63,027
h2non/paco
paco/throttle.py
throttle
def throttle(coro, limit=1, timeframe=1, return_value=None, raise_exception=False): """ Creates a throttled coroutine function that only invokes ``coro`` at most once per every time frame of seconds or milliseconds. Provide options to indicate whether func should be invoked on the lead...
python
def throttle(coro, limit=1, timeframe=1, return_value=None, raise_exception=False): """ Creates a throttled coroutine function that only invokes ``coro`` at most once per every time frame of seconds or milliseconds. Provide options to indicate whether func should be invoked on the lead...
[ "def", "throttle", "(", "coro", ",", "limit", "=", "1", ",", "timeframe", "=", "1", ",", "return_value", "=", "None", ",", "raise_exception", "=", "False", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "# Store execution limits", "limit", ...
Creates a throttled coroutine function that only invokes ``coro`` at most once per every time frame of seconds or milliseconds. Provide options to indicate whether func should be invoked on the leading and/or trailing edge of the wait timeout. Subsequent calls to the throttled coroutine return the...
[ "Creates", "a", "throttled", "coroutine", "function", "that", "only", "invokes", "coro", "at", "most", "once", "per", "every", "time", "frame", "of", "seconds", "or", "milliseconds", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/throttle.py#L16-L123
train
63,028
h2non/paco
paco/whilst.py
whilst
def whilst(coro, coro_test, assert_coro=None, *args, **kw): """ Repeatedly call `coro` coroutine function while `coro_test` returns `True`. This function is the inverse of `paco.until()`. This function is a coroutine. Arguments: coro (coroutinefunction): coroutine function to execute. ...
python
def whilst(coro, coro_test, assert_coro=None, *args, **kw): """ Repeatedly call `coro` coroutine function while `coro_test` returns `True`. This function is the inverse of `paco.until()`. This function is a coroutine. Arguments: coro (coroutinefunction): coroutine function to execute. ...
[ "def", "whilst", "(", "coro", ",", "coro_test", ",", "assert_coro", "=", "None", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ",", "coro_test", "=", "coro_test", ")", "# Store yielded values by coroutine",...
Repeatedly call `coro` coroutine function while `coro_test` returns `True`. This function is the inverse of `paco.until()`. This function is a coroutine. Arguments: coro (coroutinefunction): coroutine function to execute. coro_test (coroutinefunction): coroutine function to test. ...
[ "Repeatedly", "call", "coro", "coroutine", "function", "while", "coro_test", "returns", "True", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/whilst.py#L8-L57
train
63,029
camptocamp/anthem
anthem/lyrics/loaders.py
load_csv
def load_csv(ctx, model, path, header=None, header_exclude=None, **fmtparams): """Load a CSV from a file path. :param ctx: Anthem context :param model: Odoo model name or model klass from env :param path: absolute or relative path to CSV file. If a relative path is given you must provide a valu...
python
def load_csv(ctx, model, path, header=None, header_exclude=None, **fmtparams): """Load a CSV from a file path. :param ctx: Anthem context :param model: Odoo model name or model klass from env :param path: absolute or relative path to CSV file. If a relative path is given you must provide a valu...
[ "def", "load_csv", "(", "ctx", ",", "model", ",", "path", ",", "header", "=", "None", ",", "header_exclude", "=", "None", ",", "*", "*", "fmtparams", ")", ":", "if", "not", "os", ".", "path", ".", "isabs", "(", "path", ")", ":", "if", "ctx", ".",...
Load a CSV from a file path. :param ctx: Anthem context :param model: Odoo model name or model klass from env :param path: absolute or relative path to CSV file. If a relative path is given you must provide a value for `ODOO_DATA_PATH` in your environment or set `--odoo-data-path` o...
[ "Load", "a", "CSV", "from", "a", "file", "path", "." ]
6800730764d31a2edced12049f823fefb367e9ad
https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/loaders.py#L13-L49
train
63,030
camptocamp/anthem
anthem/lyrics/loaders.py
load_csv_stream
def load_csv_stream(ctx, model, data, header=None, header_exclude=None, **fmtparams): """Load a CSV from a stream. :param ctx: current anthem context :param model: model name as string or model klass :param data: csv data to load :param header: csv fieldnames whitelist :para...
python
def load_csv_stream(ctx, model, data, header=None, header_exclude=None, **fmtparams): """Load a CSV from a stream. :param ctx: current anthem context :param model: model name as string or model klass :param data: csv data to load :param header: csv fieldnames whitelist :para...
[ "def", "load_csv_stream", "(", "ctx", ",", "model", ",", "data", ",", "header", "=", "None", ",", "header_exclude", "=", "None", ",", "*", "*", "fmtparams", ")", ":", "_header", ",", "_rows", "=", "read_csv", "(", "data", ",", "*", "*", "fmtparams", ...
Load a CSV from a stream. :param ctx: current anthem context :param model: model name as string or model klass :param data: csv data to load :param header: csv fieldnames whitelist :param header_exclude: csv fieldnames blacklist Usage example:: from pkg_resources import Requirement, res...
[ "Load", "a", "CSV", "from", "a", "stream", "." ]
6800730764d31a2edced12049f823fefb367e9ad
https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/loaders.py#L79-L119
train
63,031
rocky/python-spark
example/python2/py2_format.py
format_python2_stmts
def format_python2_stmts(python_stmts, show_tokens=False, showast=False, showgrammar=False, compile_mode='exec'): """ formats python2 statements """ parser_debug = {'rules': False, 'transition': False, 'reduce': showgrammar, 'errorstack':...
python
def format_python2_stmts(python_stmts, show_tokens=False, showast=False, showgrammar=False, compile_mode='exec'): """ formats python2 statements """ parser_debug = {'rules': False, 'transition': False, 'reduce': showgrammar, 'errorstack':...
[ "def", "format_python2_stmts", "(", "python_stmts", ",", "show_tokens", "=", "False", ",", "showast", "=", "False", ",", "showgrammar", "=", "False", ",", "compile_mode", "=", "'exec'", ")", ":", "parser_debug", "=", "{", "'rules'", ":", "False", ",", "'tran...
formats python2 statements
[ "formats", "python2", "statements" ]
8899954bcf0e166726841a43e87c23790eb3441f
https://github.com/rocky/python-spark/blob/8899954bcf0e166726841a43e87c23790eb3441f/example/python2/py2_format.py#L686-L707
train
63,032
kalbhor/MusicNow
musicnow/improvename.py
songname
def songname(song_name): ''' Improves file name by removing crap words ''' try: song_name = splitext(song_name)[0] except IndexError: pass # Words to omit from song title for better results through spotify's API chars_filter = "()[]{}-:_/=+\"\'" words_filter = ('official...
python
def songname(song_name): ''' Improves file name by removing crap words ''' try: song_name = splitext(song_name)[0] except IndexError: pass # Words to omit from song title for better results through spotify's API chars_filter = "()[]{}-:_/=+\"\'" words_filter = ('official...
[ "def", "songname", "(", "song_name", ")", ":", "try", ":", "song_name", "=", "splitext", "(", "song_name", ")", "[", "0", "]", "except", "IndexError", ":", "pass", "# Words to omit from song title for better results through spotify's API", "chars_filter", "=", "\"()[]...
Improves file name by removing crap words
[ "Improves", "file", "name", "by", "removing", "crap", "words" ]
12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291
https://github.com/kalbhor/MusicNow/blob/12ff1ed2ea2bb7dbbfd925d7998b3ea1e20de291/musicnow/improvename.py#L5-L28
train
63,033
dchaplinsky/aiohttp_swaggerify
aiohttp_swaggerify/__init__.py
document
def document(info=None, input=None, output=None): """ Add extra information about request handler and its params """ def wrapper(func): if info is not None: setattr(func, "_swg_info", info) if input is not None: setattr(func, "_swg_input", input) if output...
python
def document(info=None, input=None, output=None): """ Add extra information about request handler and its params """ def wrapper(func): if info is not None: setattr(func, "_swg_info", info) if input is not None: setattr(func, "_swg_input", input) if output...
[ "def", "document", "(", "info", "=", "None", ",", "input", "=", "None", ",", "output", "=", "None", ")", ":", "def", "wrapper", "(", "func", ")", ":", "if", "info", "is", "not", "None", ":", "setattr", "(", "func", ",", "\"_swg_info\"", ",", "info"...
Add extra information about request handler and its params
[ "Add", "extra", "information", "about", "request", "handler", "and", "its", "params" ]
e2f2d94379b4a3bad0505e7ea09ec14ed7fcdd76
https://github.com/dchaplinsky/aiohttp_swaggerify/blob/e2f2d94379b4a3bad0505e7ea09ec14ed7fcdd76/aiohttp_swaggerify/__init__.py#L170-L183
train
63,034
h2non/paco
paco/thunk.py
thunk
def thunk(coro): """ A thunk is a subroutine that is created, often automatically, to assist a call to another subroutine. Creates a thunk coroutine which returns coroutine function that accepts no arguments and when invoked it schedules the wrapper coroutine and returns the final result. ...
python
def thunk(coro): """ A thunk is a subroutine that is created, often automatically, to assist a call to another subroutine. Creates a thunk coroutine which returns coroutine function that accepts no arguments and when invoked it schedules the wrapper coroutine and returns the final result. ...
[ "def", "thunk", "(", "coro", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "@", "asyncio", ".", "coroutine", "def", "wrapper", "(", ")", ":", "return", "(", "yield", "from", "coro", "(", ")", ")", "return", "wrapper" ]
A thunk is a subroutine that is created, often automatically, to assist a call to another subroutine. Creates a thunk coroutine which returns coroutine function that accepts no arguments and when invoked it schedules the wrapper coroutine and returns the final result. See Wikipedia page for more i...
[ "A", "thunk", "is", "a", "subroutine", "that", "is", "created", "often", "automatically", "to", "assist", "a", "call", "to", "another", "subroutine", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/thunk.py#L6-L43
train
63,035
h2non/paco
paco/reduce.py
reduce
def reduce(coro, iterable, initializer=None, limit=1, right=False, loop=None): """ Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a single value. Reduction will be executed sequentially without concurrency, so passed values...
python
def reduce(coro, iterable, initializer=None, limit=1, right=False, loop=None): """ Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a single value. Reduction will be executed sequentially without concurrency, so passed values...
[ "def", "reduce", "(", "coro", ",", "iterable", ",", "initializer", "=", "None", ",", "limit", "=", "1", ",", "right", "=", "False", ",", "loop", "=", "None", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "assert_iter", "(", "iterable"...
Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a single value. Reduction will be executed sequentially without concurrency, so passed values would be in order. This function is the asynchronous coroutine equivalent to Python s...
[ "Apply", "function", "of", "two", "arguments", "cumulatively", "to", "the", "items", "of", "sequence", "from", "left", "to", "right", "so", "as", "to", "reduce", "the", "sequence", "to", "a", "single", "value", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/reduce.py#L10-L83
train
63,036
h2non/paco
paco/times.py
times
def times(coro, limit=1, raise_exception=False, return_value=None): """ Wraps a given coroutine function to be executed only a certain amount of times. If the execution limit is exceeded, the last execution return value will be returned as result. You can optionally define a custom return valu...
python
def times(coro, limit=1, raise_exception=False, return_value=None): """ Wraps a given coroutine function to be executed only a certain amount of times. If the execution limit is exceeded, the last execution return value will be returned as result. You can optionally define a custom return valu...
[ "def", "times", "(", "coro", ",", "limit", "=", "1", ",", "raise_exception", "=", "False", ",", "return_value", "=", "None", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "# Store call times", "limit", "=", "max", "(", "limit", ",", "1"...
Wraps a given coroutine function to be executed only a certain amount of times. If the execution limit is exceeded, the last execution return value will be returned as result. You can optionally define a custom return value on exceeded via `return_value` param. This function can be used as de...
[ "Wraps", "a", "given", "coroutine", "function", "to", "be", "executed", "only", "a", "certain", "amount", "of", "times", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/times.py#L10-L84
train
63,037
camptocamp/anthem
anthem/output.py
log
def log(func=None, name=None, timing=True, timestamp=False): """ Decorator to show a description of the running function By default, it outputs the first line of the docstring. If the docstring is empty, it displays the name of the function. Alternatively, if a ``name`` is specified, it will display th...
python
def log(func=None, name=None, timing=True, timestamp=False): """ Decorator to show a description of the running function By default, it outputs the first line of the docstring. If the docstring is empty, it displays the name of the function. Alternatively, if a ``name`` is specified, it will display th...
[ "def", "log", "(", "func", "=", "None", ",", "name", "=", "None", ",", "timing", "=", "True", ",", "timestamp", "=", "False", ")", ":", "# support to be called as @log or as @log(name='')", "if", "func", "is", "None", ":", "return", "functools", ".", "partia...
Decorator to show a description of the running function By default, it outputs the first line of the docstring. If the docstring is empty, it displays the name of the function. Alternatively, if a ``name`` is specified, it will display that only. It can be called as ``@log`` or as ``@log(name='abc...
[ "Decorator", "to", "show", "a", "description", "of", "the", "running", "function" ]
6800730764d31a2edced12049f823fefb367e9ad
https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/output.py#L57-L86
train
63,038
h2non/paco
paco/constant.py
constant
def constant(value, delay=None): """ Returns a coroutine function that when called, always returns the provided value. This function has an alias: `paco.identity`. Arguments: value (mixed): value to constantly return when coroutine is called. delay (int/float): optional return valu...
python
def constant(value, delay=None): """ Returns a coroutine function that when called, always returns the provided value. This function has an alias: `paco.identity`. Arguments: value (mixed): value to constantly return when coroutine is called. delay (int/float): optional return valu...
[ "def", "constant", "(", "value", ",", "delay", "=", "None", ")", ":", "@", "asyncio", ".", "coroutine", "def", "coro", "(", ")", ":", "if", "delay", ":", "yield", "from", "asyncio", ".", "sleep", "(", "delay", ")", "return", "value", "return", "coro"...
Returns a coroutine function that when called, always returns the provided value. This function has an alias: `paco.identity`. Arguments: value (mixed): value to constantly return when coroutine is called. delay (int/float): optional return value delay in seconds. Returns: cor...
[ "Returns", "a", "coroutine", "function", "that", "when", "called", "always", "returns", "the", "provided", "value", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/constant.py#L5-L35
train
63,039
h2non/paco
paco/dropwhile.py
dropwhile
def dropwhile(coro, iterable, loop=None): """ Make an iterator that drops elements from the iterable as long as the predicate is true; afterwards, returns every element. Note, the iterator does not produce any output until the predicate first becomes false, so it may have a lengthy start-up time. ...
python
def dropwhile(coro, iterable, loop=None): """ Make an iterator that drops elements from the iterable as long as the predicate is true; afterwards, returns every element. Note, the iterator does not produce any output until the predicate first becomes false, so it may have a lengthy start-up time. ...
[ "def", "dropwhile", "(", "coro", ",", "iterable", ",", "loop", "=", "None", ")", ":", "drop", "=", "False", "@", "asyncio", ".", "coroutine", "def", "assert_fn", "(", "element", ")", ":", "nonlocal", "drop", "if", "element", "and", "not", "drop", ":", ...
Make an iterator that drops elements from the iterable as long as the predicate is true; afterwards, returns every element. Note, the iterator does not produce any output until the predicate first becomes false, so it may have a lengthy start-up time. This function is pretty much equivalent to Python ...
[ "Make", "an", "iterator", "that", "drops", "elements", "from", "the", "iterable", "as", "long", "as", "the", "predicate", "is", "true", ";", "afterwards", "returns", "every", "element", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/dropwhile.py#L9-L65
train
63,040
camptocamp/anthem
anthem/lyrics/records.py
add_xmlid
def add_xmlid(ctx, record, xmlid, noupdate=False): """ Add a XMLID on an existing record """ try: ref_id, __, __ = ctx.env['ir.model.data'].xmlid_lookup(xmlid) except ValueError: pass # does not exist, we'll create a new one else: return ctx.env['ir.model.data'].browse(ref_id) ...
python
def add_xmlid(ctx, record, xmlid, noupdate=False): """ Add a XMLID on an existing record """ try: ref_id, __, __ = ctx.env['ir.model.data'].xmlid_lookup(xmlid) except ValueError: pass # does not exist, we'll create a new one else: return ctx.env['ir.model.data'].browse(ref_id) ...
[ "def", "add_xmlid", "(", "ctx", ",", "record", ",", "xmlid", ",", "noupdate", "=", "False", ")", ":", "try", ":", "ref_id", ",", "__", ",", "__", "=", "ctx", ".", "env", "[", "'ir.model.data'", "]", ".", "xmlid_lookup", "(", "xmlid", ")", "except", ...
Add a XMLID on an existing record
[ "Add", "a", "XMLID", "on", "an", "existing", "record" ]
6800730764d31a2edced12049f823fefb367e9ad
https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/records.py#L9-L28
train
63,041
camptocamp/anthem
anthem/lyrics/records.py
create_or_update
def create_or_update(ctx, model, xmlid, values): """ Create or update a record matching xmlid with values """ if isinstance(model, basestring): model = ctx.env[model] record = ctx.env.ref(xmlid, raise_if_not_found=False) if record: record.update(values) else: record = model....
python
def create_or_update(ctx, model, xmlid, values): """ Create or update a record matching xmlid with values """ if isinstance(model, basestring): model = ctx.env[model] record = ctx.env.ref(xmlid, raise_if_not_found=False) if record: record.update(values) else: record = model....
[ "def", "create_or_update", "(", "ctx", ",", "model", ",", "xmlid", ",", "values", ")", ":", "if", "isinstance", "(", "model", ",", "basestring", ")", ":", "model", "=", "ctx", ".", "env", "[", "model", "]", "record", "=", "ctx", ".", "env", ".", "r...
Create or update a record matching xmlid with values
[ "Create", "or", "update", "a", "record", "matching", "xmlid", "with", "values" ]
6800730764d31a2edced12049f823fefb367e9ad
https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/records.py#L31-L42
train
63,042
camptocamp/anthem
anthem/lyrics/records.py
safe_record
def safe_record(ctx, item): """Make sure we get a record instance even if we pass an xmlid.""" if isinstance(item, basestring): return ctx.env.ref(item) return item
python
def safe_record(ctx, item): """Make sure we get a record instance even if we pass an xmlid.""" if isinstance(item, basestring): return ctx.env.ref(item) return item
[ "def", "safe_record", "(", "ctx", ",", "item", ")", ":", "if", "isinstance", "(", "item", ",", "basestring", ")", ":", "return", "ctx", ".", "env", ".", "ref", "(", "item", ")", "return", "item" ]
Make sure we get a record instance even if we pass an xmlid.
[ "Make", "sure", "we", "get", "a", "record", "instance", "even", "if", "we", "pass", "an", "xmlid", "." ]
6800730764d31a2edced12049f823fefb367e9ad
https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/records.py#L45-L49
train
63,043
camptocamp/anthem
anthem/lyrics/records.py
switch_company
def switch_company(ctx, company): """Context manager to switch current company. Accepts both company record and xmlid. """ current_company = ctx.env.user.company_id ctx.env.user.company_id = safe_record(ctx, company) yield ctx ctx.env.user.company_id = current_company
python
def switch_company(ctx, company): """Context manager to switch current company. Accepts both company record and xmlid. """ current_company = ctx.env.user.company_id ctx.env.user.company_id = safe_record(ctx, company) yield ctx ctx.env.user.company_id = current_company
[ "def", "switch_company", "(", "ctx", ",", "company", ")", ":", "current_company", "=", "ctx", ".", "env", ".", "user", ".", "company_id", "ctx", ".", "env", ".", "user", ".", "company_id", "=", "safe_record", "(", "ctx", ",", "company", ")", "yield", "...
Context manager to switch current company. Accepts both company record and xmlid.
[ "Context", "manager", "to", "switch", "current", "company", "." ]
6800730764d31a2edced12049f823fefb367e9ad
https://github.com/camptocamp/anthem/blob/6800730764d31a2edced12049f823fefb367e9ad/anthem/lyrics/records.py#L53-L61
train
63,044
h2non/paco
paco/apply.py
apply
def apply(coro, *args, **kw): """ Creates a continuation coroutine function with some arguments already applied. Useful as a shorthand when combined with other control flow functions. Any arguments passed to the returned function are added to the arguments originally passed to apply. This ...
python
def apply(coro, *args, **kw): """ Creates a continuation coroutine function with some arguments already applied. Useful as a shorthand when combined with other control flow functions. Any arguments passed to the returned function are added to the arguments originally passed to apply. This ...
[ "def", "apply", "(", "coro", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "@", "asyncio", ".", "coroutine", "def", "wrapper", "(", "*", "_args", ",", "*", "*", "_kw", ")", ":", "# Explicitel...
Creates a continuation coroutine function with some arguments already applied. Useful as a shorthand when combined with other control flow functions. Any arguments passed to the returned function are added to the arguments originally passed to apply. This is similar to `paco.partial()`. This ...
[ "Creates", "a", "continuation", "coroutine", "function", "with", "some", "arguments", "already", "applied", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/apply.py#L8-L54
train
63,045
h2non/paco
paco/run.py
run
def run(coro, loop=None): """ Convenient shortcut alias to ``loop.run_until_complete``. Arguments: coro (coroutine): coroutine object to schedule. loop (asyncio.BaseEventLoop): optional event loop to use. Defaults to: ``asyncio.get_event_loop()``. Returns: mixed: re...
python
def run(coro, loop=None): """ Convenient shortcut alias to ``loop.run_until_complete``. Arguments: coro (coroutine): coroutine object to schedule. loop (asyncio.BaseEventLoop): optional event loop to use. Defaults to: ``asyncio.get_event_loop()``. Returns: mixed: re...
[ "def", "run", "(", "coro", ",", "loop", "=", "None", ")", ":", "loop", "=", "loop", "or", "asyncio", ".", "get_event_loop", "(", ")", "return", "loop", ".", "run_until_complete", "(", "coro", ")" ]
Convenient shortcut alias to ``loop.run_until_complete``. Arguments: coro (coroutine): coroutine object to schedule. loop (asyncio.BaseEventLoop): optional event loop to use. Defaults to: ``asyncio.get_event_loop()``. Returns: mixed: returned value by coroutine. Usage:...
[ "Convenient", "shortcut", "alias", "to", "loop", ".", "run_until_complete", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/run.py#L4-L26
train
63,046
h2non/paco
paco/wait.py
wait
def wait(*coros_or_futures, limit=0, timeout=None, loop=None, return_exceptions=False, return_when='ALL_COMPLETED'): """ Wait for the Futures and coroutine objects given by the sequence futures to complete, with optional concurrency limit. Coroutines will be wrapped in Tasks. ``timeout`` c...
python
def wait(*coros_or_futures, limit=0, timeout=None, loop=None, return_exceptions=False, return_when='ALL_COMPLETED'): """ Wait for the Futures and coroutine objects given by the sequence futures to complete, with optional concurrency limit. Coroutines will be wrapped in Tasks. ``timeout`` c...
[ "def", "wait", "(", "*", "coros_or_futures", ",", "limit", "=", "0", ",", "timeout", "=", "None", ",", "loop", "=", "None", ",", "return_exceptions", "=", "False", ",", "return_when", "=", "'ALL_COMPLETED'", ")", ":", "# Support iterable as first argument for be...
Wait for the Futures and coroutine objects given by the sequence futures to complete, with optional concurrency limit. Coroutines will be wrapped in Tasks. ``timeout`` can be used to control the maximum number of seconds to wait before returning. timeout can be an int or float. If timeout is not sp...
[ "Wait", "for", "the", "Futures", "and", "coroutine", "objects", "given", "by", "the", "sequence", "futures", "to", "complete", "with", "optional", "concurrency", "limit", ".", "Coroutines", "will", "be", "wrapped", "in", "Tasks", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/wait.py#L8-L84
train
63,047
h2non/paco
paco/series.py
series
def series(*coros_or_futures, timeout=None, loop=None, return_exceptions=False): """ Run the given coroutine functions in series, each one running once the previous execution has completed. If any coroutines raises an exception, no more coroutines are executed. Otherwise, the coroutines ...
python
def series(*coros_or_futures, timeout=None, loop=None, return_exceptions=False): """ Run the given coroutine functions in series, each one running once the previous execution has completed. If any coroutines raises an exception, no more coroutines are executed. Otherwise, the coroutines ...
[ "def", "series", "(", "*", "coros_or_futures", ",", "timeout", "=", "None", ",", "loop", "=", "None", ",", "return_exceptions", "=", "False", ")", ":", "return", "(", "yield", "from", "gather", "(", "*", "coros_or_futures", ",", "loop", "=", "loop", ",",...
Run the given coroutine functions in series, each one running once the previous execution has completed. If any coroutines raises an exception, no more coroutines are executed. Otherwise, the coroutines returned values will be returned as `list`. ``timeout`` can be used to control the maximum numb...
[ "Run", "the", "given", "coroutine", "functions", "in", "series", "each", "one", "running", "once", "the", "previous", "execution", "has", "completed", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/series.py#L7-L68
train
63,048
h2non/paco
paco/repeat.py
repeat
def repeat(coro, times=1, step=1, limit=1, loop=None): """ Executes the coroutine function ``x`` number of times, and accumulates results in order as you would use with ``map``. Execution concurrency is configurable using ``limit`` param. This function is a coroutine. Arguments: coro...
python
def repeat(coro, times=1, step=1, limit=1, loop=None): """ Executes the coroutine function ``x`` number of times, and accumulates results in order as you would use with ``map``. Execution concurrency is configurable using ``limit`` param. This function is a coroutine. Arguments: coro...
[ "def", "repeat", "(", "coro", ",", "times", "=", "1", ",", "step", "=", "1", ",", "limit", "=", "1", ",", "loop", "=", "None", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "# Iterate and attach coroutine for defer scheduling", "times", "...
Executes the coroutine function ``x`` number of times, and accumulates results in order as you would use with ``map``. Execution concurrency is configurable using ``limit`` param. This function is a coroutine. Arguments: coro (coroutinefunction): coroutine function to schedule. times...
[ "Executes", "the", "coroutine", "function", "x", "number", "of", "times", "and", "accumulates", "results", "in", "order", "as", "you", "would", "use", "with", "map", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/repeat.py#L8-L46
train
63,049
h2non/paco
paco/once.py
once
def once(coro, raise_exception=False, return_value=None): """ Wrap a given coroutine function that is restricted to one execution. Repeated calls to the coroutine function will return the value of the first invocation. This function can be used as decorator. arguments: coro (coroutine...
python
def once(coro, raise_exception=False, return_value=None): """ Wrap a given coroutine function that is restricted to one execution. Repeated calls to the coroutine function will return the value of the first invocation. This function can be used as decorator. arguments: coro (coroutine...
[ "def", "once", "(", "coro", ",", "raise_exception", "=", "False", ",", "return_value", "=", "None", ")", ":", "return", "times", "(", "coro", ",", "limit", "=", "1", ",", "return_value", "=", "return_value", ",", "raise_exception", "=", "raise_exception", ...
Wrap a given coroutine function that is restricted to one execution. Repeated calls to the coroutine function will return the value of the first invocation. This function can be used as decorator. arguments: coro (coroutinefunction): coroutine function to wrap. raise_exception (bool):...
[ "Wrap", "a", "given", "coroutine", "function", "that", "is", "restricted", "to", "one", "execution", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/once.py#L7-L49
train
63,050
h2non/paco
paco/defer.py
defer
def defer(coro, delay=1): """ Returns a coroutine function wrapper that will defer the given coroutine execution for a certain amount of seconds in a non-blocking way. This function can be used as decorator. Arguments: coro (coroutinefunction): coroutine function to defer. delay (i...
python
def defer(coro, delay=1): """ Returns a coroutine function wrapper that will defer the given coroutine execution for a certain amount of seconds in a non-blocking way. This function can be used as decorator. Arguments: coro (coroutinefunction): coroutine function to defer. delay (i...
[ "def", "defer", "(", "coro", ",", "delay", "=", "1", ")", ":", "assert_corofunction", "(", "coro", "=", "coro", ")", "@", "asyncio", ".", "coroutine", "def", "wrapper", "(", "*", "args", ",", "*", "*", "kw", ")", ":", "# Wait until we're done", "yield"...
Returns a coroutine function wrapper that will defer the given coroutine execution for a certain amount of seconds in a non-blocking way. This function can be used as decorator. Arguments: coro (coroutinefunction): coroutine function to defer. delay (int/float): number of seconds to defer ...
[ "Returns", "a", "coroutine", "function", "wrapper", "that", "will", "defer", "the", "given", "coroutine", "execution", "for", "a", "certain", "amount", "of", "seconds", "in", "a", "non", "-", "blocking", "way", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/defer.py#L8-L48
train
63,051
h2non/paco
paco/concurrent.py
safe_run
def safe_run(coro, return_exceptions=False): """ Executes a given coroutine and optionally catches exceptions, returning them as value. This function is intended to be used internally. """ try: result = yield from coro except Exception as err: if return_exceptions: re...
python
def safe_run(coro, return_exceptions=False): """ Executes a given coroutine and optionally catches exceptions, returning them as value. This function is intended to be used internally. """ try: result = yield from coro except Exception as err: if return_exceptions: re...
[ "def", "safe_run", "(", "coro", ",", "return_exceptions", "=", "False", ")", ":", "try", ":", "result", "=", "yield", "from", "coro", "except", "Exception", "as", "err", ":", "if", "return_exceptions", ":", "result", "=", "err", "else", ":", "raise", "er...
Executes a given coroutine and optionally catches exceptions, returning them as value. This function is intended to be used internally.
[ "Executes", "a", "given", "coroutine", "and", "optionally", "catches", "exceptions", "returning", "them", "as", "value", ".", "This", "function", "is", "intended", "to", "be", "used", "internally", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L27-L39
train
63,052
h2non/paco
paco/concurrent.py
collect
def collect(coro, index, results, preserve_order=False, return_exceptions=False): """ Collect is used internally to execute coroutines and collect the returned value. This function is intended to be used internally. """ result = yield from safe_run(coro, return_exceptions=ret...
python
def collect(coro, index, results, preserve_order=False, return_exceptions=False): """ Collect is used internally to execute coroutines and collect the returned value. This function is intended to be used internally. """ result = yield from safe_run(coro, return_exceptions=ret...
[ "def", "collect", "(", "coro", ",", "index", ",", "results", ",", "preserve_order", "=", "False", ",", "return_exceptions", "=", "False", ")", ":", "result", "=", "yield", "from", "safe_run", "(", "coro", ",", "return_exceptions", "=", "return_exceptions", "...
Collect is used internally to execute coroutines and collect the returned value. This function is intended to be used internally.
[ "Collect", "is", "used", "internally", "to", "execute", "coroutines", "and", "collect", "the", "returned", "value", ".", "This", "function", "is", "intended", "to", "be", "used", "internally", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L43-L55
train
63,053
h2non/paco
paco/concurrent.py
ConcurrentExecutor.reset
def reset(self): """ Resets the executer scheduler internal state. Raises: RuntimeError: is the executor is still running. """ if self.running: raise RuntimeError('paco: executor is still running') self.pool.clear() self.observer.clear() ...
python
def reset(self): """ Resets the executer scheduler internal state. Raises: RuntimeError: is the executor is still running. """ if self.running: raise RuntimeError('paco: executor is still running') self.pool.clear() self.observer.clear() ...
[ "def", "reset", "(", "self", ")", ":", "if", "self", ".", "running", ":", "raise", "RuntimeError", "(", "'paco: executor is still running'", ")", "self", ".", "pool", ".", "clear", "(", ")", "self", ".", "observer", ".", "clear", "(", ")", "self", ".", ...
Resets the executer scheduler internal state. Raises: RuntimeError: is the executor is still running.
[ "Resets", "the", "executer", "scheduler", "internal", "state", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L133-L145
train
63,054
h2non/paco
paco/concurrent.py
ConcurrentExecutor.add
def add(self, coro, *args, **kw): """ Adds a new coroutine function with optional variadic argumetns. Arguments: coro (coroutine function): coroutine to execute. *args (mixed): optional variadic arguments Raises: TypeError: if the coro object is not ...
python
def add(self, coro, *args, **kw): """ Adds a new coroutine function with optional variadic argumetns. Arguments: coro (coroutine function): coroutine to execute. *args (mixed): optional variadic arguments Raises: TypeError: if the coro object is not ...
[ "def", "add", "(", "self", ",", "coro", ",", "*", "args", ",", "*", "*", "kw", ")", ":", "# Create coroutine object if a function is provided", "if", "asyncio", ".", "iscoroutinefunction", "(", "coro", ")", ":", "coro", "=", "coro", "(", "*", "args", ",", ...
Adds a new coroutine function with optional variadic argumetns. Arguments: coro (coroutine function): coroutine to execute. *args (mixed): optional variadic arguments Raises: TypeError: if the coro object is not a valid coroutine Returns: future...
[ "Adds", "a", "new", "coroutine", "function", "with", "optional", "variadic", "argumetns", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L184-L213
train
63,055
h2non/paco
paco/concurrent.py
ConcurrentExecutor.run
def run(self, timeout=None, return_when=None, return_exceptions=None, ignore_empty=None): """ Executes the registered coroutines in the executor queue. Arguments: timeout (int/float): max execution timeout. No limit by default. ...
python
def run(self, timeout=None, return_when=None, return_exceptions=None, ignore_empty=None): """ Executes the registered coroutines in the executor queue. Arguments: timeout (int/float): max execution timeout. No limit by default. ...
[ "def", "run", "(", "self", ",", "timeout", "=", "None", ",", "return_when", "=", "None", ",", "return_exceptions", "=", "None", ",", "ignore_empty", "=", "None", ")", ":", "# Only allow 1 concurrent execution", "if", "self", ".", "running", ":", "raise", "Ru...
Executes the registered coroutines in the executor queue. Arguments: timeout (int/float): max execution timeout. No limit by default. return_exceptions (bool): in case of coroutine exception. return_when (str): sets when coroutine should be resolved. See `asy...
[ "Executes", "the", "registered", "coroutines", "in", "the", "executor", "queue", "." ]
1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d
https://github.com/h2non/paco/blob/1e5ef4df317e7cbbcefdf67d8dee28ce90538f3d/paco/concurrent.py#L306-L390
train
63,056
gopalkoduri/pypeaks
pypeaks/intervals.py
Intervals.next_interval
def next_interval(self, interval): """ Given a value of an interval, this function returns the next interval value """ index = np.where(self.intervals == interval) if index[0][0] + 1 < len(self.intervals): return self.intervals[index[0][0] + 1] else: ...
python
def next_interval(self, interval): """ Given a value of an interval, this function returns the next interval value """ index = np.where(self.intervals == interval) if index[0][0] + 1 < len(self.intervals): return self.intervals[index[0][0] + 1] else: ...
[ "def", "next_interval", "(", "self", ",", "interval", ")", ":", "index", "=", "np", ".", "where", "(", "self", ".", "intervals", "==", "interval", ")", "if", "index", "[", "0", "]", "[", "0", "]", "+", "1", "<", "len", "(", "self", ".", "interval...
Given a value of an interval, this function returns the next interval value
[ "Given", "a", "value", "of", "an", "interval", "this", "function", "returns", "the", "next", "interval", "value" ]
59b1e4153e80c6a4c523dda241cc1713fd66161e
https://github.com/gopalkoduri/pypeaks/blob/59b1e4153e80c6a4c523dda241cc1713fd66161e/pypeaks/intervals.py#L23-L32
train
63,057
gopalkoduri/pypeaks
pypeaks/intervals.py
Intervals.nearest_interval
def nearest_interval(self, interval): """ This function returns the nearest interval to any given interval. """ thresh_range = 25 # in cents if interval < self.intervals[0] - thresh_range or interval > self.intervals[-1] + thresh_range: raise IndexError("The interval...
python
def nearest_interval(self, interval): """ This function returns the nearest interval to any given interval. """ thresh_range = 25 # in cents if interval < self.intervals[0] - thresh_range or interval > self.intervals[-1] + thresh_range: raise IndexError("The interval...
[ "def", "nearest_interval", "(", "self", ",", "interval", ")", ":", "thresh_range", "=", "25", "# in cents", "if", "interval", "<", "self", ".", "intervals", "[", "0", "]", "-", "thresh_range", "or", "interval", ">", "self", ".", "intervals", "[", "-", "1...
This function returns the nearest interval to any given interval.
[ "This", "function", "returns", "the", "nearest", "interval", "to", "any", "given", "interval", "." ]
59b1e4153e80c6a4c523dda241cc1713fd66161e
https://github.com/gopalkoduri/pypeaks/blob/59b1e4153e80c6a4c523dda241cc1713fd66161e/pypeaks/intervals.py#L34-L44
train
63,058
kgori/treeCl
treeCl/alignment.py
brent_optimise
def brent_optimise(node1, node2, min_brlen=0.001, max_brlen=10, verbose=False): """ Optimise ML distance between two partials. min and max set brackets """ from scipy.optimize import minimize_scalar wrapper = BranchLengthOptimiser(node1, node2, (min_brlen + max_brlen) / 2.) n = minimize_scalar(l...
python
def brent_optimise(node1, node2, min_brlen=0.001, max_brlen=10, verbose=False): """ Optimise ML distance between two partials. min and max set brackets """ from scipy.optimize import minimize_scalar wrapper = BranchLengthOptimiser(node1, node2, (min_brlen + max_brlen) / 2.) n = minimize_scalar(l...
[ "def", "brent_optimise", "(", "node1", ",", "node2", ",", "min_brlen", "=", "0.001", ",", "max_brlen", "=", "10", ",", "verbose", "=", "False", ")", ":", "from", "scipy", ".", "optimize", "import", "minimize_scalar", "wrapper", "=", "BranchLengthOptimiser", ...
Optimise ML distance between two partials. min and max set brackets
[ "Optimise", "ML", "distance", "between", "two", "partials", ".", "min", "and", "max", "set", "brackets" ]
fed624b3db1c19cc07175ca04e3eda6905a8d305
https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L297-L309
train
63,059
kgori/treeCl
treeCl/alignment.py
pairdists
def pairdists(alignment, subs_model, alpha=None, ncat=4, tolerance=1e-6, verbose=False): """ Load an alignment, calculate all pairwise distances and variances model parameter must be a Substitution model type from phylo_utils """ # Check if not isinstance(subs_model, phylo_utils.models.Model): ...
python
def pairdists(alignment, subs_model, alpha=None, ncat=4, tolerance=1e-6, verbose=False): """ Load an alignment, calculate all pairwise distances and variances model parameter must be a Substitution model type from phylo_utils """ # Check if not isinstance(subs_model, phylo_utils.models.Model): ...
[ "def", "pairdists", "(", "alignment", ",", "subs_model", ",", "alpha", "=", "None", ",", "ncat", "=", "4", ",", "tolerance", "=", "1e-6", ",", "verbose", "=", "False", ")", ":", "# Check", "if", "not", "isinstance", "(", "subs_model", ",", "phylo_utils",...
Load an alignment, calculate all pairwise distances and variances model parameter must be a Substitution model type from phylo_utils
[ "Load", "an", "alignment", "calculate", "all", "pairwise", "distances", "and", "variances", "model", "parameter", "must", "be", "a", "Substitution", "model", "type", "from", "phylo_utils" ]
fed624b3db1c19cc07175ca04e3eda6905a8d305
https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L311-L349
train
63,060
kgori/treeCl
treeCl/alignment.py
Alignment.write_alignment
def write_alignment(self, filename, file_format, interleaved=None): """ Write the alignment to file using Bio.AlignIO """ if file_format == 'phylip': file_format = 'phylip-relaxed' AlignIO.write(self._msa, filename, file_format)
python
def write_alignment(self, filename, file_format, interleaved=None): """ Write the alignment to file using Bio.AlignIO """ if file_format == 'phylip': file_format = 'phylip-relaxed' AlignIO.write(self._msa, filename, file_format)
[ "def", "write_alignment", "(", "self", ",", "filename", ",", "file_format", ",", "interleaved", "=", "None", ")", ":", "if", "file_format", "==", "'phylip'", ":", "file_format", "=", "'phylip-relaxed'", "AlignIO", ".", "write", "(", "self", ".", "_msa", ",",...
Write the alignment to file using Bio.AlignIO
[ "Write", "the", "alignment", "to", "file", "using", "Bio", ".", "AlignIO" ]
fed624b3db1c19cc07175ca04e3eda6905a8d305
https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L166-L172
train
63,061
kgori/treeCl
treeCl/alignment.py
Alignment.simulate
def simulate(self, nsites, transition_matrix, tree, ncat=1, alpha=1): """ Return sequences simulated under the transition matrix's model """ sim = SequenceSimulator(transition_matrix, tree, ncat, alpha) return list(sim.simulate(nsites).items())
python
def simulate(self, nsites, transition_matrix, tree, ncat=1, alpha=1): """ Return sequences simulated under the transition matrix's model """ sim = SequenceSimulator(transition_matrix, tree, ncat, alpha) return list(sim.simulate(nsites).items())
[ "def", "simulate", "(", "self", ",", "nsites", ",", "transition_matrix", ",", "tree", ",", "ncat", "=", "1", ",", "alpha", "=", "1", ")", ":", "sim", "=", "SequenceSimulator", "(", "transition_matrix", ",", "tree", ",", "ncat", ",", "alpha", ")", "retu...
Return sequences simulated under the transition matrix's model
[ "Return", "sequences", "simulated", "under", "the", "transition", "matrix", "s", "model" ]
fed624b3db1c19cc07175ca04e3eda6905a8d305
https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L230-L235
train
63,062
kgori/treeCl
treeCl/alignment.py
Alignment.bootstrap
def bootstrap(self): """ Return a new Alignment that is a bootstrap replicate of self """ new_sites = sorted(sample_wr(self.get_sites())) seqs = list(zip(self.get_names(), (''.join(seq) for seq in zip(*new_sites)))) return self.__class__(seqs)
python
def bootstrap(self): """ Return a new Alignment that is a bootstrap replicate of self """ new_sites = sorted(sample_wr(self.get_sites())) seqs = list(zip(self.get_names(), (''.join(seq) for seq in zip(*new_sites)))) return self.__class__(seqs)
[ "def", "bootstrap", "(", "self", ")", ":", "new_sites", "=", "sorted", "(", "sample_wr", "(", "self", ".", "get_sites", "(", ")", ")", ")", "seqs", "=", "list", "(", "zip", "(", "self", ".", "get_names", "(", ")", ",", "(", "''", ".", "join", "("...
Return a new Alignment that is a bootstrap replicate of self
[ "Return", "a", "new", "Alignment", "that", "is", "a", "bootstrap", "replicate", "of", "self" ]
fed624b3db1c19cc07175ca04e3eda6905a8d305
https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L237-L243
train
63,063
kgori/treeCl
treeCl/alignment.py
SequenceSimulator.simulate
def simulate(self, n): """ Evolve multiple sites during one tree traversal """ self.tree._tree.seed_node.states = self.ancestral_states(n) categories = np.random.randint(self.ncat, size=n).astype(np.intc) for node in self.tree.preorder(skip_seed=True): node.s...
python
def simulate(self, n): """ Evolve multiple sites during one tree traversal """ self.tree._tree.seed_node.states = self.ancestral_states(n) categories = np.random.randint(self.ncat, size=n).astype(np.intc) for node in self.tree.preorder(skip_seed=True): node.s...
[ "def", "simulate", "(", "self", ",", "n", ")", ":", "self", ".", "tree", ".", "_tree", ".", "seed_node", ".", "states", "=", "self", ".", "ancestral_states", "(", "n", ")", "categories", "=", "np", ".", "random", ".", "randint", "(", "self", ".", "...
Evolve multiple sites during one tree traversal
[ "Evolve", "multiple", "sites", "during", "one", "tree", "traversal" ]
fed624b3db1c19cc07175ca04e3eda6905a8d305
https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L386-L397
train
63,064
kgori/treeCl
treeCl/alignment.py
SequenceSimulator.ancestral_states
def ancestral_states(self, n): """ Generate ancestral sequence states from the equilibrium frequencies """ anc = np.empty(n, dtype=np.intc) _weighted_choices(self.state_indices, self.freqs, anc) return anc
python
def ancestral_states(self, n): """ Generate ancestral sequence states from the equilibrium frequencies """ anc = np.empty(n, dtype=np.intc) _weighted_choices(self.state_indices, self.freqs, anc) return anc
[ "def", "ancestral_states", "(", "self", ",", "n", ")", ":", "anc", "=", "np", ".", "empty", "(", "n", ",", "dtype", "=", "np", ".", "intc", ")", "_weighted_choices", "(", "self", ".", "state_indices", ",", "self", ".", "freqs", ",", "anc", ")", "re...
Generate ancestral sequence states from the equilibrium frequencies
[ "Generate", "ancestral", "sequence", "states", "from", "the", "equilibrium", "frequencies" ]
fed624b3db1c19cc07175ca04e3eda6905a8d305
https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L399-L405
train
63,065
kgori/treeCl
treeCl/alignment.py
SequenceSimulator.sequences_to_string
def sequences_to_string(self): """ Convert state indices to a string of characters """ return {k: ''.join(self.states[v]) for (k, v) in self.sequences.items()}
python
def sequences_to_string(self): """ Convert state indices to a string of characters """ return {k: ''.join(self.states[v]) for (k, v) in self.sequences.items()}
[ "def", "sequences_to_string", "(", "self", ")", ":", "return", "{", "k", ":", "''", ".", "join", "(", "self", ".", "states", "[", "v", "]", ")", "for", "(", "k", ",", "v", ")", "in", "self", ".", "sequences", ".", "items", "(", ")", "}" ]
Convert state indices to a string of characters
[ "Convert", "state", "indices", "to", "a", "string", "of", "characters" ]
fed624b3db1c19cc07175ca04e3eda6905a8d305
https://github.com/kgori/treeCl/blob/fed624b3db1c19cc07175ca04e3eda6905a8d305/treeCl/alignment.py#L418-L422
train
63,066
eerimoq/bincopy
bincopy.py
crc_srec
def crc_srec(hexstr): """Calculate the CRC for given Motorola S-Record hexstring. """ crc = sum(bytearray(binascii.unhexlify(hexstr))) crc &= 0xff crc ^= 0xff return crc
python
def crc_srec(hexstr): """Calculate the CRC for given Motorola S-Record hexstring. """ crc = sum(bytearray(binascii.unhexlify(hexstr))) crc &= 0xff crc ^= 0xff return crc
[ "def", "crc_srec", "(", "hexstr", ")", ":", "crc", "=", "sum", "(", "bytearray", "(", "binascii", ".", "unhexlify", "(", "hexstr", ")", ")", ")", "crc", "&=", "0xff", "crc", "^=", "0xff", "return", "crc" ]
Calculate the CRC for given Motorola S-Record hexstring.
[ "Calculate", "the", "CRC", "for", "given", "Motorola", "S", "-", "Record", "hexstring", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L57-L66
train
63,067
eerimoq/bincopy
bincopy.py
crc_ihex
def crc_ihex(hexstr): """Calculate the CRC for given Intel HEX hexstring. """ crc = sum(bytearray(binascii.unhexlify(hexstr))) crc &= 0xff crc = ((~crc + 1) & 0xff) return crc
python
def crc_ihex(hexstr): """Calculate the CRC for given Intel HEX hexstring. """ crc = sum(bytearray(binascii.unhexlify(hexstr))) crc &= 0xff crc = ((~crc + 1) & 0xff) return crc
[ "def", "crc_ihex", "(", "hexstr", ")", ":", "crc", "=", "sum", "(", "bytearray", "(", "binascii", ".", "unhexlify", "(", "hexstr", ")", ")", ")", "crc", "&=", "0xff", "crc", "=", "(", "(", "~", "crc", "+", "1", ")", "&", "0xff", ")", "return", ...
Calculate the CRC for given Intel HEX hexstring.
[ "Calculate", "the", "CRC", "for", "given", "Intel", "HEX", "hexstring", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L69-L78
train
63,068
eerimoq/bincopy
bincopy.py
pack_srec
def pack_srec(type_, address, size, data): """Create a Motorola S-Record record of given data. """ if type_ in '0159': line = '{:02X}{:04X}'.format(size + 2 + 1, address) elif type_ in '268': line = '{:02X}{:06X}'.format(size + 3 + 1, address) elif type_ in '37': line = '{:...
python
def pack_srec(type_, address, size, data): """Create a Motorola S-Record record of given data. """ if type_ in '0159': line = '{:02X}{:04X}'.format(size + 2 + 1, address) elif type_ in '268': line = '{:02X}{:06X}'.format(size + 3 + 1, address) elif type_ in '37': line = '{:...
[ "def", "pack_srec", "(", "type_", ",", "address", ",", "size", ",", "data", ")", ":", "if", "type_", "in", "'0159'", ":", "line", "=", "'{:02X}{:04X}'", ".", "format", "(", "size", "+", "2", "+", "1", ",", "address", ")", "elif", "type_", "in", "'2...
Create a Motorola S-Record record of given data.
[ "Create", "a", "Motorola", "S", "-", "Record", "record", "of", "given", "data", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L81-L99
train
63,069
eerimoq/bincopy
bincopy.py
unpack_srec
def unpack_srec(record): """Unpack given Motorola S-Record record into variables. """ # Minimum STSSCC, where T is type, SS is size and CC is crc. if len(record) < 6: raise Error("record '{}' too short".format(record)) if record[0] != 'S': raise Error( "record '{}' not...
python
def unpack_srec(record): """Unpack given Motorola S-Record record into variables. """ # Minimum STSSCC, where T is type, SS is size and CC is crc. if len(record) < 6: raise Error("record '{}' too short".format(record)) if record[0] != 'S': raise Error( "record '{}' not...
[ "def", "unpack_srec", "(", "record", ")", ":", "# Minimum STSSCC, where T is type, SS is size and CC is crc.", "if", "len", "(", "record", ")", "<", "6", ":", "raise", "Error", "(", "\"record '{}' too short\"", ".", "format", "(", "record", ")", ")", "if", "record...
Unpack given Motorola S-Record record into variables.
[ "Unpack", "given", "Motorola", "S", "-", "Record", "record", "into", "variables", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L102-L143
train
63,070
eerimoq/bincopy
bincopy.py
pack_ihex
def pack_ihex(type_, address, size, data): """Create a Intel HEX record of given data. """ line = '{:02X}{:04X}{:02X}'.format(size, address, type_) if data: line += binascii.hexlify(data).decode('ascii').upper() return ':{}{:02X}'.format(line, crc_ihex(line))
python
def pack_ihex(type_, address, size, data): """Create a Intel HEX record of given data. """ line = '{:02X}{:04X}{:02X}'.format(size, address, type_) if data: line += binascii.hexlify(data).decode('ascii').upper() return ':{}{:02X}'.format(line, crc_ihex(line))
[ "def", "pack_ihex", "(", "type_", ",", "address", ",", "size", ",", "data", ")", ":", "line", "=", "'{:02X}{:04X}{:02X}'", ".", "format", "(", "size", ",", "address", ",", "type_", ")", "if", "data", ":", "line", "+=", "binascii", ".", "hexlify", "(", ...
Create a Intel HEX record of given data.
[ "Create", "a", "Intel", "HEX", "record", "of", "given", "data", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L146-L156
train
63,071
eerimoq/bincopy
bincopy.py
unpack_ihex
def unpack_ihex(record): """Unpack given Intel HEX record into variables. """ # Minimum :SSAAAATTCC, where SS is size, AAAA is address, TT is # type and CC is crc. if len(record) < 11: raise Error("record '{}' too short".format(record)) if record[0] != ':': raise Error("record...
python
def unpack_ihex(record): """Unpack given Intel HEX record into variables. """ # Minimum :SSAAAATTCC, where SS is size, AAAA is address, TT is # type and CC is crc. if len(record) < 11: raise Error("record '{}' too short".format(record)) if record[0] != ':': raise Error("record...
[ "def", "unpack_ihex", "(", "record", ")", ":", "# Minimum :SSAAAATTCC, where SS is size, AAAA is address, TT is", "# type and CC is crc.", "if", "len", "(", "record", ")", "<", "11", ":", "raise", "Error", "(", "\"record '{}' too short\"", ".", "format", "(", "record", ...
Unpack given Intel HEX record into variables.
[ "Unpack", "given", "Intel", "HEX", "record", "into", "variables", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L159-L191
train
63,072
eerimoq/bincopy
bincopy.py
_Segment.chunks
def chunks(self, size=32, alignment=1): """Return chunks of the data aligned as given by `alignment`. `size` must be a multiple of `alignment`. Each chunk is returned as a named two-tuple of its address and data. """ if (size % alignment) != 0: raise Error( ...
python
def chunks(self, size=32, alignment=1): """Return chunks of the data aligned as given by `alignment`. `size` must be a multiple of `alignment`. Each chunk is returned as a named two-tuple of its address and data. """ if (size % alignment) != 0: raise Error( ...
[ "def", "chunks", "(", "self", ",", "size", "=", "32", ",", "alignment", "=", "1", ")", ":", "if", "(", "size", "%", "alignment", ")", "!=", "0", ":", "raise", "Error", "(", "'size {} is not a multiple of alignment {}'", ".", "format", "(", "size", ",", ...
Return chunks of the data aligned as given by `alignment`. `size` must be a multiple of `alignment`. Each chunk is returned as a named two-tuple of its address and data.
[ "Return", "chunks", "of", "the", "data", "aligned", "as", "given", "by", "alignment", ".", "size", "must", "be", "a", "multiple", "of", "alignment", ".", "Each", "chunk", "is", "returned", "as", "a", "named", "two", "-", "tuple", "of", "its", "address", ...
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L236-L265
train
63,073
eerimoq/bincopy
bincopy.py
_Segment.add_data
def add_data(self, minimum_address, maximum_address, data, overwrite): """Add given data to this segment. The added data must be adjacent to the current segment data, otherwise an exception is thrown. """ if minimum_address == self.maximum_address: self.maximum_address = ma...
python
def add_data(self, minimum_address, maximum_address, data, overwrite): """Add given data to this segment. The added data must be adjacent to the current segment data, otherwise an exception is thrown. """ if minimum_address == self.maximum_address: self.maximum_address = ma...
[ "def", "add_data", "(", "self", ",", "minimum_address", ",", "maximum_address", ",", "data", ",", "overwrite", ")", ":", "if", "minimum_address", "==", "self", ".", "maximum_address", ":", "self", ".", "maximum_address", "=", "maximum_address", "self", ".", "d...
Add given data to this segment. The added data must be adjacent to the current segment data, otherwise an exception is thrown.
[ "Add", "given", "data", "to", "this", "segment", ".", "The", "added", "data", "must", "be", "adjacent", "to", "the", "current", "segment", "data", "otherwise", "an", "exception", "is", "thrown", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L267-L308
train
63,074
eerimoq/bincopy
bincopy.py
_Segment.remove_data
def remove_data(self, minimum_address, maximum_address): """Remove given data range from this segment. Returns the second segment if the removed data splits this segment in two. """ if ((minimum_address >= self.maximum_address) and (maximum_address <= self.minimum_address))...
python
def remove_data(self, minimum_address, maximum_address): """Remove given data range from this segment. Returns the second segment if the removed data splits this segment in two. """ if ((minimum_address >= self.maximum_address) and (maximum_address <= self.minimum_address))...
[ "def", "remove_data", "(", "self", ",", "minimum_address", ",", "maximum_address", ")", ":", "if", "(", "(", "minimum_address", ">=", "self", ".", "maximum_address", ")", "and", "(", "maximum_address", "<=", "self", ".", "minimum_address", ")", ")", ":", "ra...
Remove given data range from this segment. Returns the second segment if the removed data splits this segment in two.
[ "Remove", "given", "data", "range", "from", "this", "segment", ".", "Returns", "the", "second", "segment", "if", "the", "removed", "data", "splits", "this", "segment", "in", "two", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L310-L350
train
63,075
eerimoq/bincopy
bincopy.py
_Segments.add
def add(self, segment, overwrite=False): """Add segments by ascending address. """ if self._list: if segment.minimum_address == self._current_segment.maximum_address: # Fast insertion for adjacent segments. self._current_segment.add_data(segment.mini...
python
def add(self, segment, overwrite=False): """Add segments by ascending address. """ if self._list: if segment.minimum_address == self._current_segment.maximum_address: # Fast insertion for adjacent segments. self._current_segment.add_data(segment.mini...
[ "def", "add", "(", "self", ",", "segment", ",", "overwrite", "=", "False", ")", ":", "if", "self", ".", "_list", ":", "if", "segment", ".", "minimum_address", "==", "self", ".", "_current_segment", ".", "maximum_address", ":", "# Fast insertion for adjacent se...
Add segments by ascending address.
[ "Add", "segments", "by", "ascending", "address", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L425-L482
train
63,076
eerimoq/bincopy
bincopy.py
_Segments.chunks
def chunks(self, size=32, alignment=1): """Iterate over all segments and return chunks of the data aligned as given by `alignment`. `size` must be a multiple of `alignment`. Each chunk is returned as a named two-tuple of its address and data. """ if (size % alignment) !...
python
def chunks(self, size=32, alignment=1): """Iterate over all segments and return chunks of the data aligned as given by `alignment`. `size` must be a multiple of `alignment`. Each chunk is returned as a named two-tuple of its address and data. """ if (size % alignment) !...
[ "def", "chunks", "(", "self", ",", "size", "=", "32", ",", "alignment", "=", "1", ")", ":", "if", "(", "size", "%", "alignment", ")", "!=", "0", ":", "raise", "Error", "(", "'size {} is not a multiple of alignment {}'", ".", "format", "(", "size", ",", ...
Iterate over all segments and return chunks of the data aligned as given by `alignment`. `size` must be a multiple of `alignment`. Each chunk is returned as a named two-tuple of its address and data.
[ "Iterate", "over", "all", "segments", "and", "return", "chunks", "of", "the", "data", "aligned", "as", "given", "by", "alignment", ".", "size", "must", "be", "a", "multiple", "of", "alignment", ".", "Each", "chunk", "is", "returned", "as", "a", "named", ...
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L504-L520
train
63,077
eerimoq/bincopy
bincopy.py
BinFile.minimum_address
def minimum_address(self): """The minimum address of the data, or ``None`` if the file is empty. """ minimum_address = self._segments.minimum_address if minimum_address is not None: minimum_address //= self.word_size_bytes return minimum_address
python
def minimum_address(self): """The minimum address of the data, or ``None`` if the file is empty. """ minimum_address = self._segments.minimum_address if minimum_address is not None: minimum_address //= self.word_size_bytes return minimum_address
[ "def", "minimum_address", "(", "self", ")", ":", "minimum_address", "=", "self", ".", "_segments", ".", "minimum_address", "if", "minimum_address", "is", "not", "None", ":", "minimum_address", "//=", "self", ".", "word_size_bytes", "return", "minimum_address" ]
The minimum address of the data, or ``None`` if the file is empty.
[ "The", "minimum", "address", "of", "the", "data", "or", "None", "if", "the", "file", "is", "empty", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L645-L655
train
63,078
eerimoq/bincopy
bincopy.py
BinFile.maximum_address
def maximum_address(self): """The maximum address of the data, or ``None`` if the file is empty. """ maximum_address = self._segments.maximum_address if maximum_address is not None: maximum_address //= self.word_size_bytes return maximum_address
python
def maximum_address(self): """The maximum address of the data, or ``None`` if the file is empty. """ maximum_address = self._segments.maximum_address if maximum_address is not None: maximum_address //= self.word_size_bytes return maximum_address
[ "def", "maximum_address", "(", "self", ")", ":", "maximum_address", "=", "self", ".", "_segments", ".", "maximum_address", "if", "maximum_address", "is", "not", "None", ":", "maximum_address", "//=", "self", ".", "word_size_bytes", "return", "maximum_address" ]
The maximum address of the data, or ``None`` if the file is empty.
[ "The", "maximum", "address", "of", "the", "data", "or", "None", "if", "the", "file", "is", "empty", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L658-L668
train
63,079
eerimoq/bincopy
bincopy.py
BinFile.add
def add(self, data, overwrite=False): """Add given data string by guessing its format. The format must be Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ if is_srec(data): self.add_srec(data, ov...
python
def add(self, data, overwrite=False): """Add given data string by guessing its format. The format must be Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ if is_srec(data): self.add_srec(data, ov...
[ "def", "add", "(", "self", ",", "data", ",", "overwrite", "=", "False", ")", ":", "if", "is_srec", "(", "data", ")", ":", "self", ".", "add_srec", "(", "data", ",", "overwrite", ")", "elif", "is_ihex", "(", "data", ")", ":", "self", ".", "add_ihex"...
Add given data string by guessing its format. The format must be Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Add", "given", "data", "string", "by", "guessing", "its", "format", ".", "The", "format", "must", "be", "Motorola", "S", "-", "Records", "Intel", "HEX", "or", "TI", "-", "TXT", ".", "Set", "overwrite", "to", "True", "to", "allow", "already", "added", ...
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L738-L752
train
63,080
eerimoq/bincopy
bincopy.py
BinFile.add_srec
def add_srec(self, records, overwrite=False): """Add given Motorola S-Records string. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ for record in StringIO(records): type_, address, size, data = unpack_srec(record.strip()) if typ...
python
def add_srec(self, records, overwrite=False): """Add given Motorola S-Records string. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ for record in StringIO(records): type_, address, size, data = unpack_srec(record.strip()) if typ...
[ "def", "add_srec", "(", "self", ",", "records", ",", "overwrite", "=", "False", ")", ":", "for", "record", "in", "StringIO", "(", "records", ")", ":", "type_", ",", "address", ",", "size", ",", "data", "=", "unpack_srec", "(", "record", ".", "strip", ...
Add given Motorola S-Records string. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Add", "given", "Motorola", "S", "-", "Records", "string", ".", "Set", "overwrite", "to", "True", "to", "allow", "already", "added", "data", "to", "be", "overwritten", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L754-L773
train
63,081
eerimoq/bincopy
bincopy.py
BinFile.add_ihex
def add_ihex(self, records, overwrite=False): """Add given Intel HEX records string. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ extended_segment_address = 0 extended_linear_address = 0 for record in StringIO(records): typ...
python
def add_ihex(self, records, overwrite=False): """Add given Intel HEX records string. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ extended_segment_address = 0 extended_linear_address = 0 for record in StringIO(records): typ...
[ "def", "add_ihex", "(", "self", ",", "records", ",", "overwrite", "=", "False", ")", ":", "extended_segment_address", "=", "0", "extended_linear_address", "=", "0", "for", "record", "in", "StringIO", "(", "records", ")", ":", "type_", ",", "address", ",", ...
Add given Intel HEX records string. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Add", "given", "Intel", "HEX", "records", "string", ".", "Set", "overwrite", "to", "True", "to", "allow", "already", "added", "data", "to", "be", "overwritten", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L775-L810
train
63,082
eerimoq/bincopy
bincopy.py
BinFile.add_ti_txt
def add_ti_txt(self, lines, overwrite=False): """Add given TI-TXT string `lines`. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ address = None eof_found = False for line in StringIO(lines): # Abort if data is found after end...
python
def add_ti_txt(self, lines, overwrite=False): """Add given TI-TXT string `lines`. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ address = None eof_found = False for line in StringIO(lines): # Abort if data is found after end...
[ "def", "add_ti_txt", "(", "self", ",", "lines", ",", "overwrite", "=", "False", ")", ":", "address", "=", "None", "eof_found", "=", "False", "for", "line", "in", "StringIO", "(", "lines", ")", ":", "# Abort if data is found after end of file.", "if", "eof_foun...
Add given TI-TXT string `lines`. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Add", "given", "TI", "-", "TXT", "string", "lines", ".", "Set", "overwrite", "to", "True", "to", "allow", "already", "added", "data", "to", "be", "overwritten", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L812-L869
train
63,083
eerimoq/bincopy
bincopy.py
BinFile.add_binary
def add_binary(self, data, address=0, overwrite=False): """Add given data at given address. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ address *= self.word_size_bytes self._segments.add(_Segment(address, ad...
python
def add_binary(self, data, address=0, overwrite=False): """Add given data at given address. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ address *= self.word_size_bytes self._segments.add(_Segment(address, ad...
[ "def", "add_binary", "(", "self", ",", "data", ",", "address", "=", "0", ",", "overwrite", "=", "False", ")", ":", "address", "*=", "self", ".", "word_size_bytes", "self", ".", "_segments", ".", "add", "(", "_Segment", "(", "address", ",", "address", "...
Add given data at given address. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Add", "given", "data", "at", "given", "address", ".", "Set", "overwrite", "to", "True", "to", "allow", "already", "added", "data", "to", "be", "overwritten", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L871-L882
train
63,084
eerimoq/bincopy
bincopy.py
BinFile.add_file
def add_file(self, filename, overwrite=False): """Open given file and add its data by guessing its format. The format must be Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'r') as fin:...
python
def add_file(self, filename, overwrite=False): """Open given file and add its data by guessing its format. The format must be Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'r') as fin:...
[ "def", "add_file", "(", "self", ",", "filename", ",", "overwrite", "=", "False", ")", ":", "with", "open", "(", "filename", ",", "'r'", ")", "as", "fin", ":", "self", ".", "add", "(", "fin", ".", "read", "(", ")", ",", "overwrite", ")" ]
Open given file and add its data by guessing its format. The format must be Motorola S-Records, Intel HEX or TI-TXT. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Open", "given", "file", "and", "add", "its", "data", "by", "guessing", "its", "format", ".", "The", "format", "must", "be", "Motorola", "S", "-", "Records", "Intel", "HEX", "or", "TI", "-", "TXT", ".", "Set", "overwrite", "to", "True", "to", "allow", ...
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L884-L892
train
63,085
eerimoq/bincopy
bincopy.py
BinFile.add_srec_file
def add_srec_file(self, filename, overwrite=False): """Open given Motorola S-Records file and add its records. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'r') as fin: self.add_srec(fin.read(), overwrite)
python
def add_srec_file(self, filename, overwrite=False): """Open given Motorola S-Records file and add its records. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'r') as fin: self.add_srec(fin.read(), overwrite)
[ "def", "add_srec_file", "(", "self", ",", "filename", ",", "overwrite", "=", "False", ")", ":", "with", "open", "(", "filename", ",", "'r'", ")", "as", "fin", ":", "self", ".", "add_srec", "(", "fin", ".", "read", "(", ")", ",", "overwrite", ")" ]
Open given Motorola S-Records file and add its records. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Open", "given", "Motorola", "S", "-", "Records", "file", "and", "add", "its", "records", ".", "Set", "overwrite", "to", "True", "to", "allow", "already", "added", "data", "to", "be", "overwritten", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L894-L902
train
63,086
eerimoq/bincopy
bincopy.py
BinFile.add_ihex_file
def add_ihex_file(self, filename, overwrite=False): """Open given Intel HEX file and add its records. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'r') as fin: self.add_ihex(fin.read(), overwrite)
python
def add_ihex_file(self, filename, overwrite=False): """Open given Intel HEX file and add its records. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'r') as fin: self.add_ihex(fin.read(), overwrite)
[ "def", "add_ihex_file", "(", "self", ",", "filename", ",", "overwrite", "=", "False", ")", ":", "with", "open", "(", "filename", ",", "'r'", ")", "as", "fin", ":", "self", ".", "add_ihex", "(", "fin", ".", "read", "(", ")", ",", "overwrite", ")" ]
Open given Intel HEX file and add its records. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Open", "given", "Intel", "HEX", "file", "and", "add", "its", "records", ".", "Set", "overwrite", "to", "True", "to", "allow", "already", "added", "data", "to", "be", "overwritten", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L904-L911
train
63,087
eerimoq/bincopy
bincopy.py
BinFile.add_ti_txt_file
def add_ti_txt_file(self, filename, overwrite=False): """Open given TI-TXT file and add its contents. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'r') as fin: self.add_ti_txt(fin.read(), overwrite)
python
def add_ti_txt_file(self, filename, overwrite=False): """Open given TI-TXT file and add its contents. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'r') as fin: self.add_ti_txt(fin.read(), overwrite)
[ "def", "add_ti_txt_file", "(", "self", ",", "filename", ",", "overwrite", "=", "False", ")", ":", "with", "open", "(", "filename", ",", "'r'", ")", "as", "fin", ":", "self", ".", "add_ti_txt", "(", "fin", ".", "read", "(", ")", ",", "overwrite", ")" ...
Open given TI-TXT file and add its contents. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Open", "given", "TI", "-", "TXT", "file", "and", "add", "its", "contents", ".", "Set", "overwrite", "to", "True", "to", "allow", "already", "added", "data", "to", "be", "overwritten", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L913-L920
train
63,088
eerimoq/bincopy
bincopy.py
BinFile.add_binary_file
def add_binary_file(self, filename, address=0, overwrite=False): """Open given binary file and add its contents. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'rb') as fin: self.add_binary(fin.read(), address, overwrite)
python
def add_binary_file(self, filename, address=0, overwrite=False): """Open given binary file and add its contents. Set `overwrite` to ``True`` to allow already added data to be overwritten. """ with open(filename, 'rb') as fin: self.add_binary(fin.read(), address, overwrite)
[ "def", "add_binary_file", "(", "self", ",", "filename", ",", "address", "=", "0", ",", "overwrite", "=", "False", ")", ":", "with", "open", "(", "filename", ",", "'rb'", ")", "as", "fin", ":", "self", ".", "add_binary", "(", "fin", ".", "read", "(", ...
Open given binary file and add its contents. Set `overwrite` to ``True`` to allow already added data to be overwritten.
[ "Open", "given", "binary", "file", "and", "add", "its", "contents", ".", "Set", "overwrite", "to", "True", "to", "allow", "already", "added", "data", "to", "be", "overwritten", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L922-L929
train
63,089
eerimoq/bincopy
bincopy.py
BinFile.as_srec
def as_srec(self, number_of_data_bytes=32, address_length_bits=32): """Format the binary file as Motorola S-Records records and return them as a string. `number_of_data_bytes` is the number of data bytes in each record. `address_length_bits` is the number of address bits in eac...
python
def as_srec(self, number_of_data_bytes=32, address_length_bits=32): """Format the binary file as Motorola S-Records records and return them as a string. `number_of_data_bytes` is the number of data bytes in each record. `address_length_bits` is the number of address bits in eac...
[ "def", "as_srec", "(", "self", ",", "number_of_data_bytes", "=", "32", ",", "address_length_bits", "=", "32", ")", ":", "header", "=", "[", "]", "if", "self", ".", "_header", "is", "not", "None", ":", "record", "=", "pack_srec", "(", "'0'", ",", "0", ...
Format the binary file as Motorola S-Records records and return them as a string. `number_of_data_bytes` is the number of data bytes in each record. `address_length_bits` is the number of address bits in each record. >>> print(binfile.as_srec()) S32500000100214...
[ "Format", "the", "binary", "file", "as", "Motorola", "S", "-", "Records", "records", "and", "return", "them", "as", "a", "string", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L931-L982
train
63,090
eerimoq/bincopy
bincopy.py
BinFile.as_ihex
def as_ihex(self, number_of_data_bytes=32, address_length_bits=32): """Format the binary file as Intel HEX records and return them as a string. `number_of_data_bytes` is the number of data bytes in each record. `address_length_bits` is the number of address bits in each ...
python
def as_ihex(self, number_of_data_bytes=32, address_length_bits=32): """Format the binary file as Intel HEX records and return them as a string. `number_of_data_bytes` is the number of data bytes in each record. `address_length_bits` is the number of address bits in each ...
[ "def", "as_ihex", "(", "self", ",", "number_of_data_bytes", "=", "32", ",", "address_length_bits", "=", "32", ")", ":", "def", "i32hex", "(", "address", ",", "extended_linear_address", ",", "data_address", ")", ":", "if", "address", ">", "0xffffffff", ":", "...
Format the binary file as Intel HEX records and return them as a string. `number_of_data_bytes` is the number of data bytes in each record. `address_length_bits` is the number of address bits in each record. >>> print(binfile.as_ihex()) :20010000214601360121470...
[ "Format", "the", "binary", "file", "as", "Intel", "HEX", "records", "and", "return", "them", "as", "a", "string", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L984-L1100
train
63,091
eerimoq/bincopy
bincopy.py
BinFile.as_ti_txt
def as_ti_txt(self): """Format the binary file as a TI-TXT file and return it as a string. >>> print(binfile.as_ti_txt()) @0100 21 46 01 36 01 21 47 01 36 00 7E FE 09 D2 19 01 21 46 01 7E 17 C2 00 01 FF 5F 16 00 21 48 01 19 19 4E 79 23 46 23 96 57 78 23 9E DA 3F 01 B2 CA...
python
def as_ti_txt(self): """Format the binary file as a TI-TXT file and return it as a string. >>> print(binfile.as_ti_txt()) @0100 21 46 01 36 01 21 47 01 36 00 7E FE 09 D2 19 01 21 46 01 7E 17 C2 00 01 FF 5F 16 00 21 48 01 19 19 4E 79 23 46 23 96 57 78 23 9E DA 3F 01 B2 CA...
[ "def", "as_ti_txt", "(", "self", ")", ":", "lines", "=", "[", "]", "for", "segment", "in", "self", ".", "_segments", ":", "lines", ".", "append", "(", "'@{:04X}'", ".", "format", "(", "segment", ".", "address", ")", ")", "for", "_", ",", "data", "i...
Format the binary file as a TI-TXT file and return it as a string. >>> print(binfile.as_ti_txt()) @0100 21 46 01 36 01 21 47 01 36 00 7E FE 09 D2 19 01 21 46 01 7E 17 C2 00 01 FF 5F 16 00 21 48 01 19 19 4E 79 23 46 23 96 57 78 23 9E DA 3F 01 B2 CA 3F 01 56 70 2B 5E 71 2B...
[ "Format", "the", "binary", "file", "as", "a", "TI", "-", "TXT", "file", "and", "return", "it", "as", "a", "string", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1102-L1125
train
63,092
eerimoq/bincopy
bincopy.py
BinFile.as_binary
def as_binary(self, minimum_address=None, maximum_address=None, padding=None): """Return a byte string of all data within given address range. `minimum_address` is the absolute minimum address of the resulting binary data. `maximum_...
python
def as_binary(self, minimum_address=None, maximum_address=None, padding=None): """Return a byte string of all data within given address range. `minimum_address` is the absolute minimum address of the resulting binary data. `maximum_...
[ "def", "as_binary", "(", "self", ",", "minimum_address", "=", "None", ",", "maximum_address", "=", "None", ",", "padding", "=", "None", ")", ":", "if", "len", "(", "self", ".", "_segments", ")", "==", "0", ":", "return", "b''", "if", "minimum_address", ...
Return a byte string of all data within given address range. `minimum_address` is the absolute minimum address of the resulting binary data. `maximum_address` is the absolute maximum address of the resulting binary data (non-inclusive). `padding` is the word value of the paddi...
[ "Return", "a", "byte", "string", "of", "all", "data", "within", "given", "address", "range", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1127-L1197
train
63,093
eerimoq/bincopy
bincopy.py
BinFile.as_array
def as_array(self, minimum_address=None, padding=None, separator=', '): """Format the binary file as a string values separated by given separator `separator`. This function can be used to generate array initialization code for C and other languages. `minimum_address` is the start addres...
python
def as_array(self, minimum_address=None, padding=None, separator=', '): """Format the binary file as a string values separated by given separator `separator`. This function can be used to generate array initialization code for C and other languages. `minimum_address` is the start addres...
[ "def", "as_array", "(", "self", ",", "minimum_address", "=", "None", ",", "padding", "=", "None", ",", "separator", "=", "', '", ")", ":", "binary_data", "=", "self", ".", "as_binary", "(", "minimum_address", ",", "padding", "=", "padding", ")", "words", ...
Format the binary file as a string values separated by given separator `separator`. This function can be used to generate array initialization code for C and other languages. `minimum_address` is the start address of the resulting binary data. `padding` is the value of the padd...
[ "Format", "the", "binary", "file", "as", "a", "string", "values", "separated", "by", "given", "separator", "separator", ".", "This", "function", "can", "be", "used", "to", "generate", "array", "initialization", "code", "for", "C", "and", "other", "languages", ...
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1199-L1233
train
63,094
eerimoq/bincopy
bincopy.py
BinFile.as_hexdump
def as_hexdump(self): """Format the binary file as a hexdump and return it as a string. >>> print(binfile.as_hexdump()) 00000100 21 46 01 36 01 21 47 01 36 00 7e fe 09 d2 19 01 |!F.6.!G.6.~.....| 00000110 21 46 01 7e 17 c2 00 01 ff 5f 16 00 21 48 01 19 |!F.~....._..!H..| 0...
python
def as_hexdump(self): """Format the binary file as a hexdump and return it as a string. >>> print(binfile.as_hexdump()) 00000100 21 46 01 36 01 21 47 01 36 00 7e fe 09 d2 19 01 |!F.6.!G.6.~.....| 00000110 21 46 01 7e 17 c2 00 01 ff 5f 16 00 21 48 01 19 |!F.~....._..!H..| 0...
[ "def", "as_hexdump", "(", "self", ")", ":", "# Empty file?", "if", "len", "(", "self", ")", "==", "0", ":", "return", "'\\n'", "non_dot_characters", "=", "set", "(", "string", ".", "printable", ")", "non_dot_characters", "-=", "set", "(", "string", ".", ...
Format the binary file as a hexdump and return it as a string. >>> print(binfile.as_hexdump()) 00000100 21 46 01 36 01 21 47 01 36 00 7e fe 09 d2 19 01 |!F.6.!G.6.~.....| 00000110 21 46 01 7e 17 c2 00 01 ff 5f 16 00 21 48 01 19 |!F.~....._..!H..| 00000120 19 4e 79 23 46 23 96 57 ...
[ "Format", "the", "binary", "file", "as", "a", "hexdump", "and", "return", "it", "as", "a", "string", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1235-L1313
train
63,095
eerimoq/bincopy
bincopy.py
BinFile.fill
def fill(self, value=b'\xff'): """Fill all empty space between segments with given value `value`. """ previous_segment_maximum_address = None fill_segments = [] for address, data in self._segments: maximum_address = address + len(data) if previous_segm...
python
def fill(self, value=b'\xff'): """Fill all empty space between segments with given value `value`. """ previous_segment_maximum_address = None fill_segments = [] for address, data in self._segments: maximum_address = address + len(data) if previous_segm...
[ "def", "fill", "(", "self", ",", "value", "=", "b'\\xff'", ")", ":", "previous_segment_maximum_address", "=", "None", "fill_segments", "=", "[", "]", "for", "address", ",", "data", "in", "self", ".", "_segments", ":", "maximum_address", "=", "address", "+", ...
Fill all empty space between segments with given value `value`.
[ "Fill", "all", "empty", "space", "between", "segments", "with", "given", "value", "value", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1315-L1338
train
63,096
eerimoq/bincopy
bincopy.py
BinFile.exclude
def exclude(self, minimum_address, maximum_address): """Exclude given range and keep the rest. `minimum_address` is the first word address to exclude (including). `maximum_address` is the last word address to exclude (excluding). """ if maximum_address < minim...
python
def exclude(self, minimum_address, maximum_address): """Exclude given range and keep the rest. `minimum_address` is the first word address to exclude (including). `maximum_address` is the last word address to exclude (excluding). """ if maximum_address < minim...
[ "def", "exclude", "(", "self", ",", "minimum_address", ",", "maximum_address", ")", ":", "if", "maximum_address", "<", "minimum_address", ":", "raise", "Error", "(", "'bad address range'", ")", "minimum_address", "*=", "self", ".", "word_size_bytes", "maximum_addres...
Exclude given range and keep the rest. `minimum_address` is the first word address to exclude (including). `maximum_address` is the last word address to exclude (excluding).
[ "Exclude", "given", "range", "and", "keep", "the", "rest", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1340-L1356
train
63,097
eerimoq/bincopy
bincopy.py
BinFile.crop
def crop(self, minimum_address, maximum_address): """Keep given range and discard the rest. `minimum_address` is the first word address to keep (including). `maximum_address` is the last word address to keep (excluding). """ minimum_address *= self.word_size_b...
python
def crop(self, minimum_address, maximum_address): """Keep given range and discard the rest. `minimum_address` is the first word address to keep (including). `maximum_address` is the last word address to keep (excluding). """ minimum_address *= self.word_size_b...
[ "def", "crop", "(", "self", ",", "minimum_address", ",", "maximum_address", ")", ":", "minimum_address", "*=", "self", ".", "word_size_bytes", "maximum_address", "*=", "self", ".", "word_size_bytes", "maximum_address_address", "=", "self", ".", "_segments", ".", "...
Keep given range and discard the rest. `minimum_address` is the first word address to keep (including). `maximum_address` is the last word address to keep (excluding).
[ "Keep", "given", "range", "and", "discard", "the", "rest", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1358-L1373
train
63,098
eerimoq/bincopy
bincopy.py
BinFile.info
def info(self): """Return a string of human readable information about the binary file. .. code-block:: python >>> print(binfile.info()) Data ranges: 0x00000100 - 0x00000140 (64 bytes) """ info = '' if self._header is not None: ...
python
def info(self): """Return a string of human readable information about the binary file. .. code-block:: python >>> print(binfile.info()) Data ranges: 0x00000100 - 0x00000140 (64 bytes) """ info = '' if self._header is not None: ...
[ "def", "info", "(", "self", ")", ":", "info", "=", "''", "if", "self", ".", "_header", "is", "not", "None", ":", "if", "self", ".", "_header_encoding", "is", "None", ":", "header", "=", "''", "for", "b", "in", "bytearray", "(", "self", ".", "header...
Return a string of human readable information about the binary file. .. code-block:: python >>> print(binfile.info()) Data ranges: 0x00000100 - 0x00000140 (64 bytes)
[ "Return", "a", "string", "of", "human", "readable", "information", "about", "the", "binary", "file", "." ]
5e02cd001c3e9b54729425db6bffad5f03e1beac
https://github.com/eerimoq/bincopy/blob/5e02cd001c3e9b54729425db6bffad5f03e1beac/bincopy.py#L1375-L1420
train
63,099