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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
SimpleListFilter.value | (self) |
Return the value (in string format) provided in the request's
query string for this filter, if any, or None if the value wasn't
provided.
|
Return the value (in string format) provided in the request's
query string for this filter, if any, or None if the value wasn't
provided.
| def value(self):
"""
Return the value (in string format) provided in the request's
query string for this filter, if any, or None if the value wasn't
provided.
"""
return self.used_parameters.get(self.parameter_name) | [
"def",
"value",
"(",
"self",
")",
":",
"return",
"self",
".",
"used_parameters",
".",
"get",
"(",
"self",
".",
"parameter_name",
")"
] | [
83,
4
] | [
89,
60
] | python | en | ['en', 'error', 'th'] | False |
SimpleListFilter.lookups | (self, request, model_admin) |
Must be overridden to return a list of tuples (value, verbose value)
|
Must be overridden to return a list of tuples (value, verbose value)
| def lookups(self, request, model_admin):
"""
Must be overridden to return a list of tuples (value, verbose value)
"""
raise NotImplementedError(
'The SimpleListFilter.lookups() method must be overridden to '
'return a list of tuples (value, verbose value).'
... | [
"def",
"lookups",
"(",
"self",
",",
"request",
",",
"model_admin",
")",
":",
"raise",
"NotImplementedError",
"(",
"'The SimpleListFilter.lookups() method must be overridden to '",
"'return a list of tuples (value, verbose value).'",
")"
] | [
91,
4
] | [
98,
9
] | python | en | ['en', 'error', 'th'] | False |
RelatedFieldListFilter.include_empty_choice | (self) |
Return True if a "(None)" choice should be included, which filters
out everything except empty relationships.
|
Return True if a "(None)" choice should be included, which filters
out everything except empty relationships.
| def include_empty_choice(self):
"""
Return True if a "(None)" choice should be included, which filters
out everything except empty relationships.
"""
return self.field.null or (self.field.is_relation and self.field.many_to_many) | [
"def",
"include_empty_choice",
"(",
"self",
")",
":",
"return",
"self",
".",
"field",
".",
"null",
"or",
"(",
"self",
".",
"field",
".",
"is_relation",
"and",
"self",
".",
"field",
".",
"many_to_many",
")"
] | [
178,
4
] | [
183,
86
] | python | en | ['en', 'error', 'th'] | False |
RelatedFieldListFilter.field_admin_ordering | (self, field, request, model_admin) |
Return the model admin's ordering for related field, if provided.
|
Return the model admin's ordering for related field, if provided.
| def field_admin_ordering(self, field, request, model_admin):
"""
Return the model admin's ordering for related field, if provided.
"""
related_admin = model_admin.admin_site._registry.get(field.remote_field.model)
if related_admin is not None:
return related_admin.get... | [
"def",
"field_admin_ordering",
"(",
"self",
",",
"field",
",",
"request",
",",
"model_admin",
")",
":",
"related_admin",
"=",
"model_admin",
".",
"admin_site",
".",
"_registry",
".",
"get",
"(",
"field",
".",
"remote_field",
".",
"model",
")",
"if",
"related... | [
195,
4
] | [
202,
17
] | python | en | ['en', 'error', 'th'] | False |
BaseSpecifier.__str__ | (self) |
Returns the str representation of this Specifier like object. This
should be representative of the Specifier itself.
|
Returns the str representation of this Specifier like object. This
should be representative of the Specifier itself.
| def __str__(self):
"""
Returns the str representation of this Specifier like object. This
should be representative of the Specifier itself.
""" | [
"def",
"__str__",
"(",
"self",
")",
":"
] | [
23,
4
] | [
27,
11
] | python | en | ['en', 'error', 'th'] | False |
BaseSpecifier.__hash__ | (self) |
Returns a hash value for this Specifier like object.
|
Returns a hash value for this Specifier like object.
| def __hash__(self):
"""
Returns a hash value for this Specifier like object.
""" | [
"def",
"__hash__",
"(",
"self",
")",
":"
] | [
30,
4
] | [
33,
11
] | python | en | ['en', 'error', 'th'] | False |
BaseSpecifier.__eq__ | (self, other) |
Returns a boolean representing whether or not the two Specifier like
objects are equal.
|
Returns a boolean representing whether or not the two Specifier like
objects are equal.
| def __eq__(self, other):
"""
Returns a boolean representing whether or not the two Specifier like
objects are equal.
""" | [
"def",
"__eq__",
"(",
"self",
",",
"other",
")",
":"
] | [
36,
4
] | [
40,
11
] | python | en | ['en', 'error', 'th'] | False |
BaseSpecifier.__ne__ | (self, other) |
Returns a boolean representing whether or not the two Specifier like
objects are not equal.
|
Returns a boolean representing whether or not the two Specifier like
objects are not equal.
| def __ne__(self, other):
"""
Returns a boolean representing whether or not the two Specifier like
objects are not equal.
""" | [
"def",
"__ne__",
"(",
"self",
",",
"other",
")",
":"
] | [
43,
4
] | [
47,
11
] | python | en | ['en', 'error', 'th'] | False |
BaseSpecifier.prereleases | (self) |
Returns whether or not pre-releases as a whole are allowed by this
specifier.
|
Returns whether or not pre-releases as a whole are allowed by this
specifier.
| def prereleases(self):
"""
Returns whether or not pre-releases as a whole are allowed by this
specifier.
""" | [
"def",
"prereleases",
"(",
"self",
")",
":"
] | [
50,
4
] | [
54,
11
] | python | en | ['en', 'error', 'th'] | False |
BaseSpecifier.prereleases | (self, value) |
Sets whether or not pre-releases as a whole are allowed by this
specifier.
|
Sets whether or not pre-releases as a whole are allowed by this
specifier.
| def prereleases(self, value):
"""
Sets whether or not pre-releases as a whole are allowed by this
specifier.
""" | [
"def",
"prereleases",
"(",
"self",
",",
"value",
")",
":"
] | [
57,
4
] | [
61,
11
] | python | en | ['en', 'error', 'th'] | False |
BaseSpecifier.contains | (self, item, prereleases=None) |
Determines if the given item is contained within this specifier.
|
Determines if the given item is contained within this specifier.
| def contains(self, item, prereleases=None):
"""
Determines if the given item is contained within this specifier.
""" | [
"def",
"contains",
"(",
"self",
",",
"item",
",",
"prereleases",
"=",
"None",
")",
":"
] | [
64,
4
] | [
67,
11
] | python | en | ['en', 'error', 'th'] | False |
BaseSpecifier.filter | (self, iterable, prereleases=None) |
Takes an iterable of items and filters them so that only items which
are contained within this specifier are allowed in it.
|
Takes an iterable of items and filters them so that only items which
are contained within this specifier are allowed in it.
| def filter(self, iterable, prereleases=None):
"""
Takes an iterable of items and filters them so that only items which
are contained within this specifier are allowed in it.
""" | [
"def",
"filter",
"(",
"self",
",",
"iterable",
",",
"prereleases",
"=",
"None",
")",
":"
] | [
70,
4
] | [
74,
11
] | python | en | ['en', 'error', 'th'] | False |
find | (path, all=False) |
Find a static file with the given path using all enabled finders.
If ``all`` is ``False`` (default), return the first matching
absolute path (or ``None`` if no match). Otherwise return a list.
|
Find a static file with the given path using all enabled finders. | def find(path, all=False):
"""
Find a static file with the given path using all enabled finders.
If ``all`` is ``False`` (default), return the first matching
absolute path (or ``None`` if no match). Otherwise return a list.
"""
searched_locations[:] = []
matches = []
for finder in get_f... | [
"def",
"find",
"(",
"path",
",",
"all",
"=",
"False",
")",
":",
"searched_locations",
"[",
":",
"]",
"=",
"[",
"]",
"matches",
"=",
"[",
"]",
"for",
"finder",
"in",
"get_finders",
"(",
")",
":",
"result",
"=",
"finder",
".",
"find",
"(",
"path",
... | [
256,
0
] | [
275,
30
] | python | en | ['en', 'error', 'th'] | False |
get_finder | (import_path) |
Import the staticfiles finder class described by import_path, where
import_path is the full Python path to the class.
|
Import the staticfiles finder class described by import_path, where
import_path is the full Python path to the class.
| def get_finder(import_path):
"""
Import the staticfiles finder class described by import_path, where
import_path is the full Python path to the class.
"""
Finder = import_string(import_path)
if not issubclass(Finder, BaseFinder):
raise ImproperlyConfigured('Finder "%s" is not a subclass ... | [
"def",
"get_finder",
"(",
"import_path",
")",
":",
"Finder",
"=",
"import_string",
"(",
"import_path",
")",
"if",
"not",
"issubclass",
"(",
"Finder",
",",
"BaseFinder",
")",
":",
"raise",
"ImproperlyConfigured",
"(",
"'Finder \"%s\" is not a subclass of \"%s\"'",
"%... | [
284,
0
] | [
293,
19
] | python | en | ['en', 'error', 'th'] | False |
BaseFinder.find | (self, path, all=False) |
Given a relative file path, find an absolute file path.
If the ``all`` parameter is False (default) return only the first found
file path; if True, return a list of all found files paths.
|
Given a relative file path, find an absolute file path. | def find(self, path, all=False):
"""
Given a relative file path, find an absolute file path.
If the ``all`` parameter is False (default) return only the first found
file path; if True, return a list of all found files paths.
"""
raise NotImplementedError('subclasses of B... | [
"def",
"find",
"(",
"self",
",",
"path",
",",
"all",
"=",
"False",
")",
":",
"raise",
"NotImplementedError",
"(",
"'subclasses of BaseFinder must provide a find() method'",
")"
] | [
29,
4
] | [
36,
90
] | python | en | ['en', 'error', 'th'] | False |
BaseFinder.list | (self, ignore_patterns) |
Given an optional list of paths to ignore, return a two item iterable
consisting of the relative path and storage instance.
|
Given an optional list of paths to ignore, return a two item iterable
consisting of the relative path and storage instance.
| def list(self, ignore_patterns):
"""
Given an optional list of paths to ignore, return a two item iterable
consisting of the relative path and storage instance.
"""
raise NotImplementedError('subclasses of BaseFinder must provide a list() method') | [
"def",
"list",
"(",
"self",
",",
"ignore_patterns",
")",
":",
"raise",
"NotImplementedError",
"(",
"'subclasses of BaseFinder must provide a list() method'",
")"
] | [
38,
4
] | [
43,
90
] | python | en | ['en', 'error', 'th'] | False |
FileSystemFinder.find | (self, path, all=False) |
Look for files in the extra locations as defined in STATICFILES_DIRS.
|
Look for files in the extra locations as defined in STATICFILES_DIRS.
| def find(self, path, all=False):
"""
Look for files in the extra locations as defined in STATICFILES_DIRS.
"""
matches = []
for prefix, root in self.locations:
if root not in searched_locations:
searched_locations.append(root)
matched_path ... | [
"def",
"find",
"(",
"self",
",",
"path",
",",
"all",
"=",
"False",
")",
":",
"matches",
"=",
"[",
"]",
"for",
"prefix",
",",
"root",
"in",
"self",
".",
"locations",
":",
"if",
"root",
"not",
"in",
"searched_locations",
":",
"searched_locations",
".",
... | [
94,
4
] | [
107,
22
] | python | en | ['en', 'error', 'th'] | False |
FileSystemFinder.find_location | (self, root, path, prefix=None) |
Find a requested static file in a location and return the found
absolute path (or ``None`` if no match).
|
Find a requested static file in a location and return the found
absolute path (or ``None`` if no match).
| def find_location(self, root, path, prefix=None):
"""
Find a requested static file in a location and return the found
absolute path (or ``None`` if no match).
"""
if prefix:
prefix = '%s%s' % (prefix, os.sep)
if not path.startswith(prefix):
... | [
"def",
"find_location",
"(",
"self",
",",
"root",
",",
"path",
",",
"prefix",
"=",
"None",
")",
":",
"if",
"prefix",
":",
"prefix",
"=",
"'%s%s'",
"%",
"(",
"prefix",
",",
"os",
".",
"sep",
")",
"if",
"not",
"path",
".",
"startswith",
"(",
"prefix"... | [
109,
4
] | [
121,
23
] | python | en | ['en', 'error', 'th'] | False |
FileSystemFinder.list | (self, ignore_patterns) |
List all files in all locations.
|
List all files in all locations.
| def list(self, ignore_patterns):
"""
List all files in all locations.
"""
for prefix, root in self.locations:
storage = self.storages[root]
for path in utils.get_files(storage, ignore_patterns):
yield path, storage | [
"def",
"list",
"(",
"self",
",",
"ignore_patterns",
")",
":",
"for",
"prefix",
",",
"root",
"in",
"self",
".",
"locations",
":",
"storage",
"=",
"self",
".",
"storages",
"[",
"root",
"]",
"for",
"path",
"in",
"utils",
".",
"get_files",
"(",
"storage",
... | [
123,
4
] | [
130,
35
] | python | en | ['en', 'error', 'th'] | False |
AppDirectoriesFinder.list | (self, ignore_patterns) |
List all files in all app storages.
|
List all files in all app storages.
| def list(self, ignore_patterns):
"""
List all files in all app storages.
"""
for storage in self.storages.values():
if storage.exists(''): # check if storage location exists
for path in utils.get_files(storage, ignore_patterns):
yield path... | [
"def",
"list",
"(",
"self",
",",
"ignore_patterns",
")",
":",
"for",
"storage",
"in",
"self",
".",
"storages",
".",
"values",
"(",
")",
":",
"if",
"storage",
".",
"exists",
"(",
"''",
")",
":",
"# check if storage location exists",
"for",
"path",
"in",
"... | [
159,
4
] | [
166,
39
] | python | en | ['en', 'error', 'th'] | False |
AppDirectoriesFinder.find | (self, path, all=False) |
Look for files in the app directories.
|
Look for files in the app directories.
| def find(self, path, all=False):
"""
Look for files in the app directories.
"""
matches = []
for app in self.apps:
app_location = self.storages[app].location
if app_location not in searched_locations:
searched_locations.append(app_location)... | [
"def",
"find",
"(",
"self",
",",
"path",
",",
"all",
"=",
"False",
")",
":",
"matches",
"=",
"[",
"]",
"for",
"app",
"in",
"self",
".",
"apps",
":",
"app_location",
"=",
"self",
".",
"storages",
"[",
"app",
"]",
".",
"location",
"if",
"app_location... | [
168,
4
] | [
182,
22
] | python | en | ['en', 'error', 'th'] | False |
AppDirectoriesFinder.find_in_app | (self, app, path) |
Find a requested static file in an app's static locations.
|
Find a requested static file in an app's static locations.
| def find_in_app(self, app, path):
"""
Find a requested static file in an app's static locations.
"""
storage = self.storages.get(app)
# Only try to find a file if the source dir actually exists.
if storage and storage.exists(path):
matched_path = storage.path(... | [
"def",
"find_in_app",
"(",
"self",
",",
"app",
",",
"path",
")",
":",
"storage",
"=",
"self",
".",
"storages",
".",
"get",
"(",
"app",
")",
"# Only try to find a file if the source dir actually exists.",
"if",
"storage",
"and",
"storage",
".",
"exists",
"(",
"... | [
184,
4
] | [
193,
35
] | python | en | ['en', 'error', 'th'] | False |
BaseStorageFinder.find | (self, path, all=False) |
Look for files in the default file storage, if it's local.
|
Look for files in the default file storage, if it's local.
| def find(self, path, all=False):
"""
Look for files in the default file storage, if it's local.
"""
try:
self.storage.path('')
except NotImplementedError:
pass
else:
if self.storage.location not in searched_locations:
se... | [
"def",
"find",
"(",
"self",
",",
"path",
",",
"all",
"=",
"False",
")",
":",
"try",
":",
"self",
".",
"storage",
".",
"path",
"(",
"''",
")",
"except",
"NotImplementedError",
":",
"pass",
"else",
":",
"if",
"self",
".",
"storage",
".",
"location",
... | [
215,
4
] | [
231,
17
] | python | en | ['en', 'error', 'th'] | False |
BaseStorageFinder.list | (self, ignore_patterns) |
List all files of the storage.
|
List all files of the storage.
| def list(self, ignore_patterns):
"""
List all files of the storage.
"""
for path in utils.get_files(self.storage, ignore_patterns):
yield path, self.storage | [
"def",
"list",
"(",
"self",
",",
"ignore_patterns",
")",
":",
"for",
"path",
"in",
"utils",
".",
"get_files",
"(",
"self",
".",
"storage",
",",
"ignore_patterns",
")",
":",
"yield",
"path",
",",
"self",
".",
"storage"
] | [
233,
4
] | [
238,
36
] | python | en | ['en', 'error', 'th'] | False |
eval | (expression, _dict={}, **kw) |
Evaluates an image expression.
:param expression: A string containing a Python-style expression.
:param options: Values to add to the evaluation context. You
can either use a dictionary, or one or more keyword
arguments.
:return: The evaluated expression. This ... |
Evaluates an image expression. | def eval(expression, _dict={}, **kw):
"""
Evaluates an image expression.
:param expression: A string containing a Python-style expression.
:param options: Values to add to the evaluation context. You
can either use a dictionary, or one or more keyword
arguments.... | [
"def",
"eval",
"(",
"expression",
",",
"_dict",
"=",
"{",
"}",
",",
"*",
"*",
"kw",
")",
":",
"# build execution namespace",
"args",
"=",
"ops",
".",
"copy",
"(",
")",
"args",
".",
"update",
"(",
"_dict",
")",
"args",
".",
"update",
"(",
"kw",
")",... | [
227,
0
] | [
252,
18
] | python | en | ['en', 'error', 'th'] | False |
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... | [
135,
4
] | [
167,
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",
","... | [
169,
4
] | [
185,
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 ... | [
187,
4
] | [
202,
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",
"(",
")",
... | [
204,
4
] | [
214,
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... | [
216,
4
] | [
261,
68
] | 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... | [
264,
4
] | [
278,
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",
"''"
] | [
280,
4
] | [
286,
47
] | python | en | ['en', 'error', 'th'] | False |
get_rmse | (output_row, output_col, actual) | Compute rmse between predicted and actual ratings.
Args:
output_row: evaluated numpy array of row_factor
output_col: evaluated numpy array of col_factor
actual: coo_matrix of actual (test) values
Returns:
rmse
| Compute rmse between predicted and actual ratings. | def get_rmse(output_row, output_col, actual):
"""Compute rmse between predicted and actual ratings.
Args:
output_row: evaluated numpy array of row_factor
output_col: evaluated numpy array of col_factor
actual: coo_matrix of actual (test) values
Returns:
rmse
"""
mse = 0
for i in xrange(act... | [
"def",
"get_rmse",
"(",
"output_row",
",",
"output_col",
",",
"actual",
")",
":",
"mse",
"=",
"0",
"for",
"i",
"in",
"xrange",
"(",
"actual",
".",
"data",
".",
"shape",
"[",
"0",
"]",
")",
":",
"row_pred",
"=",
"output_row",
"[",
"actual",
".",
"ro... | [
23,
0
] | [
42,
13
] | python | en | ['en', 'en', 'en'] | True |
simple_train | (model, input_tensor, num_iterations) | Helper function to train model on input for num_iterations.
Args:
model: WALSModel instance
input_tensor: SparseTensor for input ratings matrix
num_iterations: number of row/column updates to run
Returns:
tensorflow session, for evaluating results
| Helper function to train model on input for num_iterations. | def simple_train(model, input_tensor, num_iterations):
"""Helper function to train model on input for num_iterations.
Args:
model: WALSModel instance
input_tensor: SparseTensor for input ratings matrix
num_iterations: number of row/column updates to run
Returns:
tensorflow sessi... | [
"def",
"simple_train",
"(",
"model",
",",
"input_tensor",
",",
"num_iterations",
")",
":",
"sess",
"=",
"tf",
".",
"Session",
"(",
"graph",
"=",
"input_tensor",
".",
"graph",
")",
"with",
"input_tensor",
".",
"graph",
".",
"as_default",
"(",
")",
":",
"r... | [
45,
0
] | [
72,
13
] | python | en | ['en', 'en', 'en'] | True |
make_wts | (data, wt_type, obs_wt, feature_wt_exp, axis) | Generate observed item weights.
Args:
data: coo_matrix of ratings data
wt_type: weight type, LOG_RATINGS or LINEAR_RATINGS
obs_wt: linear weight factor
feature_wt_exp: logarithmic weight factor
axis: axis to make weights for, 1=rows/users, 0=cols/items... | Generate observed item weights. | def make_wts(data, wt_type, obs_wt, feature_wt_exp, axis):
"""Generate observed item weights.
Args:
data: coo_matrix of ratings data
wt_type: weight type, LOG_RATINGS or LINEAR_RATINGS
obs_wt: linear weight factor
feature_wt_exp: logarithmic weight factor
axis: ... | [
"def",
"make_wts",
"(",
"data",
",",
"wt_type",
",",
"obs_wt",
",",
"feature_wt_exp",
",",
"axis",
")",
":",
"# recipricol of sum of number of items across rows (if axis is 0)",
"frac",
"=",
"np",
".",
"array",
"(",
"1.0",
"/",
"(",
"data",
">",
"0.0",
")",
".... | [
79,
0
] | [
106,
12
] | python | en | ['en', 'en', 'en'] | True |
wals_model | (data, dim, reg, unobs, weights=False,
wt_type=LINEAR_RATINGS, feature_wt_exp=None,
obs_wt=LINEAR_OBS_W) | Create the WALSModel and input, row and col factor tensors.
Args:
data: scipy coo_matrix of item ratings
dim: number of latent factors
reg: regularization constant
unobs: unobserved item weight
weights: True: set obs weights, False: obs weights = un... | Create the WALSModel and input, row and col factor tensors. | def wals_model(data, dim, reg, unobs, weights=False,
wt_type=LINEAR_RATINGS, feature_wt_exp=None,
obs_wt=LINEAR_OBS_W):
"""Create the WALSModel and input, row and col factor tensors.
Args:
data: scipy coo_matrix of item ratings
dim: number of latent factor... | [
"def",
"wals_model",
"(",
"data",
",",
"dim",
",",
"reg",
",",
"unobs",
",",
"weights",
"=",
"False",
",",
"wt_type",
"=",
"LINEAR_RATINGS",
",",
"feature_wt_exp",
"=",
"None",
",",
"obs_wt",
"=",
"LINEAR_OBS_W",
")",
":",
"row_wts",
"=",
"None",
"col_wt... | [
109,
0
] | [
160,
52
] | python | en | ['en', 'en', 'en'] | True |
reset_cache | (**kwargs) |
Reset global state when LANGUAGES setting has been changed, as some
languages should no longer be accepted.
|
Reset global state when LANGUAGES setting has been changed, as some
languages should no longer be accepted.
| def reset_cache(**kwargs):
"""
Reset global state when LANGUAGES setting has been changed, as some
languages should no longer be accepted.
"""
if kwargs['setting'] in ('LANGUAGES', 'LANGUAGE_CODE'):
check_for_language.cache_clear()
get_languages.cache_clear()
get_supported_la... | [
"def",
"reset_cache",
"(",
"*",
"*",
"kwargs",
")",
":",
"if",
"kwargs",
"[",
"'setting'",
"]",
"in",
"(",
"'LANGUAGES'",
",",
"'LANGUAGE_CODE'",
")",
":",
"check_for_language",
".",
"cache_clear",
"(",
")",
"get_languages",
".",
"cache_clear",
"(",
")",
"... | [
49,
0
] | [
57,
52
] | python | en | ['en', 'error', 'th'] | False |
translation | (language) |
Return a translation object in the default 'django' domain.
|
Return a translation object in the default 'django' domain.
| def translation(language):
"""
Return a translation object in the default 'django' domain.
"""
global _translations
if language not in _translations:
_translations[language] = DjangoTranslation(language)
return _translations[language] | [
"def",
"translation",
"(",
"language",
")",
":",
"global",
"_translations",
"if",
"language",
"not",
"in",
"_translations",
":",
"_translations",
"[",
"language",
"]",
"=",
"DjangoTranslation",
"(",
"language",
")",
"return",
"_translations",
"[",
"language",
"]... | [
261,
0
] | [
268,
34
] | python | en | ['en', 'error', 'th'] | False |
activate | (language) |
Fetch the translation object for a given language and install it as the
current translation object for the current thread.
|
Fetch the translation object for a given language and install it as the
current translation object for the current thread.
| def activate(language):
"""
Fetch the translation object for a given language and install it as the
current translation object for the current thread.
"""
if not language:
return
_active.value = translation(language) | [
"def",
"activate",
"(",
"language",
")",
":",
"if",
"not",
"language",
":",
"return",
"_active",
".",
"value",
"=",
"translation",
"(",
"language",
")"
] | [
271,
0
] | [
278,
41
] | python | en | ['en', 'error', 'th'] | False |
deactivate | () |
Uninstall the active translation object so that further _() calls resolve
to the default translation object.
|
Uninstall the active translation object so that further _() calls resolve
to the default translation object.
| def deactivate():
"""
Uninstall the active translation object so that further _() calls resolve
to the default translation object.
"""
if hasattr(_active, "value"):
del _active.value | [
"def",
"deactivate",
"(",
")",
":",
"if",
"hasattr",
"(",
"_active",
",",
"\"value\"",
")",
":",
"del",
"_active",
".",
"value"
] | [
281,
0
] | [
287,
25
] | python | en | ['en', 'error', 'th'] | False |
deactivate_all | () |
Make the active translation object a NullTranslations() instance. This is
useful when we want delayed translations to appear as the original string
for some reason.
|
Make the active translation object a NullTranslations() instance. This is
useful when we want delayed translations to appear as the original string
for some reason.
| def deactivate_all():
"""
Make the active translation object a NullTranslations() instance. This is
useful when we want delayed translations to appear as the original string
for some reason.
"""
_active.value = gettext_module.NullTranslations()
_active.value.to_language = lambda *args: None | [
"def",
"deactivate_all",
"(",
")",
":",
"_active",
".",
"value",
"=",
"gettext_module",
".",
"NullTranslations",
"(",
")",
"_active",
".",
"value",
".",
"to_language",
"=",
"lambda",
"*",
"args",
":",
"None"
] | [
290,
0
] | [
297,
50
] | python | en | ['en', 'error', 'th'] | False |
get_language | () | Return the currently selected language. | Return the currently selected language. | def get_language():
"""Return the currently selected language."""
t = getattr(_active, "value", None)
if t is not None:
try:
return t.to_language()
except AttributeError:
pass
# If we don't have a real translation object, assume it's the default language.
retu... | [
"def",
"get_language",
"(",
")",
":",
"t",
"=",
"getattr",
"(",
"_active",
",",
"\"value\"",
",",
"None",
")",
"if",
"t",
"is",
"not",
"None",
":",
"try",
":",
"return",
"t",
".",
"to_language",
"(",
")",
"except",
"AttributeError",
":",
"pass",
"# I... | [
300,
0
] | [
309,
33
] | python | en | ['en', 'en', 'en'] | True |
get_language_bidi | () |
Return selected language's BiDi layout.
* False = left-to-right layout
* True = right-to-left layout
|
Return selected language's BiDi layout. | def get_language_bidi():
"""
Return selected language's BiDi layout.
* False = left-to-right layout
* True = right-to-left layout
"""
lang = get_language()
if lang is None:
return False
else:
base_lang = get_language().split('-')[0]
return base_lang in settings.L... | [
"def",
"get_language_bidi",
"(",
")",
":",
"lang",
"=",
"get_language",
"(",
")",
"if",
"lang",
"is",
"None",
":",
"return",
"False",
"else",
":",
"base_lang",
"=",
"get_language",
"(",
")",
".",
"split",
"(",
"'-'",
")",
"[",
"0",
"]",
"return",
"ba... | [
312,
0
] | [
324,
51
] | python | en | ['en', 'error', 'th'] | False |
catalog | () |
Return the current active catalog for further processing.
This can be used if you need to modify the catalog or want to access the
whole message catalog instead of just translating one string.
|
Return the current active catalog for further processing.
This can be used if you need to modify the catalog or want to access the
whole message catalog instead of just translating one string.
| def catalog():
"""
Return the current active catalog for further processing.
This can be used if you need to modify the catalog or want to access the
whole message catalog instead of just translating one string.
"""
global _default
t = getattr(_active, "value", None)
if t is not None:
... | [
"def",
"catalog",
"(",
")",
":",
"global",
"_default",
"t",
"=",
"getattr",
"(",
"_active",
",",
"\"value\"",
",",
"None",
")",
"if",
"t",
"is",
"not",
"None",
":",
"return",
"t",
"if",
"_default",
"is",
"None",
":",
"_default",
"=",
"translation",
"... | [
327,
0
] | [
340,
19
] | python | en | ['en', 'error', 'th'] | False |
gettext | (message) |
Translate the 'message' string. It uses the current thread to find the
translation object to use. If no current translation is activated, the
message will be run through the default translation object.
|
Translate the 'message' string. It uses the current thread to find the
translation object to use. If no current translation is activated, the
message will be run through the default translation object.
| def gettext(message):
"""
Translate the 'message' string. It uses the current thread to find the
translation object to use. If no current translation is activated, the
message will be run through the default translation object.
"""
global _default
eol_message = message.replace('\r\n', '\n')... | [
"def",
"gettext",
"(",
"message",
")",
":",
"global",
"_default",
"eol_message",
"=",
"message",
".",
"replace",
"(",
"'\\r\\n'",
",",
"'\\n'",
")",
".",
"replace",
"(",
"'\\r'",
",",
"'\\n'",
")",
"if",
"eol_message",
":",
"_default",
"=",
"_default",
"... | [
343,
0
] | [
366,
17
] | python | en | ['en', 'error', 'th'] | False |
gettext_noop | (message) |
Mark strings for translation but don't translate them now. This can be
used to store strings in global variables that should stay in the base
language (because they might be used externally) and will be translated
later.
|
Mark strings for translation but don't translate them now. This can be
used to store strings in global variables that should stay in the base
language (because they might be used externally) and will be translated
later.
| def gettext_noop(message):
"""
Mark strings for translation but don't translate them now. This can be
used to store strings in global variables that should stay in the base
language (because they might be used externally) and will be translated
later.
"""
return message | [
"def",
"gettext_noop",
"(",
"message",
")",
":",
"return",
"message"
] | [
380,
0
] | [
387,
18
] | python | en | ['en', 'error', 'th'] | False |
ngettext | (singular, plural, number) |
Return a string of the translation of either the singular or plural,
based on the number.
|
Return a string of the translation of either the singular or plural,
based on the number.
| def ngettext(singular, plural, number):
"""
Return a string of the translation of either the singular or plural,
based on the number.
"""
return do_ntranslate(singular, plural, number, 'ngettext') | [
"def",
"ngettext",
"(",
"singular",
",",
"plural",
",",
"number",
")",
":",
"return",
"do_ntranslate",
"(",
"singular",
",",
"plural",
",",
"number",
",",
"'ngettext'",
")"
] | [
401,
0
] | [
406,
62
] | python | en | ['en', 'error', 'th'] | False |
all_locale_paths | () |
Return a list of paths to user-provides languages files.
|
Return a list of paths to user-provides languages files.
| def all_locale_paths():
"""
Return a list of paths to user-provides languages files.
"""
globalpath = os.path.join(
os.path.dirname(sys.modules[settings.__module__].__file__), 'locale')
app_paths = []
for app_config in apps.get_app_configs():
locale_path = os.path.join(app_config... | [
"def",
"all_locale_paths",
"(",
")",
":",
"globalpath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"sys",
".",
"modules",
"[",
"settings",
".",
"__module__",
"]",
".",
"__file__",
")",
",",
"'locale'",
")",
"app... | [
420,
0
] | [
431,
59
] | python | en | ['en', 'error', 'th'] | False |
check_for_language | (lang_code) |
Check whether there is a global language file for the given language
code. This is used to decide whether a user-provided language is
available.
lru_cache should have a maxsize to prevent from memory exhaustion attacks,
as the provided language codes are taken from the HTTP request. See also
<... |
Check whether there is a global language file for the given language
code. This is used to decide whether a user-provided language is
available. | def check_for_language(lang_code):
"""
Check whether there is a global language file for the given language
code. This is used to decide whether a user-provided language is
available.
lru_cache should have a maxsize to prevent from memory exhaustion attacks,
as the provided language codes are t... | [
"def",
"check_for_language",
"(",
"lang_code",
")",
":",
"# First, a quick check to make sure lang_code is well-formed (#21458)",
"if",
"lang_code",
"is",
"None",
"or",
"not",
"language_code_re",
".",
"search",
"(",
"lang_code",
")",
":",
"return",
"False",
"return",
"a... | [
435,
0
] | [
451,
5
] | python | en | ['en', 'error', 'th'] | False |
get_languages | () |
Cache of settings.LANGUAGES in a dictionary for easy lookups by key.
|
Cache of settings.LANGUAGES in a dictionary for easy lookups by key.
| def get_languages():
"""
Cache of settings.LANGUAGES in a dictionary for easy lookups by key.
"""
return dict(settings.LANGUAGES) | [
"def",
"get_languages",
"(",
")",
":",
"return",
"dict",
"(",
"settings",
".",
"LANGUAGES",
")"
] | [
455,
0
] | [
459,
35
] | python | en | ['en', 'error', 'th'] | False |
get_supported_language_variant | (lang_code, strict=False) |
Return the language code that's listed in supported languages, possibly
selecting a more generic variant. Raise LookupError if nothing is found.
If `strict` is False (the default), look for a country-specific variant
when neither the language code nor its generic variant is found.
lru_cache shoul... |
Return the language code that's listed in supported languages, possibly
selecting a more generic variant. Raise LookupError if nothing is found. | def get_supported_language_variant(lang_code, strict=False):
"""
Return the language code that's listed in supported languages, possibly
selecting a more generic variant. Raise LookupError if nothing is found.
If `strict` is False (the default), look for a country-specific variant
when neither the ... | [
"def",
"get_supported_language_variant",
"(",
"lang_code",
",",
"strict",
"=",
"False",
")",
":",
"if",
"lang_code",
":",
"# If 'fr-ca' is not supported, try special fallback or language-only 'fr'.",
"possible_lang_codes",
"=",
"[",
"lang_code",
"]",
"try",
":",
"possible_l... | [
463,
0
] | [
494,
32
] | python | en | ['en', 'error', 'th'] | False |
get_language_from_path | (path, strict=False) |
Return the language code if there's a valid language code found in `path`.
If `strict` is False (the default), look for a country-specific variant
when neither the language code nor its generic variant is found.
|
Return the language code if there's a valid language code found in `path`. | def get_language_from_path(path, strict=False):
"""
Return the language code if there's a valid language code found in `path`.
If `strict` is False (the default), look for a country-specific variant
when neither the language code nor its generic variant is found.
"""
regex_match = language_code... | [
"def",
"get_language_from_path",
"(",
"path",
",",
"strict",
"=",
"False",
")",
":",
"regex_match",
"=",
"language_code_prefix_re",
".",
"match",
"(",
"path",
")",
"if",
"not",
"regex_match",
":",
"return",
"None",
"lang_code",
"=",
"regex_match",
"[",
"1",
... | [
497,
0
] | [
511,
19
] | python | en | ['en', 'error', 'th'] | False |
get_language_from_request | (request, check_path=False) |
Analyze the request to find what language the user wants the system to
show. Only languages listed in settings.LANGUAGES are taken into account.
If the user requests a sublanguage where we have a main language, we send
out the main language.
If check_path is True, the URL path prefix will be check... |
Analyze the request to find what language the user wants the system to
show. Only languages listed in settings.LANGUAGES are taken into account.
If the user requests a sublanguage where we have a main language, we send
out the main language. | def get_language_from_request(request, check_path=False):
"""
Analyze the request to find what language the user wants the system to
show. Only languages listed in settings.LANGUAGES are taken into account.
If the user requests a sublanguage where we have a main language, we send
out the main langua... | [
"def",
"get_language_from_request",
"(",
"request",
",",
"check_path",
"=",
"False",
")",
":",
"if",
"check_path",
":",
"lang_code",
"=",
"get_language_from_path",
"(",
"request",
".",
"path_info",
")",
"if",
"lang_code",
"is",
"not",
"None",
":",
"return",
"l... | [
514,
0
] | [
554,
37
] | python | en | ['en', 'error', 'th'] | False |
parse_accept_lang_header | (lang_string) |
Parse the lang_string, which is the body of an HTTP Accept-Language
header, and return a tuple of (lang, q-value), ordered by 'q' values.
Return an empty tuple if there are any format errors in lang_string.
|
Parse the lang_string, which is the body of an HTTP Accept-Language
header, and return a tuple of (lang, q-value), ordered by 'q' values. | def parse_accept_lang_header(lang_string):
"""
Parse the lang_string, which is the body of an HTTP Accept-Language
header, and return a tuple of (lang, q-value), ordered by 'q' values.
Return an empty tuple if there are any format errors in lang_string.
"""
result = []
pieces = accept_langu... | [
"def",
"parse_accept_lang_header",
"(",
"lang_string",
")",
":",
"result",
"=",
"[",
"]",
"pieces",
"=",
"accept_language_re",
".",
"split",
"(",
"lang_string",
".",
"lower",
"(",
")",
")",
"if",
"pieces",
"[",
"-",
"1",
"]",
":",
"return",
"(",
")",
"... | [
558,
0
] | [
579,
24
] | python | en | ['en', 'error', 'th'] | False |
DjangoTranslation.__init__ | (self, language, domain=None, localedirs=None) | Create a GNUTranslations() using many locale directories | Create a GNUTranslations() using many locale directories | def __init__(self, language, domain=None, localedirs=None):
"""Create a GNUTranslations() using many locale directories"""
gettext_module.GNUTranslations.__init__(self)
if domain is not None:
self.domain = domain
self.__language = language
self.__to_language = to_lan... | [
"def",
"__init__",
"(",
"self",
",",
"language",
",",
"domain",
"=",
"None",
",",
"localedirs",
"=",
"None",
")",
":",
"gettext_module",
".",
"GNUTranslations",
".",
"__init__",
"(",
"self",
")",
"if",
"domain",
"is",
"not",
"None",
":",
"self",
".",
"... | [
128,
4
] | [
163,
48
] | python | en | ['en', 'en', 'en'] | True |
DjangoTranslation._new_gnu_trans | (self, localedir, use_null_fallback=True) |
Return a mergeable gettext.GNUTranslations instance.
A convenience wrapper. By default gettext uses 'fallback=False'.
Using param `use_null_fallback` to avoid confusion with any other
references to 'fallback'.
|
Return a mergeable gettext.GNUTranslations instance. | def _new_gnu_trans(self, localedir, use_null_fallback=True):
"""
Return a mergeable gettext.GNUTranslations instance.
A convenience wrapper. By default gettext uses 'fallback=False'.
Using param `use_null_fallback` to avoid confusion with any other
references to 'fallback'.
... | [
"def",
"_new_gnu_trans",
"(",
"self",
",",
"localedir",
",",
"use_null_fallback",
"=",
"True",
")",
":",
"return",
"gettext_module",
".",
"translation",
"(",
"domain",
"=",
"self",
".",
"domain",
",",
"localedir",
"=",
"localedir",
",",
"languages",
"=",
"["... | [
168,
4
] | [
181,
9
] | python | en | ['en', 'error', 'th'] | False |
DjangoTranslation._init_translation_catalog | (self) | Create a base catalog using global django translations. | Create a base catalog using global django translations. | def _init_translation_catalog(self):
"""Create a base catalog using global django translations."""
settingsfile = sys.modules[settings.__module__].__file__
localedir = os.path.join(os.path.dirname(settingsfile), 'locale')
translation = self._new_gnu_trans(localedir)
self.merge(tr... | [
"def",
"_init_translation_catalog",
"(",
"self",
")",
":",
"settingsfile",
"=",
"sys",
".",
"modules",
"[",
"settings",
".",
"__module__",
"]",
".",
"__file__",
"localedir",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"("... | [
183,
4
] | [
188,
31
] | python | en | ['en', 'bg', 'en'] | True |
DjangoTranslation._add_installed_apps_translations | (self) | Merge translations from each installed app. | Merge translations from each installed app. | def _add_installed_apps_translations(self):
"""Merge translations from each installed app."""
try:
app_configs = reversed(list(apps.get_app_configs()))
except AppRegistryNotReady:
raise AppRegistryNotReady(
"The translation infrastructure cannot be initial... | [
"def",
"_add_installed_apps_translations",
"(",
"self",
")",
":",
"try",
":",
"app_configs",
"=",
"reversed",
"(",
"list",
"(",
"apps",
".",
"get_app_configs",
"(",
")",
")",
")",
"except",
"AppRegistryNotReady",
":",
"raise",
"AppRegistryNotReady",
"(",
"\"The ... | [
190,
4
] | [
203,
39
] | python | en | ['en', 'en', 'en'] | True |
DjangoTranslation._add_local_translations | (self) | Merge translations defined in LOCALE_PATHS. | Merge translations defined in LOCALE_PATHS. | def _add_local_translations(self):
"""Merge translations defined in LOCALE_PATHS."""
for localedir in reversed(settings.LOCALE_PATHS):
translation = self._new_gnu_trans(localedir)
self.merge(translation) | [
"def",
"_add_local_translations",
"(",
"self",
")",
":",
"for",
"localedir",
"in",
"reversed",
"(",
"settings",
".",
"LOCALE_PATHS",
")",
":",
"translation",
"=",
"self",
".",
"_new_gnu_trans",
"(",
"localedir",
")",
"self",
".",
"merge",
"(",
"translation",
... | [
205,
4
] | [
209,
35
] | python | en | ['en', 'en', 'en'] | True |
DjangoTranslation._add_fallback | (self, localedirs=None) | Set the GNUTranslations() fallback with the default language. | Set the GNUTranslations() fallback with the default language. | def _add_fallback(self, localedirs=None):
"""Set the GNUTranslations() fallback with the default language."""
# Don't set a fallback for the default language or any English variant
# (as it's empty, so it'll ALWAYS fall back to the default language)
if self.__language == settings.LANGUAG... | [
"def",
"_add_fallback",
"(",
"self",
",",
"localedirs",
"=",
"None",
")",
":",
"# Don't set a fallback for the default language or any English variant",
"# (as it's empty, so it'll ALWAYS fall back to the default language)",
"if",
"self",
".",
"__language",
"==",
"settings",
".",... | [
211,
4
] | [
224,
46
] | python | en | ['en', 'en', 'en'] | True |
DjangoTranslation.merge | (self, other) | Merge another translation into this catalog. | Merge another translation into this catalog. | def merge(self, other):
"""Merge another translation into this catalog."""
if not getattr(other, '_catalog', None):
return # NullTranslations() has no _catalog
if self._catalog is None:
# Take plural and _info from first catalog found (generally Django's).
se... | [
"def",
"merge",
"(",
"self",
",",
"other",
")",
":",
"if",
"not",
"getattr",
"(",
"other",
",",
"'_catalog'",
",",
"None",
")",
":",
"return",
"# NullTranslations() has no _catalog",
"if",
"self",
".",
"_catalog",
"is",
"None",
":",
"# Take plural and _info fr... | [
226,
4
] | [
238,
46
] | python | en | ['en', 'en', 'en'] | True |
DjangoTranslation.language | (self) | Return the translation language. | Return the translation language. | def language(self):
"""Return the translation language."""
return self.__language | [
"def",
"language",
"(",
"self",
")",
":",
"return",
"self",
".",
"__language"
] | [
240,
4
] | [
242,
30
] | python | en | ['en', 'zu', 'en'] | True |
DjangoTranslation.to_language | (self) | Return the translation language name. | Return the translation language name. | def to_language(self):
"""Return the translation language name."""
return self.__to_language | [
"def",
"to_language",
"(",
"self",
")",
":",
"return",
"self",
".",
"__to_language"
] | [
244,
4
] | [
246,
33
] | python | en | ['en', 'zu', 'en'] | True |
detect | (byte_str) |
Detect the encoding of the given byte string.
:param byte_str: The byte sequence to examine.
:type byte_str: ``bytes`` or ``bytearray``
|
Detect the encoding of the given byte string. | def detect(byte_str):
"""
Detect the encoding of the given byte string.
:param byte_str: The byte sequence to examine.
:type byte_str: ``bytes`` or ``bytearray``
"""
if not isinstance(byte_str, bytearray):
if not isinstance(byte_str, bytes):
raise TypeError('Expecte... | [
"def",
"detect",
"(",
"byte_str",
")",
":",
"if",
"not",
"isinstance",
"(",
"byte_str",
",",
"bytearray",
")",
":",
"if",
"not",
"isinstance",
"(",
"byte_str",
",",
"bytes",
")",
":",
"raise",
"TypeError",
"(",
"'Expected object of type bytes or bytearray, got: ... | [
26,
0
] | [
41,
27
] | python | en | ['en', 'error', 'th'] | False |
detect_all | (byte_str) |
Detect all the possible encodings of the given byte string.
:param byte_str: The byte sequence to examine.
:type byte_str: ``bytes`` or ``bytearray``
|
Detect all the possible encodings of the given byte string. | def detect_all(byte_str):
"""
Detect all the possible encodings of the given byte string.
:param byte_str: The byte sequence to examine.
:type byte_str: ``bytes`` or ``bytearray``
"""
if not isinstance(byte_str, bytearray):
if not isinstance(byte_str, bytes):
raise ... | [
"def",
"detect_all",
"(",
"byte_str",
")",
":",
"if",
"not",
"isinstance",
"(",
"byte_str",
",",
"bytearray",
")",
":",
"if",
"not",
"isinstance",
"(",
"byte_str",
",",
"bytes",
")",
":",
"raise",
"TypeError",
"(",
"'Expected object of type bytes or bytearray, g... | [
44,
0
] | [
82,
28
] | python | en | ['en', 'error', 'th'] | False |
TreeWalker.__init__ | (self, tree) | Creates a TreeWalker
:arg tree: the tree to walk
| Creates a TreeWalker | def __init__(self, tree):
"""Creates a TreeWalker
:arg tree: the tree to walk
"""
self.tree = tree | [
"def",
"__init__",
"(",
"self",
",",
"tree",
")",
":",
"self",
".",
"tree",
"=",
"tree"
] | [
26,
4
] | [
32,
24
] | python | en | ['en', 'et', 'en'] | True |
TreeWalker.error | (self, msg) | Generates an error token with the given message
:arg msg: the error message
:returns: SerializeError token
| Generates an error token with the given message | def error(self, msg):
"""Generates an error token with the given message
:arg msg: the error message
:returns: SerializeError token
"""
return {"type": "SerializeError", "data": msg} | [
"def",
"error",
"(",
"self",
",",
"msg",
")",
":",
"return",
"{",
"\"type\"",
":",
"\"SerializeError\"",
",",
"\"data\"",
":",
"msg",
"}"
] | [
37,
4
] | [
45,
54
] | python | en | ['en', 'en', 'en'] | True |
TreeWalker.emptyTag | (self, namespace, name, attrs, hasChildren=False) | Generates an EmptyTag token
:arg namespace: the namespace of the token--can be ``None``
:arg name: the name of the element
:arg attrs: the attributes of the element as a dict
:arg hasChildren: whether or not to yield a SerializationError because
this tag shouldn't have ch... | Generates an EmptyTag token | def emptyTag(self, namespace, name, attrs, hasChildren=False):
"""Generates an EmptyTag token
:arg namespace: the namespace of the token--can be ``None``
:arg name: the name of the element
:arg attrs: the attributes of the element as a dict
:arg hasChildren: whether or not to... | [
"def",
"emptyTag",
"(",
"self",
",",
"namespace",
",",
"name",
",",
"attrs",
",",
"hasChildren",
"=",
"False",
")",
":",
"yield",
"{",
"\"type\"",
":",
"\"EmptyTag\"",
",",
"\"name\"",
":",
"name",
",",
"\"namespace\"",
":",
"namespace",
",",
"\"data\"",
... | [
47,
4
] | [
66,
57
] | python | de | ['en', 'de', 'nl'] | False |
TreeWalker.startTag | (self, namespace, name, attrs) | Generates a StartTag token
:arg namespace: the namespace of the token--can be ``None``
:arg name: the name of the element
:arg attrs: the attributes of the element as a dict
:returns: StartTag token
| Generates a StartTag token | def startTag(self, namespace, name, attrs):
"""Generates a StartTag token
:arg namespace: the namespace of the token--can be ``None``
:arg name: the name of the element
:arg attrs: the attributes of the element as a dict
:returns: StartTag token
"""
return {"... | [
"def",
"startTag",
"(",
"self",
",",
"namespace",
",",
"name",
",",
"attrs",
")",
":",
"return",
"{",
"\"type\"",
":",
"\"StartTag\"",
",",
"\"name\"",
":",
"name",
",",
"\"namespace\"",
":",
"namespace",
",",
"\"data\"",
":",
"attrs",
"}"
] | [
68,
4
] | [
83,
30
] | python | en | ['en', 'de', 'en'] | True |
TreeWalker.endTag | (self, namespace, name) | Generates an EndTag token
:arg namespace: the namespace of the token--can be ``None``
:arg name: the name of the element
:returns: EndTag token
| Generates an EndTag token | def endTag(self, namespace, name):
"""Generates an EndTag token
:arg namespace: the namespace of the token--can be ``None``
:arg name: the name of the element
:returns: EndTag token
"""
return {"type": "EndTag",
"name": name,
"namespace... | [
"def",
"endTag",
"(",
"self",
",",
"namespace",
",",
"name",
")",
":",
"return",
"{",
"\"type\"",
":",
"\"EndTag\"",
",",
"\"name\"",
":",
"name",
",",
"\"namespace\"",
":",
"namespace",
"}"
] | [
85,
4
] | [
97,
39
] | python | en | ['en', 'en', 'nl'] | True |
TreeWalker.text | (self, data) | Generates SpaceCharacters and Characters tokens
Depending on what's in the data, this generates one or more
``SpaceCharacters`` and ``Characters`` tokens.
For example:
>>> from html5lib.treewalkers.base import TreeWalker
>>> # Give it an empty tree just so it instantia... | Generates SpaceCharacters and Characters tokens | def text(self, data):
"""Generates SpaceCharacters and Characters tokens
Depending on what's in the data, this generates one or more
``SpaceCharacters`` and ``Characters`` tokens.
For example:
>>> from html5lib.treewalkers.base import TreeWalker
>>> # Give it a... | [
"def",
"text",
"(",
"self",
",",
"data",
")",
":",
"data",
"=",
"data",
"middle",
"=",
"data",
".",
"lstrip",
"(",
"spaceCharacters",
")",
"left",
"=",
"data",
"[",
":",
"len",
"(",
"data",
")",
"-",
"len",
"(",
"middle",
")",
"]",
"if",
"left",
... | [
99,
4
] | [
135,
60
] | python | en | ['en', 'en', 'en'] | True |
TreeWalker.comment | (self, data) | Generates a Comment token
:arg data: the comment
:returns: Comment token
| Generates a Comment token | def comment(self, data):
"""Generates a Comment token
:arg data: the comment
:returns: Comment token
"""
return {"type": "Comment", "data": data} | [
"def",
"comment",
"(",
"self",
",",
"data",
")",
":",
"return",
"{",
"\"type\"",
":",
"\"Comment\"",
",",
"\"data\"",
":",
"data",
"}"
] | [
137,
4
] | [
145,
48
] | python | en | ['en', 'en', 'en'] | True |
TreeWalker.doctype | (self, name, publicId=None, systemId=None) | Generates a Doctype token
:arg name:
:arg publicId:
:arg systemId:
:returns: the Doctype token
| Generates a Doctype token | def doctype(self, name, publicId=None, systemId=None):
"""Generates a Doctype token
:arg name:
:arg publicId:
:arg systemId:
:returns: the Doctype token
"""
return {"type": "Doctype",
"name": name,
"publicId": publicId,
... | [
"def",
"doctype",
"(",
"self",
",",
"name",
",",
"publicId",
"=",
"None",
",",
"systemId",
"=",
"None",
")",
":",
"return",
"{",
"\"type\"",
":",
"\"Doctype\"",
",",
"\"name\"",
":",
"name",
",",
"\"publicId\"",
":",
"publicId",
",",
"\"systemId\"",
":",... | [
147,
4
] | [
162,
37
] | python | en | ['en', 'en', 'en'] | True |
TreeWalker.entity | (self, name) | Generates an Entity token
:arg name: the entity name
:returns: an Entity token
| Generates an Entity token | def entity(self, name):
"""Generates an Entity token
:arg name: the entity name
:returns: an Entity token
"""
return {"type": "Entity", "name": name} | [
"def",
"entity",
"(",
"self",
",",
"name",
")",
":",
"return",
"{",
"\"type\"",
":",
"\"Entity\"",
",",
"\"name\"",
":",
"name",
"}"
] | [
164,
4
] | [
172,
47
] | python | en | ['en', 'en', 'nl'] | True |
TreeWalker.unknown | (self, nodeType) | Handles unknown node types | Handles unknown node types | def unknown(self, nodeType):
"""Handles unknown node types"""
return self.error("Unknown node type: " + nodeType) | [
"def",
"unknown",
"(",
"self",
",",
"nodeType",
")",
":",
"return",
"self",
".",
"error",
"(",
"\"Unknown node type: \"",
"+",
"nodeType",
")"
] | [
174,
4
] | [
176,
59
] | python | en | ['en', 'de', 'en'] | True |
InvalidRod.__init__ | (self, rod) |
:param object rod:
The :class:`Rod` which is invalid.
| def __init__(self, rod):
"""
:param object rod:
The :class:`Rod` which is invalid.
"""
super(InvalidRod, self).__init__(
'invalid rod: {rod}'.format(rod=rod))
self.rod = rod | [
"def",
"__init__",
"(",
"self",
",",
"rod",
")",
":",
"super",
"(",
"InvalidRod",
",",
"self",
")",
".",
"__init__",
"(",
"'invalid rod: {rod}'",
".",
"format",
"(",
"rod",
"=",
"rod",
")",
")",
"self",
".",
"rod",
"=",
"rod"
] | [
30,
4
] | [
38,
22
] | python | en | ['en', 'error', 'th'] | False | |
InvalidRods.__init__ | (self, rods) |
:param object rods:
The :class:`Rods` which are invalid
|
:param object rods:
The :class:`Rods` which are invalid
| def __init__(self, rods):
"""
:param object rods:
The :class:`Rods` which are invalid
"""
super(InvalidRods, self).__init__(
'invalid rod: {rods}'.format(
rods=rods))
self.rods = rods | [
"def",
"__init__",
"(",
"self",
",",
"rods",
")",
":",
"super",
"(",
"InvalidRods",
",",
"self",
")",
".",
"__init__",
"(",
"'invalid rod: {rods}'",
".",
"format",
"(",
"rods",
"=",
"rods",
")",
")",
"self",
".",
"rods",
"=",
"rods"
] | [
42,
4
] | [
50,
24
] | python | en | ['en', 'error', 'th'] | False |
InvalidRodHeight.__init__ | (self, rod, max_height) |
:param Rod rod:
The :class:`Rod` which has an invalid height.
:param int max_height:
The max allowed height of the :class:`Rod`.
|
:param Rod rod:
The :class:`Rod` which has an invalid height.
:param int max_height:
The max allowed height of the :class:`Rod`.
| def __init__(self, rod, max_height):
"""
:param Rod rod:
The :class:`Rod` which has an invalid height.
:param int max_height:
The max allowed height of the :class:`Rod`.
"""
super(InvalidRodHeight, self).__init__(
'invalid rod height: {rod} exp... | [
"def",
"__init__",
"(",
"self",
",",
"rod",
",",
"max_height",
")",
":",
"super",
"(",
"InvalidRodHeight",
",",
"self",
")",
".",
"__init__",
"(",
"'invalid rod height: {rod} expecting: {height}.'",
".",
"format",
"(",
"rod",
"=",
"rod",
",",
"height",
"=",
... | [
54,
4
] | [
65,
32
] | python | en | ['en', 'error', 'th'] | False |
DuplicateDisk.__init__ | (self, rod, disk_width) |
:param Rod rod:
The duplicate :class:`Rod`.
:param int disk_width:
The width of the :class:`Disk`.
|
:param Rod rod:
The duplicate :class:`Rod`.
:param int disk_width:
The width of the :class:`Disk`.
| def __init__(self, rod, disk_width):
"""
:param Rod rod:
The duplicate :class:`Rod`.
:param int disk_width:
The width of the :class:`Disk`.
"""
super(DuplicateDisk, self).__init__(
'Duplicate disk width found: {disk_width} in: {rod}'.format(
... | [
"def",
"__init__",
"(",
"self",
",",
"rod",
",",
"disk_width",
")",
":",
"super",
"(",
"DuplicateDisk",
",",
"self",
")",
".",
"__init__",
"(",
"'Duplicate disk width found: {disk_width} in: {rod}'",
".",
"format",
"(",
"disk_width",
"=",
"disk_width",
",",
"rod... | [
73,
4
] | [
84,
36
] | python | en | ['en', 'error', 'th'] | False |
CorruptRod.__init__ | (self, rod, disk) |
:param Rod rod:
The :class:`Rod` which is corrupt.
:param int disk:
A :class:`Disk` which sits directly atop a smaller :class:`Disk`.
|
:param Rod rod:
The :class:`Rod` which is corrupt.
:param int disk:
A :class:`Disk` which sits directly atop a smaller :class:`Disk`.
| def __init__(self, rod, disk):
"""
:param Rod rod:
The :class:`Rod` which is corrupt.
:param int disk:
A :class:`Disk` which sits directly atop a smaller :class:`Disk`.
"""
super(CorruptRod, self).__init__(
'Corrupt rod, at least one disk is la... | [
"def",
"__init__",
"(",
"self",
",",
"rod",
",",
"disk",
")",
":",
"super",
"(",
"CorruptRod",
",",
"self",
")",
".",
"__init__",
"(",
"'Corrupt rod, at least one disk is larger than the one below it: {rod}'",
".",
"format",
"(",
"rod",
"=",
"rod",
")",
")",
"... | [
92,
4
] | [
103,
24
] | python | en | ['en', 'error', 'th'] | False |
InvalidStartingConditions.__init__ | (self, rods, moves) |
:param Rod rods:
The :class:`Rod`'s.
:param int moves:
Total number of moves already made (should be zero).
|
:param Rod rods:
The :class:`Rod`'s.
:param int moves:
Total number of moves already made (should be zero).
| def __init__(self, rods, moves):
"""
:param Rod rods:
The :class:`Rod`'s.
:param int moves:
Total number of moves already made (should be zero).
"""
super(InvalidStartingConditions, self).__init__(
'Invalid starting condition for rods: {rods}, ... | [
"def",
"__init__",
"(",
"self",
",",
"rods",
",",
"moves",
")",
":",
"super",
"(",
"InvalidStartingConditions",
",",
"self",
")",
".",
"__init__",
"(",
"'Invalid starting condition for rods: {rods}, with existing moves: {moves}'",
".",
"format",
"(",
"rods",
"=",
"r... | [
111,
4
] | [
122,
26
] | python | en | ['en', 'error', 'th'] | False |
InvalidEndingConditions.__init__ | (self, rods) |
:param Rod rods:
The :class:`Rod`'s.
|
:param Rod rods:
The :class:`Rod`'s.
| def __init__(self, rods):
"""
:param Rod rods:
The :class:`Rod`'s.
"""
super(InvalidEndingConditions, self).__init__(
'Invalid ending condition for rods: {rods}'.format(
rods=rods))
self.rods = rods | [
"def",
"__init__",
"(",
"self",
",",
"rods",
")",
":",
"super",
"(",
"InvalidEndingConditions",
",",
"self",
")",
".",
"__init__",
"(",
"'Invalid ending condition for rods: {rods}'",
".",
"format",
"(",
"rods",
"=",
"rods",
")",
")",
"self",
".",
"rods",
"="... | [
130,
4
] | [
138,
24
] | python | en | ['en', 'error', 'th'] | False |
InvalidTowerHeight.__init__ | (self, height) |
:param int height:
The invalid height.
|
:param int height:
The invalid height.
| def __init__(self, height):
"""
:param int height:
The invalid height.
"""
super(InvalidTowerHeight, self).__init__(
'Invalid tower height: {height}'.format(
height=height))
self.height = height | [
"def",
"__init__",
"(",
"self",
",",
"height",
")",
":",
"super",
"(",
"InvalidTowerHeight",
",",
"self",
")",
".",
"__init__",
"(",
"'Invalid tower height: {height}'",
".",
"format",
"(",
"height",
"=",
"height",
")",
")",
"self",
".",
"height",
"=",
"hei... | [
146,
4
] | [
154,
28
] | python | en | ['en', 'error', 'th'] | False |
InvalidDiskPosition.__init__ | (self, position, height) |
:param int position:
The invalid position on the :class:`Rod`.
:param int height:
The height.
|
:param int position:
The invalid position on the :class:`Rod`.
:param int height:
The height.
| def __init__(self, position, height):
"""
:param int position:
The invalid position on the :class:`Rod`.
:param int height:
The height.
"""
super(InvalidDiskPosition, self).__init__(
'Invalid disk position: {position} on Rod of height: {height}... | [
"def",
"__init__",
"(",
"self",
",",
"position",
",",
"height",
")",
":",
"super",
"(",
"InvalidDiskPosition",
",",
"self",
")",
".",
"__init__",
"(",
"'Invalid disk position: {position} on Rod of height: {height}'",
".",
"format",
"(",
"position",
"=",
"position",
... | [
162,
4
] | [
173,
28
] | python | en | ['en', 'error', 'th'] | False |
InvalidMoves.__init__ | (self, moves) |
:param int moves:
The invalid `moves`.
|
:param int moves:
The invalid `moves`.
| def __init__(self, moves):
"""
:param int moves:
The invalid `moves`.
"""
super(InvalidMoves, self).__init__(
'Invalid moves: {moves}'.format(
moves=moves))
self.moves = moves | [
"def",
"__init__",
"(",
"self",
",",
"moves",
")",
":",
"super",
"(",
"InvalidMoves",
",",
"self",
")",
".",
"__init__",
"(",
"'Invalid moves: {moves}'",
".",
"format",
"(",
"moves",
"=",
"moves",
")",
")",
"self",
".",
"moves",
"=",
"moves"
] | [
181,
4
] | [
189,
26
] | python | en | ['en', 'error', 'th'] | False |
RatingPredictionEvaluation.__init__ | (self, sep='\t', metrics=list(['MAE', 'RMSE']), all_but_one_eval=False, verbose=True, as_table=False,
table_sep='\t', as_rank=False, n_rank=(5, 10)) |
Class to evaluate predictions in a rating prediction scenario
:param sep: Delimiter for input files
:type sep: str, default '\t'
:param metrics: List of evaluation metrics
:type metrics: list, default ('MAE', 'RMSE')
:param all_but_one_eval: If True, considers only on... |
Class to evaluate predictions in a rating prediction scenario | def __init__(self, sep='\t', metrics=list(['MAE', 'RMSE']), all_but_one_eval=False, verbose=True, as_table=False,
table_sep='\t', as_rank=False, n_rank=(5, 10)):
"""
Class to evaluate predictions in a rating prediction scenario
:param sep: Delimiter for input files
:typ... | [
"def",
"__init__",
"(",
"self",
",",
"sep",
"=",
"'\\t'",
",",
"metrics",
"=",
"list",
"(",
"[",
"'MAE'",
",",
"'RMSE'",
"]",
")",
",",
"all_but_one_eval",
"=",
"False",
",",
"verbose",
"=",
"True",
",",
"as_table",
"=",
"False",
",",
"table_sep",
"=... | [
25,
4
] | [
56,
28
] | python | en | ['en', 'error', 'th'] | False |
RatingPredictionEvaluation.evaluate | (self, predictions, test_set) |
Method to calculate all the metrics for item recommendation scenario using dictionaries of ranking
and test set. Use read() in ReadFile to transform your prediction and test files in a dict
:param predictions: Dict of predictions
:type predictions: dict
:param test_set: Dictio... |
Method to calculate all the metrics for item recommendation scenario using dictionaries of ranking
and test set. Use read() in ReadFile to transform your prediction and test files in a dict | def evaluate(self, predictions, test_set):
"""
Method to calculate all the metrics for item recommendation scenario using dictionaries of ranking
and test set. Use read() in ReadFile to transform your prediction and test files in a dict
:param predictions: Dict of predictions
:t... | [
"def",
"evaluate",
"(",
"self",
",",
"predictions",
",",
"test_set",
")",
":",
"eval_results",
"=",
"{",
"}",
"predictions_list",
"=",
"[",
"]",
"test_list",
"=",
"[",
"]",
"if",
"not",
"self",
".",
"as_rank",
":",
"# Create All but one set, selecting only one... | [
58,
4
] | [
126,
27
] | python | en | ['en', 'error', 'th'] | False |
default_filter | (src, dst) | The default progress/filter callback; returns True for all files | The default progress/filter callback; returns True for all files | def default_filter(src, dst):
"""The default progress/filter callback; returns True for all files"""
return dst | [
"def",
"default_filter",
"(",
"src",
",",
"dst",
")",
":",
"return",
"dst"
] | [
22,
0
] | [
24,
14
] | python | en | ['en', 'sv', 'en'] | True |
unpack_archive | (filename, extract_dir, progress_filter=default_filter,
drivers=None) | Unpack `filename` to `extract_dir`, or raise ``UnrecognizedFormat``
`progress_filter` is a function taking two arguments: a source path
internal to the archive ('/'-separated), and a filesystem path where it
will be extracted. The callback must return the desired extract path
(which may be the same as... | Unpack `filename` to `extract_dir`, or raise ``UnrecognizedFormat`` | def unpack_archive(filename, extract_dir, progress_filter=default_filter,
drivers=None):
"""Unpack `filename` to `extract_dir`, or raise ``UnrecognizedFormat``
`progress_filter` is a function taking two arguments: a source path
internal to the archive ('/'-separated), and a filesystem path where it... | [
"def",
"unpack_archive",
"(",
"filename",
",",
"extract_dir",
",",
"progress_filter",
"=",
"default_filter",
",",
"drivers",
"=",
"None",
")",
":",
"for",
"driver",
"in",
"drivers",
"or",
"extraction_drivers",
":",
"try",
":",
"driver",
"(",
"filename",
",",
... | [
27,
0
] | [
59,
9
] | python | en | ['en', 'la', 'en'] | True |
unpack_directory | (filename, extract_dir, progress_filter=default_filter) | Unpack" a directory, using the same interface as for archives
Raises ``UnrecognizedFormat`` if `filename` is not a directory
| Unpack" a directory, using the same interface as for archives | def unpack_directory(filename, extract_dir, progress_filter=default_filter):
""""Unpack" a directory, using the same interface as for archives
Raises ``UnrecognizedFormat`` if `filename` is not a directory
"""
if not os.path.isdir(filename):
raise UnrecognizedFormat("%s is not a directory" % fi... | [
"def",
"unpack_directory",
"(",
"filename",
",",
"extract_dir",
",",
"progress_filter",
"=",
"default_filter",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"filename",
")",
":",
"raise",
"UnrecognizedFormat",
"(",
"\"%s is not a directory\"",
"%"... | [
62,
0
] | [
86,
38
] | python | en | ['en', 'en', 'en'] | True |
unpack_zipfile | (filename, extract_dir, progress_filter=default_filter) | Unpack zip `filename` to `extract_dir`
Raises ``UnrecognizedFormat`` if `filename` is not a zipfile (as determined
by ``zipfile.is_zipfile()``). See ``unpack_archive()`` for an explanation
of the `progress_filter` argument.
| Unpack zip `filename` to `extract_dir` | def unpack_zipfile(filename, extract_dir, progress_filter=default_filter):
"""Unpack zip `filename` to `extract_dir`
Raises ``UnrecognizedFormat`` if `filename` is not a zipfile (as determined
by ``zipfile.is_zipfile()``). See ``unpack_archive()`` for an explanation
of the `progress_filter` argument.
... | [
"def",
"unpack_zipfile",
"(",
"filename",
",",
"extract_dir",
",",
"progress_filter",
"=",
"default_filter",
")",
":",
"if",
"not",
"zipfile",
".",
"is_zipfile",
"(",
"filename",
")",
":",
"raise",
"UnrecognizedFormat",
"(",
"\"%s is not a zip file\"",
"%",
"(",
... | [
89,
0
] | [
123,
49
] | python | en | ['en', 'nl', 'ur'] | False |
unpack_tarfile | (filename, extract_dir, progress_filter=default_filter) | Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
by ``tarfile.open()``). See ``unpack_archive()`` for an explanation
of the `progress_filter` argument.
| Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir` | def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):
"""Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
Raises ``UnrecognizedFormat`` if `filename` is not a tarfile (as determined
by ``tarfile.open()``). See ``unpack_archive()`` for an explanation
of the `progress_filter` a... | [
"def",
"unpack_tarfile",
"(",
"filename",
",",
"extract_dir",
",",
"progress_filter",
"=",
"default_filter",
")",
":",
"try",
":",
"tarobj",
"=",
"tarfile",
".",
"open",
"(",
"filename",
")",
"except",
"tarfile",
".",
"TarError",
":",
"raise",
"UnrecognizedFor... | [
126,
0
] | [
169,
19
] | python | en | ['en', 'id', 'hi'] | False |
CacheControlAdapter.send | (self, request, cacheable_methods=None, **kw) |
Send a request. Use the request information to see if it
exists in the cache and cache the response if we need to and can.
|
Send a request. Use the request information to see if it
exists in the cache and cache the response if we need to and can.
| def send(self, request, cacheable_methods=None, **kw):
"""
Send a request. Use the request information to see if it
exists in the cache and cache the response if we need to and can.
"""
cacheable = cacheable_methods or self.cacheable_methods
if request.method in cacheable... | [
"def",
"send",
"(",
"self",
",",
"request",
",",
"cacheable_methods",
"=",
"None",
",",
"*",
"*",
"kw",
")",
":",
"cacheable",
"=",
"cacheable_methods",
"or",
"self",
".",
"cacheable_methods",
"if",
"request",
".",
"method",
"in",
"cacheable",
":",
"try",
... | [
35,
4
] | [
54,
19
] | python | en | ['en', 'error', 'th'] | False |
CacheControlAdapter.build_response | (
self, request, response, from_cache=False, cacheable_methods=None
) |
Build a response by making a request or using the cache.
This will end up calling send and returning a potentially
cached response
|
Build a response by making a request or using the cache. | def build_response(
self, request, response, from_cache=False, cacheable_methods=None
):
"""
Build a response by making a request or using the cache.
This will end up calling send and returning a potentially
cached response
"""
cacheable = cacheable_methods o... | [
"def",
"build_response",
"(",
"self",
",",
"request",
",",
"response",
",",
"from_cache",
"=",
"False",
",",
"cacheable_methods",
"=",
"None",
")",
":",
"cacheable",
"=",
"cacheable_methods",
"or",
"self",
".",
"cacheable_methods",
"if",
"not",
"from_cache",
"... | [
56,
4
] | [
128,
19
] | python | en | ['en', 'error', 'th'] | False |
split_first | (s, delims) |
.. deprecated:: 1.25
Given a string and an iterable of delimiters, split on the first found
delimiter. Return two split parts and the matched delimiter.
If not found, then the first part is the full input string.
Example::
>>> split_first('foo/bar?baz', '?/=')
('foo', 'bar?baz',... |
.. deprecated:: 1.25 | def split_first(s, delims):
"""
.. deprecated:: 1.25
Given a string and an iterable of delimiters, split on the first found
delimiter. Return two split parts and the matched delimiter.
If not found, then the first part is the full input string.
Example::
>>> split_first('foo/bar?baz'... | [
"def",
"split_first",
"(",
"s",
",",
"delims",
")",
":",
"min_idx",
"=",
"None",
"min_delim",
"=",
"None",
"for",
"d",
"in",
"delims",
":",
"idx",
"=",
"s",
".",
"find",
"(",
"d",
")",
"if",
"idx",
"<",
"0",
":",
"continue",
"if",
"min_idx",
"is"... | [
174,
0
] | [
206,
51
] | python | en | ['en', 'error', 'th'] | False |
_encode_invalid_chars | (component, allowed_chars, encoding="utf-8") | Percent-encodes a URI component without reapplying
onto an already percent-encoded component.
| Percent-encodes a URI component without reapplying
onto an already percent-encoded component.
| def _encode_invalid_chars(component, allowed_chars, encoding="utf-8"):
"""Percent-encodes a URI component without reapplying
onto an already percent-encoded component.
"""
if component is None:
return component
component = six.ensure_text(component)
# Normalize existing percent-encoded... | [
"def",
"_encode_invalid_chars",
"(",
"component",
",",
"allowed_chars",
",",
"encoding",
"=",
"\"utf-8\"",
")",
":",
"if",
"component",
"is",
"None",
":",
"return",
"component",
"component",
"=",
"six",
".",
"ensure_text",
"(",
"component",
")",
"# Normalize exi... | [
209,
0
] | [
240,
45
] | python | en | ['en', 'en', 'en'] | True |
_encode_target | (target) | Percent-encodes a request target so that there are no invalid characters | Percent-encodes a request target so that there are no invalid characters | def _encode_target(target):
"""Percent-encodes a request target so that there are no invalid characters"""
path, query = TARGET_RE.match(target).groups()
target = _encode_invalid_chars(path, PATH_CHARS)
query = _encode_invalid_chars(query, QUERY_CHARS)
if query is not None:
target += "?" + q... | [
"def",
"_encode_target",
"(",
"target",
")",
":",
"path",
",",
"query",
"=",
"TARGET_RE",
".",
"match",
"(",
"target",
")",
".",
"groups",
"(",
")",
"target",
"=",
"_encode_invalid_chars",
"(",
"path",
",",
"PATH_CHARS",
")",
"query",
"=",
"_encode_invalid... | [
319,
0
] | [
326,
17
] | python | en | ['en', 'en', 'en'] | True |
parse_url | (url) |
Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
performed to parse incomplete urls. Fields not provided will be None.
This parser is RFC 3986 compliant.
The parser logic and helper functions are based heavily on
work done in the ``rfc3986`` module.
:param str url: URL to... |
Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
performed to parse incomplete urls. Fields not provided will be None.
This parser is RFC 3986 compliant. | def parse_url(url):
"""
Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is
performed to parse incomplete urls. Fields not provided will be None.
This parser is RFC 3986 compliant.
The parser logic and helper functions are based heavily on
work done in the ``rfc3986`` module.
... | [
"def",
"parse_url",
"(",
"url",
")",
":",
"if",
"not",
"url",
":",
"# Empty",
"return",
"Url",
"(",
")",
"source_url",
"=",
"url",
"if",
"not",
"SCHEME_RE",
".",
"search",
"(",
"url",
")",
":",
"url",
"=",
"\"//\"",
"+",
"url",
"try",
":",
"scheme"... | [
329,
0
] | [
423,
5
] | python | en | ['en', 'error', 'th'] | False |
get_host | (url) |
Deprecated. Use :func:`parse_url` instead.
|
Deprecated. Use :func:`parse_url` instead.
| def get_host(url):
"""
Deprecated. Use :func:`parse_url` instead.
"""
p = parse_url(url)
return p.scheme or "http", p.hostname, p.port | [
"def",
"get_host",
"(",
"url",
")",
":",
"p",
"=",
"parse_url",
"(",
"url",
")",
"return",
"p",
".",
"scheme",
"or",
"\"http\"",
",",
"p",
".",
"hostname",
",",
"p",
".",
"port"
] | [
426,
0
] | [
431,
49
] | python | en | ['en', 'error', 'th'] | False |
Url.hostname | (self) | For backwards-compatibility with urlparse. We're nice like that. | For backwards-compatibility with urlparse. We're nice like that. | def hostname(self):
"""For backwards-compatibility with urlparse. We're nice like that."""
return self.host | [
"def",
"hostname",
"(",
"self",
")",
":",
"return",
"self",
".",
"host"
] | [
109,
4
] | [
111,
24
] | 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.