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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
MigrationWriter.as_string | (self) | Return a string of the file contents. | Return a string of the file contents. | def as_string(self):
"""Return a string of the file contents."""
items = {
"replaces_str": "",
"initial_str": "",
}
imports = set()
# Deconstruct operations
operations = []
for operation in self.migration.operations:
operation... | [
"def",
"as_string",
"(",
"self",
")",
":",
"items",
"=",
"{",
"\"replaces_str\"",
":",
"\"\"",
",",
"\"initial_str\"",
":",
"\"\"",
",",
"}",
"imports",
"=",
"set",
"(",
")",
"# Deconstruct operations",
"operations",
"=",
"[",
"]",
"for",
"operation",
"in"... | [
128,
4
] | [
198,
41
] | python | en | ['en', 'en', 'en'] | True |
FrameSymbolVisitor.visit_Name | (self, node, store_as_param=False, **kwargs) | All assignments to names go through this function. | All assignments to names go through this function. | def visit_Name(self, node, store_as_param=False, **kwargs):
"""All assignments to names go through this function."""
if store_as_param or node.ctx == 'param':
self.symbols.declare_parameter(node.name)
elif node.ctx == 'store':
self.symbols.store(node.name)
elif no... | [
"def",
"visit_Name",
"(",
"self",
",",
"node",
",",
"store_as_param",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"store_as_param",
"or",
"node",
".",
"ctx",
"==",
"'param'",
":",
"self",
".",
"symbols",
".",
"declare_parameter",
"(",
"node",
... | [
208,
4
] | [
215,
40
] | python | en | ['en', 'en', 'en'] | True |
FrameSymbolVisitor.visit_Assign | (self, node, **kwargs) | Visit assignments in the correct order. | Visit assignments in the correct order. | def visit_Assign(self, node, **kwargs):
"""Visit assignments in the correct order."""
self.visit(node.node, **kwargs)
self.visit(node.target, **kwargs) | [
"def",
"visit_Assign",
"(",
"self",
",",
"node",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"visit",
"(",
"node",
".",
"node",
",",
"*",
"*",
"kwargs",
")",
"self",
".",
"visit",
"(",
"node",
".",
"target",
",",
"*",
"*",
"kwargs",
")"
] | [
253,
4
] | [
256,
41
] | python | en | ['en', 'en', 'en'] | True |
FrameSymbolVisitor.visit_For | (self, node, **kwargs) | Visiting stops at for blocks. However the block sequence
is visited as part of the outer scope.
| Visiting stops at for blocks. However the block sequence
is visited as part of the outer scope.
| def visit_For(self, node, **kwargs):
"""Visiting stops at for blocks. However the block sequence
is visited as part of the outer scope.
"""
self.visit(node.iter, **kwargs) | [
"def",
"visit_For",
"(",
"self",
",",
"node",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"visit",
"(",
"node",
".",
"iter",
",",
"*",
"*",
"kwargs",
")"
] | [
258,
4
] | [
262,
39
] | python | en | ['en', 'en', 'en'] | True |
FrameSymbolVisitor.visit_AssignBlock | (self, node, **kwargs) | Stop visiting at block assigns. | Stop visiting at block assigns. | def visit_AssignBlock(self, node, **kwargs):
"""Stop visiting at block assigns."""
self.visit(node.target, **kwargs) | [
"def",
"visit_AssignBlock",
"(",
"self",
",",
"node",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"visit",
"(",
"node",
".",
"target",
",",
"*",
"*",
"kwargs",
")"
] | [
274,
4
] | [
276,
41
] | python | en | ['en', 'fil', 'en'] | True |
FrameSymbolVisitor.visit_Scope | (self, node, **kwargs) | Stop visiting at scopes. | Stop visiting at scopes. | def visit_Scope(self, node, **kwargs):
"""Stop visiting at scopes.""" | [
"def",
"visit_Scope",
"(",
"self",
",",
"node",
",",
"*",
"*",
"kwargs",
")",
":"
] | [
278,
4
] | [
279,
38
] | python | en | ['en', 'fil', 'en'] | True |
FrameSymbolVisitor.visit_Block | (self, node, **kwargs) | Stop visiting at blocks. | Stop visiting at blocks. | def visit_Block(self, node, **kwargs):
"""Stop visiting at blocks.""" | [
"def",
"visit_Block",
"(",
"self",
",",
"node",
",",
"*",
"*",
"kwargs",
")",
":"
] | [
281,
4
] | [
282,
38
] | python | en | ['en', 'fil', 'en'] | True |
FrameSymbolVisitor.visit_OverlayScope | (self, node, **kwargs) | Do not visit into overlay scopes. | Do not visit into overlay scopes. | def visit_OverlayScope(self, node, **kwargs):
"""Do not visit into overlay scopes.""" | [
"def",
"visit_OverlayScope",
"(",
"self",
",",
"node",
",",
"*",
"*",
"kwargs",
")",
":"
] | [
284,
4
] | [
285,
47
] | python | en | ['en', 'en', 'en'] | True |
HashedFilesMixin.file_hash | (self, name, content=None) |
Return a hash of the file with the given name and optional content.
|
Return a hash of the file with the given name and optional content.
| def file_hash(self, name, content=None):
"""
Return a hash of the file with the given name and optional content.
"""
if content is None:
return None
md5 = hashlib.md5()
for chunk in content.chunks():
md5.update(chunk)
return md5.hexdigest()... | [
"def",
"file_hash",
"(",
"self",
",",
"name",
",",
"content",
"=",
"None",
")",
":",
"if",
"content",
"is",
"None",
":",
"return",
"None",
"md5",
"=",
"hashlib",
".",
"md5",
"(",
")",
"for",
"chunk",
"in",
"content",
".",
"chunks",
"(",
")",
":",
... | [
67,
4
] | [
76,
35
] | python | en | ['en', 'error', 'th'] | False |
HashedFilesMixin._url | (self, hashed_name_func, name, force=False, hashed_files=None) |
Return the non-hashed URL in DEBUG mode.
|
Return the non-hashed URL in DEBUG mode.
| def _url(self, hashed_name_func, name, force=False, hashed_files=None):
"""
Return the non-hashed URL in DEBUG mode.
"""
if settings.DEBUG and not force:
hashed_name, fragment = name, ''
else:
clean_name, fragment = urldefrag(name)
if urlsplit(... | [
"def",
"_url",
"(",
"self",
",",
"hashed_name_func",
",",
"name",
",",
"force",
"=",
"False",
",",
"hashed_files",
"=",
"None",
")",
":",
"if",
"settings",
".",
"DEBUG",
"and",
"not",
"force",
":",
"hashed_name",
",",
"fragment",
"=",
"name",
",",
"''"... | [
111,
4
] | [
140,
33
] | python | en | ['en', 'error', 'th'] | False |
HashedFilesMixin.url | (self, name, force=False) |
Return the non-hashed URL in DEBUG mode.
|
Return the non-hashed URL in DEBUG mode.
| def url(self, name, force=False):
"""
Return the non-hashed URL in DEBUG mode.
"""
return self._url(self.stored_name, name, force) | [
"def",
"url",
"(",
"self",
",",
"name",
",",
"force",
"=",
"False",
")",
":",
"return",
"self",
".",
"_url",
"(",
"self",
".",
"stored_name",
",",
"name",
",",
"force",
")"
] | [
142,
4
] | [
146,
55
] | python | en | ['en', 'error', 'th'] | False |
HashedFilesMixin.url_converter | (self, name, hashed_files, template=None) |
Return the custom URL converter for the given file name.
|
Return the custom URL converter for the given file name.
| def url_converter(self, name, hashed_files, template=None):
"""
Return the custom URL converter for the given file name.
"""
if template is None:
template = self.default_template
def converter(matchobj):
"""
Convert the matched URL to a normal... | [
"def",
"url_converter",
"(",
"self",
",",
"name",
",",
"hashed_files",
",",
"template",
"=",
"None",
")",
":",
"if",
"template",
"is",
"None",
":",
"template",
"=",
"self",
".",
"default_template",
"def",
"converter",
"(",
"matchobj",
")",
":",
"\"\"\"\n ... | [
148,
4
] | [
200,
24
] | python | en | ['en', 'error', 'th'] | False |
HashedFilesMixin.post_process | (self, paths, dry_run=False, **options) |
Post process the given dictionary of files (called from collectstatic).
Processing is actually two separate operations:
1. renaming files to include a hash of their content for cache-busting,
and copying those files to the target storage.
2. adjusting files which contain re... |
Post process the given dictionary of files (called from collectstatic). | def post_process(self, paths, dry_run=False, **options):
"""
Post process the given dictionary of files (called from collectstatic).
Processing is actually two separate operations:
1. renaming files to include a hash of their content for cache-busting,
and copying those file... | [
"def",
"post_process",
"(",
"self",
",",
"paths",
",",
"dry_run",
"=",
"False",
",",
"*",
"*",
"options",
")",
":",
"# don't even dare to process the files if we're in dry run mode",
"if",
"dry_run",
":",
"return",
"# where to store the new paths",
"hashed_files",
"=",
... | [
202,
4
] | [
248,
46
] | python | en | ['en', 'error', 'th'] | False |
Command.load_label | (self, fixture_label) | Load fixtures files for a given label. | Load fixtures files for a given label. | def load_label(self, fixture_label):
"""Load fixtures files for a given label."""
show_progress = self.verbosity >= 3
for fixture_file, fixture_dir, fixture_name in self.find_fixtures(fixture_label):
_, ser_fmt, cmp_fmt = self.parse_name(os.path.basename(fixture_file))
op... | [
"def",
"load_label",
"(",
"self",
",",
"fixture_label",
")",
":",
"show_progress",
"=",
"self",
".",
"verbosity",
">=",
"3",
"for",
"fixture_file",
",",
"fixture_dir",
",",
"fixture_name",
"in",
"self",
".",
"find_fixtures",
"(",
"fixture_label",
")",
":",
"... | [
158,
4
] | [
222,
17
] | python | en | ['en', 'en', 'en'] | True |
Command.find_fixtures | (self, fixture_label) | Find fixture files for a given label. | Find fixture files for a given label. | def find_fixtures(self, fixture_label):
"""Find fixture files for a given label."""
if fixture_label == READ_STDIN:
return [(READ_STDIN, None, READ_STDIN)]
fixture_name, ser_fmt, cmp_fmt = self.parse_name(fixture_label)
databases = [self.using, None]
cmp_fmts = list(... | [
"def",
"find_fixtures",
"(",
"self",
",",
"fixture_label",
")",
":",
"if",
"fixture_label",
"==",
"READ_STDIN",
":",
"return",
"[",
"(",
"READ_STDIN",
",",
"None",
",",
"READ_STDIN",
")",
"]",
"fixture_name",
",",
"ser_fmt",
",",
"cmp_fmt",
"=",
"self",
".... | [
225,
4
] | [
280,
28
] | python | en | ['en', 'en', 'en'] | True |
Command.fixture_dirs | (self) |
Return a list of fixture directories.
The list contains the 'fixtures' subdirectory of each installed
application, if it exists, the directories in FIXTURE_DIRS, and the
current directory.
|
Return a list of fixture directories. | def fixture_dirs(self):
"""
Return a list of fixture directories.
The list contains the 'fixtures' subdirectory of each installed
application, if it exists, the directories in FIXTURE_DIRS, and the
current directory.
"""
dirs = []
fixture_dirs = settings.... | [
"def",
"fixture_dirs",
"(",
"self",
")",
":",
"dirs",
"=",
"[",
"]",
"fixture_dirs",
"=",
"settings",
".",
"FIXTURE_DIRS",
"if",
"len",
"(",
"fixture_dirs",
")",
"!=",
"len",
"(",
"set",
"(",
"fixture_dirs",
")",
")",
":",
"raise",
"ImproperlyConfigured",
... | [
283,
4
] | [
310,
50
] | python | en | ['en', 'error', 'th'] | False |
Command.parse_name | (self, fixture_name) |
Split fixture name in name, serialization format, compression format.
|
Split fixture name in name, serialization format, compression format.
| def parse_name(self, fixture_name):
"""
Split fixture name in name, serialization format, compression format.
"""
if fixture_name == READ_STDIN:
if not self.format:
raise CommandError('--format must be specified when reading from stdin.')
return RE... | [
"def",
"parse_name",
"(",
"self",
",",
"fixture_name",
")",
":",
"if",
"fixture_name",
"==",
"READ_STDIN",
":",
"if",
"not",
"self",
".",
"format",
":",
"raise",
"CommandError",
"(",
"'--format must be specified when reading from stdin.'",
")",
"return",
"READ_STDIN... | [
312,
4
] | [
342,
37
] | python | en | ['en', 'error', 'th'] | False |
inject_rename_contenttypes_operations | (plan=None, apps=global_apps, using=DEFAULT_DB_ALIAS, **kwargs) |
Insert a `RenameContentType` operation after every planned `RenameModel`
operation.
|
Insert a `RenameContentType` operation after every planned `RenameModel`
operation.
| def inject_rename_contenttypes_operations(plan=None, apps=global_apps, using=DEFAULT_DB_ALIAS, **kwargs):
"""
Insert a `RenameContentType` operation after every planned `RenameModel`
operation.
"""
if plan is None:
return
# Determine whether or not the ContentType model is available.
... | [
"def",
"inject_rename_contenttypes_operations",
"(",
"plan",
"=",
"None",
",",
"apps",
"=",
"global_apps",
",",
"using",
"=",
"DEFAULT_DB_ALIAS",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"plan",
"is",
"None",
":",
"return",
"# Determine whether or not the ContentT... | [
45,
0
] | [
84,
68
] | python | en | ['en', 'error', 'th'] | False |
create_contenttypes | (app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, apps=global_apps, **kwargs) |
Create content types for models in the given app.
|
Create content types for models in the given app.
| def create_contenttypes(app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, apps=global_apps, **kwargs):
"""
Create content types for models in the given app.
"""
if not app_config.models_module:
return
app_label = app_config.label
try:
app_config = apps.get_app_c... | [
"def",
"create_contenttypes",
"(",
"app_config",
",",
"verbosity",
"=",
"2",
",",
"interactive",
"=",
"True",
",",
"using",
"=",
"DEFAULT_DB_ALIAS",
",",
"apps",
"=",
"global_apps",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"app_config",
".",
"models... | [
104,
0
] | [
134,
77
] | python | en | ['en', 'error', 'th'] | False |
EmailBackend._get_filename | (self) | Return a unique file name. | Return a unique file name. | def _get_filename(self):
"""Return a unique file name."""
if self._fname is None:
timestamp = datetime.datetime.now().strftime("%Y%m%d-%H%M%S")
fname = "%s-%s.log" % (timestamp, abs(id(self)))
self._fname = os.path.join(self.file_path, fname)
return self._fnam... | [
"def",
"_get_filename",
"(",
"self",
")",
":",
"if",
"self",
".",
"_fname",
"is",
"None",
":",
"timestamp",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
".",
"strftime",
"(",
"\"%Y%m%d-%H%M%S\"",
")",
"fname",
"=",
"\"%s-%s.log\"",
"%",
"(",
... | [
44,
4
] | [
50,
26
] | python | en | ['fr', 'it', 'en'] | False |
is_known_charset | (charset) | Checks if the given charset is known to Python. | Checks if the given charset is known to Python. | def is_known_charset(charset):
"""Checks if the given charset is known to Python."""
try:
codecs.lookup(charset)
except LookupError:
return False
return True | [
"def",
"is_known_charset",
"(",
"charset",
")",
":",
"try",
":",
"codecs",
".",
"lookup",
"(",
"charset",
")",
"except",
"LookupError",
":",
"return",
"False",
"return",
"True"
] | [
33,
0
] | [
39,
15
] | python | en | ['en', 'en', 'en'] | True |
ProtobufRequestMixin.parse_protobuf | (self, proto_type) | Parse the data into an instance of proto_type. | Parse the data into an instance of proto_type. | def parse_protobuf(self, proto_type):
"""Parse the data into an instance of proto_type."""
warnings.warn(
"'werkzeug.contrib.wrappers.ProtobufRequestMixin' is"
" deprecated as of version 0.15 and will be removed in"
" version 1.0.",
DeprecationWarning,
... | [
"def",
"parse_protobuf",
"(",
"self",
",",
"proto_type",
")",
":",
"warnings",
".",
"warn",
"(",
"\"'werkzeug.contrib.wrappers.ProtobufRequestMixin' is\"",
"\" deprecated as of version 0.15 and will be removed in\"",
"\" version 1.0.\"",
",",
"DeprecationWarning",
",",
"stackleve... | [
81,
4
] | [
103,
18
] | python | en | ['en', 'en', 'en'] | True |
ReverseSlashBehaviorRequestMixin.path | (self) | Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will not include a leading slash.
| Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will not include a leading slash.
| def path(self):
"""Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will not include a leading slash.
"""
warnings.warn(
"'werkzeug.contrib.wrappers.ReverseSlashBehaviorRequestMixin'"
" is deprecated as of version... | [
"def",
"path",
"(",
"self",
")",
":",
"warnings",
".",
"warn",
"(",
"\"'werkzeug.contrib.wrappers.ReverseSlashBehaviorRequestMixin'\"",
"\" is deprecated as of version 0.15 and will be removed in\"",
"\" version 1.0.\"",
",",
"DeprecationWarning",
",",
"stacklevel",
"=",
"2",
"... | [
221,
4
] | [
235,
31
] | python | en | ['en', 'en', 'en'] | True |
ReverseSlashBehaviorRequestMixin.script_root | (self) | The root path of the script includling a trailing slash. | The root path of the script includling a trailing slash. | def script_root(self):
"""The root path of the script includling a trailing slash."""
warnings.warn(
"'werkzeug.contrib.wrappers.ReverseSlashBehaviorRequestMixin'"
" is deprecated as of version 0.15 and will be removed in"
" version 1.0.",
DeprecationWarni... | [
"def",
"script_root",
"(",
"self",
")",
":",
"warnings",
".",
"warn",
"(",
"\"'werkzeug.contrib.wrappers.ReverseSlashBehaviorRequestMixin'\"",
"\" is deprecated as of version 0.15 and will be removed in\"",
"\" version 1.0.\"",
",",
"DeprecationWarning",
",",
"stacklevel",
"=",
"... | [
238,
4
] | [
250,
37
] | python | en | ['en', 'en', 'en'] | True |
DynamicCharsetRequestMixin.unknown_charset | (self, charset) | Called if a charset was provided but is not supported by
the Python codecs module. By default latin1 is assumed then
to not lose any information, you may override this method to
change the behavior.
:param charset: the charset that was not found.
:return: the replacement charse... | Called if a charset was provided but is not supported by
the Python codecs module. By default latin1 is assumed then
to not lose any information, you may override this method to
change the behavior. | def unknown_charset(self, charset):
"""Called if a charset was provided but is not supported by
the Python codecs module. By default latin1 is assumed then
to not lose any information, you may override this method to
change the behavior.
:param charset: the charset that was not... | [
"def",
"unknown_charset",
"(",
"self",
",",
"charset",
")",
":",
"return",
"\"latin1\""
] | [
288,
4
] | [
297,
23
] | python | en | ['en', 'en', 'en'] | True |
DynamicCharsetRequestMixin.charset | (self) | The charset from the content type. | The charset from the content type. | def charset(self):
"""The charset from the content type."""
warnings.warn(
"'werkzeug.contrib.wrappers.DynamicCharsetRequestMixin'"
" is deprecated as of version 0.15 and will be removed in"
" version 1.0.",
DeprecationWarning,
stacklevel=2,
... | [
"def",
"charset",
"(",
"self",
")",
":",
"warnings",
".",
"warn",
"(",
"\"'werkzeug.contrib.wrappers.DynamicCharsetRequestMixin'\"",
"\" is deprecated as of version 0.15 and will be removed in\"",
"\" version 1.0.\"",
",",
"DeprecationWarning",
",",
"stacklevel",
"=",
"2",
",",... | [
300,
4
] | [
317,
35
] | python | en | ['en', 'en', 'en'] | True |
_WKBReader.read | (self, wkb) | Return a _pointer_ to C GEOS Geometry object from the given WKB. | Return a _pointer_ to C GEOS Geometry object from the given WKB. | def read(self, wkb):
"Return a _pointer_ to C GEOS Geometry object from the given WKB."
if isinstance(wkb, memoryview):
wkb_s = bytes(wkb)
return wkb_reader_read(self.ptr, wkb_s, len(wkb_s))
elif isinstance(wkb, (bytes, str)):
return wkb_reader_read_hex(self.p... | [
"def",
"read",
"(",
"self",
",",
"wkb",
")",
":",
"if",
"isinstance",
"(",
"wkb",
",",
"memoryview",
")",
":",
"wkb_s",
"=",
"bytes",
"(",
"wkb",
")",
"return",
"wkb_reader_read",
"(",
"self",
".",
"ptr",
",",
"wkb_s",
",",
"len",
"(",
"wkb_s",
")"... | [
146,
4
] | [
154,
27
] | python | en | ['en', 'en', 'en'] | True |
WKTWriter.write | (self, geom) | Return the WKT representation of the given geometry. | Return the WKT representation of the given geometry. | def write(self, geom):
"Return the WKT representation of the given geometry."
return wkt_writer_write(self.ptr, geom.ptr) | [
"def",
"write",
"(",
"self",
",",
"geom",
")",
":",
"return",
"wkt_writer_write",
"(",
"self",
".",
"ptr",
",",
"geom",
".",
"ptr",
")"
] | [
174,
4
] | [
176,
51
] | python | en | ['en', 'en', 'en'] | True |
WKBWriter.write | (self, geom) | Return the WKB representation of the given geometry. | Return the WKB representation of the given geometry. | def write(self, geom):
"Return the WKB representation of the given geometry."
from django.contrib.gis.geos import Polygon
geom = self._handle_empty_point(geom)
wkb = wkb_writer_write(self.ptr, geom.ptr, byref(c_size_t()))
if self.geos_version < (3, 6, 1) and isinstance(geom, Poly... | [
"def",
"write",
"(",
"self",
",",
"geom",
")",
":",
"from",
"django",
".",
"contrib",
".",
"gis",
".",
"geos",
"import",
"Polygon",
"geom",
"=",
"self",
".",
"_handle_empty_point",
"(",
"geom",
")",
"wkb",
"=",
"wkb_writer_write",
"(",
"self",
".",
"pt... | [
233,
4
] | [
242,
30
] | python | en | ['en', 'en', 'en'] | True |
WKBWriter.write_hex | (self, geom) | Return the HEXEWKB representation of the given geometry. | Return the HEXEWKB representation of the given geometry. | def write_hex(self, geom):
"Return the HEXEWKB representation of the given geometry."
from django.contrib.gis.geos.polygon import Polygon
geom = self._handle_empty_point(geom)
wkb = wkb_writer_write_hex(self.ptr, geom.ptr, byref(c_size_t()))
if self.geos_version < (3, 6, 1) and i... | [
"def",
"write_hex",
"(",
"self",
",",
"geom",
")",
":",
"from",
"django",
".",
"contrib",
".",
"gis",
".",
"geos",
".",
"polygon",
"import",
"Polygon",
"geom",
"=",
"self",
".",
"_handle_empty_point",
"(",
"geom",
")",
"wkb",
"=",
"wkb_writer_write_hex",
... | [
244,
4
] | [
251,
18
] | python | en | ['en', 'en', 'en'] | True |
Local._get_context_id | (self) |
Get the ID we should use for looking up variables
|
Get the ID we should use for looking up variables
| def _get_context_id(self):
"""
Get the ID we should use for looking up variables
"""
# Prevent a circular reference
from .sync import AsyncToSync, SyncToAsync
# First, pull the current task if we can
context_id = SyncToAsync.get_current_task()
context_is_... | [
"def",
"_get_context_id",
"(",
"self",
")",
":",
"# Prevent a circular reference",
"from",
".",
"sync",
"import",
"AsyncToSync",
",",
"SyncToAsync",
"# First, pull the current task if we can",
"context_id",
"=",
"SyncToAsync",
".",
"get_current_task",
"(",
")",
"context_i... | [
45,
4
] | [
79,
25
] | python | en | ['en', 'error', 'th'] | False |
BaseEvaluation.__init__ | (self, sep='\t', metrics=None, all_but_one_eval=False, verbose=True, as_table=False, table_sep='\t') |
Class to be base for evaluation strategies
:param sep: Delimiter for input files
:type sep: str, default '\t'
:param metrics: List of evaluation metrics
:type metrics: list, default None
:param all_but_one_eval: If True, considers only one pair (u, i) from the test se... |
Class to be base for evaluation strategies | def __init__(self, sep='\t', metrics=None, all_but_one_eval=False, verbose=True, as_table=False, table_sep='\t'):
"""
Class to be base for evaluation strategies
:param sep: Delimiter for input files
:type sep: str, default '\t'
:param metrics: List of evaluation metrics
... | [
"def",
"__init__",
"(",
"self",
",",
"sep",
"=",
"'\\t'",
",",
"metrics",
"=",
"None",
",",
"all_but_one_eval",
"=",
"False",
",",
"verbose",
"=",
"True",
",",
"as_table",
"=",
"False",
",",
"table_sep",
"=",
"'\\t'",
")",
":",
"self",
".",
"sep",
"=... | [
20,
4
] | [
48,
34
] | python | en | ['en', 'error', 'th'] | False |
BaseEvaluation.evaluate | (self, predictions, test_set) |
Method to be implemented for each strategy using their respective metrics.
Use read() in ReadFile to transform your file in a dict
:param predictions: Dictionary with ranking information
:type predictions: dict
:param test_set: Dictionary with test set information.
:ty... |
Method to be implemented for each strategy using their respective metrics.
Use read() in ReadFile to transform your file in a dict | def evaluate(self, predictions, test_set):
"""
Method to be implemented for each strategy using their respective metrics.
Use read() in ReadFile to transform your file in a dict
:param predictions: Dictionary with ranking information
:type predictions: dict
:param test_... | [
"def",
"evaluate",
"(",
"self",
",",
"predictions",
",",
"test_set",
")",
":",
"raise",
"NotImplemented"
] | [
50,
4
] | [
62,
28
] | python | en | ['en', 'error', 'th'] | False |
BaseEvaluation.evaluate_with_files | (self, prediction_file, test_file) |
Method to evaluate predictions using files
:param prediction_file: Predictions file with at least 2 columns for item recommendation
(eg. user item [score (optional)]) and 3 columns for rating prediction (eg. user item rating)
:type prediction_file: str
:param test_file: Test f... |
Method to evaluate predictions using files | def evaluate_with_files(self, prediction_file, test_file):
"""
Method to evaluate predictions using files
:param prediction_file: Predictions file with at least 2 columns for item recommendation
(eg. user item [score (optional)]) and 3 columns for rating prediction (eg. user item rating... | [
"def",
"evaluate_with_files",
"(",
"self",
",",
"prediction_file",
",",
"test_file",
")",
":",
"predict",
"=",
"ReadFile",
"(",
"prediction_file",
",",
"sep",
"=",
"self",
".",
"sep",
")",
".",
"read",
"(",
")",
"test_set",
"=",
"ReadFile",
"(",
"test_file... | [
64,
4
] | [
83,
59
] | python | en | ['en', 'error', 'th'] | False |
BaseEvaluation.evaluate_recommender | (self, predictions, test_set) |
Method to evaluate recommender results. This method should be called by item recommender algorithms
:param predictions: List with recommender output. e.g. [[user, item, score], [user, item2, score] ...]
:type predictions: list
:param test_set: Dictionary with test set information.
... |
Method to evaluate recommender results. This method should be called by item recommender algorithms | def evaluate_recommender(self, predictions, test_set):
"""
Method to evaluate recommender results. This method should be called by item recommender algorithms
:param predictions: List with recommender output. e.g. [[user, item, score], [user, item2, score] ...]
:type predictions: list
... | [
"def",
"evaluate_recommender",
"(",
"self",
",",
"predictions",
",",
"test_set",
")",
":",
"predictions_dict",
"=",
"{",
"}",
"for",
"sample",
"in",
"predictions",
":",
"predictions_dict",
".",
"setdefault",
"(",
"sample",
"[",
"0",
"]",
",",
"{",
"}",
")"... | [
85,
4
] | [
105,
56
] | python | en | ['en', 'error', 'th'] | False |
BaseEvaluation.evaluate_folds | (self, folds_dir, predictions_file_name, test_file_name, k_folds=10) |
Evaluate ranking in a set of folds. The name of folds needs to be integer and start with 0. e.g.
Exist a dir '/home/user/folds', in which contains folds 0, 1, ..., 10.
:param folds_dir: Directory of folds
:type folds_dir: str
:param k_folds: Number of folds
:type k_fol... |
Evaluate ranking in a set of folds. The name of folds needs to be integer and start with 0. e.g.
Exist a dir '/home/user/folds', in which contains folds 0, 1, ..., 10. | def evaluate_folds(self, folds_dir, predictions_file_name, test_file_name, k_folds=10):
"""
Evaluate ranking in a set of folds. The name of folds needs to be integer and start with 0. e.g.
Exist a dir '/home/user/folds', in which contains folds 0, 1, ..., 10.
:param folds_dir: Directory... | [
"def",
"evaluate_folds",
"(",
"self",
",",
"folds_dir",
",",
"predictions_file_name",
",",
"test_file_name",
",",
"k_folds",
"=",
"10",
")",
":",
"folds_results",
"=",
"defaultdict",
"(",
")",
"for",
"fold",
"in",
"range",
"(",
"k_folds",
")",
":",
"predicti... | [
107,
4
] | [
143,
28
] | python | en | ['en', 'error', 'th'] | False |
BaseEvaluation.print_results | (self, evaluation_results) |
Method to print the results
:param evaluation_results: Dictionary with results. e.g. {metric: value}
:type evaluation_results: dict
|
Method to print the results | def print_results(self, evaluation_results):
"""
Method to print the results
:param evaluation_results: Dictionary with results. e.g. {metric: value}
:type evaluation_results: dict
"""
if self.as_table:
header = ''
values = ''
for me... | [
"def",
"print_results",
"(",
"self",
",",
"evaluation_results",
")",
":",
"if",
"self",
".",
"as_table",
":",
"header",
"=",
"''",
"values",
"=",
"''",
"for",
"metric",
"in",
"self",
".",
"metrics",
":",
"header",
"+=",
"metric",
".",
"upper",
"(",
")"... | [
145,
4
] | [
167,
29
] | python | en | ['en', 'error', 'th'] | False |
MostPopular.__init__ | (self, train_file=None, test_file=None, output_file=None, sep='\t', output_sep='\t') |
Most Popular for Item Recommendation
This algorithm predicts a rank for each user using the count of number of feedback of users and items
Usage::
>> MostPopular(train, test).compute()
:param train_file: File which contains the train set. This file needs to have at least... |
Most Popular for Item Recommendation | def __init__(self, train_file=None, test_file=None, output_file=None, sep='\t', output_sep='\t'):
"""
Most Popular for Item Recommendation
This algorithm predicts a rank for each user using the count of number of feedback of users and items
Usage::
>> MostPopular(train, te... | [
"def",
"__init__",
"(",
"self",
",",
"train_file",
"=",
"None",
",",
"test_file",
"=",
"None",
",",
"output_file",
"=",
"None",
",",
"sep",
"=",
"'\\t'",
",",
"output_sep",
"=",
"'\\t'",
")",
":",
"super",
"(",
"MostPopular",
",",
"self",
")",
".",
"... | [
19,
4
] | [
51,
46
] | python | en | ['en', 'error', 'th'] | False |
MostPopular.predict | (self) |
This method predict final result, building an rank of each user of the train set.
|
This method predict final result, building an rank of each user of the train set. | def predict(self):
"""
This method predict final result, building an rank of each user of the train set.
"""
if self.test_file is not None:
for user in self.test_set['users']:
for item in self.test_set['feedback'][user]:
count_value ... | [
"def",
"predict",
"(",
"self",
")",
":",
"if",
"self",
".",
"test_file",
"is",
"not",
"None",
":",
"for",
"user",
"in",
"self",
".",
"test_set",
"[",
"'users'",
"]",
":",
"for",
"item",
"in",
"self",
".",
"test_set",
"[",
"'feedback'",
"]",
"[",
"u... | [
53,
4
] | [
77,
32
] | python | en | ['en', 'error', 'th'] | False |
MostPopular.compute | (self, verbose=True, metrics=None, verbose_evaluation=True, as_table=False, table_sep='\t') |
Extends compute method from BaseItemRecommendation. Method to run recommender algorithm
:param verbose: Print recommender and database information
:type verbose: bool, default True
:param metrics: List of evaluation measures
:type metrics: list, default None
:param ve... |
Extends compute method from BaseItemRecommendation. Method to run recommender algorithm | def compute(self, verbose=True, metrics=None, verbose_evaluation=True, as_table=False, table_sep='\t'):
"""
Extends compute method from BaseItemRecommendation. Method to run recommender algorithm
:param verbose: Print recommender and database information
:type verbose: bool, default Tru... | [
"def",
"compute",
"(",
"self",
",",
"verbose",
"=",
"True",
",",
"metrics",
"=",
"None",
",",
"verbose_evaluation",
"=",
"True",
",",
"as_table",
"=",
"False",
",",
"table_sep",
"=",
"'\\t'",
")",
":",
"super",
"(",
"MostPopular",
",",
"self",
")",
"."... | [
79,
4
] | [
112,
94
] | python | en | ['en', 'error', 'th'] | False |
create_generic_related_manager | (superclass, rel) |
Factory function to create a manager that subclasses another manager
(generally the default manager of a given model) and adds behaviors
specific to generic relations.
|
Factory function to create a manager that subclasses another manager
(generally the default manager of a given model) and adds behaviors
specific to generic relations.
| def create_generic_related_manager(superclass, rel):
"""
Factory function to create a manager that subclasses another manager
(generally the default manager of a given model) and adds behaviors
specific to generic relations.
"""
class GenericRelatedObjectManager(superclass):
def __init_... | [
"def",
"create_generic_related_manager",
"(",
"superclass",
",",
"rel",
")",
":",
"class",
"GenericRelatedObjectManager",
"(",
"superclass",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"instance",
"=",
"None",
")",
":",
"super",
"(",
")",
".",
"__init__",
... | [
507,
0
] | [
702,
38
] | python | en | ['en', 'error', 'th'] | False |
GenericForeignKey.get_filter_kwargs_for_object | (self, obj) | See corresponding method on Field | See corresponding method on Field | def get_filter_kwargs_for_object(self, obj):
"""See corresponding method on Field"""
return {
self.fk_field: getattr(obj, self.fk_field),
self.ct_field: getattr(obj, self.ct_field),
} | [
"def",
"get_filter_kwargs_for_object",
"(",
"self",
",",
"obj",
")",
":",
"return",
"{",
"self",
".",
"fk_field",
":",
"getattr",
"(",
"obj",
",",
"self",
".",
"fk_field",
")",
",",
"self",
".",
"ct_field",
":",
"getattr",
"(",
"obj",
",",
"self",
".",... | [
56,
4
] | [
61,
9
] | python | en | ['en', 'af', 'en'] | True |
GenericForeignKey.get_forward_related_filter | (self, obj) | See corresponding method on RelatedField | See corresponding method on RelatedField | def get_forward_related_filter(self, obj):
"""See corresponding method on RelatedField"""
return {
self.fk_field: obj.pk,
self.ct_field: ContentType.objects.get_for_model(obj).pk,
} | [
"def",
"get_forward_related_filter",
"(",
"self",
",",
"obj",
")",
":",
"return",
"{",
"self",
".",
"fk_field",
":",
"obj",
".",
"pk",
",",
"self",
".",
"ct_field",
":",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"obj",
")",
".",
"pk",
"... | [
63,
4
] | [
68,
9
] | python | en | ['en', 'sr', 'en'] | True |
GenericForeignKey._check_content_type_field | (self) |
Check if field named `field_name` in model `model` exists and is a
valid content_type field (is a ForeignKey to ContentType).
|
Check if field named `field_name` in model `model` exists and is a
valid content_type field (is a ForeignKey to ContentType).
| def _check_content_type_field(self):
"""
Check if field named `field_name` in model `model` exists and is a
valid content_type field (is a ForeignKey to ContentType).
"""
try:
field = self.model._meta.get_field(self.ct_field)
except FieldDoesNotExist:
... | [
"def",
"_check_content_type_field",
"(",
"self",
")",
":",
"try",
":",
"field",
"=",
"self",
".",
"model",
".",
"_meta",
".",
"get_field",
"(",
"self",
".",
"ct_field",
")",
"except",
"FieldDoesNotExist",
":",
"return",
"[",
"checks",
".",
"Error",
"(",
... | [
108,
4
] | [
156,
25
] | python | en | ['en', 'error', 'th'] | False |
GenericRelation._is_matching_generic_foreign_key | (self, field) |
Return True if field is a GenericForeignKey whose content type and
object id fields correspond to the equivalent attributes on this
GenericRelation.
|
Return True if field is a GenericForeignKey whose content type and
object id fields correspond to the equivalent attributes on this
GenericRelation.
| def _is_matching_generic_foreign_key(self, field):
"""
Return True if field is a GenericForeignKey whose content type and
object id fields correspond to the equivalent attributes on this
GenericRelation.
"""
return (
isinstance(field, GenericForeignKey) and
... | [
"def",
"_is_matching_generic_foreign_key",
"(",
"self",
",",
"field",
")",
":",
"return",
"(",
"isinstance",
"(",
"field",
",",
"GenericForeignKey",
")",
"and",
"field",
".",
"ct_field",
"==",
"self",
".",
"content_type_field_name",
"and",
"field",
".",
"fk_fiel... | [
322,
4
] | [
332,
9
] | python | en | ['en', 'error', 'th'] | False |
GenericRelation._get_path_info_with_parent | (self, filtered_relation) |
Return the path that joins the current model through any parent models.
The idea is that if you have a GFK defined on a parent model then we
need to join the parent model first, then the child model.
|
Return the path that joins the current model through any parent models.
The idea is that if you have a GFK defined on a parent model then we
need to join the parent model first, then the child model.
| def _get_path_info_with_parent(self, filtered_relation):
"""
Return the path that joins the current model through any parent models.
The idea is that if you have a GFK defined on a parent model then we
need to join the parent model first, then the child model.
"""
# With ... | [
"def",
"_get_path_info_with_parent",
"(",
"self",
",",
"filtered_relation",
")",
":",
"# With an inheritance chain ChildTag -> Tag and Tag defines the",
"# GenericForeignKey, and a TaggedItem model has a GenericRelation to",
"# ChildTag, then we need to generate a join from TaggedItem to Tag",
... | [
357,
4
] | [
395,
19
] | python | en | ['en', 'error', 'th'] | False |
GenericRelation.get_content_type | (self) |
Return the content type associated with this field's model.
|
Return the content type associated with this field's model.
| def get_content_type(self):
"""
Return the content type associated with this field's model.
"""
return ContentType.objects.get_for_model(self.model,
for_concrete_model=self.for_concrete_model) | [
"def",
"get_content_type",
"(",
"self",
")",
":",
"return",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"self",
".",
"model",
",",
"for_concrete_model",
"=",
"self",
".",
"for_concrete_model",
")"
] | [
460,
4
] | [
465,
92
] | python | en | ['en', 'error', 'th'] | False |
GenericRelation.bulk_related_objects | (self, objs, using=DEFAULT_DB_ALIAS) |
Return all objects related to ``objs`` via this ``GenericRelation``.
|
Return all objects related to ``objs`` via this ``GenericRelation``.
| def bulk_related_objects(self, objs, using=DEFAULT_DB_ALIAS):
"""
Return all objects related to ``objs`` via this ``GenericRelation``.
"""
return self.remote_field.model._base_manager.db_manager(using).filter(**{
"%s__pk" % self.content_type_field_name: ContentType.objects.db... | [
"def",
"bulk_related_objects",
"(",
"self",
",",
"objs",
",",
"using",
"=",
"DEFAULT_DB_ALIAS",
")",
":",
"return",
"self",
".",
"remote_field",
".",
"model",
".",
"_base_manager",
".",
"db_manager",
"(",
"using",
")",
".",
"filter",
"(",
"*",
"*",
"{",
... | [
475,
4
] | [
483,
10
] | python | en | ['en', 'error', 'th'] | False |
Storage.__init__ | (self, service_name, user_name) | Constructor.
Args:
service_name: string, The name of the service under which the
credentials are stored.
user_name: string, The name of the user to store credentials for.
| Constructor. | def __init__(self, service_name, user_name):
"""Constructor.
Args:
service_name: string, The name of the service under which the
credentials are stored.
user_name: string, The name of the user to store credentials for.
"""
super(Storage,... | [
"def",
"__init__",
"(",
"self",
",",
"service_name",
",",
"user_name",
")",
":",
"super",
"(",
"Storage",
",",
"self",
")",
".",
"__init__",
"(",
"lock",
"=",
"threading",
".",
"Lock",
"(",
")",
")",
"self",
".",
"_service_name",
"=",
"service_name",
"... | [
49,
4
] | [
59,
35
] | python | en | ['en', 'en', 'en'] | False |
Storage.locked_get | (self) | Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
| Retrieve Credential from file. | def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials =... | [
"def",
"locked_get",
"(",
"self",
")",
":",
"credentials",
"=",
"None",
"content",
"=",
"keyring",
".",
"get_password",
"(",
"self",
".",
"_service_name",
",",
"self",
".",
"_user_name",
")",
"if",
"content",
"is",
"not",
"None",
":",
"try",
":",
"creden... | [
61,
4
] | [
77,
26
] | python | en | ['en', 'en', 'en'] | True |
Storage.locked_put | (self, credentials) | Write Credentials to file.
Args:
credentials: Credentials, the credentials to store.
| Write Credentials to file. | def locked_put(self, credentials):
"""Write Credentials to file.
Args:
credentials: Credentials, the credentials to store.
"""
keyring.set_password(self._service_name, self._user_name,
credentials.to_json()) | [
"def",
"locked_put",
"(",
"self",
",",
"credentials",
")",
":",
"keyring",
".",
"set_password",
"(",
"self",
".",
"_service_name",
",",
"self",
".",
"_user_name",
",",
"credentials",
".",
"to_json",
"(",
")",
")"
] | [
79,
4
] | [
86,
51
] | python | en | ['en', 'en', 'en'] | True |
Storage.locked_delete | (self) | Delete Credentials file.
Args:
credentials: Credentials, the credentials to store.
| Delete Credentials file. | def locked_delete(self):
"""Delete Credentials file.
Args:
credentials: Credentials, the credentials to store.
"""
keyring.set_password(self._service_name, self._user_name, '') | [
"def",
"locked_delete",
"(",
"self",
")",
":",
"keyring",
".",
"set_password",
"(",
"self",
".",
"_service_name",
",",
"self",
".",
"_user_name",
",",
"''",
")"
] | [
88,
4
] | [
94,
69
] | python | de | ['de', 'it', 'en'] | False |
get_version | (version=None) | Return a PEP 440-compliant version number from VERSION. | Return a PEP 440-compliant version number from VERSION. | def get_version(version=None):
"""Return a PEP 440-compliant version number from VERSION."""
version = get_complete_version(version)
# Now build the two parts of the version number:
# main = X.Y[.Z]
# sub = .devN - for pre-alpha releases
# | {a|b|rc}N - for alpha, beta, and rc releases
... | [
"def",
"get_version",
"(",
"version",
"=",
"None",
")",
":",
"version",
"=",
"get_complete_version",
"(",
"version",
")",
"# Now build the two parts of the version number:",
"# main = X.Y[.Z]",
"# sub = .devN - for pre-alpha releases",
"# | {a|b|rc}N - for alpha, beta, and rc r... | [
17,
0
] | [
38,
21
] | python | en | ['en', 'en', 'en'] | True |
get_main_version | (version=None) | Return main version (X.Y[.Z]) from VERSION. | Return main version (X.Y[.Z]) from VERSION. | def get_main_version(version=None):
"""Return main version (X.Y[.Z]) from VERSION."""
version = get_complete_version(version)
parts = 2 if version[2] == 0 else 3
return '.'.join(str(x) for x in version[:parts]) | [
"def",
"get_main_version",
"(",
"version",
"=",
"None",
")",
":",
"version",
"=",
"get_complete_version",
"(",
"version",
")",
"parts",
"=",
"2",
"if",
"version",
"[",
"2",
"]",
"==",
"0",
"else",
"3",
"return",
"'.'",
".",
"join",
"(",
"str",
"(",
"... | [
41,
0
] | [
45,
52
] | python | en | ['en', 'en', 'en'] | True |
get_complete_version | (version=None) |
Return a tuple of the django version. If version argument is non-empty,
check for correctness of the tuple provided.
|
Return a tuple of the django version. If version argument is non-empty,
check for correctness of the tuple provided.
| def get_complete_version(version=None):
"""
Return a tuple of the django version. If version argument is non-empty,
check for correctness of the tuple provided.
"""
if version is None:
from django import VERSION as version
else:
assert len(version) == 5
assert version[3] ... | [
"def",
"get_complete_version",
"(",
"version",
"=",
"None",
")",
":",
"if",
"version",
"is",
"None",
":",
"from",
"django",
"import",
"VERSION",
"as",
"version",
"else",
":",
"assert",
"len",
"(",
"version",
")",
"==",
"5",
"assert",
"version",
"[",
"3",... | [
48,
0
] | [
59,
18
] | python | en | ['en', 'error', 'th'] | False |
get_git_changeset | () | Return a numeric identifier of the latest git changeset.
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
This value isn't guaranteed to be unique, but collisions are very unlikely,
so it's sufficient for generating the development version numbers.
| Return a numeric identifier of the latest git changeset. | def get_git_changeset():
"""Return a numeric identifier of the latest git changeset.
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
This value isn't guaranteed to be unique, but collisions are very unlikely,
so it's sufficient for generating the development version numbers.
... | [
"def",
"get_git_changeset",
"(",
")",
":",
"repo_dir",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"__file__",
")",
")",
")",
"git_log",
"=",
"subprocess",
".",
"run",
... | [
71,
0
] | [
89,
45
] | python | en | ['en', 'en', 'en'] | True |
get_version_tuple | (version) |
Return a tuple of version numbers (e.g. (1, 2, 3)) from the version
string (e.g. '1.2.3').
|
Return a tuple of version numbers (e.g. (1, 2, 3)) from the version
string (e.g. '1.2.3').
| def get_version_tuple(version):
"""
Return a tuple of version numbers (e.g. (1, 2, 3)) from the version
string (e.g. '1.2.3').
"""
loose_version = LooseVersion(version)
version_numbers = []
for item in loose_version.version:
if not isinstance(item, int):
break
ver... | [
"def",
"get_version_tuple",
"(",
"version",
")",
":",
"loose_version",
"=",
"LooseVersion",
"(",
"version",
")",
"version_numbers",
"=",
"[",
"]",
"for",
"item",
"in",
"loose_version",
".",
"version",
":",
"if",
"not",
"isinstance",
"(",
"item",
",",
"int",
... | [
92,
0
] | [
103,
33
] | python | en | ['en', 'error', 'th'] | False |
Deserializer | (stream_or_string, **options) | Deserialize a stream or string of JSON data. | Deserialize a stream or string of JSON data. | def Deserializer(stream_or_string, **options):
"""Deserialize a stream or string of JSON data."""
if isinstance(stream_or_string, bytes):
stream_or_string = stream_or_string.decode()
if isinstance(stream_or_string, (bytes, str)):
stream_or_string = stream_or_string.split("\n")
for line ... | [
"def",
"Deserializer",
"(",
"stream_or_string",
",",
"*",
"*",
"options",
")",
":",
"if",
"isinstance",
"(",
"stream_or_string",
",",
"bytes",
")",
":",
"stream_or_string",
"=",
"stream_or_string",
".",
"decode",
"(",
")",
"if",
"isinstance",
"(",
"stream_or_s... | [
41,
0
] | [
56,
49
] | python | en | ['en', 'en', 'en'] | True |
make_setuptools_shim_args | (
setup_py_path, # type: str
global_options=None, # type: Sequence[str]
no_user_config=False, # type: bool
unbuffered_output=False, # type: bool
) |
Get setuptools command arguments with shim wrapped setup file invocation.
:param setup_py_path: The path to setup.py to be wrapped.
:param global_options: Additional global options.
:param no_user_config: If True, disables personal user configuration.
:param unbuffered_output: If True, adds the un... |
Get setuptools command arguments with shim wrapped setup file invocation. | def make_setuptools_shim_args(
setup_py_path, # type: str
global_options=None, # type: Sequence[str]
no_user_config=False, # type: bool
unbuffered_output=False, # type: bool
):
# type: (...) -> List[str]
"""
Get setuptools command arguments with shim wrapped setup file invocation.
:... | [
"def",
"make_setuptools_shim_args",
"(",
"setup_py_path",
",",
"# type: str",
"global_options",
"=",
"None",
",",
"# type: Sequence[str]",
"no_user_config",
"=",
"False",
",",
"# type: bool",
"unbuffered_output",
"=",
"False",
",",
"# type: bool",
")",
":",
"# type: (..... | [
20,
0
] | [
44,
15
] | python | en | ['en', 'error', 'th'] | False |
TestDataLoader.__init__ | (self, in_path = "./", sampling_mode = 'link', type_constrain = True) | for link prediction | for link prediction | def __init__(self, in_path = "./", sampling_mode = 'link', type_constrain = True):
base_file = os.path.abspath(os.path.join(os.path.dirname(__file__), "../release/Base.so"))
self.lib = ctypes.cdll.LoadLibrary(base_file)
"""for link prediction"""
self.lib.getHeadBatch.argtypes = [
ctypes.c_void_p,
ctypes.c... | [
"def",
"__init__",
"(",
"self",
",",
"in_path",
"=",
"\"./\"",
",",
"sampling_mode",
"=",
"'link'",
",",
"type_constrain",
"=",
"True",
")",
":",
"base_file",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
"."... | [
26,
1
] | [
53,
13
] | python | en | ['en', 'en', 'en'] | True |
TimestampSigner.get_timestamp | (self) | Returns the current timestamp. The function must return an
integer.
| Returns the current timestamp. The function must return an
integer.
| def get_timestamp(self):
"""Returns the current timestamp. The function must return an
integer.
"""
return int(time.time()) | [
"def",
"get_timestamp",
"(",
"self",
")",
":",
"return",
"int",
"(",
"time",
".",
"time",
"(",
")",
")"
] | [
23,
4
] | [
27,
31
] | python | en | ['en', 'en', 'en'] | True |
TimestampSigner.timestamp_to_datetime | (self, ts) | Used to convert the timestamp from :meth:`get_timestamp` into
a datetime object.
| Used to convert the timestamp from :meth:`get_timestamp` into
a datetime object.
| def timestamp_to_datetime(self, ts):
"""Used to convert the timestamp from :meth:`get_timestamp` into
a datetime object.
"""
return datetime.utcfromtimestamp(ts) | [
"def",
"timestamp_to_datetime",
"(",
"self",
",",
"ts",
")",
":",
"return",
"datetime",
".",
"utcfromtimestamp",
"(",
"ts",
")"
] | [
29,
4
] | [
33,
44
] | python | en | ['en', 'en', 'en'] | True |
TimestampSigner.sign | (self, value) | Signs the given string and also attaches time information. | Signs the given string and also attaches time information. | def sign(self, value):
"""Signs the given string and also attaches time information."""
value = want_bytes(value)
timestamp = base64_encode(int_to_bytes(self.get_timestamp()))
sep = want_bytes(self.sep)
value = value + sep + timestamp
return value + sep + self.get_signatu... | [
"def",
"sign",
"(",
"self",
",",
"value",
")",
":",
"value",
"=",
"want_bytes",
"(",
"value",
")",
"timestamp",
"=",
"base64_encode",
"(",
"int_to_bytes",
"(",
"self",
".",
"get_timestamp",
"(",
")",
")",
")",
"sep",
"=",
"want_bytes",
"(",
"self",
"."... | [
35,
4
] | [
41,
54
] | python | en | ['en', 'en', 'en'] | True |
TimestampSigner.unsign | (self, value, max_age=None, return_timestamp=False) | Works like the regular :meth:`.Signer.unsign` but can also
validate the time. See the base docstring of the class for
the general behavior. If ``return_timestamp`` is ``True`` the
timestamp of the signature will be returned as a naive
:class:`datetime.datetime` object in UTC.
| Works like the regular :meth:`.Signer.unsign` but can also
validate the time. See the base docstring of the class for
the general behavior. If ``return_timestamp`` is ``True`` the
timestamp of the signature will be returned as a naive
:class:`datetime.datetime` object in UTC.
| def unsign(self, value, max_age=None, return_timestamp=False):
"""Works like the regular :meth:`.Signer.unsign` but can also
validate the time. See the base docstring of the class for
the general behavior. If ``return_timestamp`` is ``True`` the
timestamp of the signature will be returne... | [
"def",
"unsign",
"(",
"self",
",",
"value",
",",
"max_age",
"=",
"None",
",",
"return_timestamp",
"=",
"False",
")",
":",
"try",
":",
"result",
"=",
"Signer",
".",
"unsign",
"(",
"self",
",",
"value",
")",
"sig_error",
"=",
"None",
"except",
"BadSignat... | [
43,
4
] | [
98,
20
] | python | en | ['en', 'en', 'en'] | True |
TimestampSigner.validate | (self, signed_value, max_age=None) | Only validates the given signed value. Returns ``True`` if
the signature exists and is valid. | Only validates the given signed value. Returns ``True`` if
the signature exists and is valid. | def validate(self, signed_value, max_age=None):
"""Only validates the given signed value. Returns ``True`` if
the signature exists and is valid."""
try:
self.unsign(signed_value, max_age=max_age)
return True
except BadSignature:
return False | [
"def",
"validate",
"(",
"self",
",",
"signed_value",
",",
"max_age",
"=",
"None",
")",
":",
"try",
":",
"self",
".",
"unsign",
"(",
"signed_value",
",",
"max_age",
"=",
"max_age",
")",
"return",
"True",
"except",
"BadSignature",
":",
"return",
"False"
] | [
100,
4
] | [
107,
24
] | python | en | ['en', 'en', 'en'] | True |
TimedSerializer.loads | (self, s, max_age=None, return_timestamp=False, salt=None) | Reverse of :meth:`dumps`, raises :exc:`.BadSignature` if the
signature validation fails. If a ``max_age`` is provided it will
ensure the signature is not older than that time in seconds. In
case the signature is outdated, :exc:`.SignatureExpired` is
raised. All arguments are forwarded to... | Reverse of :meth:`dumps`, raises :exc:`.BadSignature` if the
signature validation fails. If a ``max_age`` is provided it will
ensure the signature is not older than that time in seconds. In
case the signature is outdated, :exc:`.SignatureExpired` is
raised. All arguments are forwarded to... | def loads(self, s, max_age=None, return_timestamp=False, salt=None):
"""Reverse of :meth:`dumps`, raises :exc:`.BadSignature` if the
signature validation fails. If a ``max_age`` is provided it will
ensure the signature is not older than that time in seconds. In
case the signature is outd... | [
"def",
"loads",
"(",
"self",
",",
"s",
",",
"max_age",
"=",
"None",
",",
"return_timestamp",
"=",
"False",
",",
"salt",
"=",
"None",
")",
":",
"s",
"=",
"want_bytes",
"(",
"s",
")",
"last_exception",
"=",
"None",
"for",
"signer",
"in",
"self",
".",
... | [
117,
4
] | [
141,
28
] | python | en | ['en', 'la', 'en'] | True |
_glibc_version_string_confstr | () |
Primary implementation of glibc_version_string using os.confstr.
|
Primary implementation of glibc_version_string using os.confstr.
| def _glibc_version_string_confstr() -> Optional[str]:
"""
Primary implementation of glibc_version_string using os.confstr.
"""
# os.confstr is quite a bit faster than ctypes.DLL. It's also less likely
# to be broken or missing. This strategy is used in the standard library
# platform module.
... | [
"def",
"_glibc_version_string_confstr",
"(",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"# os.confstr is quite a bit faster than ctypes.DLL. It's also less likely",
"# to be broken or missing. This strategy is used in the standard library",
"# platform module.",
"# https://github.com/pyt... | [
134,
0
] | [
150,
18
] | python | en | ['en', 'error', 'th'] | False |
_glibc_version_string_ctypes | () |
Fallback implementation of glibc_version_string using ctypes.
|
Fallback implementation of glibc_version_string using ctypes.
| def _glibc_version_string_ctypes() -> Optional[str]:
"""
Fallback implementation of glibc_version_string using ctypes.
"""
try:
import ctypes
except ImportError:
return None
# ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
# manpage says, "If filename is ... | [
"def",
"_glibc_version_string_ctypes",
"(",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"try",
":",
"import",
"ctypes",
"except",
"ImportError",
":",
"return",
"None",
"# ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen",
"# manpage says, \"If filename is N... | [
153,
0
] | [
194,
22
] | python | en | ['en', 'error', 'th'] | False |
_glibc_version_string | () | Returns glibc version string, or None if not using glibc. | Returns glibc version string, or None if not using glibc. | def _glibc_version_string() -> Optional[str]:
"""Returns glibc version string, or None if not using glibc."""
return _glibc_version_string_confstr() or _glibc_version_string_ctypes() | [
"def",
"_glibc_version_string",
"(",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"return",
"_glibc_version_string_confstr",
"(",
")",
"or",
"_glibc_version_string_ctypes",
"(",
")"
] | [
197,
0
] | [
199,
76
] | python | en | ['en', 'en', 'en'] | True |
_parse_glibc_version | (version_str: str) | Parse glibc version.
We use a regexp instead of str.split because we want to discard any
random junk that might come after the minor version -- this might happen
in patched/forked versions of glibc (e.g. Linaro's version of glibc
uses version strings like "2.20-2014.11"). See gh-3588.
| Parse glibc version. | def _parse_glibc_version(version_str: str) -> Tuple[int, int]:
"""Parse glibc version.
We use a regexp instead of str.split because we want to discard any
random junk that might come after the minor version -- this might happen
in patched/forked versions of glibc (e.g. Linaro's version of glibc
use... | [
"def",
"_parse_glibc_version",
"(",
"version_str",
":",
"str",
")",
"->",
"Tuple",
"[",
"int",
",",
"int",
"]",
":",
"m",
"=",
"re",
".",
"match",
"(",
"r\"(?P<major>[0-9]+)\\.(?P<minor>[0-9]+)\"",
",",
"version_str",
")",
"if",
"not",
"m",
":",
"warnings",
... | [
202,
0
] | [
218,
55
] | python | it | ['it', 'it', 'it'] | True |
Left.__init__ | (self, expression, length, **extra) |
expression: the name of a field, or an expression returning a string
length: the number of characters to return from the start of the string
|
expression: the name of a field, or an expression returning a string
length: the number of characters to return from the start of the string
| def __init__(self, expression, length, **extra):
"""
expression: the name of a field, or an expression returning a string
length: the number of characters to return from the start of the string
"""
if not hasattr(length, 'resolve_expression'):
if length < 1:
... | [
"def",
"__init__",
"(",
"self",
",",
"expression",
",",
"length",
",",
"*",
"*",
"extra",
")",
":",
"if",
"not",
"hasattr",
"(",
"length",
",",
"'resolve_expression'",
")",
":",
"if",
"length",
"<",
"1",
":",
"raise",
"ValueError",
"(",
"\"'length' must ... | [
123,
4
] | [
131,
53
] | python | en | ['en', 'error', 'th'] | False |
Substr.__init__ | (self, expression, pos, length=None, **extra) |
expression: the name of a field, or an expression returning a string
pos: an integer > 0, or an expression returning an integer
length: an optional number of characters to return
|
expression: the name of a field, or an expression returning a string
pos: an integer > 0, or an expression returning an integer
length: an optional number of characters to return
| def __init__(self, expression, pos, length=None, **extra):
"""
expression: the name of a field, or an expression returning a string
pos: an integer > 0, or an expression returning an integer
length: an optional number of characters to return
"""
if not hasattr(pos, 'resol... | [
"def",
"__init__",
"(",
"self",
",",
"expression",
",",
"pos",
",",
"length",
"=",
"None",
",",
"*",
"*",
"extra",
")",
":",
"if",
"not",
"hasattr",
"(",
"pos",
",",
"'resolve_expression'",
")",
":",
"if",
"pos",
"<",
"1",
":",
"raise",
"ValueError",... | [
294,
4
] | [
306,
47
] | python | en | ['en', 'error', 'th'] | False |
_get_dist | (metadata_directory: str) | Return a pkg_resources.Distribution for the provided
metadata directory.
| Return a pkg_resources.Distribution for the provided
metadata directory.
| def _get_dist(metadata_directory: str) -> Distribution:
"""Return a pkg_resources.Distribution for the provided
metadata directory.
"""
dist_dir = metadata_directory.rstrip(os.sep)
# Build a PathMetadata object, from path to metadata. :wink:
base_dir, dist_dir_name = os.path.split(dist_dir)
... | [
"def",
"_get_dist",
"(",
"metadata_directory",
":",
"str",
")",
"->",
"Distribution",
":",
"dist_dir",
"=",
"metadata_directory",
".",
"rstrip",
"(",
"os",
".",
"sep",
")",
"# Build a PathMetadata object, from path to metadata. :wink:",
"base_dir",
",",
"dist_dir_name",... | [
59,
0
] | [
82,
5
] | python | en | ['en', 'en', 'en'] | True |
InstallRequirement.format_debug | (self) | An un-tested helper for getting state, for debugging.
| An un-tested helper for getting state, for debugging.
| def format_debug(self) -> str:
"""An un-tested helper for getting state, for debugging.
"""
attributes = vars(self)
names = sorted(attributes)
state = (
"{}={!r}".format(attr, attributes[attr]) for attr in sorted(names)
)
return '<{name} object: {{{st... | [
"def",
"format_debug",
"(",
"self",
")",
"->",
"str",
":",
"attributes",
"=",
"vars",
"(",
"self",
")",
"names",
"=",
"sorted",
"(",
"attributes",
")",
"state",
"=",
"(",
"\"{}={!r}\"",
".",
"format",
"(",
"attr",
",",
"attributes",
"[",
"attr",
"]",
... | [
224,
4
] | [
236,
9
] | python | en | ['da', 'en', 'en'] | True |
InstallRequirement.is_pinned | (self) | Return whether I am pinned to an exact version.
For example, some-package==1.2 is pinned; some-package>1.2 is not.
| Return whether I am pinned to an exact version. | def is_pinned(self) -> bool:
"""Return whether I am pinned to an exact version.
For example, some-package==1.2 is pinned; some-package>1.2 is not.
"""
specifiers = self.specifier
return (len(specifiers) == 1 and
next(iter(specifiers)).operator in {'==', '==='}) | [
"def",
"is_pinned",
"(",
"self",
")",
"->",
"bool",
":",
"specifiers",
"=",
"self",
".",
"specifier",
"return",
"(",
"len",
"(",
"specifiers",
")",
"==",
"1",
"and",
"next",
"(",
"iter",
"(",
"specifiers",
")",
")",
".",
"operator",
"in",
"{",
"'=='"... | [
250,
4
] | [
257,
65
] | python | en | ['en', 'en', 'en'] | True |
InstallRequirement.has_hash_options | (self) | Return whether any known-good hashes are specified as options.
These activate --require-hashes mode; hashes specified as part of a
URL do not.
| Return whether any known-good hashes are specified as options. | def has_hash_options(self) -> bool:
"""Return whether any known-good hashes are specified as options.
These activate --require-hashes mode; hashes specified as part of a
URL do not.
"""
return bool(self.hash_options) | [
"def",
"has_hash_options",
"(",
"self",
")",
"->",
"bool",
":",
"return",
"bool",
"(",
"self",
".",
"hash_options",
")"
] | [
272,
4
] | [
279,
38
] | python | en | ['en', 'en', 'en'] | True |
InstallRequirement.hashes | (self, trust_internet: bool = True) | Return a hash-comparer that considers my option- and URL-based
hashes to be known-good.
Hashes in URLs--ones embedded in the requirements file, not ones
downloaded from an index server--are almost peers with ones from
flags. They satisfy --require-hashes (whether it was implicitly or
... | Return a hash-comparer that considers my option- and URL-based
hashes to be known-good. | def hashes(self, trust_internet: bool = True) -> Hashes:
"""Return a hash-comparer that considers my option- and URL-based
hashes to be known-good.
Hashes in URLs--ones embedded in the requirements file, not ones
downloaded from an index server--are almost peers with ones from
f... | [
"def",
"hashes",
"(",
"self",
",",
"trust_internet",
":",
"bool",
"=",
"True",
")",
"->",
"Hashes",
":",
"good_hashes",
"=",
"self",
".",
"hash_options",
".",
"copy",
"(",
")",
"link",
"=",
"self",
".",
"link",
"if",
"trust_internet",
"else",
"self",
"... | [
281,
4
] | [
300,
34
] | python | en | ['en', 'en', 'en'] | True |
InstallRequirement.from_path | (self) | Format a nice indicator to show where this "comes from"
| Format a nice indicator to show where this "comes from"
| def from_path(self) -> Optional[str]:
"""Format a nice indicator to show where this "comes from"
"""
if self.req is None:
return None
s = str(self.req)
if self.comes_from:
if isinstance(self.comes_from, str):
comes_from = self.comes_from
... | [
"def",
"from_path",
"(",
"self",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"if",
"self",
".",
"req",
"is",
"None",
":",
"return",
"None",
"s",
"=",
"str",
"(",
"self",
".",
"req",
")",
"if",
"self",
".",
"comes_from",
":",
"if",
"isinstance",
... | [
302,
4
] | [
315,
16
] | python | en | ['en', 'en', 'en'] | True |
InstallRequirement._set_requirement | (self) | Set requirement after generating metadata.
| Set requirement after generating metadata.
| def _set_requirement(self) -> None:
"""Set requirement after generating metadata.
"""
assert self.req is None
assert self.metadata is not None
assert self.source_dir is not None
# Construct a Requirement object from the generated metadata
if isinstance(parse_vers... | [
"def",
"_set_requirement",
"(",
"self",
")",
"->",
"None",
":",
"assert",
"self",
".",
"req",
"is",
"None",
"assert",
"self",
".",
"metadata",
"is",
"not",
"None",
"assert",
"self",
".",
"source_dir",
"is",
"not",
"None",
"# Construct a Requirement object from... | [
360,
4
] | [
379,
9
] | python | en | ['da', 'en', 'en'] | True |
InstallRequirement.check_if_exists | (self, use_user_site: bool) | Find an installed distribution that satisfies or conflicts
with this requirement, and set self.satisfied_by or
self.should_reinstall appropriately.
| Find an installed distribution that satisfies or conflicts
with this requirement, and set self.satisfied_by or
self.should_reinstall appropriately.
| def check_if_exists(self, use_user_site: bool) -> None:
"""Find an installed distribution that satisfies or conflicts
with this requirement, and set self.satisfied_by or
self.should_reinstall appropriately.
"""
if self.req is None:
return
existing_dist = get_d... | [
"def",
"check_if_exists",
"(",
"self",
",",
"use_user_site",
":",
"bool",
")",
"->",
"None",
":",
"if",
"self",
".",
"req",
"is",
"None",
":",
"return",
"existing_dist",
"=",
"get_distribution",
"(",
"self",
".",
"req",
".",
"name",
")",
"if",
"not",
"... | [
396,
4
] | [
437,
49
] | python | en | ['en', 'en', 'en'] | True |
InstallRequirement.load_pyproject_toml | (self) | Load the pyproject.toml file.
After calling this routine, all of the attributes related to PEP 517
processing for this requirement have been set. In particular, the
use_pep517 attribute can be used to determine whether we should
follow the PEP 517 or legacy (setup.py) code path.
... | Load the pyproject.toml file. | def load_pyproject_toml(self) -> None:
"""Load the pyproject.toml file.
After calling this routine, all of the attributes related to PEP 517
processing for this requirement have been set. In particular, the
use_pep517 attribute can be used to determine whether we should
follow t... | [
"def",
"load_pyproject_toml",
"(",
"self",
")",
"->",
"None",
":",
"pyproject_toml_data",
"=",
"load_pyproject_toml",
"(",
"self",
".",
"use_pep517",
",",
"self",
".",
"pyproject_toml_path",
",",
"self",
".",
"setup_py_path",
",",
"str",
"(",
"self",
")",
")",... | [
465,
4
] | [
490,
9
] | python | en | ['en', 'en', 'en'] | True |
InstallRequirement._generate_metadata | (self) | Invokes metadata generator functions, with the required arguments.
| Invokes metadata generator functions, with the required arguments.
| def _generate_metadata(self) -> str:
"""Invokes metadata generator functions, with the required arguments.
"""
if not self.use_pep517:
assert self.unpacked_source_directory
if not os.path.exists(self.setup_py_path):
raise InstallationError(
... | [
"def",
"_generate_metadata",
"(",
"self",
")",
"->",
"str",
":",
"if",
"not",
"self",
".",
"use_pep517",
":",
"assert",
"self",
".",
"unpacked_source_directory",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"self",
".",
"setup_py_path",
")",
":",
... | [
492,
4
] | [
516,
9
] | python | en | ['en', 'en', 'en'] | True |
InstallRequirement.prepare_metadata | (self) | Ensure that project metadata is available.
Under PEP 517, call the backend hook to prepare the metadata.
Under legacy processing, call setup.py egg-info.
| Ensure that project metadata is available. | def prepare_metadata(self) -> None:
"""Ensure that project metadata is available.
Under PEP 517, call the backend hook to prepare the metadata.
Under legacy processing, call setup.py egg-info.
"""
assert self.source_dir
with indent_log():
self.metadata_direc... | [
"def",
"prepare_metadata",
"(",
"self",
")",
"->",
"None",
":",
"assert",
"self",
".",
"source_dir",
"with",
"indent_log",
"(",
")",
":",
"self",
".",
"metadata_directory",
"=",
"self",
".",
"_generate_metadata",
"(",
")",
"# Act on the newly generated metadata, b... | [
518,
4
] | [
535,
44
] | python | en | ['en', 'en', 'en'] | True |
InstallRequirement.ensure_has_source_dir | (
self,
parent_dir: str,
autodelete: bool = False,
parallel_builds: bool = False,
) | Ensure that a source_dir is set.
This will create a temporary build dir if the name of the requirement
isn't known yet.
:param parent_dir: The ideal pip parent_dir for the source_dir.
Generally src_dir for editables and build_dir for sdists.
:return: self.source_dir
... | Ensure that a source_dir is set. | def ensure_has_source_dir(
self,
parent_dir: str,
autodelete: bool = False,
parallel_builds: bool = False,
) -> None:
"""Ensure that a source_dir is set.
This will create a temporary build dir if the name of the requirement
isn't known yet.
:param pa... | [
"def",
"ensure_has_source_dir",
"(",
"self",
",",
"parent_dir",
":",
"str",
",",
"autodelete",
":",
"bool",
"=",
"False",
",",
"parallel_builds",
":",
"bool",
"=",
"False",
",",
")",
"->",
"None",
":",
"if",
"self",
".",
"source_dir",
"is",
"None",
":",
... | [
565,
4
] | [
585,
13
] | python | en | ['en', 'fr', 'en'] | True |
InstallRequirement.uninstall | (
self, auto_confirm: bool = False, verbose: bool = False
) |
Uninstall the distribution currently satisfying this requirement.
Prompts before removing or modifying files unless
``auto_confirm`` is True.
Refuses to delete or modify files outside of ``sys.prefix`` -
thus uninstallation within a virtual environment can only
modify ... |
Uninstall the distribution currently satisfying this requirement. | def uninstall(
self, auto_confirm: bool = False, verbose: bool = False
) -> Optional[UninstallPathSet]:
"""
Uninstall the distribution currently satisfying this requirement.
Prompts before removing or modifying files unless
``auto_confirm`` is True.
Refuses to delet... | [
"def",
"uninstall",
"(",
"self",
",",
"auto_confirm",
":",
"bool",
"=",
"False",
",",
"verbose",
":",
"bool",
"=",
"False",
")",
"->",
"Optional",
"[",
"UninstallPathSet",
"]",
":",
"assert",
"self",
".",
"req",
"dist",
"=",
"get_distribution",
"(",
"sel... | [
609,
4
] | [
633,
34
] | python | en | ['en', 'error', 'th'] | False |
InstallRequirement.archive | (self, build_dir: Optional[str]) | Saves archive to provided build_dir.
Used for saving downloaded VCS requirements as part of `pip download`.
| Saves archive to provided build_dir. | def archive(self, build_dir: Optional[str]) -> None:
"""Saves archive to provided build_dir.
Used for saving downloaded VCS requirements as part of `pip download`.
"""
assert self.source_dir
if build_dir is None:
return
create_archive = True
archive_... | [
"def",
"archive",
"(",
"self",
",",
"build_dir",
":",
"Optional",
"[",
"str",
"]",
")",
"->",
"None",
":",
"assert",
"self",
".",
"source_dir",
"if",
"build_dir",
"is",
"None",
":",
"return",
"create_archive",
"=",
"True",
"archive_name",
"=",
"'{}-{}.zip'... | [
649,
4
] | [
709,
59
] | python | en | ['en', 'en', 'en'] | True |
split_template_path | (template) | Split a path into segments and perform a sanity check. If it detects
'..' in the path it will raise a `TemplateNotFound` error.
| Split a path into segments and perform a sanity check. If it detects
'..' in the path it will raise a `TemplateNotFound` error.
| def split_template_path(template):
"""Split a path into segments and perform a sanity check. If it detects
'..' in the path it will raise a `TemplateNotFound` error.
"""
pieces = []
for piece in template.split('/'):
if path.sep in piece \
or (path.altsep and path.altsep in piece)... | [
"def",
"split_template_path",
"(",
"template",
")",
":",
"pieces",
"=",
"[",
"]",
"for",
"piece",
"in",
"template",
".",
"split",
"(",
"'/'",
")",
":",
"if",
"path",
".",
"sep",
"in",
"piece",
"or",
"(",
"path",
".",
"altsep",
"and",
"path",
".",
"... | [
21,
0
] | [
33,
17
] | python | en | ['en', 'en', 'en'] | True |
BaseLoader.get_source | (self, environment, template) | Get the template source, filename and reload helper for a template.
It's passed the environment and template name and has to return a
tuple in the form ``(source, filename, uptodate)`` or raise a
`TemplateNotFound` error if it can't locate the template.
The source part of the returned t... | Get the template source, filename and reload helper for a template.
It's passed the environment and template name and has to return a
tuple in the form ``(source, filename, uptodate)`` or raise a
`TemplateNotFound` error if it can't locate the template. | def get_source(self, environment, template):
"""Get the template source, filename and reload helper for a template.
It's passed the environment and template name and has to return a
tuple in the form ``(source, filename, uptodate)`` or raise a
`TemplateNotFound` error if it can't locate ... | [
"def",
"get_source",
"(",
"self",
",",
"environment",
",",
"template",
")",
":",
"if",
"not",
"self",
".",
"has_source_access",
":",
"raise",
"RuntimeError",
"(",
"'%s cannot provide access to the source'",
"%",
"self",
".",
"__class__",
".",
"__name__",
")",
"r... | [
69,
4
] | [
90,
40
] | python | en | ['en', 'en', 'en'] | True |
BaseLoader.list_templates | (self) | Iterates over all templates. If the loader does not support that
it should raise a :exc:`TypeError` which is the default behavior.
| Iterates over all templates. If the loader does not support that
it should raise a :exc:`TypeError` which is the default behavior.
| def list_templates(self):
"""Iterates over all templates. If the loader does not support that
it should raise a :exc:`TypeError` which is the default behavior.
"""
raise TypeError('this loader cannot iterate over all templates') | [
"def",
"list_templates",
"(",
"self",
")",
":",
"raise",
"TypeError",
"(",
"'this loader cannot iterate over all templates'",
")"
] | [
92,
4
] | [
96,
72
] | python | en | ['en', 'en', 'en'] | True |
BaseLoader.load | (self, environment, name, globals=None) | Loads a template. This method looks up the template in the cache
or loads one by calling :meth:`get_source`. Subclasses should not
override this method as loaders working on collections of other
loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`)
will not call this method ... | Loads a template. This method looks up the template in the cache
or loads one by calling :meth:`get_source`. Subclasses should not
override this method as loaders working on collections of other
loaders (such as :class:`PrefixLoader` or :class:`ChoiceLoader`)
will not call this method ... | def load(self, environment, name, globals=None):
"""Loads a template. This method looks up the template in the cache
or loads one by calling :meth:`get_source`. Subclasses should not
override this method as loaders working on collections of other
loaders (such as :class:`PrefixLoader` ... | [
"def",
"load",
"(",
"self",
",",
"environment",
",",
"name",
",",
"globals",
"=",
"None",
")",
":",
"code",
"=",
"None",
"if",
"globals",
"is",
"None",
":",
"globals",
"=",
"{",
"}",
"# first we try to get the source for this template together",
"# with the file... | [
99,
4
] | [
134,
70
] | python | en | ['en', 'en', 'en'] | True |
BaseDatabaseFeatures.supports_explaining_query_execution | (self) | Does this backend support explaining query execution? | Does this backend support explaining query execution? | def supports_explaining_query_execution(self):
"""Does this backend support explaining query execution?"""
return self.connection.ops.explain_prefix is not None | [
"def",
"supports_explaining_query_execution",
"(",
"self",
")",
":",
"return",
"self",
".",
"connection",
".",
"ops",
".",
"explain_prefix",
"is",
"not",
"None"
] | [
340,
4
] | [
342,
61
] | python | en | ['en', 'en', 'en'] | True |
BaseDatabaseFeatures.supports_transactions | (self) | Confirm support for transactions. | Confirm support for transactions. | def supports_transactions(self):
"""Confirm support for transactions."""
with self.connection.cursor() as cursor:
cursor.execute('CREATE TABLE ROLLBACK_TEST (X INT)')
self.connection.set_autocommit(False)
cursor.execute('INSERT INTO ROLLBACK_TEST (X) VALUES (8)')
... | [
"def",
"supports_transactions",
"(",
"self",
")",
":",
"with",
"self",
".",
"connection",
".",
"cursor",
"(",
")",
"as",
"cursor",
":",
"cursor",
".",
"execute",
"(",
"'CREATE TABLE ROLLBACK_TEST (X INT)'",
")",
"self",
".",
"connection",
".",
"set_autocommit",
... | [
345,
4
] | [
356,
25
] | python | en | ['en', 'en', 'en'] | True |
HTTPConnection.host | (self) |
Getter method to remove any trailing dots that indicate the hostname is an FQDN.
In general, SSL certificates don't include the trailing dot indicating a
fully-qualified domain name, and thus, they don't validate properly when
checked against a domain name that includes the dot. In add... |
Getter method to remove any trailing dots that indicate the hostname is an FQDN. | def host(self):
"""
Getter method to remove any trailing dots that indicate the hostname is an FQDN.
In general, SSL certificates don't include the trailing dot indicating a
fully-qualified domain name, and thus, they don't validate properly when
checked against a domain name th... | [
"def",
"host",
"(",
"self",
")",
":",
"return",
"self",
".",
"_dns_host",
".",
"rstrip",
"(",
"\".\"",
")"
] | [
127,
4
] | [
143,
41
] | python | en | ['en', 'error', 'th'] | False |
HTTPConnection.host | (self, value) |
Setter for the `host` property.
We assume that only urllib3 uses the _dns_host attribute; httplib itself
only uses `host`, and it seems reasonable that other libraries follow suit.
|
Setter for the `host` property. | def host(self, value):
"""
Setter for the `host` property.
We assume that only urllib3 uses the _dns_host attribute; httplib itself
only uses `host`, and it seems reasonable that other libraries follow suit.
"""
self._dns_host = value | [
"def",
"host",
"(",
"self",
",",
"value",
")",
":",
"self",
".",
"_dns_host",
"=",
"value"
] | [
146,
4
] | [
153,
30
] | python | en | ['en', 'error', 'th'] | False |
HTTPConnection._new_conn | (self) | Establish a socket connection and set nodelay settings on it.
:return: New socket connection.
| Establish a socket connection and set nodelay settings on it. | def _new_conn(self):
"""Establish a socket connection and set nodelay settings on it.
:return: New socket connection.
"""
extra_kw = {}
if self.source_address:
extra_kw["source_address"] = self.source_address
if self.socket_options:
extra_kw["soc... | [
"def",
"_new_conn",
"(",
"self",
")",
":",
"extra_kw",
"=",
"{",
"}",
"if",
"self",
".",
"source_address",
":",
"extra_kw",
"[",
"\"source_address\"",
"]",
"=",
"self",
".",
"source_address",
"if",
"self",
".",
"socket_options",
":",
"extra_kw",
"[",
"\"so... | [
155,
4
] | [
184,
19
] | python | en | ['en', 'st', 'en'] | True |
HTTPConnection.request_chunked | (self, method, url, body=None, headers=None) |
Alternative to the common request method, which sends the
body with chunked encoding and not as one block
|
Alternative to the common request method, which sends the
body with chunked encoding and not as one block
| def request_chunked(self, method, url, body=None, headers=None):
"""
Alternative to the common request method, which sends the
body with chunked encoding and not as one block
"""
headers = headers or {}
header_keys = set([six.ensure_str(k.lower()) for k in headers])
... | [
"def",
"request_chunked",
"(",
"self",
",",
"method",
",",
"url",
",",
"body",
"=",
"None",
",",
"headers",
"=",
"None",
")",
":",
"headers",
"=",
"headers",
"or",
"{",
"}",
"header_keys",
"=",
"set",
"(",
"[",
"six",
".",
"ensure_str",
"(",
"k",
"... | [
235,
4
] | [
272,
31
] | python | en | ['en', 'error', 'th'] | False |
HTTPSConnection.set_cert | (
self,
key_file=None,
cert_file=None,
cert_reqs=None,
key_password=None,
ca_certs=None,
assert_hostname=None,
assert_fingerprint=None,
ca_cert_dir=None,
ca_cert_data=None,
) |
This method should only be called once, before the connection is used.
|
This method should only be called once, before the connection is used.
| def set_cert(
self,
key_file=None,
cert_file=None,
cert_reqs=None,
key_password=None,
ca_certs=None,
assert_hostname=None,
assert_fingerprint=None,
ca_cert_dir=None,
ca_cert_data=None,
):
"""
This method should only be c... | [
"def",
"set_cert",
"(",
"self",
",",
"key_file",
"=",
"None",
",",
"cert_file",
"=",
"None",
",",
"cert_reqs",
"=",
"None",
",",
"key_password",
"=",
"None",
",",
"ca_certs",
"=",
"None",
",",
"assert_hostname",
"=",
"None",
",",
"assert_fingerprint",
"=",... | [
317,
4
] | [
348,
40
] | python | en | ['en', 'error', 'th'] | False |
HTTPSConnection._connect_tls_proxy | (self, hostname, conn) |
Establish a TLS connection to the proxy using the provided SSL context.
|
Establish a TLS connection to the proxy using the provided SSL context.
| def _connect_tls_proxy(self, hostname, conn):
"""
Establish a TLS connection to the proxy using the provided SSL context.
"""
proxy_config = self.proxy_config
ssl_context = proxy_config.ssl_context
if ssl_context:
# If the user provided a proxy context, we ass... | [
"def",
"_connect_tls_proxy",
"(",
"self",
",",
"hostname",
",",
"conn",
")",
":",
"proxy_config",
"=",
"self",
".",
"proxy_config",
"ssl_context",
"=",
"proxy_config",
".",
"ssl_context",
"if",
"ssl_context",
":",
"# If the user provided a proxy context, we assume CA an... | [
470,
4
] | [
506,
9
] | python | en | ['en', 'error', 'th'] | False |
request | (method, url, **kwargs) | Constructs and sends a :class:`Request <Request>`.
:param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary, list of tuples or bytes to se... | Constructs and sends a :class:`Request <Request>`. | def request(method, url, **kwargs):
"""Constructs and sends a :class:`Request <Request>`.
:param method: method for the new :class:`Request` object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
:param url: URL for the new :class:`Request` object.
:param params: (optional... | [
"def",
"request",
"(",
"method",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"# By using the 'with' statement we are sure the session is closed, thus we",
"# avoid leaving sockets open which can trigger a ResourceWarning in some",
"# cases, and look like a memory leak in others.",
"... | [
15,
0
] | [
60,
64
] | python | en | ['en', 'en', 'en'] | True |
get | (url, params=None, **kwargs) | r"""Sends a GET request.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary, list of tuples or bytes to send
in the query string for the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` o... | r"""Sends a GET request. | def get(url, params=None, **kwargs):
r"""Sends a GET request.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary, list of tuples or bytes to send
in the query string for the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
... | [
"def",
"get",
"(",
"url",
",",
"params",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"request",
"(",
"'get'",
",",
"url",
",",
"params",
"=",
"params",
",",
"*",
"*",
"kwargs",
")"
] | [
63,
0
] | [
74,
55
] | python | en | ['en', 'co', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.