Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
EggMetadata.__init__ | (self, importer) | Create a metadata provider from a zipimporter | Create a metadata provider from a zipimporter | def __init__(self, importer):
"""Create a metadata provider from a zipimporter"""
self.zip_pre = importer.archive + os.sep
self.loader = importer
if importer.prefix:
self.module_path = os.path.join(importer.archive, importer.prefix)
else:
self.module_path... | [
"def",
"__init__",
"(",
"self",
",",
"importer",
")",
":",
"self",
".",
"zip_pre",
"=",
"importer",
".",
"archive",
"+",
"os",
".",
"sep",
"self",
".",
"loader",
"=",
"importer",
"if",
"importer",
".",
"prefix",
":",
"self",
".",
"module_path",
"=",
... | [
1952,
4
] | [
1961,
28
] | python | en | ['en', 'en', 'en'] | True |
EntryPoint.load | (self, require=True, *args, **kwargs) |
Require packages for this EntryPoint, then resolve it.
|
Require packages for this EntryPoint, then resolve it.
| def load(self, require=True, *args, **kwargs):
"""
Require packages for this EntryPoint, then resolve it.
"""
if not require or args or kwargs:
warnings.warn(
"Parameters to load are deprecated. Call .resolve and "
".require separately.",
... | [
"def",
"load",
"(",
"self",
",",
"require",
"=",
"True",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"require",
"or",
"args",
"or",
"kwargs",
":",
"warnings",
".",
"warn",
"(",
"\"Parameters to load are deprecated. Call .resolve and \"... | [
2448,
4
] | [
2461,
29
] | python | en | ['en', 'error', 'th'] | False |
EntryPoint.resolve | (self) |
Resolve the entry point from its module and attrs.
|
Resolve the entry point from its module and attrs.
| def resolve(self):
"""
Resolve the entry point from its module and attrs.
"""
module = __import__(self.module_name, fromlist=['__name__'], level=0)
try:
return functools.reduce(getattr, self.attrs, module)
except AttributeError as exc:
raise Import... | [
"def",
"resolve",
"(",
"self",
")",
":",
"module",
"=",
"__import__",
"(",
"self",
".",
"module_name",
",",
"fromlist",
"=",
"[",
"'__name__'",
"]",
",",
"level",
"=",
"0",
")",
"try",
":",
"return",
"functools",
".",
"reduce",
"(",
"getattr",
",",
"... | [
2463,
4
] | [
2471,
48
] | python | en | ['en', 'error', 'th'] | False |
EntryPoint.parse | (cls, src, dist=None) | Parse a single entry point from string `src`
Entry point syntax follows the form::
name = some.module:some.attr [extra1, extra2]
The entry name and module name are required, but the ``:attrs`` and
``[extras]`` parts are optional
| Parse a single entry point from string `src` | def parse(cls, src, dist=None):
"""Parse a single entry point from string `src`
Entry point syntax follows the form::
name = some.module:some.attr [extra1, extra2]
The entry name and module name are required, but the ``:attrs`` and
``[extras]`` parts are optional
"... | [
"def",
"parse",
"(",
"cls",
",",
"src",
",",
"dist",
"=",
"None",
")",
":",
"m",
"=",
"cls",
".",
"pattern",
".",
"match",
"(",
"src",
")",
"if",
"not",
"m",
":",
"msg",
"=",
"\"EntryPoint must be in 'name=module:attrs [extras]' format\"",
"raise",
"ValueE... | [
2496,
4
] | [
2513,
67
] | python | en | ['en', 'en', 'en'] | True |
EntryPoint.parse_group | (cls, group, lines, dist=None) | Parse an entry point group | Parse an entry point group | def parse_group(cls, group, lines, dist=None):
"""Parse an entry point group"""
if not MODULE(group):
raise ValueError("Invalid group name", group)
this = {}
for line in yield_lines(lines):
ep = cls.parse(line, dist)
if ep.name in this:
... | [
"def",
"parse_group",
"(",
"cls",
",",
"group",
",",
"lines",
",",
"dist",
"=",
"None",
")",
":",
"if",
"not",
"MODULE",
"(",
"group",
")",
":",
"raise",
"ValueError",
"(",
"\"Invalid group name\"",
",",
"group",
")",
"this",
"=",
"{",
"}",
"for",
"l... | [
2525,
4
] | [
2535,
19
] | python | en | ['en', 'en', 'en'] | True |
EntryPoint.parse_map | (cls, data, dist=None) | Parse a map of entry point groups | Parse a map of entry point groups | def parse_map(cls, data, dist=None):
"""Parse a map of entry point groups"""
if isinstance(data, dict):
data = data.items()
else:
data = split_sections(data)
maps = {}
for group, lines in data:
if group is None:
if not lines:
... | [
"def",
"parse_map",
"(",
"cls",
",",
"data",
",",
"dist",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"dict",
")",
":",
"data",
"=",
"data",
".",
"items",
"(",
")",
"else",
":",
"data",
"=",
"split_sections",
"(",
"data",
")",
"m... | [
2538,
4
] | [
2554,
19
] | python | en | ['en', 'en', 'en'] | True |
Distribution._dep_map | (self) |
A map of extra to its list of (direct) requirements
for this distribution, including the null extra.
|
A map of extra to its list of (direct) requirements
for this distribution, including the null extra.
| def _dep_map(self):
"""
A map of extra to its list of (direct) requirements
for this distribution, including the null extra.
"""
try:
return self.__dep_map
except AttributeError:
self.__dep_map = self._filter_extras(self._build_dep_map())
r... | [
"def",
"_dep_map",
"(",
"self",
")",
":",
"try",
":",
"return",
"self",
".",
"__dep_map",
"except",
"AttributeError",
":",
"self",
".",
"__dep_map",
"=",
"self",
".",
"_filter_extras",
"(",
"self",
".",
"_build_dep_map",
"(",
")",
")",
"return",
"self",
... | [
2703,
4
] | [
2712,
29
] | python | en | ['en', 'error', 'th'] | False |
Distribution._filter_extras | (dm) |
Given a mapping of extras to dependencies, strip off
environment markers and filter out any dependencies
not matching the markers.
|
Given a mapping of extras to dependencies, strip off
environment markers and filter out any dependencies
not matching the markers.
| def _filter_extras(dm):
"""
Given a mapping of extras to dependencies, strip off
environment markers and filter out any dependencies
not matching the markers.
"""
for extra in list(filter(None, dm)):
new_extra = extra
reqs = dm.pop(extra)
... | [
"def",
"_filter_extras",
"(",
"dm",
")",
":",
"for",
"extra",
"in",
"list",
"(",
"filter",
"(",
"None",
",",
"dm",
")",
")",
":",
"new_extra",
"=",
"extra",
"reqs",
"=",
"dm",
".",
"pop",
"(",
"extra",
")",
"new_extra",
",",
"_",
",",
"marker",
"... | [
2715,
4
] | [
2734,
17
] | python | en | ['en', 'error', 'th'] | False |
Distribution.requires | (self, extras=()) | List of Requirements needed for this distro if `extras` are used | List of Requirements needed for this distro if `extras` are used | def requires(self, extras=()):
"""List of Requirements needed for this distro if `extras` are used"""
dm = self._dep_map
deps = []
deps.extend(dm.get(None, ()))
for ext in extras:
try:
deps.extend(dm[safe_extra(ext)])
except KeyError as e:
... | [
"def",
"requires",
"(",
"self",
",",
"extras",
"=",
"(",
")",
")",
":",
"dm",
"=",
"self",
".",
"_dep_map",
"deps",
"=",
"[",
"]",
"deps",
".",
"extend",
"(",
"dm",
".",
"get",
"(",
"None",
",",
"(",
")",
")",
")",
"for",
"ext",
"in",
"extras... | [
2743,
4
] | [
2755,
19
] | python | en | ['en', 'en', 'en'] | True |
Distribution._get_metadata_path_for_display | (self, name) |
Return the path to the given metadata file, if available.
|
Return the path to the given metadata file, if available.
| def _get_metadata_path_for_display(self, name):
"""
Return the path to the given metadata file, if available.
"""
try:
# We need to access _get_metadata_path() on the provider object
# directly rather than through this class's __getattr__()
# since _ge... | [
"def",
"_get_metadata_path_for_display",
"(",
"self",
",",
"name",
")",
":",
"try",
":",
"# We need to access _get_metadata_path() on the provider object",
"# directly rather than through this class's __getattr__()",
"# since _get_metadata_path() is marked private.",
"path",
"=",
"self... | [
2757,
4
] | [
2772,
19
] | python | en | ['en', 'error', 'th'] | False |
Distribution.activate | (self, path=None, replace=False) | Ensure distribution is importable on `path` (default=sys.path) | Ensure distribution is importable on `path` (default=sys.path) | def activate(self, path=None, replace=False):
"""Ensure distribution is importable on `path` (default=sys.path)"""
if path is None:
path = sys.path
self.insert_on(path, replace=replace)
if path is sys.path:
fixup_namespace_packages(self.location)
for p... | [
"def",
"activate",
"(",
"self",
",",
"path",
"=",
"None",
",",
"replace",
"=",
"False",
")",
":",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"sys",
".",
"path",
"self",
".",
"insert_on",
"(",
"path",
",",
"replace",
"=",
"replace",
")",
"if",
... | [
2785,
4
] | [
2794,
42
] | python | en | ['en', 'en', 'en'] | True |
Distribution.egg_name | (self) | Return what this distribution's standard .egg filename should be | Return what this distribution's standard .egg filename should be | def egg_name(self):
"""Return what this distribution's standard .egg filename should be"""
filename = "%s-%s-py%s" % (
to_filename(self.project_name), to_filename(self.version),
self.py_version or PY_MAJOR
)
if self.platform:
filename += '-' + self.pl... | [
"def",
"egg_name",
"(",
"self",
")",
":",
"filename",
"=",
"\"%s-%s-py%s\"",
"%",
"(",
"to_filename",
"(",
"self",
".",
"project_name",
")",
",",
"to_filename",
"(",
"self",
".",
"version",
")",
",",
"self",
".",
"py_version",
"or",
"PY_MAJOR",
")",
"if"... | [
2796,
4
] | [
2805,
23
] | python | en | ['en', 'en', 'en'] | True |
Distribution.__getattr__ | (self, attr) | Delegate all unrecognized public attributes to .metadata provider | Delegate all unrecognized public attributes to .metadata provider | def __getattr__(self, attr):
"""Delegate all unrecognized public attributes to .metadata provider"""
if attr.startswith('_'):
raise AttributeError(attr)
return getattr(self._provider, attr) | [
"def",
"__getattr__",
"(",
"self",
",",
"attr",
")",
":",
"if",
"attr",
".",
"startswith",
"(",
"'_'",
")",
":",
"raise",
"AttributeError",
"(",
"attr",
")",
"return",
"getattr",
"(",
"self",
".",
"_provider",
",",
"attr",
")"
] | [
2821,
4
] | [
2825,
44
] | python | en | ['en', 'it', 'en'] | True |
Distribution.as_requirement | (self) | Return a ``Requirement`` that matches this distribution exactly | Return a ``Requirement`` that matches this distribution exactly | def as_requirement(self):
"""Return a ``Requirement`` that matches this distribution exactly"""
if isinstance(self.parsed_version, packaging.version.Version):
spec = "%s==%s" % (self.project_name, self.parsed_version)
else:
spec = "%s===%s" % (self.project_name, self.pars... | [
"def",
"as_requirement",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"parsed_version",
",",
"packaging",
".",
"version",
".",
"Version",
")",
":",
"spec",
"=",
"\"%s==%s\"",
"%",
"(",
"self",
".",
"project_name",
",",
"self",
".",
"parse... | [
2847,
4
] | [
2854,
38
] | python | en | ['en', 'en', 'en'] | True |
Distribution.load_entry_point | (self, group, name) | Return the `name` entry point of `group` or raise ImportError | Return the `name` entry point of `group` or raise ImportError | def load_entry_point(self, group, name):
"""Return the `name` entry point of `group` or raise ImportError"""
ep = self.get_entry_info(group, name)
if ep is None:
raise ImportError("Entry point %r not found" % ((group, name),))
return ep.load() | [
"def",
"load_entry_point",
"(",
"self",
",",
"group",
",",
"name",
")",
":",
"ep",
"=",
"self",
".",
"get_entry_info",
"(",
"group",
",",
"name",
")",
"if",
"ep",
"is",
"None",
":",
"raise",
"ImportError",
"(",
"\"Entry point %r not found\"",
"%",
"(",
"... | [
2856,
4
] | [
2861,
24
] | python | en | ['en', 'en', 'en'] | True |
Distribution.get_entry_map | (self, group=None) | Return the entry point map for `group`, or the full entry map | Return the entry point map for `group`, or the full entry map | def get_entry_map(self, group=None):
"""Return the entry point map for `group`, or the full entry map"""
try:
ep_map = self._ep_map
except AttributeError:
ep_map = self._ep_map = EntryPoint.parse_map(
self._get_metadata('entry_points.txt'), self
... | [
"def",
"get_entry_map",
"(",
"self",
",",
"group",
"=",
"None",
")",
":",
"try",
":",
"ep_map",
"=",
"self",
".",
"_ep_map",
"except",
"AttributeError",
":",
"ep_map",
"=",
"self",
".",
"_ep_map",
"=",
"EntryPoint",
".",
"parse_map",
"(",
"self",
".",
... | [
2863,
4
] | [
2873,
21
] | python | en | ['en', 'en', 'en'] | True |
Distribution.get_entry_info | (self, group, name) | Return the EntryPoint object for `group`+`name`, or ``None`` | Return the EntryPoint object for `group`+`name`, or ``None`` | def get_entry_info(self, group, name):
"""Return the EntryPoint object for `group`+`name`, or ``None``"""
return self.get_entry_map(group).get(name) | [
"def",
"get_entry_info",
"(",
"self",
",",
"group",
",",
"name",
")",
":",
"return",
"self",
".",
"get_entry_map",
"(",
"group",
")",
".",
"get",
"(",
"name",
")"
] | [
2875,
4
] | [
2877,
50
] | python | en | ['en', 'en', 'en'] | True |
Distribution.insert_on | (self, path, loc=None, replace=False) | Ensure self.location is on path
If replace=False (default):
- If location is already in path anywhere, do nothing.
- Else:
- If it's an egg and its parent directory is on path,
insert just ahead of the parent.
- Else: add to the end of path.
... | Ensure self.location is on path | def insert_on(self, path, loc=None, replace=False):
"""Ensure self.location is on path
If replace=False (default):
- If location is already in path anywhere, do nothing.
- Else:
- If it's an egg and its parent directory is on path,
insert just ahead... | [
"def",
"insert_on",
"(",
"self",
",",
"path",
",",
"loc",
"=",
"None",
",",
"replace",
"=",
"False",
")",
":",
"loc",
"=",
"loc",
"or",
"self",
".",
"location",
"if",
"not",
"loc",
":",
"return",
"nloc",
"=",
"_normalize_cached",
"(",
"loc",
")",
"... | [
2879,
4
] | [
2945,
14
] | python | en | ['en', 'en', 'en'] | True |
Distribution.clone | (self, **kw) | Copy this distribution, substituting in any changed keyword args | Copy this distribution, substituting in any changed keyword args | def clone(self, **kw):
"""Copy this distribution, substituting in any changed keyword args"""
names = 'project_name version py_version platform location precedence'
for attr in names.split():
kw.setdefault(attr, getattr(self, attr, None))
kw.setdefault('metadata', self._provi... | [
"def",
"clone",
"(",
"self",
",",
"*",
"*",
"kw",
")",
":",
"names",
"=",
"'project_name version py_version platform location precedence'",
"for",
"attr",
"in",
"names",
".",
"split",
"(",
")",
":",
"kw",
".",
"setdefault",
"(",
"attr",
",",
"getattr",
"(",
... | [
2977,
4
] | [
2983,
35
] | python | en | ['en', 'en', 'en'] | True |
EggInfoDistribution._reload_version | (self) |
Packages installed by distutils (e.g. numpy or scipy),
which uses an old safe_version, and so
their version numbers can get mangled when
converted to filenames (e.g., 1.11.0.dev0+2329eae to
1.11.0.dev0_2329eae). These distributions will not be
parsed properly
dow... |
Packages installed by distutils (e.g. numpy or scipy),
which uses an old safe_version, and so
their version numbers can get mangled when
converted to filenames (e.g., 1.11.0.dev0+2329eae to
1.11.0.dev0_2329eae). These distributions will not be
parsed properly
dow... | def _reload_version(self):
"""
Packages installed by distutils (e.g. numpy or scipy),
which uses an old safe_version, and so
their version numbers can get mangled when
converted to filenames (e.g., 1.11.0.dev0+2329eae to
1.11.0.dev0_2329eae). These distributions will not ... | [
"def",
"_reload_version",
"(",
"self",
")",
":",
"md_version",
"=",
"self",
".",
"_get_version",
"(",
")",
"if",
"md_version",
":",
"self",
".",
"_version",
"=",
"md_version",
"return",
"self"
] | [
2991,
4
] | [
3006,
19
] | python | en | ['en', 'error', 'th'] | False |
make_model_tuple | (model) |
Take a model or a string of the form "app_label.ModelName" and return a
corresponding ("app_label", "modelname") tuple. If a tuple is passed in,
assume it's a valid model tuple already and return it unchanged.
|
Take a model or a string of the form "app_label.ModelName" and return a
corresponding ("app_label", "modelname") tuple. If a tuple is passed in,
assume it's a valid model tuple already and return it unchanged.
| def make_model_tuple(model):
"""
Take a model or a string of the form "app_label.ModelName" and return a
corresponding ("app_label", "modelname") tuple. If a tuple is passed in,
assume it's a valid model tuple already and return it unchanged.
"""
try:
if isinstance(model, tuple):
... | [
"def",
"make_model_tuple",
"(",
"model",
")",
":",
"try",
":",
"if",
"isinstance",
"(",
"model",
",",
"tuple",
")",
":",
"model_tuple",
"=",
"model",
"elif",
"isinstance",
"(",
"model",
",",
"str",
")",
":",
"app_label",
",",
"model_name",
"=",
"model",
... | [
0,
0
] | [
20,
9
] | python | en | ['en', 'error', 'th'] | False |
evaluate_model | (
filepath,
train_start=0,
train_end=60000,
test_start=0,
test_end=10000,
batch_size=128,
testing=False,
num_threads=None,
) |
Run evaluation on a saved model
:param filepath: path to model to evaluate
:param train_start: index of first training set example
:param train_end: index of last training set example
:param test_start: index of first test set example
:param test_end: index of last test set example
:param b... |
Run evaluation on a saved model
:param filepath: path to model to evaluate
:param train_start: index of first training set example
:param train_end: index of last training set example
:param test_start: index of first test set example
:param test_end: index of last test set example
:param b... | def evaluate_model(
filepath,
train_start=0,
train_end=60000,
test_start=0,
test_end=10000,
batch_size=128,
testing=False,
num_threads=None,
):
"""
Run evaluation on a saved model
:param filepath: path to model to evaluate
:param train_start: index of first training set e... | [
"def",
"evaluate_model",
"(",
"filepath",
",",
"train_start",
"=",
"0",
",",
"train_end",
"=",
"60000",
",",
"test_start",
"=",
"0",
",",
"test_end",
"=",
"10000",
",",
"batch_size",
"=",
"128",
",",
"testing",
"=",
"False",
",",
"num_threads",
"=",
"Non... | [
26,
0
] | [
104,
68
] | python | en | ['en', 'error', 'th'] | False |
create_tf_addition_model | (custom_op_path) |
A simple addition model that uses a custom op
|
A simple addition model that uses a custom op
| def create_tf_addition_model(custom_op_path):
"""
A simple addition model that uses a custom op
"""
addition_op_module = tf.load_op_library(custom_op_path)
g = tf.Graph()
with g.as_default():
with tf.name_scope("some_namespace"):
x = tf.placeholder(tf.float32, name="in_x")
... | [
"def",
"create_tf_addition_model",
"(",
"custom_op_path",
")",
":",
"addition_op_module",
"=",
"tf",
".",
"load_op_library",
"(",
"custom_op_path",
")",
"g",
"=",
"tf",
".",
"Graph",
"(",
")",
"with",
"g",
".",
"as_default",
"(",
")",
":",
"with",
"tf",
".... | [
26,
0
] | [
41,
27
] | python | en | ['en', 'error', 'th'] | False |
send_to_push_bouncer | (
method: str,
endpoint: str,
post_data: Union[bytes, Mapping[str, Union[str, bytes]]],
extra_headers: Mapping[str, str] = {},
) | While it does actually send the notice, this function has a lot of
code and comments around error handling for the push notifications
bouncer. There are several classes of failures, each with its own
potential solution:
* Network errors with requests.request. We raise an exception to signal
it ... | While it does actually send the notice, this function has a lot of
code and comments around error handling for the push notifications
bouncer. There are several classes of failures, each with its own
potential solution: | def send_to_push_bouncer(
method: str,
endpoint: str,
post_data: Union[bytes, Mapping[str, Union[str, bytes]]],
extra_headers: Mapping[str, str] = {},
) -> Dict[str, object]:
"""While it does actually send the notice, this function has a lot of
code and comments around error handling for the pus... | [
"def",
"send_to_push_bouncer",
"(",
"method",
":",
"str",
",",
"endpoint",
":",
"str",
",",
"post_data",
":",
"Union",
"[",
"bytes",
",",
"Mapping",
"[",
"str",
",",
"Union",
"[",
"str",
",",
"bytes",
"]",
"]",
"]",
",",
"extra_headers",
":",
"Mapping"... | [
25,
0
] | [
99,
36
] | python | en | ['en', 'en', 'en'] | True |
get_all_headers | (message, key) |
Given an HTTPMessage, return all headers matching a given key.
|
Given an HTTPMessage, return all headers matching a given key.
| def get_all_headers(message, key):
"""
Given an HTTPMessage, return all headers matching a given key.
"""
return message.get_all(key) | [
"def",
"get_all_headers",
"(",
"message",
",",
"key",
")",
":",
"return",
"message",
".",
"get_all",
"(",
"key",
")"
] | [
10,
0
] | [
14,
31
] | python | en | ['en', 'error', 'th'] | False |
iter_vscode_ext | (name=None) | Iterates over installed VSCode Extensions.
Args:
name (str, optional): Name of Extension to Yield
| Iterates over installed VSCode Extensions. | def iter_vscode_ext(name=None):
"""Iterates over installed VSCode Extensions.
Args:
name (str, optional): Name of Extension to Yield
"""
_cmd = "code --list-extensions --show-versions"
proc = subproc.run(_cmd, stdout=subproc.PIPE, stderr=subproc.PIPE, shell=True)
results = [e.strip() f... | [
"def",
"iter_vscode_ext",
"(",
"name",
"=",
"None",
")",
":",
"_cmd",
"=",
"\"code --list-extensions --show-versions\"",
"proc",
"=",
"subproc",
".",
"run",
"(",
"_cmd",
",",
"stdout",
"=",
"subproc",
".",
"PIPE",
",",
"stderr",
"=",
"subproc",
".",
"PIPE",
... | [
15,
0
] | [
30,
31
] | python | en | ['en', 'en', 'en'] | True |
vscode_ext_min_version | (ext, min_version=VSCODE_MS_PY_MINVER, info=None) | Check if installed VScode Extension meets requirements.
Args:
ext (str): Name of Extension to Test
min_version (str, optional): Minimum version.
Defaults to VSCODE_MS_PY_MINVER.
info (str, optional): Additional information to output.
Defaults to None.
Returns:
... | Check if installed VScode Extension meets requirements. | def vscode_ext_min_version(ext, min_version=VSCODE_MS_PY_MINVER, info=None):
"""Check if installed VScode Extension meets requirements.
Args:
ext (str): Name of Extension to Test
min_version (str, optional): Minimum version.
Defaults to VSCODE_MS_PY_MINVER.
info (str, option... | [
"def",
"vscode_ext_min_version",
"(",
"ext",
",",
"min_version",
"=",
"VSCODE_MS_PY_MINVER",
",",
"info",
"=",
"None",
")",
":",
"try",
":",
"name",
",",
"vers",
"=",
"next",
"(",
"iter_vscode_ext",
"(",
"name",
"=",
"ext",
")",
",",
"(",
"ext",
",",
"... | [
33,
0
] | [
63,
20
] | python | en | ['en', 'en', 'en'] | True |
normalize_together | (option_together) |
option_together can be either a tuple of tuples, or a single
tuple of two strings. Normalize it to a tuple of tuples, so that
calling code can uniformly expect that.
|
option_together can be either a tuple of tuples, or a single
tuple of two strings. Normalize it to a tuple of tuples, so that
calling code can uniformly expect that.
| def normalize_together(option_together):
"""
option_together can be either a tuple of tuples, or a single
tuple of two strings. Normalize it to a tuple of tuples, so that
calling code can uniformly expect that.
"""
try:
if not option_together:
return ()
if not isinsta... | [
"def",
"normalize_together",
"(",
"option_together",
")",
":",
"try",
":",
"if",
"not",
"option_together",
":",
"return",
"(",
")",
"if",
"not",
"isinstance",
"(",
"option_together",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"raise",
"TypeError",
"fir... | [
38,
0
] | [
57,
30
] | python | en | ['en', 'error', 'th'] | False |
Options._format_names_with_class | (self, cls, objs) | App label/class name interpolation for object names. | App label/class name interpolation for object names. | def _format_names_with_class(self, cls, objs):
"""App label/class name interpolation for object names."""
new_objs = []
for obj in objs:
obj = obj.clone()
obj.name = obj.name % {
'app_label': cls._meta.app_label.lower(),
'class': cls.__name... | [
"def",
"_format_names_with_class",
"(",
"self",
",",
"cls",
",",
"objs",
")",
":",
"new_objs",
"=",
"[",
"]",
"for",
"obj",
"in",
"objs",
":",
"obj",
"=",
"obj",
".",
"clone",
"(",
")",
"obj",
".",
"name",
"=",
"obj",
".",
"name",
"%",
"{",
"'app... | [
209,
4
] | [
219,
23
] | python | en | ['nb', 'en', 'en'] | True |
Options.setup_proxy | (self, target) |
Do the internal setup so that the current model is a proxy for
"target".
|
Do the internal setup so that the current model is a proxy for
"target".
| def setup_proxy(self, target):
"""
Do the internal setup so that the current model is a proxy for
"target".
"""
self.pk = target._meta.pk
self.proxy_for_model = target
self.db_table = target._meta.db_table | [
"def",
"setup_proxy",
"(",
"self",
",",
"target",
")",
":",
"self",
".",
"pk",
"=",
"target",
".",
"_meta",
".",
"pk",
"self",
".",
"proxy_for_model",
"=",
"target",
"self",
".",
"db_table",
"=",
"target",
".",
"_meta",
".",
"db_table"
] | [
300,
4
] | [
307,
45
] | python | en | ['en', 'error', 'th'] | False |
Options.can_migrate | (self, connection) |
Return True if the model can/should be migrated on the `connection`.
`connection` can be either a real connection or a connection alias.
|
Return True if the model can/should be migrated on the `connection`.
`connection` can be either a real connection or a connection alias.
| def can_migrate(self, connection):
"""
Return True if the model can/should be migrated on the `connection`.
`connection` can be either a real connection or a connection alias.
"""
if self.proxy or self.swapped or not self.managed:
return False
if isinstance(co... | [
"def",
"can_migrate",
"(",
"self",
",",
"connection",
")",
":",
"if",
"self",
".",
"proxy",
"or",
"self",
".",
"swapped",
"or",
"not",
"self",
".",
"managed",
":",
"return",
"False",
"if",
"isinstance",
"(",
"connection",
",",
"str",
")",
":",
"connect... | [
315,
4
] | [
329,
19
] | python | en | ['en', 'error', 'th'] | False |
Options.verbose_name_raw | (self) | Return the untranslated verbose name. | Return the untranslated verbose name. | def verbose_name_raw(self):
"""Return the untranslated verbose name."""
with override(None):
return str(self.verbose_name) | [
"def",
"verbose_name_raw",
"(",
"self",
")",
":",
"with",
"override",
"(",
"None",
")",
":",
"return",
"str",
"(",
"self",
".",
"verbose_name",
")"
] | [
332,
4
] | [
335,
41
] | python | en | ['en', 'da', 'en'] | True |
Options.swapped | (self) |
Has this model been swapped out for another? If so, return the model
name of the replacement; otherwise, return None.
For historical reasons, model name lookups using get_model() are
case insensitive, so we make sure we are case insensitive here.
|
Has this model been swapped out for another? If so, return the model
name of the replacement; otherwise, return None. | def swapped(self):
"""
Has this model been swapped out for another? If so, return the model
name of the replacement; otherwise, return None.
For historical reasons, model name lookups using get_model() are
case insensitive, so we make sure we are case insensitive here.
"... | [
"def",
"swapped",
"(",
"self",
")",
":",
"if",
"self",
".",
"swappable",
":",
"swapped_for",
"=",
"getattr",
"(",
"settings",
",",
"self",
".",
"swappable",
",",
"None",
")",
"if",
"swapped_for",
":",
"try",
":",
"swapped_label",
",",
"swapped_object",
"... | [
338,
4
] | [
360,
19
] | python | en | ['en', 'error', 'th'] | False |
Options.fields | (self) |
Return a list of all forward fields on the model and its parents,
excluding ManyToManyFields.
Private API intended only to be used by Django itself; get_fields()
combined with filtering of field properties is the public API for
obtaining this field list.
|
Return a list of all forward fields on the model and its parents,
excluding ManyToManyFields. | def fields(self):
"""
Return a list of all forward fields on the model and its parents,
excluding ManyToManyFields.
Private API intended only to be used by Django itself; get_fields()
combined with filtering of field properties is the public API for
obtaining this field ... | [
"def",
"fields",
"(",
"self",
")",
":",
"# For legacy reasons, the fields property should only contain forward",
"# fields that are not private or with a m2m cardinality. Therefore we",
"# pass these three filters as filters to the generator.",
"# The third lambda is a longwinded way of checking f... | [
439,
4
] | [
470,
9
] | python | en | ['en', 'error', 'th'] | False |
Options.concrete_fields | (self) |
Return a list of all concrete fields on the model and its parents.
Private API intended only to be used by Django itself; get_fields()
combined with filtering of field properties is the public API for
obtaining this field list.
|
Return a list of all concrete fields on the model and its parents. | def concrete_fields(self):
"""
Return a list of all concrete fields on the model and its parents.
Private API intended only to be used by Django itself; get_fields()
combined with filtering of field properties is the public API for
obtaining this field list.
"""
... | [
"def",
"concrete_fields",
"(",
"self",
")",
":",
"return",
"make_immutable_fields_list",
"(",
"\"concrete_fields\"",
",",
"(",
"f",
"for",
"f",
"in",
"self",
".",
"fields",
"if",
"f",
".",
"concrete",
")",
")"
] | [
473,
4
] | [
483,
9
] | python | en | ['en', 'error', 'th'] | False |
Options.local_concrete_fields | (self) |
Return a list of all concrete fields on the model.
Private API intended only to be used by Django itself; get_fields()
combined with filtering of field properties is the public API for
obtaining this field list.
|
Return a list of all concrete fields on the model. | def local_concrete_fields(self):
"""
Return a list of all concrete fields on the model.
Private API intended only to be used by Django itself; get_fields()
combined with filtering of field properties is the public API for
obtaining this field list.
"""
return mak... | [
"def",
"local_concrete_fields",
"(",
"self",
")",
":",
"return",
"make_immutable_fields_list",
"(",
"\"local_concrete_fields\"",
",",
"(",
"f",
"for",
"f",
"in",
"self",
".",
"local_fields",
"if",
"f",
".",
"concrete",
")",
")"
] | [
486,
4
] | [
496,
9
] | python | en | ['en', 'error', 'th'] | False |
Options.many_to_many | (self) |
Return a list of all many to many fields on the model and its parents.
Private API intended only to be used by Django itself; get_fields()
combined with filtering of field properties is the public API for
obtaining this list.
|
Return a list of all many to many fields on the model and its parents. | def many_to_many(self):
"""
Return a list of all many to many fields on the model and its parents.
Private API intended only to be used by Django itself; get_fields()
combined with filtering of field properties is the public API for
obtaining this list.
"""
retur... | [
"def",
"many_to_many",
"(",
"self",
")",
":",
"return",
"make_immutable_fields_list",
"(",
"\"many_to_many\"",
",",
"(",
"f",
"for",
"f",
"in",
"self",
".",
"_get_fields",
"(",
"reverse",
"=",
"False",
")",
"if",
"f",
".",
"is_relation",
"and",
"f",
".",
... | [
499,
4
] | [
510,
9
] | python | en | ['en', 'error', 'th'] | False |
Options.related_objects | (self) |
Return all related objects pointing to the current model. The related
objects can come from a one-to-one, one-to-many, or many-to-many field
relation type.
Private API intended only to be used by Django itself; get_fields()
combined with filtering of field properties is the pub... |
Return all related objects pointing to the current model. The related
objects can come from a one-to-one, one-to-many, or many-to-many field
relation type. | def related_objects(self):
"""
Return all related objects pointing to the current model. The related
objects can come from a one-to-one, one-to-many, or many-to-many field
relation type.
Private API intended only to be used by Django itself; get_fields()
combined with fi... | [
"def",
"related_objects",
"(",
"self",
")",
":",
"all_related_fields",
"=",
"self",
".",
"_get_fields",
"(",
"forward",
"=",
"False",
",",
"reverse",
"=",
"True",
",",
"include_hidden",
"=",
"True",
")",
"return",
"make_immutable_fields_list",
"(",
"\"related_ob... | [
513,
4
] | [
527,
9
] | python | en | ['en', 'error', 'th'] | False |
Options.get_field | (self, field_name) |
Return a field instance given the name of a forward or reverse field.
|
Return a field instance given the name of a forward or reverse field.
| def get_field(self, field_name):
"""
Return a field instance given the name of a forward or reverse field.
"""
try:
# In order to avoid premature loading of the relation tree
# (expensive) we prefer checking if the field is a forward field.
return self... | [
"def",
"get_field",
"(",
"self",
",",
"field_name",
")",
":",
"try",
":",
"# In order to avoid premature loading of the relation tree",
"# (expensive) we prefer checking if the field is a forward field.",
"return",
"self",
".",
"_forward_fields_map",
"[",
"field_name",
"]",
"ex... | [
559,
4
] | [
582,
98
] | python | en | ['en', 'error', 'th'] | False |
Options.get_base_chain | (self, model) |
Return a list of parent classes leading to `model` (ordered from
closest to most distant ancestor). This has to handle the case where
`model` is a grandparent or even more distant relation.
|
Return a list of parent classes leading to `model` (ordered from
closest to most distant ancestor). This has to handle the case where
`model` is a grandparent or even more distant relation.
| def get_base_chain(self, model):
"""
Return a list of parent classes leading to `model` (ordered from
closest to most distant ancestor). This has to handle the case where
`model` is a grandparent or even more distant relation.
"""
if not self.parents:
return [... | [
"def",
"get_base_chain",
"(",
"self",
",",
"model",
")",
":",
"if",
"not",
"self",
".",
"parents",
":",
"return",
"[",
"]",
"if",
"model",
"in",
"self",
".",
"parents",
":",
"return",
"[",
"model",
"]",
"for",
"parent",
"in",
"self",
".",
"parents",
... | [
584,
4
] | [
599,
17
] | python | en | ['en', 'error', 'th'] | False |
Options.get_parent_list | (self) |
Return all the ancestors of this model as a list ordered by MRO.
Useful for determining if something is an ancestor, regardless of lineage.
|
Return all the ancestors of this model as a list ordered by MRO.
Useful for determining if something is an ancestor, regardless of lineage.
| def get_parent_list(self):
"""
Return all the ancestors of this model as a list ordered by MRO.
Useful for determining if something is an ancestor, regardless of lineage.
"""
result = OrderedSet(self.parents)
for parent in self.parents:
for ancestor in parent.... | [
"def",
"get_parent_list",
"(",
"self",
")",
":",
"result",
"=",
"OrderedSet",
"(",
"self",
".",
"parents",
")",
"for",
"parent",
"in",
"self",
".",
"parents",
":",
"for",
"ancestor",
"in",
"parent",
".",
"_meta",
".",
"get_parent_list",
"(",
")",
":",
... | [
601,
4
] | [
610,
27
] | python | en | ['en', 'error', 'th'] | False |
Options.get_ancestor_link | (self, ancestor) |
Return the field on the current model which points to the given
"ancestor". This is possible an indirect link (a pointer to a parent
model, which points, eventually, to the ancestor). Used when
constructing table joins for model inheritance.
Return None if the model isn't an an... |
Return the field on the current model which points to the given
"ancestor". This is possible an indirect link (a pointer to a parent
model, which points, eventually, to the ancestor). Used when
constructing table joins for model inheritance. | def get_ancestor_link(self, ancestor):
"""
Return the field on the current model which points to the given
"ancestor". This is possible an indirect link (a pointer to a parent
model, which points, eventually, to the ancestor). Used when
constructing table joins for model inherita... | [
"def",
"get_ancestor_link",
"(",
"self",
",",
"ancestor",
")",
":",
"if",
"ancestor",
"in",
"self",
".",
"parents",
":",
"return",
"self",
".",
"parents",
"[",
"ancestor",
"]",
"for",
"parent",
"in",
"self",
".",
"parents",
":",
"# Tries to get a link field ... | [
612,
4
] | [
630,
58
] | python | en | ['en', 'error', 'th'] | False |
Options.get_path_to_parent | (self, parent) |
Return a list of PathInfos containing the path from the current
model to the parent model, or an empty list if parent is not a
parent of the current model.
|
Return a list of PathInfos containing the path from the current
model to the parent model, or an empty list if parent is not a
parent of the current model.
| def get_path_to_parent(self, parent):
"""
Return a list of PathInfos containing the path from the current
model to the parent model, or an empty list if parent is not a
parent of the current model.
"""
if self.model is parent:
return []
# Skip the chai... | [
"def",
"get_path_to_parent",
"(",
"self",
",",
"parent",
")",
":",
"if",
"self",
".",
"model",
"is",
"parent",
":",
"return",
"[",
"]",
"# Skip the chain of proxy to the concrete proxied model.",
"proxied_model",
"=",
"self",
".",
"concrete_model",
"path",
"=",
"[... | [
632,
4
] | [
660,
19
] | python | en | ['en', 'error', 'th'] | False |
Options.get_path_from_parent | (self, parent) |
Return a list of PathInfos containing the path from the parent
model to the current model, or an empty list if parent is not a
parent of the current model.
|
Return a list of PathInfos containing the path from the parent
model to the current model, or an empty list if parent is not a
parent of the current model.
| def get_path_from_parent(self, parent):
"""
Return a list of PathInfos containing the path from the parent
model to the current model, or an empty list if parent is not a
parent of the current model.
"""
if self.model is parent:
return []
model = self.... | [
"def",
"get_path_from_parent",
"(",
"self",
",",
"parent",
")",
":",
"if",
"self",
".",
"model",
"is",
"parent",
":",
"return",
"[",
"]",
"model",
"=",
"self",
".",
"concrete_model",
"# Get a reversed base chain including both the current and parent",
"# models.",
"... | [
662,
4
] | [
682,
19
] | python | en | ['en', 'error', 'th'] | False |
Options._populate_directed_relation_graph | (self) |
This method is used by each model to find its reverse objects. As this
method is very expensive and is accessed frequently (it looks up every
field in a model, in every app), it is computed on first access and then
is set as a property on every model.
|
This method is used by each model to find its reverse objects. As this
method is very expensive and is accessed frequently (it looks up every
field in a model, in every app), it is computed on first access and then
is set as a property on every model.
| def _populate_directed_relation_graph(self):
"""
This method is used by each model to find its reverse objects. As this
method is very expensive and is accessed frequently (it looks up every
field in a model, in every app), it is computed on first access and then
is set as a prop... | [
"def",
"_populate_directed_relation_graph",
"(",
"self",
")",
":",
"related_objects_graph",
"=",
"defaultdict",
"(",
"list",
")",
"all_models",
"=",
"self",
".",
"apps",
".",
"get_models",
"(",
"include_auto_created",
"=",
"True",
")",
"for",
"model",
"in",
"all... | [
684,
4
] | [
718,
71
] | python | en | ['en', 'error', 'th'] | False |
Options.get_fields | (self, include_parents=True, include_hidden=False) |
Return a list of fields associated to the model. By default, include
forward and reverse fields, fields derived from inheritance, but not
hidden fields. The returned fields can be changed using the parameters:
- include_parents: include fields derived from inheritance
- include... |
Return a list of fields associated to the model. By default, include
forward and reverse fields, fields derived from inheritance, but not
hidden fields. The returned fields can be changed using the parameters: | def get_fields(self, include_parents=True, include_hidden=False):
"""
Return a list of fields associated to the model. By default, include
forward and reverse fields, fields derived from inheritance, but not
hidden fields. The returned fields can be changed using the parameters:
... | [
"def",
"get_fields",
"(",
"self",
",",
"include_parents",
"=",
"True",
",",
"include_hidden",
"=",
"False",
")",
":",
"if",
"include_parents",
"is",
"False",
":",
"include_parents",
"=",
"PROXY_PARENTS",
"return",
"self",
".",
"_get_fields",
"(",
"include_parent... | [
737,
4
] | [
749,
95
] | python | en | ['en', 'error', 'th'] | False |
Options._get_fields | (self, forward=True, reverse=True, include_parents=True, include_hidden=False,
seen_models=None) |
Internal helper function to return fields of the model.
* If forward=True, then fields defined on this model are returned.
* If reverse=True, then relations pointing to this model are returned.
* If include_hidden=True, then fields with is_hidden=True are returned.
* The include... |
Internal helper function to return fields of the model.
* If forward=True, then fields defined on this model are returned.
* If reverse=True, then relations pointing to this model are returned.
* If include_hidden=True, then fields with is_hidden=True are returned.
* The include... | def _get_fields(self, forward=True, reverse=True, include_parents=True, include_hidden=False,
seen_models=None):
"""
Internal helper function to return fields of the model.
* If forward=True, then fields defined on this model are returned.
* If reverse=True, then rela... | [
"def",
"_get_fields",
"(",
"self",
",",
"forward",
"=",
"True",
",",
"reverse",
"=",
"True",
",",
"include_parents",
"=",
"True",
",",
"include_hidden",
"=",
"False",
",",
"seen_models",
"=",
"None",
")",
":",
"if",
"include_parents",
"not",
"in",
"(",
"... | [
751,
4
] | [
833,
21
] | python | en | ['en', 'error', 'th'] | False |
Options._property_names | (self) | Return a set of the names of the properties defined on the model. | Return a set of the names of the properties defined on the model. | def _property_names(self):
"""Return a set of the names of the properties defined on the model."""
names = []
for name in dir(self.model):
attr = inspect.getattr_static(self.model, name)
if isinstance(attr, property):
names.append(name)
return froz... | [
"def",
"_property_names",
"(",
"self",
")",
":",
"names",
"=",
"[",
"]",
"for",
"name",
"in",
"dir",
"(",
"self",
".",
"model",
")",
":",
"attr",
"=",
"inspect",
".",
"getattr_static",
"(",
"self",
".",
"model",
",",
"name",
")",
"if",
"isinstance",
... | [
836,
4
] | [
843,
31
] | python | en | ['en', 'en', 'en'] | True |
Options.db_returning_fields | (self) |
Private API intended only to be used by Django itself.
Fields to be returned after a database insert.
|
Private API intended only to be used by Django itself.
Fields to be returned after a database insert.
| def db_returning_fields(self):
"""
Private API intended only to be used by Django itself.
Fields to be returned after a database insert.
"""
return [
field for field in self._get_fields(forward=True, reverse=False, include_parents=PROXY_PARENTS)
if getattr... | [
"def",
"db_returning_fields",
"(",
"self",
")",
":",
"return",
"[",
"field",
"for",
"field",
"in",
"self",
".",
"_get_fields",
"(",
"forward",
"=",
"True",
",",
"reverse",
"=",
"False",
",",
"include_parents",
"=",
"PROXY_PARENTS",
")",
"if",
"getattr",
"(... | [
846,
4
] | [
854,
9
] | python | en | ['en', 'error', 'th'] | False |
NestedObjectsTests.test_on_delete_do_nothing | (self) |
Check that the nested collector doesn't query for DO_NOTHING objects.
|
Check that the nested collector doesn't query for DO_NOTHING objects.
| def test_on_delete_do_nothing(self):
"""
Check that the nested collector doesn't query for DO_NOTHING objects.
"""
n = NestedObjects(using=DEFAULT_DB_ALIAS)
objs = [Event.objects.create()]
EventGuide.objects.create(event=objs[0])
with self.assertNumQueries(2):
... | [
"def",
"test_on_delete_do_nothing",
"(",
"self",
")",
":",
"n",
"=",
"NestedObjects",
"(",
"using",
"=",
"DEFAULT_DB_ALIAS",
")",
"objs",
"=",
"[",
"Event",
".",
"objects",
".",
"create",
"(",
")",
"]",
"EventGuide",
".",
"objects",
".",
"create",
"(",
"... | [
71,
4
] | [
80,
27
] | python | en | ['en', 'error', 'th'] | False |
NestedObjectsTests.test_relation_on_abstract | (self) |
#21846 -- Check that `NestedObjects.collect()` doesn't trip
(AttributeError) on the special notation for relations on abstract
models (related_name that contains %(app_label)s and/or %(class)s).
|
#21846 -- Check that `NestedObjects.collect()` doesn't trip
(AttributeError) on the special notation for relations on abstract
models (related_name that contains %(app_label)s and/or %(class)s).
| def test_relation_on_abstract(self):
"""
#21846 -- Check that `NestedObjects.collect()` doesn't trip
(AttributeError) on the special notation for relations on abstract
models (related_name that contains %(app_label)s and/or %(class)s).
"""
n = NestedObjects(using=DEFAULT_... | [
"def",
"test_relation_on_abstract",
"(",
"self",
")",
":",
"n",
"=",
"NestedObjects",
"(",
"using",
"=",
"DEFAULT_DB_ALIAS",
")",
"Car",
".",
"objects",
".",
"create",
"(",
")",
"n",
".",
"collect",
"(",
"[",
"Vehicle",
".",
"objects",
".",
"first",
"(",... | [
82,
4
] | [
90,
44
] | python | en | ['en', 'error', 'th'] | False |
UtilTests.test_values_from_lookup_field | (self) |
Regression test for #12654: lookup_field
|
Regression test for #12654: lookup_field
| def test_values_from_lookup_field(self):
"""
Regression test for #12654: lookup_field
"""
SITE_NAME = 'example.com'
TITLE_TEXT = 'Some title'
CREATED_DATE = datetime.min
ADMIN_METHOD = 'admin method'
SIMPLE_FUNCTION = 'function'
INSTANCE_ATTRIBUTE ... | [
"def",
"test_values_from_lookup_field",
"(",
"self",
")",
":",
"SITE_NAME",
"=",
"'example.com'",
"TITLE_TEXT",
"=",
"'Some title'",
"CREATED_DATE",
"=",
"datetime",
".",
"min",
"ADMIN_METHOD",
"=",
"'admin method'",
"SIMPLE_FUNCTION",
"=",
"'function'",
"INSTANCE_ATTRI... | [
94,
4
] | [
136,
51
] | python | en | ['en', 'error', 'th'] | False |
UtilTests.test_null_display_for_field | (self) |
Regression test for #12550: display_for_field should handle None
value.
|
Regression test for #12550: display_for_field should handle None
value.
| def test_null_display_for_field(self):
"""
Regression test for #12550: display_for_field should handle None
value.
"""
display_value = display_for_field(None, models.CharField())
self.assertEqual(display_value, EMPTY_CHANGELIST_VALUE)
display_value = display_for_... | [
"def",
"test_null_display_for_field",
"(",
"self",
")",
":",
"display_value",
"=",
"display_for_field",
"(",
"None",
",",
"models",
".",
"CharField",
"(",
")",
")",
"self",
".",
"assertEqual",
"(",
"display_value",
",",
"EMPTY_CHANGELIST_VALUE",
")",
"display_valu... | [
138,
4
] | [
169,
63
] | python | en | ['en', 'error', 'th'] | False |
UtilTests.test_label_for_field | (self) |
Tests for label_for_field
|
Tests for label_for_field
| def test_label_for_field(self):
"""
Tests for label_for_field
"""
self.assertEqual(
label_for_field("title", Article),
"title"
)
self.assertEqual(
label_for_field("title2", Article),
"another name"
)
self.ass... | [
"def",
"test_label_for_field",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"label_for_field",
"(",
"\"title\"",
",",
"Article",
")",
",",
"\"title\"",
")",
"self",
".",
"assertEqual",
"(",
"label_for_field",
"(",
"\"title2\"",
",",
"Article",
")",
... | [
171,
4
] | [
245,
9
] | python | en | ['en', 'error', 'th'] | False |
UtilTests.test_related_name | (self) |
Regression test for #13963
|
Regression test for #13963
| def test_related_name(self):
"""
Regression test for #13963
"""
self.assertEqual(
label_for_field('location', Event, return_attr=True),
('location', None),
)
self.assertEqual(
label_for_field('event', Location, return_attr=True),
... | [
"def",
"test_related_name",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"label_for_field",
"(",
"'location'",
",",
"Event",
",",
"return_attr",
"=",
"True",
")",
",",
"(",
"'location'",
",",
"None",
")",
",",
")",
"self",
".",
"assertEqual",
... | [
261,
4
] | [
276,
9
] | python | en | ['en', 'error', 'th'] | False |
UtilTests.test_logentry_unicode | (self) |
Regression test for #15661
|
Regression test for #15661
| def test_logentry_unicode(self):
"""
Regression test for #15661
"""
log_entry = admin.models.LogEntry()
log_entry.action_flag = admin.models.ADDITION
self.assertTrue(
six.text_type(log_entry).startswith('Added ')
)
log_entry.action_flag = adm... | [
"def",
"test_logentry_unicode",
"(",
"self",
")",
":",
"log_entry",
"=",
"admin",
".",
"models",
".",
"LogEntry",
"(",
")",
"log_entry",
".",
"action_flag",
"=",
"admin",
".",
"models",
".",
"ADDITION",
"self",
".",
"assertTrue",
"(",
"six",
".",
"text_typ... | [
278,
4
] | [
301,
69
] | python | en | ['en', 'error', 'th'] | False |
UtilTests.test_flatten_fieldsets | (self) |
Regression test for #18051
|
Regression test for #18051
| def test_flatten_fieldsets(self):
"""
Regression test for #18051
"""
fieldsets = (
(None, {
'fields': ('url', 'title', ('content', 'sites'))
}),
)
self.assertEqual(flatten_fieldsets(fieldsets), ['url', 'title', 'content', 'sites'])
... | [
"def",
"test_flatten_fieldsets",
"(",
"self",
")",
":",
"fieldsets",
"=",
"(",
"(",
"None",
",",
"{",
"'fields'",
":",
"(",
"'url'",
",",
"'title'",
",",
"(",
"'content'",
",",
"'sites'",
")",
")",
"}",
")",
",",
")",
"self",
".",
"assertEqual",
"(",... | [
337,
4
] | [
353,
92
] | python | en | ['en', 'error', 'th'] | False |
ReservationSerializer.get_extra_fields | (self, includes, context) | Define extra fields that can be included via query parameters. Method from ExtraDataMixin. | Define extra fields that can be included via query parameters. Method from ExtraDataMixin. | def get_extra_fields(self, includes, context):
from .resource import ResourceInlineSerializer
""" Define extra fields that can be included via query parameters. Method from ExtraDataMixin."""
extra_fields = {}
if 'resource_detail' in includes:
extra_fields['resource'] = Reso... | [
"def",
"get_extra_fields",
"(",
"self",
",",
"includes",
",",
"context",
")",
":",
"from",
".",
"resource",
"import",
"ResourceInlineSerializer",
"extra_fields",
"=",
"{",
"}",
"if",
"'resource_detail'",
"in",
"includes",
":",
"extra_fields",
"[",
"'resource'",
... | [
151,
4
] | [
158,
27
] | python | en | ['en', 'en', 'en'] | True |
ReservationFilterSet.filter_reserver_info_search | (self, queryset, name, value) |
A partial copy of rest_framework.filters.SearchFilter.filter_queryset.
Needed due to custom filters applied to queryset within this ReservationFilterSet.
Does not support comma separation of values, i.e. '?reserver_info_search=foo,bar' will
be considered as one string - 'foo,bar'.
... |
A partial copy of rest_framework.filters.SearchFilter.filter_queryset.
Needed due to custom filters applied to queryset within this ReservationFilterSet. | def filter_reserver_info_search(self, queryset, name, value):
"""
A partial copy of rest_framework.filters.SearchFilter.filter_queryset.
Needed due to custom filters applied to queryset within this ReservationFilterSet.
Does not support comma separation of values, i.e. '?reserver_info_s... | [
"def",
"filter_reserver_info_search",
"(",
"self",
",",
"queryset",
",",
"name",
",",
"value",
")",
":",
"if",
"not",
"value",
":",
"return",
"queryset",
"fields",
"=",
"(",
"'user__first_name'",
",",
"'user__last_name'",
",",
"'user__email'",
")",
"conditions",... | [
530,
4
] | [
558,
64
] | python | en | ['en', 'error', 'th'] | False |
api_opbeat_webhook | (
request: HttpRequest,
user_profile: UserProfile,
payload: Dict[str, Any] = REQ(argument_type="body"),
) |
This uses the subject name from opbeat to make the subject,
and the summary from Opbeat as the message body, with
details about the object mentioned.
|
This uses the subject name from opbeat to make the subject,
and the summary from Opbeat as the message body, with
details about the object mentioned.
| def api_opbeat_webhook(
request: HttpRequest,
user_profile: UserProfile,
payload: Dict[str, Any] = REQ(argument_type="body"),
) -> HttpResponse:
"""
This uses the subject name from opbeat to make the subject,
and the summary from Opbeat as the message body, with
details about the object ment... | [
"def",
"api_opbeat_webhook",
"(",
"request",
":",
"HttpRequest",
",",
"user_profile",
":",
"UserProfile",
",",
"payload",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
"=",
"REQ",
"(",
"argument_type",
"=",
"\"body\"",
")",
",",
")",
"->",
"HttpResponse",
":",... | [
100,
0
] | [
116,
25
] | python | en | ['en', 'error', 'th'] | False |
Loader.load_template_source | (self, template_name, template_dirs=None) |
Loads templates from Python eggs via pkg_resource.resource_string.
For every installed app, it tries to get the resource (app, template_name).
|
Loads templates from Python eggs via pkg_resource.resource_string. | def load_template_source(self, template_name, template_dirs=None):
"""
Loads templates from Python eggs via pkg_resource.resource_string.
For every installed app, it tries to get the resource (app, template_name).
"""
if resource_string is not None:
pkg_name = 'templ... | [
"def",
"load_template_source",
"(",
"self",
",",
"template_name",
",",
"template_dirs",
"=",
"None",
")",
":",
"if",
"resource_string",
"is",
"not",
"None",
":",
"pkg_name",
"=",
"'templates/'",
"+",
"template_name",
"for",
"app_config",
"in",
"apps",
".",
"ge... | [
18,
4
] | [
34,
49
] | python | en | ['en', 'error', 'th'] | False |
HerokuCore.authenticate | (self, api_key) | Logs user into Heroku with given api_key. | Logs user into Heroku with given api_key. | def authenticate(self, api_key):
"""Logs user into Heroku with given api_key."""
self._api_key = api_key
# Attach auth to session.
self._session.auth = ('', self._api_key)
return self._verify_api_key() | [
"def",
"authenticate",
"(",
"self",
",",
"api_key",
")",
":",
"self",
".",
"_api_key",
"=",
"api_key",
"# Attach auth to session.",
"self",
".",
"_session",
".",
"auth",
"=",
"(",
"''",
",",
"self",
".",
"_api_key",
")",
"return",
"self",
".",
"_verify_api... | [
39,
4
] | [
46,
37
] | python | en | ['en', 'ceb', 'en'] | True |
HerokuCore._resource_serialize | (o) | Returns JSON serialization of given object. | Returns JSON serialization of given object. | def _resource_serialize(o):
"""Returns JSON serialization of given object."""
return json.dumps(o) | [
"def",
"_resource_serialize",
"(",
"o",
")",
":",
"return",
"json",
".",
"dumps",
"(",
"o",
")"
] | [
77,
4
] | [
79,
28
] | python | en | ['en', 'en', 'en'] | True |
HerokuCore._resource_deserialize | (s) | Returns dict deserialization of a given JSON string. | Returns dict deserialization of a given JSON string. | def _resource_deserialize(s):
"""Returns dict deserialization of a given JSON string."""
try:
return json.loads(s)
except ValueError:
raise ResponseError('The API Response was not valid.') | [
"def",
"_resource_deserialize",
"(",
"s",
")",
":",
"try",
":",
"return",
"json",
".",
"loads",
"(",
"s",
")",
"except",
"ValueError",
":",
"raise",
"ResponseError",
"(",
"'The API Response was not valid.'",
")"
] | [
82,
4
] | [
88,
66
] | python | en | ['en', 'en', 'en'] | True |
HerokuCore._http_resource | (self, method, resource, params=None, data=None) | Makes an HTTP request. | Makes an HTTP request. | def _http_resource(self, method, resource, params=None, data=None):
"""Makes an HTTP request."""
if not is_collection(resource):
resource = [resource]
url = self._url_for(*resource)
r = self._session.request(method, url, params=params, data=data)
if r.status_code =... | [
"def",
"_http_resource",
"(",
"self",
",",
"method",
",",
"resource",
",",
"params",
"=",
"None",
",",
"data",
"=",
"None",
")",
":",
"if",
"not",
"is_collection",
"(",
"resource",
")",
":",
"resource",
"=",
"[",
"resource",
"]",
"url",
"=",
"self",
... | [
90,
4
] | [
106,
16
] | python | en | ['en', 'en', 'en'] | True |
HerokuCore._get_resource | (self, resource, obj, params=None, **kwargs) | Returns a mapped object from an HTTP resource. | Returns a mapped object from an HTTP resource. | def _get_resource(self, resource, obj, params=None, **kwargs):
"""Returns a mapped object from an HTTP resource."""
r = self._http_resource('GET', resource, params=params)
item = self._resource_deserialize(r.content)
return obj.new_from_dict(item, h=self, **kwargs) | [
"def",
"_get_resource",
"(",
"self",
",",
"resource",
",",
"obj",
",",
"params",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"r",
"=",
"self",
".",
"_http_resource",
"(",
"'GET'",
",",
"resource",
",",
"params",
"=",
"params",
")",
"item",
"=",
... | [
108,
4
] | [
113,
56
] | python | en | ['en', 'en', 'en'] | True |
HerokuCore._get_resources | (self, resource, obj, params=None, map=None, **kwargs) | Returns a list of mapped objects from an HTTP resource. | Returns a list of mapped objects from an HTTP resource. | def _get_resources(self, resource, obj, params=None, map=None, **kwargs):
"""Returns a list of mapped objects from an HTTP resource."""
r = self._http_resource('GET', resource, params=params)
d_items = self._resource_deserialize(r.content)
items = [obj.new_from_dict(item, h=self, **kwa... | [
"def",
"_get_resources",
"(",
"self",
",",
"resource",
",",
"obj",
",",
"params",
"=",
"None",
",",
"map",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"r",
"=",
"self",
".",
"_http_resource",
"(",
"'GET'",
",",
"resource",
",",
"params",
"=",
"... | [
115,
4
] | [
130,
28
] | python | en | ['en', 'en', 'en'] | True |
ASGIHandler.__call__ | (self, scope, receive, send) |
Async entrypoint - parses the request and hands off to get_response.
|
Async entrypoint - parses the request and hands off to get_response.
| async def __call__(self, scope, receive, send):
"""
Async entrypoint - parses the request and hands off to get_response.
"""
# Serve only HTTP connections.
# FIXME: Allow to override this.
if scope['type'] != 'http':
raise ValueError(
'Django c... | [
"async",
"def",
"__call__",
"(",
"self",
",",
"scope",
",",
"receive",
",",
"send",
")",
":",
"# Serve only HTTP connections.",
"# FIXME: Allow to override this.",
"if",
"scope",
"[",
"'type'",
"]",
"!=",
"'http'",
":",
"raise",
"ValueError",
"(",
"'Django can onl... | [
136,
4
] | [
172,
48
] | python | en | ['en', 'error', 'th'] | False |
ASGIHandler.read_body | (self, receive) | Reads a HTTP body from an ASGI connection. | Reads a HTTP body from an ASGI connection. | async def read_body(self, receive):
"""Reads a HTTP body from an ASGI connection."""
# Use the tempfile that auto rolls-over to a disk file as it fills up.
body_file = tempfile.SpooledTemporaryFile(max_size=settings.FILE_UPLOAD_MAX_MEMORY_SIZE, mode='w+b')
while True:
message... | [
"async",
"def",
"read_body",
"(",
"self",
",",
"receive",
")",
":",
"# Use the tempfile that auto rolls-over to a disk file as it fills up.",
"body_file",
"=",
"tempfile",
".",
"SpooledTemporaryFile",
"(",
"max_size",
"=",
"settings",
".",
"FILE_UPLOAD_MAX_MEMORY_SIZE",
","... | [
174,
4
] | [
190,
24
] | python | en | ['en', 'en', 'en'] | True |
ASGIHandler.create_request | (self, scope, body_file) |
Create the Request object and returns either (request, None) or
(None, response) if there is an error response.
|
Create the Request object and returns either (request, None) or
(None, response) if there is an error response.
| def create_request(self, scope, body_file):
"""
Create the Request object and returns either (request, None) or
(None, response) if there is an error response.
"""
try:
return self.request_class(scope, body_file), None
except UnicodeDecodeError:
lo... | [
"def",
"create_request",
"(",
"self",
",",
"scope",
",",
"body_file",
")",
":",
"try",
":",
"return",
"self",
".",
"request_class",
"(",
"scope",
",",
"body_file",
")",
",",
"None",
"except",
"UnicodeDecodeError",
":",
"logger",
".",
"warning",
"(",
"'Bad ... | [
192,
4
] | [
207,
74
] | python | en | ['en', 'error', 'th'] | False |
ASGIHandler.handle_uncaught_exception | (self, request, resolver, exc_info) | Last-chance handler for exceptions. | Last-chance handler for exceptions. | def handle_uncaught_exception(self, request, resolver, exc_info):
"""Last-chance handler for exceptions."""
# There's no WSGI server to catch the exception further up
# if this fails, so translate it into a plain text response.
try:
return super().handle_uncaught_exception(re... | [
"def",
"handle_uncaught_exception",
"(",
"self",
",",
"request",
",",
"resolver",
",",
"exc_info",
")",
":",
"# There's no WSGI server to catch the exception further up",
"# if this fails, so translate it into a plain text response.",
"try",
":",
"return",
"super",
"(",
")",
... | [
209,
4
] | [
219,
13
] | python | en | ['da', 'en', 'en'] | True |
ASGIHandler.send_response | (self, response, send) | Encode and send a response out over ASGI. | Encode and send a response out over ASGI. | async def send_response(self, response, send):
"""Encode and send a response out over ASGI."""
# Collect cookies into headers. Have to preserve header case as there
# are some non-RFC compliant clients that require e.g. Content-Type.
response_headers = []
for header, value in res... | [
"async",
"def",
"send_response",
"(",
"self",
",",
"response",
",",
"send",
")",
":",
"# Collect cookies into headers. Have to preserve header case as there",
"# are some non-RFC compliant clients that require e.g. Content-Type.",
"response_headers",
"=",
"[",
"]",
"for",
"header... | [
221,
4
] | [
266,
24
] | python | en | ['en', 'en', 'en'] | True |
ASGIHandler.chunk_bytes | (cls, data) |
Chunks some data up so it can be sent in reasonable size messages.
Yields (chunk, last_chunk) tuples.
|
Chunks some data up so it can be sent in reasonable size messages.
Yields (chunk, last_chunk) tuples.
| def chunk_bytes(cls, data):
"""
Chunks some data up so it can be sent in reasonable size messages.
Yields (chunk, last_chunk) tuples.
"""
position = 0
if not data:
yield data, True
return
while position < len(data):
yield (
... | [
"def",
"chunk_bytes",
"(",
"cls",
",",
"data",
")",
":",
"position",
"=",
"0",
"if",
"not",
"data",
":",
"yield",
"data",
",",
"True",
"return",
"while",
"position",
"<",
"len",
"(",
"data",
")",
":",
"yield",
"(",
"data",
"[",
"position",
":",
"po... | [
269,
4
] | [
283,
38
] | python | en | ['en', 'error', 'th'] | False |
ASGIHandler.get_script_prefix | (self, scope) |
Return the script prefix to use from either the scope or a setting.
|
Return the script prefix to use from either the scope or a setting.
| def get_script_prefix(self, scope):
"""
Return the script prefix to use from either the scope or a setting.
"""
if settings.FORCE_SCRIPT_NAME:
return settings.FORCE_SCRIPT_NAME
return scope.get('root_path', '') or '' | [
"def",
"get_script_prefix",
"(",
"self",
",",
"scope",
")",
":",
"if",
"settings",
".",
"FORCE_SCRIPT_NAME",
":",
"return",
"settings",
".",
"FORCE_SCRIPT_NAME",
"return",
"scope",
".",
"get",
"(",
"'root_path'",
",",
"''",
")",
"or",
"''"
] | [
285,
4
] | [
291,
47
] | python | en | ['en', 'error', 'th'] | False |
requires_to_requires_dist | (requirement) | Return the version specifier for a requirement in PEP 345/566 fashion. | Return the version specifier for a requirement in PEP 345/566 fashion. | def requires_to_requires_dist(requirement):
"""Return the version specifier for a requirement in PEP 345/566 fashion."""
if getattr(requirement, 'url', None):
return " @ " + requirement.url
requires_dist = []
for op, ver in requirement.specs:
requires_dist.append(op + ver)
if not re... | [
"def",
"requires_to_requires_dist",
"(",
"requirement",
")",
":",
"if",
"getattr",
"(",
"requirement",
",",
"'url'",
",",
"None",
")",
":",
"return",
"\" @ \"",
"+",
"requirement",
".",
"url",
"requires_dist",
"=",
"[",
"]",
"for",
"op",
",",
"ver",
"in",
... | [
17,
0
] | [
27,
52
] | python | en | ['en', 'en', 'en'] | True |
convert_requirements | (requirements) | Yield Requires-Dist: strings for parsed requirements strings. | Yield Requires-Dist: strings for parsed requirements strings. | def convert_requirements(requirements):
"""Yield Requires-Dist: strings for parsed requirements strings."""
for req in requirements:
parsed_requirement = pkg_resources.Requirement.parse(req)
spec = requires_to_requires_dist(parsed_requirement)
extras = ",".join(sorted(parsed_requirement.... | [
"def",
"convert_requirements",
"(",
"requirements",
")",
":",
"for",
"req",
"in",
"requirements",
":",
"parsed_requirement",
"=",
"pkg_resources",
".",
"Requirement",
".",
"parse",
"(",
"req",
")",
"spec",
"=",
"requires_to_requires_dist",
"(",
"parsed_requirement",... | [
30,
0
] | [
38,
63
] | python | en | ['en', 'en', 'en'] | True |
generate_requirements | (extras_require) |
Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
and ('Provides-Extra', 'extra') tuples.
extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
using the empty extra {'': [requirements]} to hold install_requires.
|
Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
and ('Provides-Extra', 'extra') tuples. | def generate_requirements(extras_require):
"""
Convert requirements from a setup()-style dictionary to ('Requires-Dist', 'requirement')
and ('Provides-Extra', 'extra') tuples.
extras_require is a dictionary of {extra: [requirements]} as passed to setup(),
using the empty extra {'': [requirements]} ... | [
"def",
"generate_requirements",
"(",
"extras_require",
")",
":",
"for",
"extra",
",",
"depends",
"in",
"extras_require",
".",
"items",
"(",
")",
":",
"condition",
"=",
"''",
"extra",
"=",
"extra",
"or",
"''",
"if",
"':'",
"in",
"extra",
":",
"# setuptools ... | [
41,
0
] | [
66,
54
] | python | en | ['en', 'error', 'th'] | False |
pkginfo_to_metadata | (egg_info_path, pkginfo_path) |
Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
|
Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
| def pkginfo_to_metadata(egg_info_path, pkginfo_path):
"""
Convert .egg-info directory with PKG-INFO to the Metadata 2.1 format
"""
pkg_info = read_pkg_info(pkginfo_path)
pkg_info.replace_header('Metadata-Version', '2.1')
# Those will be regenerated from `requires.txt`.
del pkg_info['Provides... | [
"def",
"pkginfo_to_metadata",
"(",
"egg_info_path",
",",
"pkginfo_path",
")",
":",
"pkg_info",
"=",
"read_pkg_info",
"(",
"pkginfo_path",
")",
"pkg_info",
".",
"replace_header",
"(",
"'Metadata-Version'",
",",
"'2.1'",
")",
"# Those will be regenerated from `requires.txt`... | [
69,
0
] | [
95,
19
] | python | en | ['en', 'error', 'th'] | False |
pkginfo_unicode | (pkg_info, field) | Hack to coax Unicode out of an email Message() - Python 3.3+ | Hack to coax Unicode out of an email Message() - Python 3.3+ | def pkginfo_unicode(pkg_info, field):
"""Hack to coax Unicode out of an email Message() - Python 3.3+"""
text = pkg_info[field]
field = field.lower()
if not isinstance(text, str):
for item in pkg_info.raw_items():
if item[0].lower() == field:
text = item[1].encode('as... | [
"def",
"pkginfo_unicode",
"(",
"pkg_info",
",",
"field",
")",
":",
"text",
"=",
"pkg_info",
"[",
"field",
"]",
"field",
"=",
"field",
".",
"lower",
"(",
")",
"if",
"not",
"isinstance",
"(",
"text",
",",
"str",
")",
":",
"for",
"item",
"in",
"pkg_info... | [
98,
0
] | [
109,
15
] | python | en | ['en', 'en', 'en'] | True |
dedent_description | (pkg_info) |
Dedent and convert pkg_info['Description'] to Unicode.
|
Dedent and convert pkg_info['Description'] to Unicode.
| def dedent_description(pkg_info):
"""
Dedent and convert pkg_info['Description'] to Unicode.
"""
description = pkg_info['Description']
# Python 3 Unicode handling, sorta.
surrogates = False
if not isinstance(description, str):
surrogates = True
description = pkginfo_unicode(... | [
"def",
"dedent_description",
"(",
"pkg_info",
")",
":",
"description",
"=",
"pkg_info",
"[",
"'Description'",
"]",
"# Python 3 Unicode handling, sorta.",
"surrogates",
"=",
"False",
"if",
"not",
"isinstance",
"(",
"description",
",",
"str",
")",
":",
"surrogates",
... | [
112,
0
] | [
137,
29
] | python | en | ['en', 'error', 'th'] | False |
as_utc | (instant) |
Convert a datetime to UTC.
:param instant: The datetime to convert
:return: Datetime in UTC.
|
Convert a datetime to UTC. | def as_utc(instant):
"""
Convert a datetime to UTC.
:param instant: The datetime to convert
:return: Datetime in UTC.
"""
if instant.tzinfo:
return instant.astimezone(utc)
return utc.localize(instant) | [
"def",
"as_utc",
"(",
"instant",
")",
":",
"if",
"instant",
".",
"tzinfo",
":",
"return",
"instant",
".",
"astimezone",
"(",
"utc",
")",
"return",
"utc",
".",
"localize",
"(",
"instant",
")"
] | [
5,
0
] | [
14,
32
] | python | en | ['en', 'error', 'th'] | False |
format_date_for_xml | (instant) |
Format a date in the format expected by EWS (ISO 8601, zulu time)
:param instant: The date to format
:return: Formatted string
:rtype: str
|
Format a date in the format expected by EWS (ISO 8601, zulu time) | def format_date_for_xml(instant):
"""
Format a date in the format expected by EWS (ISO 8601, zulu time)
:param instant: The date to format
:return: Formatted string
:rtype: str
"""
return as_utc(instant).strftime(EXCHANGE_DATETIME_FORMAT) | [
"def",
"format_date_for_xml",
"(",
"instant",
")",
":",
"return",
"as_utc",
"(",
"instant",
")",
".",
"strftime",
"(",
"EXCHANGE_DATETIME_FORMAT",
")"
] | [
17,
0
] | [
25,
61
] | python | en | ['en', 'error', 'th'] | False |
cli | (ctx, mpy, skip_checks=False) | CLI Application for creating/managing Micropython Projects. | CLI Application for creating/managing Micropython Projects. | def cli(ctx, mpy, skip_checks=False):
"""CLI Application for creating/managing Micropython Projects."""
if ctx.invoked_subcommand is None:
if not mpy.project.exists:
return click.echo(ctx.get_help())
latest = utils.is_update_available()
if latest:
log = Log.get_logger("MicroP... | [
"def",
"cli",
"(",
"ctx",
",",
"mpy",
",",
"skip_checks",
"=",
"False",
")",
":",
"if",
"ctx",
".",
"invoked_subcommand",
"is",
"None",
":",
"if",
"not",
"mpy",
".",
"project",
".",
"exists",
":",
"return",
"click",
".",
"echo",
"(",
"ctx",
".",
"g... | [
29,
0
] | [
40,
36
] | python | en | ['en', 'en', 'en'] | True |
stubs | () | Manage Micropy Stubs.
\b
Stub files are what enable linting,
Intellisense, Autocompletion, and more.
\b
To achieve the best results, you can install
stubs specific to your device/firmware using:
micropy stubs add <STUB_NAME>
For more info, please check micropy stubs add --help
... | Manage Micropy Stubs. | def stubs():
"""Manage Micropy Stubs.
\b
Stub files are what enable linting,
Intellisense, Autocompletion, and more.
\b
To achieve the best results, you can install
stubs specific to your device/firmware using:
micropy stubs add <STUB_NAME>
For more info, please check micropy... | [
"def",
"stubs",
"(",
")",
":"
] | [
44,
0
] | [
59,
7
] | python | en | ['en', 'en', 'en'] | True |
init | (mpy, path, name=None, template=None) | Create new Micropython Project.
\b When creating a new project, all files will be placed under the
generated <PROJECT_NAME> folder.
| Create new Micropython Project. | def init(mpy, path, name=None, template=None):
"""Create new Micropython Project.
\b When creating a new project, all files will be placed under the
generated <PROJECT_NAME> folder.
"""
mpy.log.title("Creating New Project")
if not path:
path = Path.cwd()
default_name = path.nam... | [
"def",
"init",
"(",
"mpy",
",",
"path",
",",
"name",
"=",
"None",
",",
"template",
"=",
"None",
")",
":",
"mpy",
".",
"log",
".",
"title",
"(",
"\"Creating New Project\"",
")",
"if",
"not",
"path",
":",
"path",
"=",
"Path",
".",
"cwd",
"(",
")",
... | [
76,
0
] | [
109,
66
] | python | en | ['en', 'en', 'en'] | True |
install | (mpy, packages, dev=False, path=None) | Install Packages as Project Requirements.
\b
Install a project dependency while enabling
intellisense, autocompletion, and linting for it.
\b
If no packages are passed and a requirements.txt file is found,
then micropy will install all packages listed in it.
\b
If the --dev flag is pa... | Install Packages as Project Requirements. | def install(mpy, packages, dev=False, path=None):
"""Install Packages as Project Requirements.
\b
Install a project dependency while enabling
intellisense, autocompletion, and linting for it.
\b
If no packages are passed and a requirements.txt file is found,
then micropy will install all p... | [
"def",
"install",
"(",
"mpy",
",",
"packages",
",",
"dev",
"=",
"False",
",",
"path",
"=",
"None",
")",
":",
"project",
"=",
"mpy",
".",
"project",
"if",
"not",
"project",
".",
"exists",
":",
"mpy",
".",
"log",
".",
"error",
"(",
"\"You are not curre... | [
124,
0
] | [
183,
31
] | python | en | ['en', 'en', 'en'] | True |
add | (mpy, stub_name, force=False) | Add Stubs from package or path.
\b
In general, stub package names follow this schema:
<device>-<firmware>-<version>
\b
For example:
esp32-micropython-1.11.0
\b
You can search premade stub packages using:
micropy stubs search <QUERY>
Checkout the docs on Github for... | Add Stubs from package or path. | def add(mpy, stub_name, force=False):
"""Add Stubs from package or path.
\b
In general, stub package names follow this schema:
<device>-<firmware>-<version>
\b
For example:
esp32-micropython-1.11.0
\b
You can search premade stub packages using:
micropy stubs search... | [
"def",
"add",
"(",
"mpy",
",",
"stub_name",
",",
"force",
"=",
"False",
")",
":",
"mpy",
".",
"stubs",
".",
"verbose_log",
"(",
"True",
")",
"proj",
"=",
"mpy",
".",
"project",
"mpy",
".",
"log",
".",
"title",
"(",
"f\"Adding $[{stub_name}] to stubs\"",
... | [
190,
0
] | [
222,
31
] | python | en | ['en', 'en', 'en'] | True |
search | (mpy, query) | Search available Stubs. | Search available Stubs. | def search(mpy, query):
"""Search available Stubs."""
mpy.log.title(f"Searching Stub Repositories...")
results = mpy.stubs.search_remote(query)
mpy.log.title(f"Results for $[{query}]:")
for pkg, installed in results:
name = f"{pkg} $B[(Installed)]" if installed else pkg
mpy.log.info(... | [
"def",
"search",
"(",
"mpy",
",",
"query",
")",
":",
"mpy",
".",
"log",
".",
"title",
"(",
"f\"Searching Stub Repositories...\"",
")",
"results",
"=",
"mpy",
".",
"stubs",
".",
"search_remote",
"(",
"query",
")",
"mpy",
".",
"log",
".",
"title",
"(",
"... | [
228,
0
] | [
235,
26
] | python | en | ['en', 'en', 'en'] | True |
list | (mpy) | List installed stubs. | List installed stubs. | def list(mpy):
"""List installed stubs."""
def print_stubs(stub_list):
for firm, stubs in stub_list:
if stubs:
title = str(firm).capitalize()
mpy.log.title(f"$[{title}]:")
for stub in stubs:
mpy.log.info(str(stub))
mpy... | [
"def",
"list",
"(",
"mpy",
")",
":",
"def",
"print_stubs",
"(",
"stub_list",
")",
":",
"for",
"firm",
",",
"stubs",
"in",
"stub_list",
":",
"if",
"stubs",
":",
"title",
"=",
"str",
"(",
"firm",
")",
".",
"capitalize",
"(",
")",
"mpy",
".",
"log",
... | [
240,
0
] | [
260,
26
] | python | en | ['en', 'et', 'en'] | True |
create | (mpy, port, verbose=False) | Create stubs from a pyboard at <PORT>
\b
MicropyCli uses Josverl's micropython-stubber for stub creation.
For more information, please visit the repository
at: https://github.com/Josverl/micropython-stubber
| Create stubs from a pyboard at <PORT> | def create(mpy, port, verbose=False):
"""Create stubs from a pyboard at <PORT>
\b
MicropyCli uses Josverl's micropython-stubber for stub creation.
For more information, please visit the repository
at: https://github.com/Josverl/micropython-stubber
"""
if not utils.CREATE_STUBS_INSTALLED:
... | [
"def",
"create",
"(",
"mpy",
",",
"port",
",",
"verbose",
"=",
"False",
")",
":",
"if",
"not",
"utils",
".",
"CREATE_STUBS_INSTALLED",
":",
"mpy",
".",
"log",
".",
"error",
"(",
"\"\\nMissing requirements!\"",
")",
"mpy",
".",
"log",
".",
"info",
"(",
... | [
267,
0
] | [
286,
50
] | python | en | ['en', 'en', 'en'] | True |
TestFilenameGenerator.test_django_locales | (self) |
Test that gen_filenames() also yields the built-in django locale files.
|
Test that gen_filenames() also yields the built-in django locale files.
| def test_django_locales(self):
"""
Test that gen_filenames() also yields the built-in django locale files.
"""
filenames = list(gen_filenames())
self.assertIn(os.path.join(os.path.dirname(conf.__file__), 'locale',
'nl', 'LC_MESSAGES', 'django.mo... | [
"def",
"test_django_locales",
"(",
"self",
")",
":",
"filenames",
"=",
"list",
"(",
"gen_filenames",
"(",
")",
")",
"self",
".",
"assertIn",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"conf",
".",
"__file__",
")... | [
20,
4
] | [
27,
32
] | python | en | ['en', 'error', 'th'] | False |
TestFilenameGenerator.test_locale_paths_setting | (self) |
Test that gen_filenames also yields from LOCALE_PATHS locales.
|
Test that gen_filenames also yields from LOCALE_PATHS locales.
| def test_locale_paths_setting(self):
"""
Test that gen_filenames also yields from LOCALE_PATHS locales.
"""
filenames = list(gen_filenames())
self.assertIn(os.path.join(LOCALE_PATH, 'nl', 'LC_MESSAGES', 'django.mo'),
filenames) | [
"def",
"test_locale_paths_setting",
"(",
"self",
")",
":",
"filenames",
"=",
"list",
"(",
"gen_filenames",
"(",
")",
")",
"self",
".",
"assertIn",
"(",
"os",
".",
"path",
".",
"join",
"(",
"LOCALE_PATH",
",",
"'nl'",
",",
"'LC_MESSAGES'",
",",
"'django.mo'... | [
30,
4
] | [
36,
32
] | python | en | ['en', 'error', 'th'] | False |
TestFilenameGenerator.test_project_root_locale | (self) |
Test that gen_filenames also yields from the current directory (project
root).
|
Test that gen_filenames also yields from the current directory (project
root).
| def test_project_root_locale(self):
"""
Test that gen_filenames also yields from the current directory (project
root).
"""
old_cwd = os.getcwd()
os.chdir(os.path.dirname(__file__))
try:
filenames = list(gen_filenames())
self.assertIn(
... | [
"def",
"test_project_root_locale",
"(",
"self",
")",
":",
"old_cwd",
"=",
"os",
".",
"getcwd",
"(",
")",
"os",
".",
"chdir",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
")",
"try",
":",
"filenames",
"=",
"list",
"(",
"gen_filenames",
... | [
39,
4
] | [
52,
29
] | python | en | ['en', 'error', 'th'] | False |
TestFilenameGenerator.test_app_locales | (self) |
Test that gen_filenames also yields from locale dirs in installed apps.
|
Test that gen_filenames also yields from locale dirs in installed apps.
| def test_app_locales(self):
"""
Test that gen_filenames also yields from locale dirs in installed apps.
"""
filenames = list(gen_filenames())
self.assertIn(os.path.join(os.path.dirname(admin.__file__), 'locale',
'nl', 'LC_MESSAGES', 'django.mo')... | [
"def",
"test_app_locales",
"(",
"self",
")",
":",
"filenames",
"=",
"list",
"(",
"gen_filenames",
"(",
")",
")",
"self",
".",
"assertIn",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"admin",
".",
"__file__",
")",... | [
55,
4
] | [
62,
32
] | python | en | ['en', 'error', 'th'] | False |
TestFilenameGenerator.test_no_i18n | (self) |
If i18n machinery is disabled, there is no need for watching the
locale files.
|
If i18n machinery is disabled, there is no need for watching the
locale files.
| def test_no_i18n(self):
"""
If i18n machinery is disabled, there is no need for watching the
locale files.
"""
filenames = list(gen_filenames())
self.assertNotIn(
os.path.join(os.path.dirname(conf.__file__), 'locale', 'nl',
'LC_MESSAGE... | [
"def",
"test_no_i18n",
"(",
"self",
")",
":",
"filenames",
"=",
"list",
"(",
"gen_filenames",
"(",
")",
")",
"self",
".",
"assertNotIn",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"conf",
".",
"__file__",
")",
... | [
65,
4
] | [
74,
22
] | python | en | ['en', 'error', 'th'] | False |
TestFilenameGenerator.test_only_new_files | (self) |
When calling a second time gen_filenames with only_new = True, only
files from newly loaded modules should be given.
|
When calling a second time gen_filenames with only_new = True, only
files from newly loaded modules should be given.
| def test_only_new_files(self):
"""
When calling a second time gen_filenames with only_new = True, only
files from newly loaded modules should be given.
"""
list(gen_filenames())
from fractions import Fraction # NOQA
filenames2 = list(gen_filenames(only_new=True))... | [
"def",
"test_only_new_files",
"(",
"self",
")",
":",
"list",
"(",
"gen_filenames",
"(",
")",
")",
"from",
"fractions",
"import",
"Fraction",
"# NOQA",
"filenames2",
"=",
"list",
"(",
"gen_filenames",
"(",
"only_new",
"=",
"True",
")",
")",
"self",
".",
"as... | [
76,
4
] | [
86,
74
] | python | en | ['en', 'error', 'th'] | False |
samefile | (p1, p2) |
Determine if two paths reference the same file.
Augments os.path.samefile to work on Windows and
suppresses errors if the path doesn't exist.
|
Determine if two paths reference the same file. | def samefile(p1, p2):
"""
Determine if two paths reference the same file.
Augments os.path.samefile to work on Windows and
suppresses errors if the path doesn't exist.
"""
both_exist = os.path.exists(p1) and os.path.exists(p2)
use_samefile = hasattr(os.path, 'samefile') and both_exist
i... | [
"def",
"samefile",
"(",
"p1",
",",
"p2",
")",
":",
"both_exist",
"=",
"os",
".",
"path",
".",
"exists",
"(",
"p1",
")",
"and",
"os",
".",
"path",
".",
"exists",
"(",
"p2",
")",
"use_samefile",
"=",
"hasattr",
"(",
"os",
".",
"path",
",",
"'samefi... | [
82,
0
] | [
95,
29
] | python | en | ['en', 'error', 'th'] | False |
get_site_dirs | () |
Return a list of 'site' dirs
|
Return a list of 'site' dirs
| def get_site_dirs():
"""
Return a list of 'site' dirs
"""
sitedirs = []
# start with PYTHONPATH
sitedirs.extend(_pythonpath())
prefixes = [sys.prefix]
if sys.exec_prefix != sys.prefix:
prefixes.append(sys.exec_prefix)
for prefix in prefixes:
if prefix:
... | [
"def",
"get_site_dirs",
"(",
")",
":",
"sitedirs",
"=",
"[",
"]",
"# start with PYTHONPATH",
"sitedirs",
".",
"extend",
"(",
"_pythonpath",
"(",
")",
")",
"prefixes",
"=",
"[",
"sys",
".",
"prefix",
"]",
"if",
"sys",
".",
"exec_prefix",
"!=",
"sys",
".",... | [
1365,
0
] | [
1427,
19
] | python | en | ['en', 'error', 'th'] | False |
expand_paths | (inputs) | Yield sys.path directories that might contain "old-style" packages | Yield sys.path directories that might contain "old-style" packages | def expand_paths(inputs):
"""Yield sys.path directories that might contain "old-style" packages"""
seen = {}
for dirname in inputs:
dirname = normalize_path(dirname)
if dirname in seen:
continue
seen[dirname] = 1
if not os.path.isdir(dirname):
conti... | [
"def",
"expand_paths",
"(",
"inputs",
")",
":",
"seen",
"=",
"{",
"}",
"for",
"dirname",
"in",
"inputs",
":",
"dirname",
"=",
"normalize_path",
"(",
"dirname",
")",
"if",
"dirname",
"in",
"seen",
":",
"continue",
"seen",
"[",
"dirname",
"]",
"=",
"1",
... | [
1430,
0
] | [
1468,
52
] | python | en | ['en', 'en', 'en'] | True |
extract_wininst_cfg | (dist_filename) | Extract configuration data from a bdist_wininst .exe
Returns a configparser.RawConfigParser, or None
| Extract configuration data from a bdist_wininst .exe | def extract_wininst_cfg(dist_filename):
"""Extract configuration data from a bdist_wininst .exe
Returns a configparser.RawConfigParser, or None
"""
f = open(dist_filename, 'rb')
try:
endrec = zipfile._EndRecData(f)
if endrec is None:
return None
prepended = (end... | [
"def",
"extract_wininst_cfg",
"(",
"dist_filename",
")",
":",
"f",
"=",
"open",
"(",
"dist_filename",
",",
"'rb'",
")",
"try",
":",
"endrec",
"=",
"zipfile",
".",
"_EndRecData",
"(",
"f",
")",
"if",
"endrec",
"is",
"None",
":",
"return",
"None",
"prepend... | [
1471,
0
] | [
1509,
17
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.