partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
test | load_config_from_cli | Loads config, checking CLI arguments for a config file | goodconf/contrib/django.py | def load_config_from_cli(config: GoodConf, argv: List[str]) -> List[str]:
"""Loads config, checking CLI arguments for a config file"""
# Monkey patch Django's command parser
from django.core.management.base import BaseCommand
original_parser = BaseCommand.create_parser
def patched_parser(self, pro... | def load_config_from_cli(config: GoodConf, argv: List[str]) -> List[str]:
"""Loads config, checking CLI arguments for a config file"""
# Monkey patch Django's command parser
from django.core.management.base import BaseCommand
original_parser = BaseCommand.create_parser
def patched_parser(self, pro... | [
"Loads",
"config",
"checking",
"CLI",
"arguments",
"for",
"a",
"config",
"file"
] | lincolnloop/goodconf | python | https://github.com/lincolnloop/goodconf/blob/19515da5783f86b9516dbf81531107c2d9eae567/goodconf/contrib/django.py#L10-L33 | [
"def",
"load_config_from_cli",
"(",
"config",
":",
"GoodConf",
",",
"argv",
":",
"List",
"[",
"str",
"]",
")",
"->",
"List",
"[",
"str",
"]",
":",
"# Monkey patch Django's command parser",
"from",
"django",
".",
"core",
".",
"management",
".",
"base",
"impor... | 19515da5783f86b9516dbf81531107c2d9eae567 |
test | execute_from_command_line_with_config | Load's config then runs Django's execute_from_command_line | goodconf/contrib/django.py | def execute_from_command_line_with_config(config: GoodConf, argv: List[str]):
"""Load's config then runs Django's execute_from_command_line"""
with load_config_from_cli(config, argv) as args:
from django.core.management import execute_from_command_line
execute_from_command_line(args) | def execute_from_command_line_with_config(config: GoodConf, argv: List[str]):
"""Load's config then runs Django's execute_from_command_line"""
with load_config_from_cli(config, argv) as args:
from django.core.management import execute_from_command_line
execute_from_command_line(args) | [
"Load",
"s",
"config",
"then",
"runs",
"Django",
"s",
"execute_from_command_line"
] | lincolnloop/goodconf | python | https://github.com/lincolnloop/goodconf/blob/19515da5783f86b9516dbf81531107c2d9eae567/goodconf/contrib/django.py#L36-L40 | [
"def",
"execute_from_command_line_with_config",
"(",
"config",
":",
"GoodConf",
",",
"argv",
":",
"List",
"[",
"str",
"]",
")",
":",
"with",
"load_config_from_cli",
"(",
"config",
",",
"argv",
")",
"as",
"args",
":",
"from",
"django",
".",
"core",
".",
"ma... | 19515da5783f86b9516dbf81531107c2d9eae567 |
test | argparser_add_argument | Adds argument for config to existing argparser | goodconf/contrib/argparse.py | def argparser_add_argument(parser: argparse.ArgumentParser, config: GoodConf):
"""Adds argument for config to existing argparser"""
help = "Config file."
if config.file_env_var:
help += (" Can also be configured via the "
"environment variable: {}".format(config.file_env_var))
i... | def argparser_add_argument(parser: argparse.ArgumentParser, config: GoodConf):
"""Adds argument for config to existing argparser"""
help = "Config file."
if config.file_env_var:
help += (" Can also be configured via the "
"environment variable: {}".format(config.file_env_var))
i... | [
"Adds",
"argument",
"for",
"config",
"to",
"existing",
"argparser"
] | lincolnloop/goodconf | python | https://github.com/lincolnloop/goodconf/blob/19515da5783f86b9516dbf81531107c2d9eae567/goodconf/contrib/argparse.py#L5-L14 | [
"def",
"argparser_add_argument",
"(",
"parser",
":",
"argparse",
".",
"ArgumentParser",
",",
"config",
":",
"GoodConf",
")",
":",
"help",
"=",
"\"Config file.\"",
"if",
"config",
".",
"file_env_var",
":",
"help",
"+=",
"(",
"\" Can also be configured via the \"",
... | 19515da5783f86b9516dbf81531107c2d9eae567 |
test | _load_config | Given a file path, parse it based on its extension (YAML or JSON)
and return the values as a Python dictionary. JSON is the default if an
extension can't be determined. | goodconf/__init__.py | def _load_config(path: str) -> dict:
"""
Given a file path, parse it based on its extension (YAML or JSON)
and return the values as a Python dictionary. JSON is the default if an
extension can't be determined.
"""
__, ext = os.path.splitext(path)
if ext in ['.yaml', '.yml']:
import r... | def _load_config(path: str) -> dict:
"""
Given a file path, parse it based on its extension (YAML or JSON)
and return the values as a Python dictionary. JSON is the default if an
extension can't be determined.
"""
__, ext = os.path.splitext(path)
if ext in ['.yaml', '.yml']:
import r... | [
"Given",
"a",
"file",
"path",
"parse",
"it",
"based",
"on",
"its",
"extension",
"(",
"YAML",
"or",
"JSON",
")",
"and",
"return",
"the",
"values",
"as",
"a",
"Python",
"dictionary",
".",
"JSON",
"is",
"the",
"default",
"if",
"an",
"extension",
"can",
"t... | lincolnloop/goodconf | python | https://github.com/lincolnloop/goodconf/blob/19515da5783f86b9516dbf81531107c2d9eae567/goodconf/__init__.py#L18-L32 | [
"def",
"_load_config",
"(",
"path",
":",
"str",
")",
"->",
"dict",
":",
"__",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"path",
")",
"if",
"ext",
"in",
"[",
"'.yaml'",
",",
"'.yml'",
"]",
":",
"import",
"ruamel",
".",
"yaml",
"loa... | 19515da5783f86b9516dbf81531107c2d9eae567 |
test | GoodConf.load | Find config file and set values | goodconf/__init__.py | def load(self, filename: str = None):
"""Find config file and set values"""
if filename:
self.config_file = _find_file(filename)
else:
if self.file_env_var and self.file_env_var in os.environ:
self.config_file = _find_file(os.environ[self.file_env_var])
... | def load(self, filename: str = None):
"""Find config file and set values"""
if filename:
self.config_file = _find_file(filename)
else:
if self.file_env_var and self.file_env_var in os.environ:
self.config_file = _find_file(os.environ[self.file_env_var])
... | [
"Find",
"config",
"file",
"and",
"set",
"values"
] | lincolnloop/goodconf | python | https://github.com/lincolnloop/goodconf/blob/19515da5783f86b9516dbf81531107c2d9eae567/goodconf/__init__.py#L66-L85 | [
"def",
"load",
"(",
"self",
",",
"filename",
":",
"str",
"=",
"None",
")",
":",
"if",
"filename",
":",
"self",
".",
"config_file",
"=",
"_find_file",
"(",
"filename",
")",
"else",
":",
"if",
"self",
".",
"file_env_var",
"and",
"self",
".",
"file_env_va... | 19515da5783f86b9516dbf81531107c2d9eae567 |
test | GoodConf.generate_yaml | Dumps initial config in YAML | goodconf/__init__.py | def generate_yaml(cls, **override):
"""
Dumps initial config in YAML
"""
import ruamel.yaml
yaml = ruamel.yaml.YAML()
yaml_str = StringIO()
yaml.dump(cls.get_initial(**override), stream=yaml_str)
yaml_str.seek(0)
dict_from_yaml = yaml.load(yaml_str... | def generate_yaml(cls, **override):
"""
Dumps initial config in YAML
"""
import ruamel.yaml
yaml = ruamel.yaml.YAML()
yaml_str = StringIO()
yaml.dump(cls.get_initial(**override), stream=yaml_str)
yaml_str.seek(0)
dict_from_yaml = yaml.load(yaml_str... | [
"Dumps",
"initial",
"config",
"in",
"YAML"
] | lincolnloop/goodconf | python | https://github.com/lincolnloop/goodconf/blob/19515da5783f86b9516dbf81531107c2d9eae567/goodconf/__init__.py#L99-L119 | [
"def",
"generate_yaml",
"(",
"cls",
",",
"*",
"*",
"override",
")",
":",
"import",
"ruamel",
".",
"yaml",
"yaml",
"=",
"ruamel",
".",
"yaml",
".",
"YAML",
"(",
")",
"yaml_str",
"=",
"StringIO",
"(",
")",
"yaml",
".",
"dump",
"(",
"cls",
".",
"get_i... | 19515da5783f86b9516dbf81531107c2d9eae567 |
test | GoodConf.generate_markdown | Documents values in markdown | goodconf/__init__.py | def generate_markdown(cls):
"""
Documents values in markdown
"""
lines = []
if cls.__doc__:
lines.extend(['# {}'.format(cls.__doc__), ''])
for k, v in cls._values.items():
lines.append('* **{}** '.format(k))
if v.required:
... | def generate_markdown(cls):
"""
Documents values in markdown
"""
lines = []
if cls.__doc__:
lines.extend(['# {}'.format(cls.__doc__), ''])
for k, v in cls._values.items():
lines.append('* **{}** '.format(k))
if v.required:
... | [
"Documents",
"values",
"in",
"markdown"
] | lincolnloop/goodconf | python | https://github.com/lincolnloop/goodconf/blob/19515da5783f86b9516dbf81531107c2d9eae567/goodconf/__init__.py#L129-L145 | [
"def",
"generate_markdown",
"(",
"cls",
")",
":",
"lines",
"=",
"[",
"]",
"if",
"cls",
".",
"__doc__",
":",
"lines",
".",
"extend",
"(",
"[",
"'# {}'",
".",
"format",
"(",
"cls",
".",
"__doc__",
")",
",",
"''",
"]",
")",
"for",
"k",
",",
"v",
"... | 19515da5783f86b9516dbf81531107c2d9eae567 |
test | Value.cast | converts string to type requested by `cast_as` | goodconf/values.py | def cast(self, val: str):
"""converts string to type requested by `cast_as`"""
try:
return getattr(self, 'cast_as_{}'.format(
self.cast_as.__name__.lower()))(val)
except AttributeError:
return self.cast_as(val) | def cast(self, val: str):
"""converts string to type requested by `cast_as`"""
try:
return getattr(self, 'cast_as_{}'.format(
self.cast_as.__name__.lower()))(val)
except AttributeError:
return self.cast_as(val) | [
"converts",
"string",
"to",
"type",
"requested",
"by",
"cast_as"
] | lincolnloop/goodconf | python | https://github.com/lincolnloop/goodconf/blob/19515da5783f86b9516dbf81531107c2d9eae567/goodconf/values.py#L96-L102 | [
"def",
"cast",
"(",
"self",
",",
"val",
":",
"str",
")",
":",
"try",
":",
"return",
"getattr",
"(",
"self",
",",
"'cast_as_{}'",
".",
"format",
"(",
"self",
".",
"cast_as",
".",
"__name__",
".",
"lower",
"(",
")",
")",
")",
"(",
"val",
")",
"exce... | 19515da5783f86b9516dbf81531107c2d9eae567 |
test | list_dates_between | Returns all dates from first to last included. | currency_converter/currency_converter.py | def list_dates_between(first_date, last_date):
"""Returns all dates from first to last included."""
return [first_date + timedelta(days=n)
for n in range(1 + (last_date - first_date).days)] | def list_dates_between(first_date, last_date):
"""Returns all dates from first to last included."""
return [first_date + timedelta(days=n)
for n in range(1 + (last_date - first_date).days)] | [
"Returns",
"all",
"dates",
"from",
"first",
"to",
"last",
"included",
"."
] | alexprengere/currencyconverter | python | https://github.com/alexprengere/currencyconverter/blob/e3cb0d693819c0c824214225b23a47e9380f71df/currency_converter/currency_converter.py#L60-L63 | [
"def",
"list_dates_between",
"(",
"first_date",
",",
"last_date",
")",
":",
"return",
"[",
"first_date",
"+",
"timedelta",
"(",
"days",
"=",
"n",
")",
"for",
"n",
"in",
"range",
"(",
"1",
"+",
"(",
"last_date",
"-",
"first_date",
")",
".",
"days",
")",... | e3cb0d693819c0c824214225b23a47e9380f71df |
test | parse_date | Fast %Y-%m-%d parsing. | currency_converter/currency_converter.py | def parse_date(s):
"""Fast %Y-%m-%d parsing."""
try:
return datetime.date(int(s[:4]), int(s[5:7]), int(s[8:10]))
except ValueError: # other accepted format used in one-day data set
return datetime.datetime.strptime(s, '%d %B %Y').date() | def parse_date(s):
"""Fast %Y-%m-%d parsing."""
try:
return datetime.date(int(s[:4]), int(s[5:7]), int(s[8:10]))
except ValueError: # other accepted format used in one-day data set
return datetime.datetime.strptime(s, '%d %B %Y').date() | [
"Fast",
"%Y",
"-",
"%m",
"-",
"%d",
"parsing",
"."
] | alexprengere/currencyconverter | python | https://github.com/alexprengere/currencyconverter/blob/e3cb0d693819c0c824214225b23a47e9380f71df/currency_converter/currency_converter.py#L67-L72 | [
"def",
"parse_date",
"(",
"s",
")",
":",
"try",
":",
"return",
"datetime",
".",
"date",
"(",
"int",
"(",
"s",
"[",
":",
"4",
"]",
")",
",",
"int",
"(",
"s",
"[",
"5",
":",
"7",
"]",
")",
",",
"int",
"(",
"s",
"[",
"8",
":",
"10",
"]",
"... | e3cb0d693819c0c824214225b23a47e9380f71df |
test | CurrencyConverter.load_file | To be subclassed if alternate methods of loading data. | currency_converter/currency_converter.py | def load_file(self, currency_file):
"""To be subclassed if alternate methods of loading data.
"""
if currency_file.startswith(('http://', 'https://')):
content = urlopen(currency_file).read()
else:
with open(currency_file, 'rb') as f:
content = f.r... | def load_file(self, currency_file):
"""To be subclassed if alternate methods of loading data.
"""
if currency_file.startswith(('http://', 'https://')):
content = urlopen(currency_file).read()
else:
with open(currency_file, 'rb') as f:
content = f.r... | [
"To",
"be",
"subclassed",
"if",
"alternate",
"methods",
"of",
"loading",
"data",
"."
] | alexprengere/currencyconverter | python | https://github.com/alexprengere/currencyconverter/blob/e3cb0d693819c0c824214225b23a47e9380f71df/currency_converter/currency_converter.py#L147-L159 | [
"def",
"load_file",
"(",
"self",
",",
"currency_file",
")",
":",
"if",
"currency_file",
".",
"startswith",
"(",
"(",
"'http://'",
",",
"'https://'",
")",
")",
":",
"content",
"=",
"urlopen",
"(",
"currency_file",
")",
".",
"read",
"(",
")",
"else",
":",
... | e3cb0d693819c0c824214225b23a47e9380f71df |
test | CurrencyConverter._set_missing_to_none | Fill missing rates of a currency with the closest available ones. | currency_converter/currency_converter.py | def _set_missing_to_none(self, currency):
"""Fill missing rates of a currency with the closest available ones."""
rates = self._rates[currency]
first_date, last_date = self.bounds[currency]
for date in list_dates_between(first_date, last_date):
if date not in rates:
... | def _set_missing_to_none(self, currency):
"""Fill missing rates of a currency with the closest available ones."""
rates = self._rates[currency]
first_date, last_date = self.bounds[currency]
for date in list_dates_between(first_date, last_date):
if date not in rates:
... | [
"Fill",
"missing",
"rates",
"of",
"a",
"currency",
"with",
"the",
"closest",
"available",
"ones",
"."
] | alexprengere/currencyconverter | python | https://github.com/alexprengere/currencyconverter/blob/e3cb0d693819c0c824214225b23a47e9380f71df/currency_converter/currency_converter.py#L192-L206 | [
"def",
"_set_missing_to_none",
"(",
"self",
",",
"currency",
")",
":",
"rates",
"=",
"self",
".",
"_rates",
"[",
"currency",
"]",
"first_date",
",",
"last_date",
"=",
"self",
".",
"bounds",
"[",
"currency",
"]",
"for",
"date",
"in",
"list_dates_between",
"... | e3cb0d693819c0c824214225b23a47e9380f71df |
test | CurrencyConverter._compute_missing_rates | Fill missing rates of a currency.
This is done by linear interpolation of the two closest available rates.
:param str currency: The currency to fill missing rates for. | currency_converter/currency_converter.py | def _compute_missing_rates(self, currency):
"""Fill missing rates of a currency.
This is done by linear interpolation of the two closest available rates.
:param str currency: The currency to fill missing rates for.
"""
rates = self._rates[currency]
# tmp will store the... | def _compute_missing_rates(self, currency):
"""Fill missing rates of a currency.
This is done by linear interpolation of the two closest available rates.
:param str currency: The currency to fill missing rates for.
"""
rates = self._rates[currency]
# tmp will store the... | [
"Fill",
"missing",
"rates",
"of",
"a",
"currency",
"."
] | alexprengere/currencyconverter | python | https://github.com/alexprengere/currencyconverter/blob/e3cb0d693819c0c824214225b23a47e9380f71df/currency_converter/currency_converter.py#L208-L243 | [
"def",
"_compute_missing_rates",
"(",
"self",
",",
"currency",
")",
":",
"rates",
"=",
"self",
".",
"_rates",
"[",
"currency",
"]",
"# tmp will store the closest rates forward and backward",
"tmp",
"=",
"defaultdict",
"(",
"lambda",
":",
"[",
"None",
",",
"None",
... | e3cb0d693819c0c824214225b23a47e9380f71df |
test | CurrencyConverter._get_rate | Get a rate for a given currency and date.
:type date: datetime.date
>>> from datetime import date
>>> c = CurrencyConverter()
>>> c._get_rate('USD', date=date(2014, 3, 28))
1.375...
>>> c._get_rate('BGN', date=date(2010, 11, 21))
Traceback (most recent call last... | currency_converter/currency_converter.py | def _get_rate(self, currency, date):
"""Get a rate for a given currency and date.
:type date: datetime.date
>>> from datetime import date
>>> c = CurrencyConverter()
>>> c._get_rate('USD', date=date(2014, 3, 28))
1.375...
>>> c._get_rate('BGN', date=date(2010, 1... | def _get_rate(self, currency, date):
"""Get a rate for a given currency and date.
:type date: datetime.date
>>> from datetime import date
>>> c = CurrencyConverter()
>>> c._get_rate('USD', date=date(2014, 3, 28))
1.375...
>>> c._get_rate('BGN', date=date(2010, 1... | [
"Get",
"a",
"rate",
"for",
"a",
"given",
"currency",
"and",
"date",
"."
] | alexprengere/currencyconverter | python | https://github.com/alexprengere/currencyconverter/blob/e3cb0d693819c0c824214225b23a47e9380f71df/currency_converter/currency_converter.py#L245-L284 | [
"def",
"_get_rate",
"(",
"self",
",",
"currency",
",",
"date",
")",
":",
"if",
"currency",
"==",
"self",
".",
"ref_currency",
":",
"return",
"1.0",
"if",
"date",
"not",
"in",
"self",
".",
"_rates",
"[",
"currency",
"]",
":",
"first_date",
",",
"last_da... | e3cb0d693819c0c824214225b23a47e9380f71df |
test | CurrencyConverter.convert | Convert amount from a currency to another one.
:param float amount: The amount of `currency` to convert.
:param str currency: The currency to convert from.
:param str new_currency: The currency to convert to.
:param datetime.date date: Use the conversion rate of this date. If this
... | currency_converter/currency_converter.py | def convert(self, amount, currency, new_currency='EUR', date=None):
"""Convert amount from a currency to another one.
:param float amount: The amount of `currency` to convert.
:param str currency: The currency to convert from.
:param str new_currency: The currency to convert to.
... | def convert(self, amount, currency, new_currency='EUR', date=None):
"""Convert amount from a currency to another one.
:param float amount: The amount of `currency` to convert.
:param str currency: The currency to convert from.
:param str new_currency: The currency to convert to.
... | [
"Convert",
"amount",
"from",
"a",
"currency",
"to",
"another",
"one",
"."
] | alexprengere/currencyconverter | python | https://github.com/alexprengere/currencyconverter/blob/e3cb0d693819c0c824214225b23a47e9380f71df/currency_converter/currency_converter.py#L286-L323 | [
"def",
"convert",
"(",
"self",
",",
"amount",
",",
"currency",
",",
"new_currency",
"=",
"'EUR'",
",",
"date",
"=",
"None",
")",
":",
"for",
"c",
"in",
"currency",
",",
"new_currency",
":",
"if",
"c",
"not",
"in",
"self",
".",
"currencies",
":",
"rai... | e3cb0d693819c0c824214225b23a47e9380f71df |
test | grouper | Group iterable by n elements.
>>> for t in grouper('abcdefg', 3, fillvalue='x'):
... print(''.join(t))
abc
def
gxx | currency_converter/__main__.py | def grouper(iterable, n, fillvalue=None):
"""Group iterable by n elements.
>>> for t in grouper('abcdefg', 3, fillvalue='x'):
... print(''.join(t))
abc
def
gxx
"""
return list(zip_longest(*[iter(iterable)] * n, fillvalue=fillvalue)) | def grouper(iterable, n, fillvalue=None):
"""Group iterable by n elements.
>>> for t in grouper('abcdefg', 3, fillvalue='x'):
... print(''.join(t))
abc
def
gxx
"""
return list(zip_longest(*[iter(iterable)] * n, fillvalue=fillvalue)) | [
"Group",
"iterable",
"by",
"n",
"elements",
"."
] | alexprengere/currencyconverter | python | https://github.com/alexprengere/currencyconverter/blob/e3cb0d693819c0c824214225b23a47e9380f71df/currency_converter/__main__.py#L16-L25 | [
"def",
"grouper",
"(",
"iterable",
",",
"n",
",",
"fillvalue",
"=",
"None",
")",
":",
"return",
"list",
"(",
"zip_longest",
"(",
"*",
"[",
"iter",
"(",
"iterable",
")",
"]",
"*",
"n",
",",
"fillvalue",
"=",
"fillvalue",
")",
")"
] | e3cb0d693819c0c824214225b23a47e9380f71df |
test | animate | Animate given frame for set number of iterations.
Parameters
----------
frames : list
Frames for animating
interval : float
Interval between two frames
name : str
Name of animation
iterations : int, optional
Number of loops for animations | examples/examples.py | def animate(frames, interval, name, iterations=2):
"""Animate given frame for set number of iterations.
Parameters
----------
frames : list
Frames for animating
interval : float
Interval between two frames
name : str
Name of animation
iterations : int, optional
... | def animate(frames, interval, name, iterations=2):
"""Animate given frame for set number of iterations.
Parameters
----------
frames : list
Frames for animating
interval : float
Interval between two frames
name : str
Name of animation
iterations : int, optional
... | [
"Animate",
"given",
"frame",
"for",
"set",
"number",
"of",
"iterations",
"."
] | manrajgrover/py-spinners | python | https://github.com/manrajgrover/py-spinners/blob/2400b5f355049a691202671cb2ccf2b269eef4a3/examples/examples.py#L75-L96 | [
"def",
"animate",
"(",
"frames",
",",
"interval",
",",
"name",
",",
"iterations",
"=",
"2",
")",
":",
"for",
"i",
"in",
"range",
"(",
"iterations",
")",
":",
"for",
"frame",
"in",
"frames",
":",
"frame",
"=",
"get_coded_text",
"(",
"frame",
")",
"out... | 2400b5f355049a691202671cb2ccf2b269eef4a3 |
test | DimacsCnf.tostring | Convert Cnf object ot Dimacs cnf string
cnf: Cnf object
In the converted Cnf there will be only numbers for
variable names. The conversion guarantees that the
variables will be numbered alphabetically. | satispy/io/dimacs_cnf.py | def tostring(self, cnf):
"""Convert Cnf object ot Dimacs cnf string
cnf: Cnf object
In the converted Cnf there will be only numbers for
variable names. The conversion guarantees that the
variables will be numbered alphabetically.
"""
self.varname... | def tostring(self, cnf):
"""Convert Cnf object ot Dimacs cnf string
cnf: Cnf object
In the converted Cnf there will be only numbers for
variable names. The conversion guarantees that the
variables will be numbered alphabetically.
"""
self.varname... | [
"Convert",
"Cnf",
"object",
"ot",
"Dimacs",
"cnf",
"string",
"cnf",
":",
"Cnf",
"object",
"In",
"the",
"converted",
"Cnf",
"there",
"will",
"be",
"only",
"numbers",
"for",
"variable",
"names",
".",
"The",
"conversion",
"guarantees",
"that",
"the",
"variables... | netom/satispy | python | https://github.com/netom/satispy/blob/0201a7bffd9070441b9e82187348d61c53922b6b/satispy/io/dimacs_cnf.py#L18-L51 | [
"def",
"tostring",
"(",
"self",
",",
"cnf",
")",
":",
"self",
".",
"varname_dict",
"=",
"{",
"}",
"self",
".",
"varobj_dict",
"=",
"{",
"}",
"varis",
"=",
"set",
"(",
")",
"for",
"d",
"in",
"cnf",
".",
"dis",
":",
"for",
"v",
"in",
"d",
":",
... | 0201a7bffd9070441b9e82187348d61c53922b6b |
test | reduceCnf | I just found a remarkably large bug in my SAT solver and found an
interesting solution.
Remove all b | -b
(-b | b) & (b | -a) & (-b | a) & (a | -a)
becomes
(b | -a) & (-b | a)
Remove all (-e) & (-e)
(-e | a) & (-e | a) & (-e | a) & (-e | a)
becomes
(-e | a)
(-b | b | c) becomes ... | satispy/cnf.py | def reduceCnf(cnf):
"""
I just found a remarkably large bug in my SAT solver and found an
interesting solution.
Remove all b | -b
(-b | b) & (b | -a) & (-b | a) & (a | -a)
becomes
(b | -a) & (-b | a)
Remove all (-e) & (-e)
(-e | a) & (-e | a) & (-e | a) & (-e | a)
becomes
(-... | def reduceCnf(cnf):
"""
I just found a remarkably large bug in my SAT solver and found an
interesting solution.
Remove all b | -b
(-b | b) & (b | -a) & (-b | a) & (a | -a)
becomes
(b | -a) & (-b | a)
Remove all (-e) & (-e)
(-e | a) & (-e | a) & (-e | a) & (-e | a)
becomes
(-... | [
"I",
"just",
"found",
"a",
"remarkably",
"large",
"bug",
"in",
"my",
"SAT",
"solver",
"and",
"found",
"an",
"interesting",
"solution",
".",
"Remove",
"all",
"b",
"|",
"-",
"b",
"(",
"-",
"b",
"|",
"b",
")",
"&",
"(",
"b",
"|",
"-",
"a",
")",
"&... | netom/satispy | python | https://github.com/netom/satispy/blob/0201a7bffd9070441b9e82187348d61c53922b6b/satispy/cnf.py#L128-L156 | [
"def",
"reduceCnf",
"(",
"cnf",
")",
":",
"output",
"=",
"Cnf",
"(",
")",
"for",
"x",
"in",
"cnf",
".",
"dis",
":",
"dont_add",
"=",
"False",
"for",
"y",
"in",
"x",
":",
"for",
"z",
"in",
"x",
":",
"if",
"z",
"==",
"-",
"y",
":",
"dont_add",
... | 0201a7bffd9070441b9e82187348d61c53922b6b |
test | Ephemeris.load | [DEPRECATED] Load the polynomial series for `name` and return it. | jplephem/ephem.py | def load(self, name):
"""[DEPRECATED] Load the polynomial series for `name` and return it."""
s = self.sets.get(name)
if s is None:
self.sets[name] = s = np.load(self.path('jpl-%s.npy' % name))
return s | def load(self, name):
"""[DEPRECATED] Load the polynomial series for `name` and return it."""
s = self.sets.get(name)
if s is None:
self.sets[name] = s = np.load(self.path('jpl-%s.npy' % name))
return s | [
"[",
"DEPRECATED",
"]",
"Load",
"the",
"polynomial",
"series",
"for",
"name",
"and",
"return",
"it",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/ephem.py#L41-L46 | [
"def",
"load",
"(",
"self",
",",
"name",
")",
":",
"s",
"=",
"self",
".",
"sets",
".",
"get",
"(",
"name",
")",
"if",
"s",
"is",
"None",
":",
"self",
".",
"sets",
"[",
"name",
"]",
"=",
"s",
"=",
"np",
".",
"load",
"(",
"self",
".",
"path",... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Ephemeris.position | [DEPRECATED] Compute the position of `name` at time ``tdb [+ tdb2]``.
The position is returned as a NumPy array ``[x y z]``.
The barycentric dynamical time `tdb` argument should be a float.
If there are many dates you want computed, then make `tdb` an
array, which is more efficient tha... | jplephem/ephem.py | def position(self, name, tdb, tdb2=0.0):
"""[DEPRECATED] Compute the position of `name` at time ``tdb [+ tdb2]``.
The position is returned as a NumPy array ``[x y z]``.
The barycentric dynamical time `tdb` argument should be a float.
If there are many dates you want computed, then make... | def position(self, name, tdb, tdb2=0.0):
"""[DEPRECATED] Compute the position of `name` at time ``tdb [+ tdb2]``.
The position is returned as a NumPy array ``[x y z]``.
The barycentric dynamical time `tdb` argument should be a float.
If there are many dates you want computed, then make... | [
"[",
"DEPRECATED",
"]",
"Compute",
"the",
"position",
"of",
"name",
"at",
"time",
"tdb",
"[",
"+",
"tdb2",
"]",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/ephem.py#L48-L68 | [
"def",
"position",
"(",
"self",
",",
"name",
",",
"tdb",
",",
"tdb2",
"=",
"0.0",
")",
":",
"bundle",
"=",
"self",
".",
"compute_bundle",
"(",
"name",
",",
"tdb",
",",
"tdb2",
")",
"return",
"self",
".",
"position_from_bundle",
"(",
"bundle",
")"
] | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Ephemeris.position_and_velocity | [DEPRECATED] Compute the position and velocity of `name` at ``tdb [+ tdb2]``.
The position and velocity are returned in a 2-tuple::
([x y z], [xdot ydot zdot])
The barycentric dynamical time `tdb` argument should be a float.
If there are many dates you want computed, then make `td... | jplephem/ephem.py | def position_and_velocity(self, name, tdb, tdb2=0.0):
"""[DEPRECATED] Compute the position and velocity of `name` at ``tdb [+ tdb2]``.
The position and velocity are returned in a 2-tuple::
([x y z], [xdot ydot zdot])
The barycentric dynamical time `tdb` argument should be a float.... | def position_and_velocity(self, name, tdb, tdb2=0.0):
"""[DEPRECATED] Compute the position and velocity of `name` at ``tdb [+ tdb2]``.
The position and velocity are returned in a 2-tuple::
([x y z], [xdot ydot zdot])
The barycentric dynamical time `tdb` argument should be a float.... | [
"[",
"DEPRECATED",
"]",
"Compute",
"the",
"position",
"and",
"velocity",
"of",
"name",
"at",
"tdb",
"[",
"+",
"tdb2",
"]",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/ephem.py#L70-L94 | [
"def",
"position_and_velocity",
"(",
"self",
",",
"name",
",",
"tdb",
",",
"tdb2",
"=",
"0.0",
")",
":",
"bundle",
"=",
"self",
".",
"compute_bundle",
"(",
"name",
",",
"tdb",
",",
"tdb2",
")",
"position",
"=",
"self",
".",
"position_from_bundle",
"(",
... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Ephemeris.compute | [DEPRECATED] Legacy routine that concatenates position and velocity vectors.
This routine is deprecated. Use the methods `position()` and
`position_and_velocity()` instead. This method follows the same
calling convention, but incurs extra copy operations in order to
return a single Nu... | jplephem/ephem.py | def compute(self, name, tdb):
"""[DEPRECATED] Legacy routine that concatenates position and velocity vectors.
This routine is deprecated. Use the methods `position()` and
`position_and_velocity()` instead. This method follows the same
calling convention, but incurs extra copy operatio... | def compute(self, name, tdb):
"""[DEPRECATED] Legacy routine that concatenates position and velocity vectors.
This routine is deprecated. Use the methods `position()` and
`position_and_velocity()` instead. This method follows the same
calling convention, but incurs extra copy operatio... | [
"[",
"DEPRECATED",
"]",
"Legacy",
"routine",
"that",
"concatenates",
"position",
"and",
"velocity",
"vectors",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/ephem.py#L96-L110 | [
"def",
"compute",
"(",
"self",
",",
"name",
",",
"tdb",
")",
":",
"bundle",
"=",
"self",
".",
"compute_bundle",
"(",
"name",
",",
"tdb",
",",
"0.0",
")",
"position",
"=",
"self",
".",
"position_from_bundle",
"(",
"bundle",
")",
"velocity",
"=",
"self",... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Ephemeris.compute_bundle | [DEPRECATED] Return a tuple of coefficients and parameters for `tdb`.
The return value is a tuple that bundles together the
coefficients and other Chebyshev intermediate values that are
needed for the computation of either the position or velocity.
The bundle can then be passed to eithe... | jplephem/ephem.py | def compute_bundle(self, name, tdb, tdb2=0.0):
"""[DEPRECATED] Return a tuple of coefficients and parameters for `tdb`.
The return value is a tuple that bundles together the
coefficients and other Chebyshev intermediate values that are
needed for the computation of either the position o... | def compute_bundle(self, name, tdb, tdb2=0.0):
"""[DEPRECATED] Return a tuple of coefficients and parameters for `tdb`.
The return value is a tuple that bundles together the
coefficients and other Chebyshev intermediate values that are
needed for the computation of either the position o... | [
"[",
"DEPRECATED",
"]",
"Return",
"a",
"tuple",
"of",
"coefficients",
"and",
"parameters",
"for",
"tdb",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/ephem.py#L112-L171 | [
"def",
"compute_bundle",
"(",
"self",
",",
"name",
",",
"tdb",
",",
"tdb2",
"=",
"0.0",
")",
":",
"input_was_scalar",
"=",
"getattr",
"(",
"tdb",
",",
"'shape'",
",",
"(",
")",
")",
"==",
"(",
")",
"if",
"input_was_scalar",
":",
"tdb",
"=",
"np",
"... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Ephemeris.position_from_bundle | [DEPRECATED] Return position, given the `coefficient_bundle()` return value. | jplephem/ephem.py | def position_from_bundle(self, bundle):
"""[DEPRECATED] Return position, given the `coefficient_bundle()` return value."""
coefficients, days_per_set, T, twot1 = bundle
return (T.T * coefficients).sum(axis=2) | def position_from_bundle(self, bundle):
"""[DEPRECATED] Return position, given the `coefficient_bundle()` return value."""
coefficients, days_per_set, T, twot1 = bundle
return (T.T * coefficients).sum(axis=2) | [
"[",
"DEPRECATED",
"]",
"Return",
"position",
"given",
"the",
"coefficient_bundle",
"()",
"return",
"value",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/ephem.py#L173-L177 | [
"def",
"position_from_bundle",
"(",
"self",
",",
"bundle",
")",
":",
"coefficients",
",",
"days_per_set",
",",
"T",
",",
"twot1",
"=",
"bundle",
"return",
"(",
"T",
".",
"T",
"*",
"coefficients",
")",
".",
"sum",
"(",
"axis",
"=",
"2",
")"
] | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Ephemeris.velocity_from_bundle | [DEPRECATED] Return velocity, given the `coefficient_bundle()` return value. | jplephem/ephem.py | def velocity_from_bundle(self, bundle):
"""[DEPRECATED] Return velocity, given the `coefficient_bundle()` return value."""
coefficients, days_per_set, T, twot1 = bundle
coefficient_count = coefficients.shape[2]
# Chebyshev derivative:
dT = np.empty_like(T)
dT[0] = 0.0
... | def velocity_from_bundle(self, bundle):
"""[DEPRECATED] Return velocity, given the `coefficient_bundle()` return value."""
coefficients, days_per_set, T, twot1 = bundle
coefficient_count = coefficients.shape[2]
# Chebyshev derivative:
dT = np.empty_like(T)
dT[0] = 0.0
... | [
"[",
"DEPRECATED",
"]",
"Return",
"velocity",
"given",
"the",
"coefficient_bundle",
"()",
"return",
"value",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/ephem.py#L179-L196 | [
"def",
"velocity_from_bundle",
"(",
"self",
",",
"bundle",
")",
":",
"coefficients",
",",
"days_per_set",
",",
"T",
",",
"twot1",
"=",
"bundle",
"coefficient_count",
"=",
"coefficients",
".",
"shape",
"[",
"2",
"]",
"# Chebyshev derivative:",
"dT",
"=",
"np",
... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | DAF.read_record | Return record `n` as 1,024 bytes; records are indexed from 1. | jplephem/daf.py | def read_record(self, n):
"""Return record `n` as 1,024 bytes; records are indexed from 1."""
self.file.seek(n * K - K)
return self.file.read(K) | def read_record(self, n):
"""Return record `n` as 1,024 bytes; records are indexed from 1."""
self.file.seek(n * K - K)
return self.file.read(K) | [
"Return",
"record",
"n",
"as",
"1",
"024",
"bytes",
";",
"records",
"are",
"indexed",
"from",
"1",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/daf.py#L74-L77 | [
"def",
"read_record",
"(",
"self",
",",
"n",
")",
":",
"self",
".",
"file",
".",
"seek",
"(",
"n",
"*",
"K",
"-",
"K",
")",
"return",
"self",
".",
"file",
".",
"read",
"(",
"K",
")"
] | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | DAF.write_record | Write `data` to file record `n`; records are indexed from 1. | jplephem/daf.py | def write_record(self, n, data):
"""Write `data` to file record `n`; records are indexed from 1."""
self.file.seek(n * K - K)
return self.file.write(data) | def write_record(self, n, data):
"""Write `data` to file record `n`; records are indexed from 1."""
self.file.seek(n * K - K)
return self.file.write(data) | [
"Write",
"data",
"to",
"file",
"record",
"n",
";",
"records",
"are",
"indexed",
"from",
"1",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/daf.py#L79-L82 | [
"def",
"write_record",
"(",
"self",
",",
"n",
",",
"data",
")",
":",
"self",
".",
"file",
".",
"seek",
"(",
"n",
"*",
"K",
"-",
"K",
")",
"return",
"self",
".",
"file",
".",
"write",
"(",
"data",
")"
] | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | DAF.map_words | Return a memory-map of the elements `start` through `end`.
The memory map will offer the 8-byte double-precision floats
("elements") in the file from index `start` through to the index
`end`, inclusive, both counting the first float as element 1.
Memory maps must begin on a page boundar... | jplephem/daf.py | def map_words(self, start, end):
"""Return a memory-map of the elements `start` through `end`.
The memory map will offer the 8-byte double-precision floats
("elements") in the file from index `start` through to the index
`end`, inclusive, both counting the first float as element 1.
... | def map_words(self, start, end):
"""Return a memory-map of the elements `start` through `end`.
The memory map will offer the 8-byte double-precision floats
("elements") in the file from index `start` through to the index
`end`, inclusive, both counting the first float as element 1.
... | [
"Return",
"a",
"memory",
"-",
"map",
"of",
"the",
"elements",
"start",
"through",
"end",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/daf.py#L92-L117 | [
"def",
"map_words",
"(",
"self",
",",
"start",
",",
"end",
")",
":",
"i",
",",
"j",
"=",
"8",
"*",
"start",
"-",
"8",
",",
"8",
"*",
"end",
"try",
":",
"fileno",
"=",
"self",
".",
"file",
".",
"fileno",
"(",
")",
"except",
"(",
"AttributeError"... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | DAF.comments | Return the text inside the comment area of the file. | jplephem/daf.py | def comments(self):
"""Return the text inside the comment area of the file."""
record_numbers = range(2, self.fward)
if not record_numbers:
return ''
data = b''.join(self.read_record(n)[0:1000] for n in record_numbers)
try:
return data[:data.find(b'\4')].d... | def comments(self):
"""Return the text inside the comment area of the file."""
record_numbers = range(2, self.fward)
if not record_numbers:
return ''
data = b''.join(self.read_record(n)[0:1000] for n in record_numbers)
try:
return data[:data.find(b'\4')].d... | [
"Return",
"the",
"text",
"inside",
"the",
"comment",
"area",
"of",
"the",
"file",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/daf.py#L119-L130 | [
"def",
"comments",
"(",
"self",
")",
":",
"record_numbers",
"=",
"range",
"(",
"2",
",",
"self",
".",
"fward",
")",
"if",
"not",
"record_numbers",
":",
"return",
"''",
"data",
"=",
"b''",
".",
"join",
"(",
"self",
".",
"read_record",
"(",
"n",
")",
... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | DAF.read_array | Return floats from `start` to `end` inclusive, indexed from 1.
The entire range of floats is immediately read into memory from
the file, making this efficient for small sequences of floats
whose values are all needed immediately. | jplephem/daf.py | def read_array(self, start, end):
"""Return floats from `start` to `end` inclusive, indexed from 1.
The entire range of floats is immediately read into memory from
the file, making this efficient for small sequences of floats
whose values are all needed immediately.
"""
... | def read_array(self, start, end):
"""Return floats from `start` to `end` inclusive, indexed from 1.
The entire range of floats is immediately read into memory from
the file, making this efficient for small sequences of floats
whose values are all needed immediately.
"""
... | [
"Return",
"floats",
"from",
"start",
"to",
"end",
"inclusive",
"indexed",
"from",
"1",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/daf.py#L132-L144 | [
"def",
"read_array",
"(",
"self",
",",
"start",
",",
"end",
")",
":",
"f",
"=",
"self",
".",
"file",
"f",
".",
"seek",
"(",
"8",
"*",
"(",
"start",
"-",
"1",
")",
")",
"length",
"=",
"1",
"+",
"end",
"-",
"start",
"data",
"=",
"f",
".",
"re... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | DAF.map_array | Return floats from `start` to `end` inclusive, indexed from 1.
Instead of pausing to load all of the floats into RAM, this
routine creates a memory map which will load data from the file
only as it is accessed, and then will let it expire back out to
disk later. This is very efficient ... | jplephem/daf.py | def map_array(self, start, end):
"""Return floats from `start` to `end` inclusive, indexed from 1.
Instead of pausing to load all of the floats into RAM, this
routine creates a memory map which will load data from the file
only as it is accessed, and then will let it expire back out to
... | def map_array(self, start, end):
"""Return floats from `start` to `end` inclusive, indexed from 1.
Instead of pausing to load all of the floats into RAM, this
routine creates a memory map which will load data from the file
only as it is accessed, and then will let it expire back out to
... | [
"Return",
"floats",
"from",
"start",
"to",
"end",
"inclusive",
"indexed",
"from",
"1",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/daf.py#L146-L160 | [
"def",
"map_array",
"(",
"self",
",",
"start",
",",
"end",
")",
":",
"if",
"self",
".",
"_array",
"is",
"None",
":",
"self",
".",
"_map",
",",
"skip",
"=",
"self",
".",
"map_words",
"(",
"1",
",",
"self",
".",
"free",
"-",
"1",
")",
"assert",
"... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | DAF.summary_records | Yield (record_number, n_summaries, record_data) for each record.
Readers will only use the second two values in each tuple.
Writers can update the record using the `record_number`. | jplephem/daf.py | def summary_records(self):
"""Yield (record_number, n_summaries, record_data) for each record.
Readers will only use the second two values in each tuple.
Writers can update the record using the `record_number`.
"""
record_number = self.fward
unpack = self.summary_contro... | def summary_records(self):
"""Yield (record_number, n_summaries, record_data) for each record.
Readers will only use the second two values in each tuple.
Writers can update the record using the `record_number`.
"""
record_number = self.fward
unpack = self.summary_contro... | [
"Yield",
"(",
"record_number",
"n_summaries",
"record_data",
")",
"for",
"each",
"record",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/daf.py#L162-L175 | [
"def",
"summary_records",
"(",
"self",
")",
":",
"record_number",
"=",
"self",
".",
"fward",
"unpack",
"=",
"self",
".",
"summary_control_struct",
".",
"unpack",
"while",
"record_number",
":",
"data",
"=",
"self",
".",
"read_record",
"(",
"record_number",
")",... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | DAF.summaries | Yield (name, (value, value, ...)) for each summary in the file. | jplephem/daf.py | def summaries(self):
"""Yield (name, (value, value, ...)) for each summary in the file."""
length = self.summary_length
step = self.summary_step
for record_number, n_summaries, summary_data in self.summary_records():
name_data = self.read_record(record_number + 1)
... | def summaries(self):
"""Yield (name, (value, value, ...)) for each summary in the file."""
length = self.summary_length
step = self.summary_step
for record_number, n_summaries, summary_data in self.summary_records():
name_data = self.read_record(record_number + 1)
... | [
"Yield",
"(",
"name",
"(",
"value",
"value",
"...",
"))",
"for",
"each",
"summary",
"in",
"the",
"file",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/daf.py#L177-L188 | [
"def",
"summaries",
"(",
"self",
")",
":",
"length",
"=",
"self",
".",
"summary_length",
"step",
"=",
"self",
".",
"summary_step",
"for",
"record_number",
",",
"n_summaries",
",",
"summary_data",
"in",
"self",
".",
"summary_records",
"(",
")",
":",
"name_dat... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | DAF.add_array | Add a new array to the DAF file.
The summary will be initialized with the `name` and `values`,
and will have its start word and end word fields set to point to
where the `array` of floats has been appended to the file. | jplephem/daf.py | def add_array(self, name, values, array):
"""Add a new array to the DAF file.
The summary will be initialized with the `name` and `values`,
and will have its start word and end word fields set to point to
where the `array` of floats has been appended to the file.
"""
f ... | def add_array(self, name, values, array):
"""Add a new array to the DAF file.
The summary will be initialized with the `name` and `values`,
and will have its start word and end word fields set to point to
where the `array` of floats has been appended to the file.
"""
f ... | [
"Add",
"a",
"new",
"array",
"to",
"the",
"DAF",
"file",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/daf.py#L202-L255 | [
"def",
"add_array",
"(",
"self",
",",
"name",
",",
"values",
",",
"array",
")",
":",
"f",
"=",
"self",
".",
"file",
"scs",
"=",
"self",
".",
"summary_control_struct",
"record_number",
"=",
"self",
".",
"bward",
"data",
"=",
"bytearray",
"(",
"self",
".... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | SPK.close | Close this SPK file. | jplephem/spk.py | def close(self):
"""Close this SPK file."""
self.daf.file.close()
for segment in self.segments:
if hasattr(segment, '_data'):
del segment._data
self.daf._array = None
self.daf._map = None | def close(self):
"""Close this SPK file."""
self.daf.file.close()
for segment in self.segments:
if hasattr(segment, '_data'):
del segment._data
self.daf._array = None
self.daf._map = None | [
"Close",
"this",
"SPK",
"file",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/spk.py#L46-L53 | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"daf",
".",
"file",
".",
"close",
"(",
")",
"for",
"segment",
"in",
"self",
".",
"segments",
":",
"if",
"hasattr",
"(",
"segment",
",",
"'_data'",
")",
":",
"del",
"segment",
".",
"_data",
"self",... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Segment.describe | Return a textual description of the segment. | jplephem/spk.py | def describe(self, verbose=True):
"""Return a textual description of the segment."""
center = titlecase(target_names.get(self.center, 'Unknown center'))
target = titlecase(target_names.get(self.target, 'Unknown target'))
text = ('{0.start_jd:.2f}..{0.end_jd:.2f} {1} ({0.center})'
... | def describe(self, verbose=True):
"""Return a textual description of the segment."""
center = titlecase(target_names.get(self.center, 'Unknown center'))
target = titlecase(target_names.get(self.target, 'Unknown target'))
text = ('{0.start_jd:.2f}..{0.end_jd:.2f} {1} ({0.center})'
... | [
"Return",
"a",
"textual",
"description",
"of",
"the",
"segment",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/spk.py#L109-L118 | [
"def",
"describe",
"(",
"self",
",",
"verbose",
"=",
"True",
")",
":",
"center",
"=",
"titlecase",
"(",
"target_names",
".",
"get",
"(",
"self",
".",
"center",
",",
"'Unknown center'",
")",
")",
"target",
"=",
"titlecase",
"(",
"target_names",
".",
"get"... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Segment.compute | Compute the component values for the time `tdb` plus `tdb2`. | jplephem/spk.py | def compute(self, tdb, tdb2=0.0):
"""Compute the component values for the time `tdb` plus `tdb2`."""
for position in self.generate(tdb, tdb2):
return position | def compute(self, tdb, tdb2=0.0):
"""Compute the component values for the time `tdb` plus `tdb2`."""
for position in self.generate(tdb, tdb2):
return position | [
"Compute",
"the",
"component",
"values",
"for",
"the",
"time",
"tdb",
"plus",
"tdb2",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/spk.py#L120-L123 | [
"def",
"compute",
"(",
"self",
",",
"tdb",
",",
"tdb2",
"=",
"0.0",
")",
":",
"for",
"position",
"in",
"self",
".",
"generate",
"(",
"tdb",
",",
"tdb2",
")",
":",
"return",
"position"
] | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | BinaryPCK.close | Close this file. | jplephem/binary_pck.py | def close(self):
"""Close this file."""
self.daf.file.close()
for segment in self.segments:
if hasattr(segment, '_data'):
del segment._data | def close(self):
"""Close this file."""
self.daf.file.close()
for segment in self.segments:
if hasattr(segment, '_data'):
del segment._data | [
"Close",
"this",
"file",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/binary_pck.py#L42-L47 | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"daf",
".",
"file",
".",
"close",
"(",
")",
"for",
"segment",
"in",
"self",
".",
"segments",
":",
"if",
"hasattr",
"(",
"segment",
",",
"'_data'",
")",
":",
"del",
"segment",
".",
"_data"
] | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Segment.describe | Return a textual description of the segment. | jplephem/binary_pck.py | def describe(self, verbose=True):
"""Return a textual description of the segment."""
body = titlecase(target_names.get(self.body, 'Unknown body'))
text = ('{0.start_jd:.2f}..{0.end_jd:.2f} frame={0.frame}'
' {1} ({0.body})'.format(self, body))
if verbose:
tex... | def describe(self, verbose=True):
"""Return a textual description of the segment."""
body = titlecase(target_names.get(self.body, 'Unknown body'))
text = ('{0.start_jd:.2f}..{0.end_jd:.2f} frame={0.frame}'
' {1} ({0.body})'.format(self, body))
if verbose:
tex... | [
"Return",
"a",
"textual",
"description",
"of",
"the",
"segment",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/binary_pck.py#L92-L100 | [
"def",
"describe",
"(",
"self",
",",
"verbose",
"=",
"True",
")",
":",
"body",
"=",
"titlecase",
"(",
"target_names",
".",
"get",
"(",
"self",
".",
"body",
",",
"'Unknown body'",
")",
")",
"text",
"=",
"(",
"'{0.start_jd:.2f}..{0.end_jd:.2f} frame={0.frame}'",... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Segment._load | Map the coefficients into memory using a NumPy array. | jplephem/binary_pck.py | def _load(self):
"""Map the coefficients into memory using a NumPy array.
"""
if self.data_type == 2:
component_count = 3
else:
raise ValueError('only binary PCK data type 2 is supported')
init, intlen, rsize, n = self.daf.read_array(self.end_i - 3, self... | def _load(self):
"""Map the coefficients into memory using a NumPy array.
"""
if self.data_type == 2:
component_count = 3
else:
raise ValueError('only binary PCK data type 2 is supported')
init, intlen, rsize, n = self.daf.read_array(self.end_i - 3, self... | [
"Map",
"the",
"coefficients",
"into",
"memory",
"using",
"a",
"NumPy",
"array",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/binary_pck.py#L102-L121 | [
"def",
"_load",
"(",
"self",
")",
":",
"if",
"self",
".",
"data_type",
"==",
"2",
":",
"component_count",
"=",
"3",
"else",
":",
"raise",
"ValueError",
"(",
"'only binary PCK data type 2 is supported'",
")",
"init",
",",
"intlen",
",",
"rsize",
",",
"n",
"... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | Segment.compute | Generate angles and derivatives for time `tdb` plus `tdb2`.
If ``derivative`` is true, return a tuple containing both the
angle and its derivative; otherwise simply return the angles. | jplephem/binary_pck.py | def compute(self, tdb, tdb2, derivative=True):
"""Generate angles and derivatives for time `tdb` plus `tdb2`.
If ``derivative`` is true, return a tuple containing both the
angle and its derivative; otherwise simply return the angles.
"""
scalar = not getattr(tdb, 'shape', 0) an... | def compute(self, tdb, tdb2, derivative=True):
"""Generate angles and derivatives for time `tdb` plus `tdb2`.
If ``derivative`` is true, return a tuple containing both the
angle and its derivative; otherwise simply return the angles.
"""
scalar = not getattr(tdb, 'shape', 0) an... | [
"Generate",
"angles",
"and",
"derivatives",
"for",
"time",
"tdb",
"plus",
"tdb2",
"."
] | brandon-rhodes/python-jplephem | python | https://github.com/brandon-rhodes/python-jplephem/blob/48c99ce40c627e24c95479d8845e312ea168f567/jplephem/binary_pck.py#L123-L188 | [
"def",
"compute",
"(",
"self",
",",
"tdb",
",",
"tdb2",
",",
"derivative",
"=",
"True",
")",
":",
"scalar",
"=",
"not",
"getattr",
"(",
"tdb",
",",
"'shape'",
",",
"0",
")",
"and",
"not",
"getattr",
"(",
"tdb2",
",",
"'shape'",
",",
"0",
")",
"if... | 48c99ce40c627e24c95479d8845e312ea168f567 |
test | notify | Show system notification with duration t (ms) | MusicBoxApi/utils.py | def notify(msg, msg_type=0, t=None):
"Show system notification with duration t (ms)"
if platform.system() == 'Darwin':
command = notify_command_osx(msg, msg_type, t)
else:
command = notify_command_linux(msg, t)
os.system(command.encode('utf-8')) | def notify(msg, msg_type=0, t=None):
"Show system notification with duration t (ms)"
if platform.system() == 'Darwin':
command = notify_command_osx(msg, msg_type, t)
else:
command = notify_command_linux(msg, t)
os.system(command.encode('utf-8')) | [
"Show",
"system",
"notification",
"with",
"duration",
"t",
"(",
"ms",
")"
] | wzpan/MusicBoxApi | python | https://github.com/wzpan/MusicBoxApi/blob/d539d4b06c59bdf79b8d44756c325e39fde81f13/MusicBoxApi/utils.py#L38-L44 | [
"def",
"notify",
"(",
"msg",
",",
"msg_type",
"=",
"0",
",",
"t",
"=",
"None",
")",
":",
"if",
"platform",
".",
"system",
"(",
")",
"==",
"'Darwin'",
":",
"command",
"=",
"notify_command_osx",
"(",
"msg",
",",
"msg_type",
",",
"t",
")",
"else",
":"... | d539d4b06c59bdf79b8d44756c325e39fde81f13 |
test | geturls_new_api | 批量获取音乐的地址 | MusicBoxApi/api.py | def geturls_new_api(song_ids):
""" 批量获取音乐的地址 """
br_to_quality = {128000: 'MD 128k', 320000: 'HD 320k'}
alters = NetEase().songs_detail_new_api(song_ids)
urls = [alter['url'] for alter in alters]
return urls | def geturls_new_api(song_ids):
""" 批量获取音乐的地址 """
br_to_quality = {128000: 'MD 128k', 320000: 'HD 320k'}
alters = NetEase().songs_detail_new_api(song_ids)
urls = [alter['url'] for alter in alters]
return urls | [
"批量获取音乐的地址"
] | wzpan/MusicBoxApi | python | https://github.com/wzpan/MusicBoxApi/blob/d539d4b06c59bdf79b8d44756c325e39fde81f13/MusicBoxApi/api.py#L180-L185 | [
"def",
"geturls_new_api",
"(",
"song_ids",
")",
":",
"br_to_quality",
"=",
"{",
"128000",
":",
"'MD 128k'",
",",
"320000",
":",
"'HD 320k'",
"}",
"alters",
"=",
"NetEase",
"(",
")",
".",
"songs_detail_new_api",
"(",
"song_ids",
")",
"urls",
"=",
"[",
"alte... | d539d4b06c59bdf79b8d44756c325e39fde81f13 |
test | LoggingVisitor.visit_Call | Visit a function call.
We expect every logging statement and string format to be a function call. | logging_format/visitor.py | def visit_Call(self, node):
"""
Visit a function call.
We expect every logging statement and string format to be a function call.
"""
# CASE 1: We're in a logging statement
if self.within_logging_statement():
if self.within_logging_argument() and self.is_for... | def visit_Call(self, node):
"""
Visit a function call.
We expect every logging statement and string format to be a function call.
"""
# CASE 1: We're in a logging statement
if self.within_logging_statement():
if self.within_logging_argument() and self.is_for... | [
"Visit",
"a",
"function",
"call",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L65-L111 | [
"def",
"visit_Call",
"(",
"self",
",",
"node",
")",
":",
"# CASE 1: We're in a logging statement",
"if",
"self",
".",
"within_logging_statement",
"(",
")",
":",
"if",
"self",
".",
"within_logging_argument",
"(",
")",
"and",
"self",
".",
"is_format_call",
"(",
"n... | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.visit_BinOp | Process binary operations while processing the first logging argument. | logging_format/visitor.py | def visit_BinOp(self, node):
"""
Process binary operations while processing the first logging argument.
"""
if self.within_logging_statement() and self.within_logging_argument():
# handle percent format
if isinstance(node.op, Mod):
self.violations... | def visit_BinOp(self, node):
"""
Process binary operations while processing the first logging argument.
"""
if self.within_logging_statement() and self.within_logging_argument():
# handle percent format
if isinstance(node.op, Mod):
self.violations... | [
"Process",
"binary",
"operations",
"while",
"processing",
"the",
"first",
"logging",
"argument",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L113-L125 | [
"def",
"visit_BinOp",
"(",
"self",
",",
"node",
")",
":",
"if",
"self",
".",
"within_logging_statement",
"(",
")",
"and",
"self",
".",
"within_logging_argument",
"(",
")",
":",
"# handle percent format",
"if",
"isinstance",
"(",
"node",
".",
"op",
",",
"Mod"... | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.visit_Dict | Process dict arguments. | logging_format/visitor.py | def visit_Dict(self, node):
"""
Process dict arguments.
"""
if self.should_check_whitelist(node):
for key in node.keys:
if key.s in self.whitelist or key.s.startswith("debug_"):
continue
self.violations.append((self.current... | def visit_Dict(self, node):
"""
Process dict arguments.
"""
if self.should_check_whitelist(node):
for key in node.keys:
if key.s in self.whitelist or key.s.startswith("debug_"):
continue
self.violations.append((self.current... | [
"Process",
"dict",
"arguments",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L127-L142 | [
"def",
"visit_Dict",
"(",
"self",
",",
"node",
")",
":",
"if",
"self",
".",
"should_check_whitelist",
"(",
"node",
")",
":",
"for",
"key",
"in",
"node",
".",
"keys",
":",
"if",
"key",
".",
"s",
"in",
"self",
".",
"whitelist",
"or",
"key",
".",
"s",... | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.visit_JoinedStr | Process f-string arguments. | logging_format/visitor.py | def visit_JoinedStr(self, node):
"""
Process f-string arguments.
"""
if version_info >= (3, 6):
if self.within_logging_statement():
if any(isinstance(i, FormattedValue) for i in node.values):
if self.within_logging_argument():
... | def visit_JoinedStr(self, node):
"""
Process f-string arguments.
"""
if version_info >= (3, 6):
if self.within_logging_statement():
if any(isinstance(i, FormattedValue) for i in node.values):
if self.within_logging_argument():
... | [
"Process",
"f",
"-",
"string",
"arguments",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L144-L154 | [
"def",
"visit_JoinedStr",
"(",
"self",
",",
"node",
")",
":",
"if",
"version_info",
">=",
"(",
"3",
",",
"6",
")",
":",
"if",
"self",
".",
"within_logging_statement",
"(",
")",
":",
"if",
"any",
"(",
"isinstance",
"(",
"i",
",",
"FormattedValue",
")",
... | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.visit_keyword | Process keyword arguments. | logging_format/visitor.py | def visit_keyword(self, node):
"""
Process keyword arguments.
"""
if self.should_check_whitelist(node):
if node.arg not in self.whitelist and not node.arg.startswith("debug_"):
self.violations.append((self.current_logging_call, WHITELIST_VIOLATION.format(node... | def visit_keyword(self, node):
"""
Process keyword arguments.
"""
if self.should_check_whitelist(node):
if node.arg not in self.whitelist and not node.arg.startswith("debug_"):
self.violations.append((self.current_logging_call, WHITELIST_VIOLATION.format(node... | [
"Process",
"keyword",
"arguments",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L156-L168 | [
"def",
"visit_keyword",
"(",
"self",
",",
"node",
")",
":",
"if",
"self",
".",
"should_check_whitelist",
"(",
"node",
")",
":",
"if",
"node",
".",
"arg",
"not",
"in",
"self",
".",
"whitelist",
"and",
"not",
"node",
".",
"arg",
".",
"startswith",
"(",
... | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.visit_ExceptHandler | Process except blocks. | logging_format/visitor.py | def visit_ExceptHandler(self, node):
"""
Process except blocks.
"""
name = self.get_except_handler_name(node)
if not name:
super(LoggingVisitor, self).generic_visit(node)
return
self.current_except_names.append(name)
super(LoggingVisitor,... | def visit_ExceptHandler(self, node):
"""
Process except blocks.
"""
name = self.get_except_handler_name(node)
if not name:
super(LoggingVisitor, self).generic_visit(node)
return
self.current_except_names.append(name)
super(LoggingVisitor,... | [
"Process",
"except",
"blocks",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L170-L182 | [
"def",
"visit_ExceptHandler",
"(",
"self",
",",
"node",
")",
":",
"name",
"=",
"self",
".",
"get_except_handler_name",
"(",
"node",
")",
"if",
"not",
"name",
":",
"super",
"(",
"LoggingVisitor",
",",
"self",
")",
".",
"generic_visit",
"(",
"node",
")",
"... | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.detect_logging_level | Heuristic to decide whether an AST Call is a logging call. | logging_format/visitor.py | def detect_logging_level(self, node):
"""
Heuristic to decide whether an AST Call is a logging call.
"""
try:
if self.get_id_attr(node.func.value) == "warnings":
return None
# NB: We could also look at the argument signature or the target attribut... | def detect_logging_level(self, node):
"""
Heuristic to decide whether an AST Call is a logging call.
"""
try:
if self.get_id_attr(node.func.value) == "warnings":
return None
# NB: We could also look at the argument signature or the target attribut... | [
"Heuristic",
"to",
"decide",
"whether",
"an",
"AST",
"Call",
"is",
"a",
"logging",
"call",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L184-L197 | [
"def",
"detect_logging_level",
"(",
"self",
",",
"node",
")",
":",
"try",
":",
"if",
"self",
".",
"get_id_attr",
"(",
"node",
".",
"func",
".",
"value",
")",
"==",
"\"warnings\"",
":",
"return",
"None",
"# NB: We could also look at the argument signature or the ta... | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.get_except_handler_name | Helper to get the exception name from an ExceptHandler node in both py2 and py3. | logging_format/visitor.py | def get_except_handler_name(self, node):
"""
Helper to get the exception name from an ExceptHandler node in both py2 and py3.
"""
name = node.name
if not name:
return None
if version_info < (3,):
return name.id
return name | def get_except_handler_name(self, node):
"""
Helper to get the exception name from an ExceptHandler node in both py2 and py3.
"""
name = node.name
if not name:
return None
if version_info < (3,):
return name.id
return name | [
"Helper",
"to",
"get",
"the",
"exception",
"name",
"from",
"an",
"ExceptHandler",
"node",
"in",
"both",
"py2",
"and",
"py3",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L228-L239 | [
"def",
"get_except_handler_name",
"(",
"self",
",",
"node",
")",
":",
"name",
"=",
"node",
".",
"name",
"if",
"not",
"name",
":",
"return",
"None",
"if",
"version_info",
"<",
"(",
"3",
",",
")",
":",
"return",
"name",
".",
"id",
"return",
"name"
] | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.get_id_attr | Check if value has id attribute and return it.
:param value: The value to get id from.
:return: The value.id. | logging_format/visitor.py | def get_id_attr(self, value):
"""Check if value has id attribute and return it.
:param value: The value to get id from.
:return: The value.id.
"""
if not hasattr(value, "id") and hasattr(value, "value"):
value = value.value
return value.id | def get_id_attr(self, value):
"""Check if value has id attribute and return it.
:param value: The value to get id from.
:return: The value.id.
"""
if not hasattr(value, "id") and hasattr(value, "value"):
value = value.value
return value.id | [
"Check",
"if",
"value",
"has",
"id",
"attribute",
"and",
"return",
"it",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L241-L249 | [
"def",
"get_id_attr",
"(",
"self",
",",
"value",
")",
":",
"if",
"not",
"hasattr",
"(",
"value",
",",
"\"id\"",
")",
"and",
"hasattr",
"(",
"value",
",",
"\"value\"",
")",
":",
"value",
"=",
"value",
".",
"value",
"return",
"value",
".",
"id"
] | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.is_bare_exception | Checks if the node is a bare exception name from an except block. | logging_format/visitor.py | def is_bare_exception(self, node):
"""
Checks if the node is a bare exception name from an except block.
"""
return isinstance(node, Name) and node.id in self.current_except_names | def is_bare_exception(self, node):
"""
Checks if the node is a bare exception name from an except block.
"""
return isinstance(node, Name) and node.id in self.current_except_names | [
"Checks",
"if",
"the",
"node",
"is",
"a",
"bare",
"exception",
"name",
"from",
"an",
"except",
"block",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L251-L256 | [
"def",
"is_bare_exception",
"(",
"self",
",",
"node",
")",
":",
"return",
"isinstance",
"(",
"node",
",",
"Name",
")",
"and",
"node",
".",
"id",
"in",
"self",
".",
"current_except_names"
] | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.is_str_exception | Checks if the node is the expression str(e) or unicode(e), where e is an exception name from an except block | logging_format/visitor.py | def is_str_exception(self, node):
"""
Checks if the node is the expression str(e) or unicode(e), where e is an exception name from an except block
"""
return (
isinstance(node, Call)
and isinstance(node.func, Name)
and node.func.id in ('str', 'unicode... | def is_str_exception(self, node):
"""
Checks if the node is the expression str(e) or unicode(e), where e is an exception name from an except block
"""
return (
isinstance(node, Call)
and isinstance(node.func, Name)
and node.func.id in ('str', 'unicode... | [
"Checks",
"if",
"the",
"node",
"is",
"the",
"expression",
"str",
"(",
"e",
")",
"or",
"unicode",
"(",
"e",
")",
"where",
"e",
"is",
"an",
"exception",
"name",
"from",
"an",
"except",
"block"
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L258-L269 | [
"def",
"is_str_exception",
"(",
"self",
",",
"node",
")",
":",
"return",
"(",
"isinstance",
"(",
"node",
",",
"Call",
")",
"and",
"isinstance",
"(",
"node",
".",
"func",
",",
"Name",
")",
"and",
"node",
".",
"func",
".",
"id",
"in",
"(",
"'str'",
"... | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | LoggingVisitor.check_exc_info | Reports a violation if exc_info keyword is used with logging.error or logging.exception. | logging_format/visitor.py | def check_exc_info(self, node):
"""
Reports a violation if exc_info keyword is used with logging.error or logging.exception.
"""
if self.current_logging_level not in ('error', 'exception'):
return
for kw in node.keywords:
if kw.arg == 'exc_info':
... | def check_exc_info(self, node):
"""
Reports a violation if exc_info keyword is used with logging.error or logging.exception.
"""
if self.current_logging_level not in ('error', 'exception'):
return
for kw in node.keywords:
if kw.arg == 'exc_info':
... | [
"Reports",
"a",
"violation",
"if",
"exc_info",
"keyword",
"is",
"used",
"with",
"logging",
".",
"error",
"or",
"logging",
".",
"exception",
"."
] | globality-corp/flake8-logging-format | python | https://github.com/globality-corp/flake8-logging-format/blob/3c6ce53d0ff1ec369799cff0ed6d048343252e40/logging_format/visitor.py#L275-L289 | [
"def",
"check_exc_info",
"(",
"self",
",",
"node",
")",
":",
"if",
"self",
".",
"current_logging_level",
"not",
"in",
"(",
"'error'",
",",
"'exception'",
")",
":",
"return",
"for",
"kw",
"in",
"node",
".",
"keywords",
":",
"if",
"kw",
".",
"arg",
"==",... | 3c6ce53d0ff1ec369799cff0ed6d048343252e40 |
test | delete_file_if_needed | Delete file from database only if needed.
When editing and the filefield is a new file,
deletes the previous file (if any) from the database.
Call this function immediately BEFORE saving the instance. | db_file_storage/model_utils.py | def delete_file_if_needed(instance, filefield_name):
"""Delete file from database only if needed.
When editing and the filefield is a new file,
deletes the previous file (if any) from the database.
Call this function immediately BEFORE saving the instance.
"""
if instance.pk:
model_clas... | def delete_file_if_needed(instance, filefield_name):
"""Delete file from database only if needed.
When editing and the filefield is a new file,
deletes the previous file (if any) from the database.
Call this function immediately BEFORE saving the instance.
"""
if instance.pk:
model_clas... | [
"Delete",
"file",
"from",
"database",
"only",
"if",
"needed",
"."
] | victor-o-silva/db_file_storage | python | https://github.com/victor-o-silva/db_file_storage/blob/ff5375422246c42b8a7bba558f1c3b49bb985f36/db_file_storage/model_utils.py#L5-L36 | [
"def",
"delete_file_if_needed",
"(",
"instance",
",",
"filefield_name",
")",
":",
"if",
"instance",
".",
"pk",
":",
"model_class",
"=",
"type",
"(",
"instance",
")",
"# Check if there is a file for the instance in the database",
"if",
"model_class",
".",
"objects",
".... | ff5375422246c42b8a7bba558f1c3b49bb985f36 |
test | delete_file | Delete the file (if any) from the database.
Call this function immediately AFTER deleting the instance. | db_file_storage/model_utils.py | def delete_file(instance, filefield_name):
"""Delete the file (if any) from the database.
Call this function immediately AFTER deleting the instance.
"""
file_instance = getattr(instance, filefield_name)
if file_instance:
DatabaseFileStorage().delete(file_instance.name) | def delete_file(instance, filefield_name):
"""Delete the file (if any) from the database.
Call this function immediately AFTER deleting the instance.
"""
file_instance = getattr(instance, filefield_name)
if file_instance:
DatabaseFileStorage().delete(file_instance.name) | [
"Delete",
"the",
"file",
"(",
"if",
"any",
")",
"from",
"the",
"database",
"."
] | victor-o-silva/db_file_storage | python | https://github.com/victor-o-silva/db_file_storage/blob/ff5375422246c42b8a7bba558f1c3b49bb985f36/db_file_storage/model_utils.py#L39-L46 | [
"def",
"delete_file",
"(",
"instance",
",",
"filefield_name",
")",
":",
"file_instance",
"=",
"getattr",
"(",
"instance",
",",
"filefield_name",
")",
"if",
"file_instance",
":",
"DatabaseFileStorage",
"(",
")",
".",
"delete",
"(",
"file_instance",
".",
"name",
... | ff5375422246c42b8a7bba558f1c3b49bb985f36 |
test | db_file_widget | Edit the download-link inner text. | db_file_storage/form_widgets.py | def db_file_widget(cls):
"""Edit the download-link inner text."""
def get_link_display(url):
unquoted = unquote(url.split('%2F')[-1])
if sys.version_info.major == 2: # python 2
from django.utils.encoding import force_unicode
unquoted = force_unicode(unquoted)
re... | def db_file_widget(cls):
"""Edit the download-link inner text."""
def get_link_display(url):
unquoted = unquote(url.split('%2F')[-1])
if sys.version_info.major == 2: # python 2
from django.utils.encoding import force_unicode
unquoted = force_unicode(unquoted)
re... | [
"Edit",
"the",
"download",
"-",
"link",
"inner",
"text",
"."
] | victor-o-silva/db_file_storage | python | https://github.com/victor-o-silva/db_file_storage/blob/ff5375422246c42b8a7bba558f1c3b49bb985f36/db_file_storage/form_widgets.py#L14-L40 | [
"def",
"db_file_widget",
"(",
"cls",
")",
":",
"def",
"get_link_display",
"(",
"url",
")",
":",
"unquoted",
"=",
"unquote",
"(",
"url",
".",
"split",
"(",
"'%2F'",
")",
"[",
"-",
"1",
"]",
")",
"if",
"sys",
".",
"version_info",
".",
"major",
"==",
... | ff5375422246c42b8a7bba558f1c3b49bb985f36 |
test | PDFTemplateResponse.rendered_content | Returns the freshly rendered content for the template and context
described by the PDFResponse.
This *does not* set the final content of the response. To set the
response content, you must either call render(), or set the
content explicitly using the value of this property. | wkhtmltopdf/views.py | def rendered_content(self):
"""Returns the freshly rendered content for the template and context
described by the PDFResponse.
This *does not* set the final content of the response. To set the
response content, you must either call render(), or set the
content explicitly using t... | def rendered_content(self):
"""Returns the freshly rendered content for the template and context
described by the PDFResponse.
This *does not* set the final content of the response. To set the
response content, you must either call render(), or set the
content explicitly using t... | [
"Returns",
"the",
"freshly",
"rendered",
"content",
"for",
"the",
"template",
"and",
"context",
"described",
"by",
"the",
"PDFResponse",
"."
] | incuna/django-wkhtmltopdf | python | https://github.com/incuna/django-wkhtmltopdf/blob/4e73f604c48f7f449c916c4257a72af59517322c/wkhtmltopdf/views.py#L64-L82 | [
"def",
"rendered_content",
"(",
"self",
")",
":",
"cmd_options",
"=",
"self",
".",
"cmd_options",
".",
"copy",
"(",
")",
"return",
"render_pdf_from_template",
"(",
"self",
".",
"resolve_template",
"(",
"self",
".",
"template_name",
")",
",",
"self",
".",
"re... | 4e73f604c48f7f449c916c4257a72af59517322c |
test | PDFTemplateView.render_to_response | Returns a PDF response with a template rendered with the given context. | wkhtmltopdf/views.py | def render_to_response(self, context, **response_kwargs):
"""
Returns a PDF response with a template rendered with the given context.
"""
filename = response_kwargs.pop('filename', None)
cmd_options = response_kwargs.pop('cmd_options', None)
if issubclass(self.response_c... | def render_to_response(self, context, **response_kwargs):
"""
Returns a PDF response with a template rendered with the given context.
"""
filename = response_kwargs.pop('filename', None)
cmd_options = response_kwargs.pop('cmd_options', None)
if issubclass(self.response_c... | [
"Returns",
"a",
"PDF",
"response",
"with",
"a",
"template",
"rendered",
"with",
"the",
"given",
"context",
"."
] | incuna/django-wkhtmltopdf | python | https://github.com/incuna/django-wkhtmltopdf/blob/4e73f604c48f7f449c916c4257a72af59517322c/wkhtmltopdf/views.py#L134-L161 | [
"def",
"render_to_response",
"(",
"self",
",",
"context",
",",
"*",
"*",
"response_kwargs",
")",
":",
"filename",
"=",
"response_kwargs",
".",
"pop",
"(",
"'filename'",
",",
"None",
")",
"cmd_options",
"=",
"response_kwargs",
".",
"pop",
"(",
"'cmd_options'",
... | 4e73f604c48f7f449c916c4257a72af59517322c |
test | _options_to_args | Converts ``options`` into a list of command-line arguments.
Skip arguments where no value is provided
For flag-type (No argument) variables, pass only the name and only then if the value is True | wkhtmltopdf/utils.py | def _options_to_args(**options):
"""
Converts ``options`` into a list of command-line arguments.
Skip arguments where no value is provided
For flag-type (No argument) variables, pass only the name and only then if the value is True
"""
flags = []
for name in sorted(options):
value = ... | def _options_to_args(**options):
"""
Converts ``options`` into a list of command-line arguments.
Skip arguments where no value is provided
For flag-type (No argument) variables, pass only the name and only then if the value is True
"""
flags = []
for name in sorted(options):
value = ... | [
"Converts",
"options",
"into",
"a",
"list",
"of",
"command",
"-",
"line",
"arguments",
".",
"Skip",
"arguments",
"where",
"no",
"value",
"is",
"provided",
"For",
"flag",
"-",
"type",
"(",
"No",
"argument",
")",
"variables",
"pass",
"only",
"the",
"name",
... | incuna/django-wkhtmltopdf | python | https://github.com/incuna/django-wkhtmltopdf/blob/4e73f604c48f7f449c916c4257a72af59517322c/wkhtmltopdf/utils.py#L52-L70 | [
"def",
"_options_to_args",
"(",
"*",
"*",
"options",
")",
":",
"flags",
"=",
"[",
"]",
"for",
"name",
"in",
"sorted",
"(",
"options",
")",
":",
"value",
"=",
"options",
"[",
"name",
"]",
"formatted_flag",
"=",
"'--%s'",
"%",
"name",
"if",
"len",
"(",... | 4e73f604c48f7f449c916c4257a72af59517322c |
test | wkhtmltopdf | Converts html to PDF using http://wkhtmltopdf.org/.
pages: List of file paths or URLs of the html to be converted.
output: Optional output file path. If None, the output is returned.
**kwargs: Passed to wkhtmltopdf via _extra_args() (See
https://github.com/antialize/wkhtmltopdf/blob/master/RE... | wkhtmltopdf/utils.py | def wkhtmltopdf(pages, output=None, **kwargs):
"""
Converts html to PDF using http://wkhtmltopdf.org/.
pages: List of file paths or URLs of the html to be converted.
output: Optional output file path. If None, the output is returned.
**kwargs: Passed to wkhtmltopdf via _extra_args() (See
... | def wkhtmltopdf(pages, output=None, **kwargs):
"""
Converts html to PDF using http://wkhtmltopdf.org/.
pages: List of file paths or URLs of the html to be converted.
output: Optional output file path. If None, the output is returned.
**kwargs: Passed to wkhtmltopdf via _extra_args() (See
... | [
"Converts",
"html",
"to",
"PDF",
"using",
"http",
":",
"//",
"wkhtmltopdf",
".",
"org",
"/",
"."
] | incuna/django-wkhtmltopdf | python | https://github.com/incuna/django-wkhtmltopdf/blob/4e73f604c48f7f449c916c4257a72af59517322c/wkhtmltopdf/utils.py#L73-L147 | [
"def",
"wkhtmltopdf",
"(",
"pages",
",",
"output",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"pages",
",",
"six",
".",
"string_types",
")",
":",
"# Support a single page.",
"pages",
"=",
"[",
"pages",
"]",
"if",
"output",
... | 4e73f604c48f7f449c916c4257a72af59517322c |
test | http_quote | Given a unicode string, will do its dandiest to give you back a
valid ascii charset string you can use in, say, http headers and the
like. | wkhtmltopdf/utils.py | def http_quote(string):
"""
Given a unicode string, will do its dandiest to give you back a
valid ascii charset string you can use in, say, http headers and the
like.
"""
if isinstance(string, six.text_type):
try:
import unidecode
except ImportError:
pass
... | def http_quote(string):
"""
Given a unicode string, will do its dandiest to give you back a
valid ascii charset string you can use in, say, http headers and the
like.
"""
if isinstance(string, six.text_type):
try:
import unidecode
except ImportError:
pass
... | [
"Given",
"a",
"unicode",
"string",
"will",
"do",
"its",
"dandiest",
"to",
"give",
"you",
"back",
"a",
"valid",
"ascii",
"charset",
"string",
"you",
"can",
"use",
"in",
"say",
"http",
"headers",
"and",
"the",
"like",
"."
] | incuna/django-wkhtmltopdf | python | https://github.com/incuna/django-wkhtmltopdf/blob/4e73f604c48f7f449c916c4257a72af59517322c/wkhtmltopdf/utils.py#L254-L270 | [
"def",
"http_quote",
"(",
"string",
")",
":",
"if",
"isinstance",
"(",
"string",
",",
"six",
".",
"text_type",
")",
":",
"try",
":",
"import",
"unidecode",
"except",
"ImportError",
":",
"pass",
"else",
":",
"string",
"=",
"unidecode",
".",
"unidecode",
"... | 4e73f604c48f7f449c916c4257a72af59517322c |
test | make_absolute_paths | Convert all MEDIA files into a file://URL paths in order to
correctly get it displayed in PDFs. | wkhtmltopdf/utils.py | def make_absolute_paths(content):
"""Convert all MEDIA files into a file://URL paths in order to
correctly get it displayed in PDFs."""
overrides = [
{
'root': settings.MEDIA_ROOT,
'url': settings.MEDIA_URL,
},
{
'root': settings.STATIC_ROOT,
... | def make_absolute_paths(content):
"""Convert all MEDIA files into a file://URL paths in order to
correctly get it displayed in PDFs."""
overrides = [
{
'root': settings.MEDIA_ROOT,
'url': settings.MEDIA_URL,
},
{
'root': settings.STATIC_ROOT,
... | [
"Convert",
"all",
"MEDIA",
"files",
"into",
"a",
"file",
":",
"//",
"URL",
"paths",
"in",
"order",
"to",
"correctly",
"get",
"it",
"displayed",
"in",
"PDFs",
"."
] | incuna/django-wkhtmltopdf | python | https://github.com/incuna/django-wkhtmltopdf/blob/4e73f604c48f7f449c916c4257a72af59517322c/wkhtmltopdf/utils.py#L278-L308 | [
"def",
"make_absolute_paths",
"(",
"content",
")",
":",
"overrides",
"=",
"[",
"{",
"'root'",
":",
"settings",
".",
"MEDIA_ROOT",
",",
"'url'",
":",
"settings",
".",
"MEDIA_URL",
",",
"}",
",",
"{",
"'root'",
":",
"settings",
".",
"STATIC_ROOT",
",",
"'u... | 4e73f604c48f7f449c916c4257a72af59517322c |
test | Grok.match | If text is matched with pattern, return variable names specified(%{pattern:variable name})
in pattern and their corresponding values.If not matched, return None.
custom patterns can be passed in by custom_patterns(pattern name, pattern regular expression pair)
or custom_patterns_dir. | pygrok/pygrok.py | def match(self, text):
"""If text is matched with pattern, return variable names specified(%{pattern:variable name})
in pattern and their corresponding values.If not matched, return None.
custom patterns can be passed in by custom_patterns(pattern name, pattern regular expression pair)
o... | def match(self, text):
"""If text is matched with pattern, return variable names specified(%{pattern:variable name})
in pattern and their corresponding values.If not matched, return None.
custom patterns can be passed in by custom_patterns(pattern name, pattern regular expression pair)
o... | [
"If",
"text",
"is",
"matched",
"with",
"pattern",
"return",
"variable",
"names",
"specified",
"(",
"%",
"{",
"pattern",
":",
"variable",
"name",
"}",
")",
"in",
"pattern",
"and",
"their",
"corresponding",
"values",
".",
"If",
"not",
"matched",
"return",
"N... | garyelephant/pygrok | python | https://github.com/garyelephant/pygrok/blob/de9e3f92f5a52f0fc101aaa0f694f52aee6afba8/pygrok/pygrok.py#L33-L57 | [
"def",
"match",
"(",
"self",
",",
"text",
")",
":",
"match_obj",
"=",
"None",
"if",
"self",
".",
"fullmatch",
":",
"match_obj",
"=",
"self",
".",
"regex_obj",
".",
"fullmatch",
"(",
"text",
")",
"else",
":",
"match_obj",
"=",
"self",
".",
"regex_obj",
... | de9e3f92f5a52f0fc101aaa0f694f52aee6afba8 |
test | configure | Sets defaults for ``class Meta`` declarations.
Arguments can either be extracted from a `module` (in that case
all attributes starting from `prefix` are used):
>>> import foo
>>> configure(foo)
or passed explicictly as keyword arguments:
>>> configure(database='foo')
.. warning:: Curren... | minimongo/options.py | def configure(module=None, prefix='MONGODB_', **kwargs):
"""Sets defaults for ``class Meta`` declarations.
Arguments can either be extracted from a `module` (in that case
all attributes starting from `prefix` are used):
>>> import foo
>>> configure(foo)
or passed explicictly as keyword argume... | def configure(module=None, prefix='MONGODB_', **kwargs):
"""Sets defaults for ``class Meta`` declarations.
Arguments can either be extracted from a `module` (in that case
all attributes starting from `prefix` are used):
>>> import foo
>>> configure(foo)
or passed explicictly as keyword argume... | [
"Sets",
"defaults",
"for",
"class",
"Meta",
"declarations",
"."
] | slacy/minimongo | python | https://github.com/slacy/minimongo/blob/29f38994831163b17bc625c82258068f1f90efa5/minimongo/options.py#L10-L35 | [
"def",
"configure",
"(",
"module",
"=",
"None",
",",
"prefix",
"=",
"'MONGODB_'",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"module",
"is",
"not",
"None",
"and",
"isinstance",
"(",
"module",
",",
"types",
".",
"ModuleType",
")",
":",
"# Search module for ... | 29f38994831163b17bc625c82258068f1f90efa5 |
test | _Options._configure | Updates class-level defaults for :class:`_Options` container. | minimongo/options.py | def _configure(cls, **defaults):
"""Updates class-level defaults for :class:`_Options` container."""
for attr in defaults:
setattr(cls, attr, defaults[attr]) | def _configure(cls, **defaults):
"""Updates class-level defaults for :class:`_Options` container."""
for attr in defaults:
setattr(cls, attr, defaults[attr]) | [
"Updates",
"class",
"-",
"level",
"defaults",
"for",
":",
"class",
":",
"_Options",
"container",
"."
] | slacy/minimongo | python | https://github.com/slacy/minimongo/blob/29f38994831163b17bc625c82258068f1f90efa5/minimongo/options.py#L82-L85 | [
"def",
"_configure",
"(",
"cls",
",",
"*",
"*",
"defaults",
")",
":",
"for",
"attr",
"in",
"defaults",
":",
"setattr",
"(",
"cls",
",",
"attr",
",",
"defaults",
"[",
"attr",
"]",
")"
] | 29f38994831163b17bc625c82258068f1f90efa5 |
test | to_underscore | Converts a given string from CamelCase to under_score.
>>> to_underscore('FooBar')
'foo_bar' | minimongo/model.py | def to_underscore(string):
"""Converts a given string from CamelCase to under_score.
>>> to_underscore('FooBar')
'foo_bar'
"""
new_string = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\1_\2', string)
new_string = re.sub(r'([a-z\d])([A-Z])', r'\1_\2', new_string)
return new_string.lower() | def to_underscore(string):
"""Converts a given string from CamelCase to under_score.
>>> to_underscore('FooBar')
'foo_bar'
"""
new_string = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\1_\2', string)
new_string = re.sub(r'([a-z\d])([A-Z])', r'\1_\2', new_string)
return new_string.lower() | [
"Converts",
"a",
"given",
"string",
"from",
"CamelCase",
"to",
"under_score",
"."
] | slacy/minimongo | python | https://github.com/slacy/minimongo/blob/29f38994831163b17bc625c82258068f1f90efa5/minimongo/model.py#L241-L249 | [
"def",
"to_underscore",
"(",
"string",
")",
":",
"new_string",
"=",
"re",
".",
"sub",
"(",
"r'([A-Z]+)([A-Z][a-z])'",
",",
"r'\\1_\\2'",
",",
"string",
")",
"new_string",
"=",
"re",
".",
"sub",
"(",
"r'([a-z\\d])([A-Z])'",
",",
"r'\\1_\\2'",
",",
"new_string",... | 29f38994831163b17bc625c82258068f1f90efa5 |
test | ModelBase.auto_index | Builds all indices, listed in model's Meta class.
>>> class SomeModel(Model)
... class Meta:
... indices = (
... Index('foo'),
... )
.. note:: this will result in calls to
:meth:`pymongo.collection.Collect... | minimongo/model.py | def auto_index(mcs):
"""Builds all indices, listed in model's Meta class.
>>> class SomeModel(Model)
... class Meta:
... indices = (
... Index('foo'),
... )
.. note:: this will result in calls to
:... | def auto_index(mcs):
"""Builds all indices, listed in model's Meta class.
>>> class SomeModel(Model)
... class Meta:
... indices = (
... Index('foo'),
... )
.. note:: this will result in calls to
:... | [
"Builds",
"all",
"indices",
"listed",
"in",
"model",
"s",
"Meta",
"class",
"."
] | slacy/minimongo | python | https://github.com/slacy/minimongo/blob/29f38994831163b17bc625c82258068f1f90efa5/minimongo/model.py#L83-L98 | [
"def",
"auto_index",
"(",
"mcs",
")",
":",
"for",
"index",
"in",
"mcs",
".",
"_meta",
".",
"indices",
":",
"index",
".",
"ensure",
"(",
"mcs",
".",
"collection",
")"
] | 29f38994831163b17bc625c82258068f1f90efa5 |
test | Collection.find | Same as :meth:`pymongo.collection.Collection.find`, except
it returns the right document class. | minimongo/collection.py | def find(self, *args, **kwargs):
"""Same as :meth:`pymongo.collection.Collection.find`, except
it returns the right document class.
"""
return Cursor(self, *args, wrap=self.document_class, **kwargs) | def find(self, *args, **kwargs):
"""Same as :meth:`pymongo.collection.Collection.find`, except
it returns the right document class.
"""
return Cursor(self, *args, wrap=self.document_class, **kwargs) | [
"Same",
"as",
":",
"meth",
":",
"pymongo",
".",
"collection",
".",
"Collection",
".",
"find",
"except",
"it",
"returns",
"the",
"right",
"document",
"class",
"."
] | slacy/minimongo | python | https://github.com/slacy/minimongo/blob/29f38994831163b17bc625c82258068f1f90efa5/minimongo/collection.py#L44-L48 | [
"def",
"find",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"Cursor",
"(",
"self",
",",
"*",
"args",
",",
"wrap",
"=",
"self",
".",
"document_class",
",",
"*",
"*",
"kwargs",
")"
] | 29f38994831163b17bc625c82258068f1f90efa5 |
test | Collection.find_one | Same as :meth:`pymongo.collection.Collection.find_one`, except
it returns the right document class. | minimongo/collection.py | def find_one(self, *args, **kwargs):
"""Same as :meth:`pymongo.collection.Collection.find_one`, except
it returns the right document class.
"""
data = super(Collection, self).find_one(*args, **kwargs)
if data:
return self.document_class(data)
return None | def find_one(self, *args, **kwargs):
"""Same as :meth:`pymongo.collection.Collection.find_one`, except
it returns the right document class.
"""
data = super(Collection, self).find_one(*args, **kwargs)
if data:
return self.document_class(data)
return None | [
"Same",
"as",
":",
"meth",
":",
"pymongo",
".",
"collection",
".",
"Collection",
".",
"find_one",
"except",
"it",
"returns",
"the",
"right",
"document",
"class",
"."
] | slacy/minimongo | python | https://github.com/slacy/minimongo/blob/29f38994831163b17bc625c82258068f1f90efa5/minimongo/collection.py#L50-L57 | [
"def",
"find_one",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"data",
"=",
"super",
"(",
"Collection",
",",
"self",
")",
".",
"find_one",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"if",
"data",
":",
"return",
"self",
... | 29f38994831163b17bc625c82258068f1f90efa5 |
test | CsvParser.parse_file | Load and parse a .csv file | pricedb/csv.py | def parse_file(self, file_path, currency) -> List[PriceModel]:
""" Load and parse a .csv file """
# load file
# read csv into memory?
contents = self.load_file(file_path)
prices = []
# parse price elements
for line in contents:
price = self.pa... | def parse_file(self, file_path, currency) -> List[PriceModel]:
""" Load and parse a .csv file """
# load file
# read csv into memory?
contents = self.load_file(file_path)
prices = []
# parse price elements
for line in contents:
price = self.pa... | [
"Load",
"and",
"parse",
"a",
".",
"csv",
"file"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/csv.py#L28-L42 | [
"def",
"parse_file",
"(",
"self",
",",
"file_path",
",",
"currency",
")",
"->",
"List",
"[",
"PriceModel",
"]",
":",
"# load file",
"# read csv into memory?",
"contents",
"=",
"self",
".",
"load_file",
"(",
"file_path",
")",
"prices",
"=",
"[",
"]",
"# parse... | b4fd366b7763891c690fe3000b8840e656da023e |
test | CsvParser.load_file | Loads the content of the text file | pricedb/csv.py | def load_file(self, file_path) -> List[str]:
""" Loads the content of the text file """
content = []
content = read_lines_from_file(file_path)
return content | def load_file(self, file_path) -> List[str]:
""" Loads the content of the text file """
content = []
content = read_lines_from_file(file_path)
return content | [
"Loads",
"the",
"content",
"of",
"the",
"text",
"file"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/csv.py#L44-L48 | [
"def",
"load_file",
"(",
"self",
",",
"file_path",
")",
"->",
"List",
"[",
"str",
"]",
":",
"content",
"=",
"[",
"]",
"content",
"=",
"read_lines_from_file",
"(",
"file_path",
")",
"return",
"content"
] | b4fd366b7763891c690fe3000b8840e656da023e |
test | CsvParser.parse_line | Parse a CSV line into a price element | pricedb/csv.py | def parse_line(self, line: str) -> PriceModel:
""" Parse a CSV line into a price element """
line = line.rstrip()
parts = line.split(',')
result = PriceModel()
# symbol
result.symbol = self.translate_symbol(parts[0])
# value
result.value = Decimal(parts... | def parse_line(self, line: str) -> PriceModel:
""" Parse a CSV line into a price element """
line = line.rstrip()
parts = line.split(',')
result = PriceModel()
# symbol
result.symbol = self.translate_symbol(parts[0])
# value
result.value = Decimal(parts... | [
"Parse",
"a",
"CSV",
"line",
"into",
"a",
"price",
"element"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/csv.py#L50-L75 | [
"def",
"parse_line",
"(",
"self",
",",
"line",
":",
"str",
")",
"->",
"PriceModel",
":",
"line",
"=",
"line",
".",
"rstrip",
"(",
")",
"parts",
"=",
"line",
".",
"split",
"(",
"','",
")",
"result",
"=",
"PriceModel",
"(",
")",
"# symbol",
"result",
... | b4fd366b7763891c690fe3000b8840e656da023e |
test | CsvParser.translate_symbol | translate the incoming symbol into locally-used | pricedb/csv.py | def translate_symbol(self, in_symbol: str) -> str:
""" translate the incoming symbol into locally-used """
# read all mappings from the db
if not self.symbol_maps:
self.__load_symbol_maps()
# translate the incoming symbol
result = self.symbol_maps[in_symbol] if in_sym... | def translate_symbol(self, in_symbol: str) -> str:
""" translate the incoming symbol into locally-used """
# read all mappings from the db
if not self.symbol_maps:
self.__load_symbol_maps()
# translate the incoming symbol
result = self.symbol_maps[in_symbol] if in_sym... | [
"translate",
"the",
"incoming",
"symbol",
"into",
"locally",
"-",
"used"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/csv.py#L77-L85 | [
"def",
"translate_symbol",
"(",
"self",
",",
"in_symbol",
":",
"str",
")",
"->",
"str",
":",
"# read all mappings from the db",
"if",
"not",
"self",
".",
"symbol_maps",
":",
"self",
".",
"__load_symbol_maps",
"(",
")",
"# translate the incoming symbol",
"result",
... | b4fd366b7763891c690fe3000b8840e656da023e |
test | CsvParser.__load_symbol_maps | Loads all symbol maps from db | pricedb/csv.py | def __load_symbol_maps(self):
""" Loads all symbol maps from db """
repo = SymbolMapRepository(self.__get_session())
all_maps = repo.get_all()
self.symbol_maps = {}
for item in all_maps:
self.symbol_maps[item.in_symbol] = item.out_symbol | def __load_symbol_maps(self):
""" Loads all symbol maps from db """
repo = SymbolMapRepository(self.__get_session())
all_maps = repo.get_all()
self.symbol_maps = {}
for item in all_maps:
self.symbol_maps[item.in_symbol] = item.out_symbol | [
"Loads",
"all",
"symbol",
"maps",
"from",
"db"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/csv.py#L87-L93 | [
"def",
"__load_symbol_maps",
"(",
"self",
")",
":",
"repo",
"=",
"SymbolMapRepository",
"(",
"self",
".",
"__get_session",
"(",
")",
")",
"all_maps",
"=",
"repo",
".",
"get_all",
"(",
")",
"self",
".",
"symbol_maps",
"=",
"{",
"}",
"for",
"item",
"in",
... | b4fd366b7763891c690fe3000b8840e656da023e |
test | CsvParser.__get_session | Reuses the same db session | pricedb/csv.py | def __get_session(self):
""" Reuses the same db session """
if not self.session:
self.session = dal.get_default_session()
return self.session | def __get_session(self):
""" Reuses the same db session """
if not self.session:
self.session = dal.get_default_session()
return self.session | [
"Reuses",
"the",
"same",
"db",
"session"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/csv.py#L95-L99 | [
"def",
"__get_session",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"session",
":",
"self",
".",
"session",
"=",
"dal",
".",
"get_default_session",
"(",
")",
"return",
"self",
".",
"session"
] | b4fd366b7763891c690fe3000b8840e656da023e |
test | add | Add individual price | pricedb/cli.py | def add(symbol: str, date, value, currency: str):
""" Add individual price """
symbol = symbol.upper()
currency = currency.upper()
app = PriceDbApplication()
price = PriceModel()
# security = SecuritySymbol("", "")
price.symbol.parse(symbol)
# price.symbol.mnemonic = price.symbol.mnemo... | def add(symbol: str, date, value, currency: str):
""" Add individual price """
symbol = symbol.upper()
currency = currency.upper()
app = PriceDbApplication()
price = PriceModel()
# security = SecuritySymbol("", "")
price.symbol.parse(symbol)
# price.symbol.mnemonic = price.symbol.mnemo... | [
"Add",
"individual",
"price"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/cli.py#L30-L56 | [
"def",
"add",
"(",
"symbol",
":",
"str",
",",
"date",
",",
"value",
",",
"currency",
":",
"str",
")",
":",
"symbol",
"=",
"symbol",
".",
"upper",
"(",
")",
"currency",
"=",
"currency",
".",
"upper",
"(",
")",
"app",
"=",
"PriceDbApplication",
"(",
... | b4fd366b7763891c690fe3000b8840e656da023e |
test | import_csv | Import prices from CSV file | pricedb/cli.py | def import_csv(filepath: str, currency: str):
""" Import prices from CSV file """
logger.debug(f"currency = {currency}")
# auto-convert to uppercase.
currency = currency.upper()
app = PriceDbApplication()
app.logger = logger
app.import_prices(filepath, currency) | def import_csv(filepath: str, currency: str):
""" Import prices from CSV file """
logger.debug(f"currency = {currency}")
# auto-convert to uppercase.
currency = currency.upper()
app = PriceDbApplication()
app.logger = logger
app.import_prices(filepath, currency) | [
"Import",
"prices",
"from",
"CSV",
"file"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/cli.py#L63-L71 | [
"def",
"import_csv",
"(",
"filepath",
":",
"str",
",",
"currency",
":",
"str",
")",
":",
"logger",
".",
"debug",
"(",
"f\"currency = {currency}\"",
")",
"# auto-convert to uppercase.",
"currency",
"=",
"currency",
".",
"upper",
"(",
")",
"app",
"=",
"PriceDbAp... | b4fd366b7763891c690fe3000b8840e656da023e |
test | last | displays last price, for symbol if provided | pricedb/cli.py | def last(symbol: str):
""" displays last price, for symbol if provided """
app = PriceDbApplication()
# convert to uppercase
if symbol:
symbol = symbol.upper()
# extract namespace
sec_symbol = SecuritySymbol("", "")
sec_symbol.parse(symbol)
latest = app.get_late... | def last(symbol: str):
""" displays last price, for symbol if provided """
app = PriceDbApplication()
# convert to uppercase
if symbol:
symbol = symbol.upper()
# extract namespace
sec_symbol = SecuritySymbol("", "")
sec_symbol.parse(symbol)
latest = app.get_late... | [
"displays",
"last",
"price",
"for",
"symbol",
"if",
"provided"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/cli.py#L76-L94 | [
"def",
"last",
"(",
"symbol",
":",
"str",
")",
":",
"app",
"=",
"PriceDbApplication",
"(",
")",
"# convert to uppercase",
"if",
"symbol",
":",
"symbol",
"=",
"symbol",
".",
"upper",
"(",
")",
"# extract namespace",
"sec_symbol",
"=",
"SecuritySymbol",
"(",
"... | b4fd366b7763891c690fe3000b8840e656da023e |
test | list_prices | Display all prices | pricedb/cli.py | def list_prices(date, currency, last):
""" Display all prices """
app = PriceDbApplication()
app.logger = logger
if last:
# fetch only the last prices
prices = app.get_latest_prices()
else:
prices = app.get_prices(date, currency)
for price in prices:
print(price)... | def list_prices(date, currency, last):
""" Display all prices """
app = PriceDbApplication()
app.logger = logger
if last:
# fetch only the last prices
prices = app.get_latest_prices()
else:
prices = app.get_prices(date, currency)
for price in prices:
print(price)... | [
"Display",
"all",
"prices"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/cli.py#L102-L115 | [
"def",
"list_prices",
"(",
"date",
",",
"currency",
",",
"last",
")",
":",
"app",
"=",
"PriceDbApplication",
"(",
")",
"app",
".",
"logger",
"=",
"logger",
"if",
"last",
":",
"# fetch only the last prices",
"prices",
"=",
"app",
".",
"get_latest_prices",
"("... | b4fd366b7763891c690fe3000b8840e656da023e |
test | download | Download the latest prices | pricedb/cli.py | def download(ctx, help: bool, symbol: str, namespace: str, agent: str, currency: str):
""" Download the latest prices """
if help:
click.echo(ctx.get_help())
ctx.exit()
app = PriceDbApplication()
app.logger = logger
if currency:
currency = currency.strip()
currency ... | def download(ctx, help: bool, symbol: str, namespace: str, agent: str, currency: str):
""" Download the latest prices """
if help:
click.echo(ctx.get_help())
ctx.exit()
app = PriceDbApplication()
app.logger = logger
if currency:
currency = currency.strip()
currency ... | [
"Download",
"the",
"latest",
"prices"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/cli.py#L127-L141 | [
"def",
"download",
"(",
"ctx",
",",
"help",
":",
"bool",
",",
"symbol",
":",
"str",
",",
"namespace",
":",
"str",
",",
"agent",
":",
"str",
",",
"currency",
":",
"str",
")",
":",
"if",
"help",
":",
"click",
".",
"echo",
"(",
"ctx",
".",
"get_help... | b4fd366b7763891c690fe3000b8840e656da023e |
test | prune | Delete old prices, leaving just the last. | pricedb/cli.py | def prune(symbol: str, all: str):
""" Delete old prices, leaving just the last. """
app = PriceDbApplication()
app.logger = logger
count = 0
if symbol is not None:
sec_symbol = SecuritySymbol("", "")
sec_symbol.parse(symbol)
deleted = app.prune(sec_symbol)
if delete... | def prune(symbol: str, all: str):
""" Delete old prices, leaving just the last. """
app = PriceDbApplication()
app.logger = logger
count = 0
if symbol is not None:
sec_symbol = SecuritySymbol("", "")
sec_symbol.parse(symbol)
deleted = app.prune(sec_symbol)
if delete... | [
"Delete",
"old",
"prices",
"leaving",
"just",
"the",
"last",
"."
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/cli.py#L148-L164 | [
"def",
"prune",
"(",
"symbol",
":",
"str",
",",
"all",
":",
"str",
")",
":",
"app",
"=",
"PriceDbApplication",
"(",
")",
"app",
".",
"logger",
"=",
"logger",
"count",
"=",
"0",
"if",
"symbol",
"is",
"not",
"None",
":",
"sec_symbol",
"=",
"SecuritySym... | b4fd366b7763891c690fe3000b8840e656da023e |
test | get_default_session | Return the default session. The path is read from the default config. | pricedb/dal.py | def get_default_session():
""" Return the default session. The path is read from the default config. """
from .config import Config, ConfigKeys
db_path = Config().get(ConfigKeys.price_database)
if not db_path:
raise ValueError("Price database not set in the configuration file!")
return get_... | def get_default_session():
""" Return the default session. The path is read from the default config. """
from .config import Config, ConfigKeys
db_path = Config().get(ConfigKeys.price_database)
if not db_path:
raise ValueError("Price database not set in the configuration file!")
return get_... | [
"Return",
"the",
"default",
"session",
".",
"The",
"path",
"is",
"read",
"from",
"the",
"default",
"config",
"."
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/dal.py#L68-L75 | [
"def",
"get_default_session",
"(",
")",
":",
"from",
".",
"config",
"import",
"Config",
",",
"ConfigKeys",
"db_path",
"=",
"Config",
"(",
")",
".",
"get",
"(",
"ConfigKeys",
".",
"price_database",
")",
"if",
"not",
"db_path",
":",
"raise",
"ValueError",
"(... | b4fd366b7763891c690fe3000b8840e656da023e |
test | add_map | Creates a symbol mapping | pricedb/map_cli.py | def add_map(incoming, outgoing):
""" Creates a symbol mapping """
db_path = Config().get(ConfigKeys.pricedb_path)
session = get_session(db_path)
new_map = SymbolMap()
new_map.in_symbol = incoming
new_map.out_symbol = outgoing
session.add(new_map)
session.commit()
click.echo("Record... | def add_map(incoming, outgoing):
""" Creates a symbol mapping """
db_path = Config().get(ConfigKeys.pricedb_path)
session = get_session(db_path)
new_map = SymbolMap()
new_map.in_symbol = incoming
new_map.out_symbol = outgoing
session.add(new_map)
session.commit()
click.echo("Record... | [
"Creates",
"a",
"symbol",
"mapping"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/map_cli.py#L14-L25 | [
"def",
"add_map",
"(",
"incoming",
",",
"outgoing",
")",
":",
"db_path",
"=",
"Config",
"(",
")",
".",
"get",
"(",
"ConfigKeys",
".",
"pricedb_path",
")",
"session",
"=",
"get_session",
"(",
"db_path",
")",
"new_map",
"=",
"SymbolMap",
"(",
")",
"new_map... | b4fd366b7763891c690fe3000b8840e656da023e |
test | list_maps | Displays all symbol maps | pricedb/map_cli.py | def list_maps():
""" Displays all symbol maps """
db_path = Config().get(ConfigKeys.price_database)
session = get_session(db_path)
maps = session.query(SymbolMap).all()
for item in maps:
click.echo(item) | def list_maps():
""" Displays all symbol maps """
db_path = Config().get(ConfigKeys.price_database)
session = get_session(db_path)
maps = session.query(SymbolMap).all()
for item in maps:
click.echo(item) | [
"Displays",
"all",
"symbol",
"maps"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/map_cli.py#L28-L35 | [
"def",
"list_maps",
"(",
")",
":",
"db_path",
"=",
"Config",
"(",
")",
".",
"get",
"(",
"ConfigKeys",
".",
"price_database",
")",
"session",
"=",
"get_session",
"(",
"db_path",
")",
"maps",
"=",
"session",
".",
"query",
"(",
"SymbolMap",
")",
".",
"all... | b4fd366b7763891c690fe3000b8840e656da023e |
test | SymbolMapRepository.get_by_id | Finds the map by in-symbol | pricedb/repositories.py | def get_by_id(self, symbol: str) -> SymbolMap:
""" Finds the map by in-symbol """
return self.query.filter(SymbolMap.in_symbol == symbol).first() | def get_by_id(self, symbol: str) -> SymbolMap:
""" Finds the map by in-symbol """
return self.query.filter(SymbolMap.in_symbol == symbol).first() | [
"Finds",
"the",
"map",
"by",
"in",
"-",
"symbol"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/repositories.py#L11-L13 | [
"def",
"get_by_id",
"(",
"self",
",",
"symbol",
":",
"str",
")",
"->",
"SymbolMap",
":",
"return",
"self",
".",
"query",
".",
"filter",
"(",
"SymbolMap",
".",
"in_symbol",
"==",
"symbol",
")",
".",
"first",
"(",
")"
] | b4fd366b7763891c690fe3000b8840e656da023e |
test | read_lines_from_file | Read text lines from a file | pricedb/utils.py | def read_lines_from_file(file_path: str) -> List[str]:
""" Read text lines from a file """
# check if the file exists?
with open(file_path) as csv_file:
content = csv_file.readlines()
return content | def read_lines_from_file(file_path: str) -> List[str]:
""" Read text lines from a file """
# check if the file exists?
with open(file_path) as csv_file:
content = csv_file.readlines()
return content | [
"Read",
"text",
"lines",
"from",
"a",
"file"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/utils.py#L5-L10 | [
"def",
"read_lines_from_file",
"(",
"file_path",
":",
"str",
")",
"->",
"List",
"[",
"str",
"]",
":",
"# check if the file exists?",
"with",
"open",
"(",
"file_path",
")",
"as",
"csv_file",
":",
"content",
"=",
"csv_file",
".",
"readlines",
"(",
")",
"return... | b4fd366b7763891c690fe3000b8840e656da023e |
test | PriceMapper.map_entity | Map the price entity | pricedb/mappers.py | def map_entity(self, entity: dal.Price) -> PriceModel:
""" Map the price entity """
if not entity:
return None
result = PriceModel()
result.currency = entity.currency
# date/time
dt_string = entity.date
format_string = "%Y-%m-%d"
if entity.ti... | def map_entity(self, entity: dal.Price) -> PriceModel:
""" Map the price entity """
if not entity:
return None
result = PriceModel()
result.currency = entity.currency
# date/time
dt_string = entity.date
format_string = "%Y-%m-%d"
if entity.ti... | [
"Map",
"the",
"price",
"entity"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/mappers.py#L15-L42 | [
"def",
"map_entity",
"(",
"self",
",",
"entity",
":",
"dal",
".",
"Price",
")",
"->",
"PriceModel",
":",
"if",
"not",
"entity",
":",
"return",
"None",
"result",
"=",
"PriceModel",
"(",
")",
"result",
".",
"currency",
"=",
"entity",
".",
"currency",
"# ... | b4fd366b7763891c690fe3000b8840e656da023e |
test | PriceMapper.map_model | Parse into the Price entity, ready for saving | pricedb/mappers.py | def map_model(self, model: PriceModel) -> Price:
""" Parse into the Price entity, ready for saving """
# assert isinstance(model, PriceModel)
assert isinstance(model.symbol, SecuritySymbol)
assert isinstance(model.datum, Datum)
entity = Price()
# Format date as ISO stri... | def map_model(self, model: PriceModel) -> Price:
""" Parse into the Price entity, ready for saving """
# assert isinstance(model, PriceModel)
assert isinstance(model.symbol, SecuritySymbol)
assert isinstance(model.datum, Datum)
entity = Price()
# Format date as ISO stri... | [
"Parse",
"into",
"the",
"Price",
"entity",
"ready",
"for",
"saving"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/mappers.py#L44-L76 | [
"def",
"map_model",
"(",
"self",
",",
"model",
":",
"PriceModel",
")",
"->",
"Price",
":",
"# assert isinstance(model, PriceModel)",
"assert",
"isinstance",
"(",
"model",
".",
"symbol",
",",
"SecuritySymbol",
")",
"assert",
"isinstance",
"(",
"model",
".",
"datu... | b4fd366b7763891c690fe3000b8840e656da023e |
test | Config.__read_config | Read the config file | pricedb/config.py | def __read_config(self, file_path: str):
""" Read the config file """
if not os.path.exists(file_path):
raise FileNotFoundError(f"File path not found: {file_path}")
# check if file exists
if not os.path.isfile(file_path):
self.logger.error(f"file not found: {file_... | def __read_config(self, file_path: str):
""" Read the config file """
if not os.path.exists(file_path):
raise FileNotFoundError(f"File path not found: {file_path}")
# check if file exists
if not os.path.isfile(file_path):
self.logger.error(f"file not found: {file_... | [
"Read",
"the",
"config",
"file"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/config.py#L52-L61 | [
"def",
"__read_config",
"(",
"self",
",",
"file_path",
":",
"str",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"file_path",
")",
":",
"raise",
"FileNotFoundError",
"(",
"f\"File path not found: {file_path}\"",
")",
"# check if file exists",
"if... | b4fd366b7763891c690fe3000b8840e656da023e |
test | Config.__get_config_template_path | gets the default config path from resources | pricedb/config.py | def __get_config_template_path(self) -> str:
""" gets the default config path from resources """
filename = resource_filename(
Requirement.parse(package_name),
template_path + config_filename)
return filename | def __get_config_template_path(self) -> str:
""" gets the default config path from resources """
filename = resource_filename(
Requirement.parse(package_name),
template_path + config_filename)
return filename | [
"gets",
"the",
"default",
"config",
"path",
"from",
"resources"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/config.py#L63-L68 | [
"def",
"__get_config_template_path",
"(",
"self",
")",
"->",
"str",
":",
"filename",
"=",
"resource_filename",
"(",
"Requirement",
".",
"parse",
"(",
"package_name",
")",
",",
"template_path",
"+",
"config_filename",
")",
"return",
"filename"
] | b4fd366b7763891c690fe3000b8840e656da023e |
test | Config.__create_user_config | Copy the config template into user's directory | pricedb/config.py | def __create_user_config(self):
""" Copy the config template into user's directory """
src_path = self.__get_config_template_path()
src = os.path.abspath(src_path)
if not os.path.exists(src):
message = f"Config template not found {src}"
self.logger.error(message)... | def __create_user_config(self):
""" Copy the config template into user's directory """
src_path = self.__get_config_template_path()
src = os.path.abspath(src_path)
if not os.path.exists(src):
message = f"Config template not found {src}"
self.logger.error(message)... | [
"Copy",
"the",
"config",
"template",
"into",
"user",
"s",
"directory"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/config.py#L74-L89 | [
"def",
"__create_user_config",
"(",
"self",
")",
":",
"src_path",
"=",
"self",
".",
"__get_config_template_path",
"(",
")",
"src",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"src_path",
")",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"src",
... | b4fd366b7763891c690fe3000b8840e656da023e |
test | Config.get_config_path | Returns the path where the active config file is expected.
This is the user's profile folder. | pricedb/config.py | def get_config_path(self) -> str:
"""
Returns the path where the active config file is expected.
This is the user's profile folder.
"""
dst_dir = self.__get_user_path()
dst = dst_dir + "/" + config_filename
return dst | def get_config_path(self) -> str:
"""
Returns the path where the active config file is expected.
This is the user's profile folder.
"""
dst_dir = self.__get_user_path()
dst = dst_dir + "/" + config_filename
return dst | [
"Returns",
"the",
"path",
"where",
"the",
"active",
"config",
"file",
"is",
"expected",
".",
"This",
"is",
"the",
"user",
"s",
"profile",
"folder",
"."
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/config.py#L91-L98 | [
"def",
"get_config_path",
"(",
"self",
")",
"->",
"str",
":",
"dst_dir",
"=",
"self",
".",
"__get_user_path",
"(",
")",
"dst",
"=",
"dst_dir",
"+",
"\"/\"",
"+",
"config_filename",
"return",
"dst"
] | b4fd366b7763891c690fe3000b8840e656da023e |
test | Config.get_contents | Reads the contents of the config file | pricedb/config.py | def get_contents(self) -> str:
""" Reads the contents of the config file """
content = None
# with open(file_path) as cfg_file:
# contents = cfg_file.read()
# Dump the current contents into an in-memory file.
in_memory = io.StringIO("")
self.config.write(in_m... | def get_contents(self) -> str:
""" Reads the contents of the config file """
content = None
# with open(file_path) as cfg_file:
# contents = cfg_file.read()
# Dump the current contents into an in-memory file.
in_memory = io.StringIO("")
self.config.write(in_m... | [
"Reads",
"the",
"contents",
"of",
"the",
"config",
"file"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/config.py#L100-L113 | [
"def",
"get_contents",
"(",
"self",
")",
"->",
"str",
":",
"content",
"=",
"None",
"# with open(file_path) as cfg_file:",
"# contents = cfg_file.read()",
"# Dump the current contents into an in-memory file.",
"in_memory",
"=",
"io",
".",
"StringIO",
"(",
"\"\"",
")",
... | b4fd366b7763891c690fe3000b8840e656da023e |
test | Config.set | Sets a value in config | pricedb/config.py | def set(self, option: ConfigKeys, value):
""" Sets a value in config """
assert isinstance(option, ConfigKeys)
# As currently we only have 1 section.
section = SECTION
self.config.set(section, option.name, value)
self.save() | def set(self, option: ConfigKeys, value):
""" Sets a value in config """
assert isinstance(option, ConfigKeys)
# As currently we only have 1 section.
section = SECTION
self.config.set(section, option.name, value)
self.save() | [
"Sets",
"a",
"value",
"in",
"config"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/config.py#L115-L122 | [
"def",
"set",
"(",
"self",
",",
"option",
":",
"ConfigKeys",
",",
"value",
")",
":",
"assert",
"isinstance",
"(",
"option",
",",
"ConfigKeys",
")",
"# As currently we only have 1 section.",
"section",
"=",
"SECTION",
"self",
".",
"config",
".",
"set",
"(",
"... | b4fd366b7763891c690fe3000b8840e656da023e |
test | Config.get | Retrieves a config value | pricedb/config.py | def get(self, option: ConfigKeys):
""" Retrieves a config value """
assert isinstance(option, ConfigKeys)
# Currently only one section is used
section = SECTION
return self.config.get(section, option.name) | def get(self, option: ConfigKeys):
""" Retrieves a config value """
assert isinstance(option, ConfigKeys)
# Currently only one section is used
section = SECTION
return self.config.get(section, option.name) | [
"Retrieves",
"a",
"config",
"value"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/config.py#L124-L130 | [
"def",
"get",
"(",
"self",
",",
"option",
":",
"ConfigKeys",
")",
":",
"assert",
"isinstance",
"(",
"option",
",",
"ConfigKeys",
")",
"# Currently only one section is used",
"section",
"=",
"SECTION",
"return",
"self",
".",
"config",
".",
"get",
"(",
"section"... | b4fd366b7763891c690fe3000b8840e656da023e |
test | Config.save | Save the config file | pricedb/config.py | def save(self):
""" Save the config file """
file_path = self.get_config_path()
contents = self.get_contents()
with open(file_path, mode='w') as cfg_file:
cfg_file.write(contents) | def save(self):
""" Save the config file """
file_path = self.get_config_path()
contents = self.get_contents()
with open(file_path, mode='w') as cfg_file:
cfg_file.write(contents) | [
"Save",
"the",
"config",
"file"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/config.py#L132-L137 | [
"def",
"save",
"(",
"self",
")",
":",
"file_path",
"=",
"self",
".",
"get_config_path",
"(",
")",
"contents",
"=",
"self",
".",
"get_contents",
"(",
")",
"with",
"open",
"(",
"file_path",
",",
"mode",
"=",
"'w'",
")",
"as",
"cfg_file",
":",
"cfg_file",... | b4fd366b7763891c690fe3000b8840e656da023e |
test | SecuritySymbol.parse | Splits the symbol into namespace, symbol tuple | pricedb/model.py | def parse(self, symbol: str) -> (str, str):
""" Splits the symbol into namespace, symbol tuple """
symbol_parts = symbol.split(":")
namespace = None
mnemonic = symbol
if len(symbol_parts) > 1:
namespace = symbol_parts[0]
mnemonic = symbol_parts[1]
... | def parse(self, symbol: str) -> (str, str):
""" Splits the symbol into namespace, symbol tuple """
symbol_parts = symbol.split(":")
namespace = None
mnemonic = symbol
if len(symbol_parts) > 1:
namespace = symbol_parts[0]
mnemonic = symbol_parts[1]
... | [
"Splits",
"the",
"symbol",
"into",
"namespace",
"symbol",
"tuple"
] | MisterY/price-database | python | https://github.com/MisterY/price-database/blob/b4fd366b7763891c690fe3000b8840e656da023e/pricedb/model.py#L15-L28 | [
"def",
"parse",
"(",
"self",
",",
"symbol",
":",
"str",
")",
"->",
"(",
"str",
",",
"str",
")",
":",
"symbol_parts",
"=",
"symbol",
".",
"split",
"(",
"\":\"",
")",
"namespace",
"=",
"None",
"mnemonic",
"=",
"symbol",
"if",
"len",
"(",
"symbol_parts"... | b4fd366b7763891c690fe3000b8840e656da023e |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.