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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
BasePasswordHasher.safe_summary | (self, encoded) |
Return a summary of safe values.
The result is a dictionary and will be used where the password field
must be displayed to construct a safe representation of the password.
|
Return a summary of safe values. | def safe_summary(self, encoded):
"""
Return a summary of safe values.
The result is a dictionary and will be used where the password field
must be displayed to construct a safe representation of the password.
"""
raise NotImplementedError('subclasses of BasePasswordHashe... | [
"def",
"safe_summary",
"(",
"self",
",",
"encoded",
")",
":",
"raise",
"NotImplementedError",
"(",
"'subclasses of BasePasswordHasher must provide a safe_summary() method'",
")"
] | [
202,
4
] | [
209,
106
] | python | en | ['en', 'error', 'th'] | False |
BasePasswordHasher.harden_runtime | (self, password, encoded) |
Bridge the runtime gap between the work factor supplied in `encoded`
and the work factor suggested by this hasher.
Taking PBKDF2 as an example, if `encoded` contains 20000 iterations and
`self.iterations` is 30000, this method should run password through
another 10000 iteration... |
Bridge the runtime gap between the work factor supplied in `encoded`
and the work factor suggested by this hasher. | def harden_runtime(self, password, encoded):
"""
Bridge the runtime gap between the work factor supplied in `encoded`
and the work factor suggested by this hasher.
Taking PBKDF2 as an example, if `encoded` contains 20000 iterations and
`self.iterations` is 30000, this method sho... | [
"def",
"harden_runtime",
"(",
"self",
",",
"password",
",",
"encoded",
")",
":",
"warnings",
".",
"warn",
"(",
"'subclasses of BasePasswordHasher should provide a harden_runtime() method'",
")"
] | [
214,
4
] | [
225,
98
] | python | en | ['en', 'error', 'th'] | False |
Argon2PasswordHasher._decode | (self, encoded) |
Split an encoded hash and return: (
algorithm, variety, version, time_cost, memory_cost,
parallelism, salt, data,
).
|
Split an encoded hash and return: (
algorithm, variety, version, time_cost, memory_cost,
parallelism, salt, data,
).
| def _decode(self, encoded):
"""
Split an encoded hash and return: (
algorithm, variety, version, time_cost, memory_cost,
parallelism, salt, data,
).
"""
bits = encoded.split('$')
if len(bits) == 5:
# Argon2 < 1.3
algorithm, ... | [
"def",
"_decode",
"(",
"self",
",",
"encoded",
")",
":",
"bits",
"=",
"encoded",
".",
"split",
"(",
"'$'",
")",
"if",
"len",
"(",
"bits",
")",
"==",
"5",
":",
"# Argon2 < 1.3",
"algorithm",
",",
"variety",
",",
"raw_params",
",",
"salt",
",",
"data",... | [
359,
4
] | [
384,
9
] | python | en | ['en', 'error', 'th'] | False |
AboutPageTest.test_split_by | (self) | Utility function primarily used in authors page | Utility function primarily used in authors page | def test_split_by(self) -> None:
"""Utility function primarily used in authors page"""
flat_list = [1, 2, 3, 4, 5, 6, 7, 8, 9]
expected_result = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
self.assertEqual(split_by(flat_list, 3, None), expected_result) | [
"def",
"test_split_by",
"(",
"self",
")",
"->",
"None",
":",
"flat_list",
"=",
"[",
"1",
",",
"2",
",",
"3",
",",
"4",
",",
"5",
",",
"6",
",",
"7",
",",
"8",
",",
"9",
"]",
"expected_result",
"=",
"[",
"[",
"1",
",",
"2",
",",
"3",
"]",
... | [
362,
4
] | [
366,
71
] | python | en | ['en', 'en', 'en'] | True |
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",
... | [
238,
0
] | [
257,
30
] | python | en | ['en', 'error', 'th'] | False |
get_finder | (import_path) |
Imports the staticfiles finder class described by import_path, where
import_path is the full Python path to the class.
|
Imports the staticfiles finder class described by import_path, where
import_path is the full Python path to the class.
| def get_finder(import_path):
"""
Imports 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\"'",
"%... | [
266,
0
] | [
275,
19
] | python | en | ['en', 'error', 'th'] | False |
BaseFinder.find | (self, path, all=False) |
Given a relative file path this ought to find an
absolute file path.
If the ``all`` parameter is ``False`` (default) only
the first found file path will be returned; if set
to ``True`` a list of all found files paths is returned.
|
Given a relative file path this ought to find an
absolute file path. | def find(self, path, all=False):
"""
Given a relative file path this ought to find an
absolute file path.
If the ``all`` parameter is ``False`` (default) only
the first found file path will be returned; if set
to ``True`` a list of all found files paths is returned.
... | [
"def",
"find",
"(",
"self",
",",
"path",
",",
"all",
"=",
"False",
")",
":",
"raise",
"NotImplementedError",
"(",
"'subclasses of BaseFinder must provide a find() method'",
")"
] | [
23,
4
] | [
32,
90
] | python | en | ['en', 'error', 'th'] | False |
BaseFinder.list | (self, ignore_patterns) |
Given an optional list of paths to ignore, this should return
a two item iterable consisting of the relative path and storage
instance.
|
Given an optional list of paths to ignore, this should 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, this should 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'",
")"
] | [
34,
4
] | [
40,
90
] | python | en | ['en', 'error', 'th'] | False |
FileSystemFinder.find | (self, path, all=False) |
Looks for files in the extra locations
as defined in ``STATICFILES_DIRS``.
|
Looks for files in the extra locations
as defined in ``STATICFILES_DIRS``.
| def find(self, path, all=False):
"""
Looks 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)
... | [
"def",
"find",
"(",
"self",
",",
"path",
",",
"all",
"=",
"False",
")",
":",
"matches",
"=",
"[",
"]",
"for",
"prefix",
",",
"root",
"in",
"self",
".",
"locations",
":",
"if",
"root",
"not",
"in",
"searched_locations",
":",
"searched_locations",
".",
... | [
74,
4
] | [
88,
22
] | python | en | ['en', 'error', 'th'] | False |
FileSystemFinder.find_location | (self, root, path, prefix=None) |
Finds a requested static file in a location, returning the found
absolute path (or ``None`` if no match).
|
Finds a requested static file in a location, returning the found
absolute path (or ``None`` if no match).
| def find_location(self, root, path, prefix=None):
"""
Finds a requested static file in a location, returning 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"... | [
90,
4
] | [
102,
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",
... | [
104,
4
] | [
111,
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 six.itervalues(self.storages):
if storage.exists(''): # check if storage location exists
for path in utils.get_files(storage, ignore_patterns):
yie... | [
"def",
"list",
"(",
"self",
",",
"ignore_patterns",
")",
":",
"for",
"storage",
"in",
"six",
".",
"itervalues",
"(",
"self",
".",
"storages",
")",
":",
"if",
"storage",
".",
"exists",
"(",
"''",
")",
":",
"# check if storage location exists",
"for",
"path"... | [
140,
4
] | [
147,
39
] | python | en | ['en', 'error', 'th'] | False |
AppDirectoriesFinder.find | (self, path, all=False) |
Looks for files in the app directories.
|
Looks for files in the app directories.
| def find(self, path, all=False):
"""
Looks 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... | [
149,
4
] | [
163,
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, None)
if storage:
# only try to find a file if the source dir actually exists
if storage.exists(path):
mat... | [
"def",
"find_in_app",
"(",
"self",
",",
"app",
",",
"path",
")",
":",
"storage",
"=",
"self",
".",
"storages",
".",
"get",
"(",
"app",
",",
"None",
")",
"if",
"storage",
":",
"# only try to find a file if the source dir actually exists",
"if",
"storage",
".",
... | [
165,
4
] | [
175,
39
] | python | en | ['en', 'error', 'th'] | False |
BaseStorageFinder.find | (self, path, all=False) |
Looks for files in the default file storage, if it's local.
|
Looks for files in the default file storage, if it's local.
| def find(self, path, all=False):
"""
Looks 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:
s... | [
"def",
"find",
"(",
"self",
",",
"path",
",",
"all",
"=",
"False",
")",
":",
"try",
":",
"self",
".",
"storage",
".",
"path",
"(",
"''",
")",
"except",
"NotImplementedError",
":",
"pass",
"else",
":",
"if",
"self",
".",
"storage",
".",
"location",
... | [
197,
4
] | [
213,
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"
] | [
215,
4
] | [
220,
36
] | python | en | ['en', 'error', 'th'] | False |
AnsiToWin32.should_wrap | (self) |
True if this class is actually needed. If false, then the output
stream will not be affected, nor will win32 calls be issued, so
wrapping stdout is not actually required. This will generally be
False on non-Windows platforms, unless optional functionality like
autoreset has been... |
True if this class is actually needed. If false, then the output
stream will not be affected, nor will win32 calls be issued, so
wrapping stdout is not actually required. This will generally be
False on non-Windows platforms, unless optional functionality like
autoreset has been... | def should_wrap(self):
'''
True if this class is actually needed. If false, then the output
stream will not be affected, nor will win32 calls be issued, so
wrapping stdout is not actually required. This will generally be
False on non-Windows platforms, unless optional functionali... | [
"def",
"should_wrap",
"(",
"self",
")",
":",
"return",
"self",
".",
"convert",
"or",
"self",
".",
"strip",
"or",
"self",
".",
"autoreset"
] | [
105,
4
] | [
113,
59
] | python | en | ['en', 'error', 'th'] | False |
AnsiToWin32.write_and_convert | (self, text) |
Write the given text to our wrapped stream, stripping any ANSI
sequences from the text, and optionally converting them into win32
calls.
|
Write the given text to our wrapped stream, stripping any ANSI
sequences from the text, and optionally converting them into win32
calls.
| def write_and_convert(self, text):
'''
Write the given text to our wrapped stream, stripping any ANSI
sequences from the text, and optionally converting them into win32
calls.
'''
cursor = 0
text = self.convert_osc(text)
for match in self.ANSI_CSI_RE.findi... | [
"def",
"write_and_convert",
"(",
"self",
",",
"text",
")",
":",
"cursor",
"=",
"0",
"text",
"=",
"self",
".",
"convert_osc",
"(",
"text",
")",
"for",
"match",
"in",
"self",
".",
"ANSI_CSI_RE",
".",
"finditer",
"(",
"text",
")",
":",
"start",
",",
"en... | [
176,
4
] | [
189,
54
] | python | en | ['en', 'error', 'th'] | False |
get_wsgi_application | () |
The public interface to Django's WSGI support. Return a WSGI callable.
Avoids making django.core.handlers.WSGIHandler a public API, in case the
internal WSGI implementation changes or moves in the future.
|
The public interface to Django's WSGI support. Return a WSGI callable. | def get_wsgi_application():
"""
The public interface to Django's WSGI support. Return a WSGI callable.
Avoids making django.core.handlers.WSGIHandler a public API, in case the
internal WSGI implementation changes or moves in the future.
"""
django.setup(set_prefix=False)
return WSGIHandler(... | [
"def",
"get_wsgi_application",
"(",
")",
":",
"django",
".",
"setup",
"(",
"set_prefix",
"=",
"False",
")",
"return",
"WSGIHandler",
"(",
")"
] | [
4,
0
] | [
12,
24
] | 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():
# type: () -> 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",
"(",
")",
":",
"# type: () -> Optional[str]",
"return",
"glibc_version_string_confstr",
"(",
")",
"or",
"glibc_version_string_ctypes",
"(",
")"
] | [
14,
0
] | [
17,
74
] | python | en | ['en', 'en', '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():
# type: () -> 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",
"(",
")",
":",
"# type: () -> 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/python/cpython/b... | [
20,
0
] | [
35,
18
] | python | en | ['en', 'en', 'en'] | True |
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():
# type: () -> 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",
"(",
")",
":",
"# type: () -> 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 NULL, then the... | [
38,
0
] | [
66,
22
] | python | en | ['en', 'en', 'en'] | True |
libc_ver | () | Try to determine the glibc version
Returns a tuple of strings (lib, version) which default to empty strings
in case the lookup fails.
| Try to determine the glibc version | def libc_ver():
# type: () -> Tuple[str, str]
"""Try to determine the glibc version
Returns a tuple of strings (lib, version) which default to empty strings
in case the lookup fails.
"""
glibc_version = glibc_version_string()
if glibc_version is None:
return ("", "")
else:
... | [
"def",
"libc_ver",
"(",
")",
":",
"# type: () -> Tuple[str, str]",
"glibc_version",
"=",
"glibc_version_string",
"(",
")",
"if",
"glibc_version",
"is",
"None",
":",
"return",
"(",
"\"\"",
",",
"\"\"",
")",
"else",
":",
"return",
"(",
"\"glibc\"",
",",
"glibc_v... | [
86,
0
] | [
97,
39
] | python | en | ['en', 'en', 'en'] | True |
AccessMixin.get_login_url | (self) |
Override this method to override the login_url attribute.
|
Override this method to override the login_url attribute.
| def get_login_url(self):
"""
Override this method to override the login_url attribute.
"""
login_url = self.login_url or settings.LOGIN_URL
if not login_url:
raise ImproperlyConfigured(
'{0} is missing the login_url attribute. Define {0}.login_url, set... | [
"def",
"get_login_url",
"(",
"self",
")",
":",
"login_url",
"=",
"self",
".",
"login_url",
"or",
"settings",
".",
"LOGIN_URL",
"if",
"not",
"login_url",
":",
"raise",
"ImproperlyConfigured",
"(",
"'{0} is missing the login_url attribute. Define {0}.login_url, settings.LOG... | [
16,
4
] | [
26,
29
] | python | en | ['en', 'error', 'th'] | False |
AccessMixin.get_permission_denied_message | (self) |
Override this method to override the permission_denied_message attribute.
|
Override this method to override the permission_denied_message attribute.
| def get_permission_denied_message(self):
"""
Override this method to override the permission_denied_message attribute.
"""
return self.permission_denied_message | [
"def",
"get_permission_denied_message",
"(",
"self",
")",
":",
"return",
"self",
".",
"permission_denied_message"
] | [
28,
4
] | [
32,
45
] | python | en | ['en', 'error', 'th'] | False |
AccessMixin.get_redirect_field_name | (self) |
Override this method to override the redirect_field_name attribute.
|
Override this method to override the redirect_field_name attribute.
| def get_redirect_field_name(self):
"""
Override this method to override the redirect_field_name attribute.
"""
return self.redirect_field_name | [
"def",
"get_redirect_field_name",
"(",
"self",
")",
":",
"return",
"self",
".",
"redirect_field_name"
] | [
34,
4
] | [
38,
39
] | python | en | ['en', 'error', 'th'] | False |
PermissionRequiredMixin.get_permission_required | (self) |
Override this method to override the permission_required attribute.
Must return an iterable.
|
Override this method to override the permission_required attribute.
Must return an iterable.
| def get_permission_required(self):
"""
Override this method to override the permission_required attribute.
Must return an iterable.
"""
if self.permission_required is None:
raise ImproperlyConfigured(
'{0} is missing the permission_required attribute. ... | [
"def",
"get_permission_required",
"(",
"self",
")",
":",
"if",
"self",
".",
"permission_required",
"is",
"None",
":",
"raise",
"ImproperlyConfigured",
"(",
"'{0} is missing the permission_required attribute. Define {0}.permission_required, or override '",
"'{0}.get_permission_requi... | [
58,
4
] | [
72,
20
] | python | en | ['en', 'error', 'th'] | False |
PermissionRequiredMixin.has_permission | (self) |
Override this method to customize the way permissions are checked.
|
Override this method to customize the way permissions are checked.
| def has_permission(self):
"""
Override this method to customize the way permissions are checked.
"""
perms = self.get_permission_required()
return self.request.user.has_perms(perms) | [
"def",
"has_permission",
"(",
"self",
")",
":",
"perms",
"=",
"self",
".",
"get_permission_required",
"(",
")",
"return",
"self",
".",
"request",
".",
"user",
".",
"has_perms",
"(",
"perms",
")"
] | [
74,
4
] | [
79,
49
] | python | en | ['en', 'error', 'th'] | False |
UserPassesTestMixin.get_test_func | (self) |
Override this method to use a different test_func method.
|
Override this method to use a different test_func method.
| def get_test_func(self):
"""
Override this method to use a different test_func method.
"""
return self.test_func | [
"def",
"get_test_func",
"(",
"self",
")",
":",
"return",
"self",
".",
"test_func"
] | [
98,
4
] | [
102,
29
] | python | en | ['en', 'error', 'th'] | False |
register_handler | (handler) |
Install application-specific HDF5 image handler.
:param handler: Handler object.
|
Install application-specific HDF5 image handler. | def register_handler(handler):
"""
Install application-specific HDF5 image handler.
:param handler: Handler object.
"""
global _handler
_handler = handler | [
"def",
"register_handler",
"(",
"handler",
")",
":",
"global",
"_handler",
"_handler",
"=",
"handler"
] | [
16,
0
] | [
23,
22
] | python | en | ['en', 'error', 'th'] | False |
test_order_price_check_success | (user_api_client, product, two_hour_reservation) | Test the endpoint returns price calculations for given product without persisting anything | Test the endpoint returns price calculations for given product without persisting anything | def test_order_price_check_success(user_api_client, product, two_hour_reservation):
"""Test the endpoint returns price calculations for given product without persisting anything"""
order_count_before = Order.objects.count()
price_check_data = {
"order_lines": [
{
"produ... | [
"def",
"test_order_price_check_success",
"(",
"user_api_client",
",",
"product",
",",
"two_hour_reservation",
")",
":",
"order_count_before",
"=",
"Order",
".",
"objects",
".",
"count",
"(",
")",
"price_check_data",
"=",
"{",
"\"order_lines\"",
":",
"[",
"{",
"\"p... | [
44,
0
] | [
69,
54
] | python | en | ['en', 'en', 'en'] | True |
test_order_price_check_begin_time_after_end_time | (user_api_client, product, two_hour_reservation) | Test the endpoint returns 400 for bad time input | Test the endpoint returns 400 for bad time input | def test_order_price_check_begin_time_after_end_time(user_api_client, product, two_hour_reservation):
"""Test the endpoint returns 400 for bad time input"""
order_count_before = Order.objects.count()
price_check_data = {
"order_lines": [
{
"product": product.product_id,... | [
"def",
"test_order_price_check_begin_time_after_end_time",
"(",
"user_api_client",
",",
"product",
",",
"two_hour_reservation",
")",
":",
"order_count_before",
"=",
"Order",
".",
"objects",
".",
"count",
"(",
")",
"price_check_data",
"=",
"{",
"\"order_lines\"",
":",
... | [
72,
0
] | [
89,
38
] | python | en | ['en', 'en', 'en'] | True |
patch_cache_control | (response, **kwargs) |
This function patches the Cache-Control header by adding all
keyword arguments to it. The transformation is as follows:
* All keyword parameter names are turned to lowercase, and underscores
are converted to hyphens.
* If the value of a parameter is True (exactly True, not just a
true valu... |
This function patches the Cache-Control header by adding all
keyword arguments to it. The transformation is as follows: | def patch_cache_control(response, **kwargs):
"""
This function patches the Cache-Control header by adding all
keyword arguments to it. The transformation is as follows:
* All keyword parameter names are turned to lowercase, and underscores
are converted to hyphens.
* If the value of a paramet... | [
"def",
"patch_cache_control",
"(",
"response",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"dictitem",
"(",
"s",
")",
":",
"t",
"=",
"s",
".",
"split",
"(",
"'='",
",",
"1",
")",
"if",
"len",
"(",
"t",
")",
">",
"1",
":",
"return",
"(",
"t",
"[... | [
34,
0
] | [
80,
34
] | python | en | ['en', 'error', 'th'] | False |
get_max_age | (response) |
Returns the max-age from the response Cache-Control header as an integer
(or ``None`` if it wasn't found or wasn't an integer.
|
Returns the max-age from the response Cache-Control header as an integer
(or ``None`` if it wasn't found or wasn't an integer.
| def get_max_age(response):
"""
Returns the max-age from the response Cache-Control header as an integer
(or ``None`` if it wasn't found or wasn't an integer.
"""
if not response.has_header('Cache-Control'):
return
cc = dict(_to_tuple(el) for el in
cc_delim_re.split(response['Cach... | [
"def",
"get_max_age",
"(",
"response",
")",
":",
"if",
"not",
"response",
".",
"has_header",
"(",
"'Cache-Control'",
")",
":",
"return",
"cc",
"=",
"dict",
"(",
"_to_tuple",
"(",
"el",
")",
"for",
"el",
"in",
"cc_delim_re",
".",
"split",
"(",
"response",... | [
83,
0
] | [
96,
16
] | python | en | ['en', 'error', 'th'] | False |
patch_response_headers | (response, cache_timeout=None) |
Adds some useful headers to the given HttpResponse object:
ETag, Last-Modified, Expires and Cache-Control
Each header is only added if it isn't already set.
cache_timeout is in seconds. The CACHE_MIDDLEWARE_SECONDS setting is used
by default.
|
Adds some useful headers to the given HttpResponse object:
ETag, Last-Modified, Expires and Cache-Control | def patch_response_headers(response, cache_timeout=None):
"""
Adds some useful headers to the given HttpResponse object:
ETag, Last-Modified, Expires and Cache-Control
Each header is only added if it isn't already set.
cache_timeout is in seconds. The CACHE_MIDDLEWARE_SECONDS setting is used
... | [
"def",
"patch_response_headers",
"(",
"response",
",",
"cache_timeout",
"=",
"None",
")",
":",
"if",
"cache_timeout",
"is",
"None",
":",
"cache_timeout",
"=",
"settings",
".",
"CACHE_MIDDLEWARE_SECONDS",
"if",
"cache_timeout",
"<",
"0",
":",
"cache_timeout",
"=",
... | [
105,
0
] | [
128,
56
] | python | en | ['en', 'error', 'th'] | False |
add_never_cache_headers | (response) |
Adds headers to a response to indicate that a page should never be cached.
|
Adds headers to a response to indicate that a page should never be cached.
| def add_never_cache_headers(response):
"""
Adds headers to a response to indicate that a page should never be cached.
"""
patch_response_headers(response, cache_timeout=-1) | [
"def",
"add_never_cache_headers",
"(",
"response",
")",
":",
"patch_response_headers",
"(",
"response",
",",
"cache_timeout",
"=",
"-",
"1",
")"
] | [
131,
0
] | [
135,
54
] | python | en | ['en', 'error', 'th'] | False |
patch_vary_headers | (response, newheaders) |
Adds (or updates) the "Vary" header in the given HttpResponse object.
newheaders is a list of header names that should be in "Vary". Existing
headers in "Vary" aren't removed.
|
Adds (or updates) the "Vary" header in the given HttpResponse object.
newheaders is a list of header names that should be in "Vary". Existing
headers in "Vary" aren't removed.
| def patch_vary_headers(response, newheaders):
"""
Adds (or updates) the "Vary" header in the given HttpResponse object.
newheaders is a list of header names that should be in "Vary". Existing
headers in "Vary" aren't removed.
"""
# Note that we need to keep the original order intact, because cac... | [
"def",
"patch_vary_headers",
"(",
"response",
",",
"newheaders",
")",
":",
"# Note that we need to keep the original order intact, because cache",
"# implementations may rely on the order of the Vary contents in, say,",
"# computing an MD5 hash.",
"if",
"response",
".",
"has_header",
"... | [
138,
0
] | [
155,
67
] | python | en | ['en', 'error', 'th'] | False |
has_vary_header | (response, header_query) |
Checks to see if the response has a given header name in its Vary header.
|
Checks to see if the response has a given header name in its Vary header.
| def has_vary_header(response, header_query):
"""
Checks to see if the response has a given header name in its Vary header.
"""
if not response.has_header('Vary'):
return False
vary_headers = cc_delim_re.split(response['Vary'])
existing_headers = set(header.lower() for header in vary_head... | [
"def",
"has_vary_header",
"(",
"response",
",",
"header_query",
")",
":",
"if",
"not",
"response",
".",
"has_header",
"(",
"'Vary'",
")",
":",
"return",
"False",
"vary_headers",
"=",
"cc_delim_re",
".",
"split",
"(",
"response",
"[",
"'Vary'",
"]",
")",
"e... | [
158,
0
] | [
166,
51
] | python | en | ['en', 'error', 'th'] | False |
_i18n_cache_key_suffix | (request, cache_key) | If necessary, adds the current locale or time zone to the cache key. | If necessary, adds the current locale or time zone to the cache key. | def _i18n_cache_key_suffix(request, cache_key):
"""If necessary, adds the current locale or time zone to the cache key."""
if settings.USE_I18N or settings.USE_L10N:
# first check if LocaleMiddleware or another middleware added
# LANGUAGE_CODE to request, then fall back to the active language
... | [
"def",
"_i18n_cache_key_suffix",
"(",
"request",
",",
"cache_key",
")",
":",
"if",
"settings",
".",
"USE_I18N",
"or",
"settings",
".",
"USE_L10N",
":",
"# first check if LocaleMiddleware or another middleware added",
"# LANGUAGE_CODE to request, then fall back to the active langu... | [
169,
0
] | [
183,
20
] | python | en | ['en', 'en', 'en'] | True |
_generate_cache_key | (request, method, headerlist, key_prefix) | Returns a cache key from the headers given in the header list. | Returns a cache key from the headers given in the header list. | def _generate_cache_key(request, method, headerlist, key_prefix):
"""Returns a cache key from the headers given in the header list."""
ctx = hashlib.md5()
for header in headerlist:
value = request.META.get(header, None)
if value is not None:
ctx.update(force_bytes(value))
url... | [
"def",
"_generate_cache_key",
"(",
"request",
",",
"method",
",",
"headerlist",
",",
"key_prefix",
")",
":",
"ctx",
"=",
"hashlib",
".",
"md5",
"(",
")",
"for",
"header",
"in",
"headerlist",
":",
"value",
"=",
"request",
".",
"META",
".",
"get",
"(",
"... | [
186,
0
] | [
196,
53
] | python | en | ['en', 'en', 'en'] | True |
_generate_cache_header_key | (key_prefix, request) | Returns a cache key for the header cache. | Returns a cache key for the header cache. | def _generate_cache_header_key(key_prefix, request):
"""Returns a cache key for the header cache."""
url = hashlib.md5(force_bytes(iri_to_uri(request.build_absolute_uri())))
cache_key = 'views.decorators.cache.cache_header.%s.%s' % (
key_prefix, url.hexdigest())
return _i18n_cache_key_suffix(req... | [
"def",
"_generate_cache_header_key",
"(",
"key_prefix",
",",
"request",
")",
":",
"url",
"=",
"hashlib",
".",
"md5",
"(",
"force_bytes",
"(",
"iri_to_uri",
"(",
"request",
".",
"build_absolute_uri",
"(",
")",
")",
")",
")",
"cache_key",
"=",
"'views.decorators... | [
199,
0
] | [
204,
53
] | python | en | ['en', 'en', 'en'] | True |
get_cache_key | (request, key_prefix=None, method='GET', cache=None) |
Returns a cache key based on the request URL and query. It can be used
in the request phase because it pulls the list of headers to take into
account from the global URL registry and uses those to build a cache key
to check against.
If there is no headerlist stored, the page needs to be rebuilt, s... |
Returns a cache key based on the request URL and query. It can be used
in the request phase because it pulls the list of headers to take into
account from the global URL registry and uses those to build a cache key
to check against. | def get_cache_key(request, key_prefix=None, method='GET', cache=None):
"""
Returns a cache key based on the request URL and query. It can be used
in the request phase because it pulls the list of headers to take into
account from the global URL registry and uses those to build a cache key
to check a... | [
"def",
"get_cache_key",
"(",
"request",
",",
"key_prefix",
"=",
"None",
",",
"method",
"=",
"'GET'",
",",
"cache",
"=",
"None",
")",
":",
"if",
"key_prefix",
"is",
"None",
":",
"key_prefix",
"=",
"settings",
".",
"CACHE_MIDDLEWARE_KEY_PREFIX",
"cache_key",
"... | [
207,
0
] | [
226,
19
] | python | en | ['en', 'error', 'th'] | False |
learn_cache_key | (request, response, cache_timeout=None, key_prefix=None, cache=None) |
Learns what headers to take into account for some request URL from the
response object. It stores those headers in a global URL registry so that
later access to that URL will know what headers to take into account
without building the response object itself. The headers are named in the
Vary header... |
Learns what headers to take into account for some request URL from the
response object. It stores those headers in a global URL registry so that
later access to that URL will know what headers to take into account
without building the response object itself. The headers are named in the
Vary header... | def learn_cache_key(request, response, cache_timeout=None, key_prefix=None, cache=None):
"""
Learns what headers to take into account for some request URL from the
response object. It stores those headers in a global URL registry so that
later access to that URL will know what headers to take into accou... | [
"def",
"learn_cache_key",
"(",
"request",
",",
"response",
",",
"cache_timeout",
"=",
"None",
",",
"key_prefix",
"=",
"None",
",",
"cache",
"=",
"None",
")",
":",
"if",
"key_prefix",
"is",
"None",
":",
"key_prefix",
"=",
"settings",
".",
"CACHE_MIDDLEWARE_KE... | [
229,
0
] | [
268,
75
] | python | en | ['en', 'error', 'th'] | False |
check_installation | (cur_file) | Warn user if running cleverhans from a different directory than tutorial. | Warn user if running cleverhans from a different directory than tutorial. | def check_installation(cur_file):
"""Warn user if running cleverhans from a different directory than tutorial."""
cur_dir = os.path.split(os.path.dirname(os.path.abspath(cur_file)))[0]
ch_dir = os.path.split(cleverhans.__path__[0])[0]
if cur_dir != ch_dir:
warnings.warn(
"It appears ... | [
"def",
"check_installation",
"(",
"cur_file",
")",
":",
"cur_dir",
"=",
"os",
".",
"path",
".",
"split",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"cur_file",
")",
")",
")",
"[",
"0",
"]",
"ch_dir",
"=",
... | [
12,
0
] | [
25,
9
] | python | en | ['en', 'en', 'en'] | True |
SolanoHookTests.test_solano_message_001 | (self) |
Build notifications are generated by Solano Labs after build completes.
|
Build notifications are generated by Solano Labs after build completes.
| def test_solano_message_001(self) -> None:
"""
Build notifications are generated by Solano Labs after build completes.
"""
expected_topic = "build update"
expected_message = """
Build update (see [build log](https://ci.solanolabs.com:443/reports/3316175)):
* **Author**: solano-ci... | [
"def",
"test_solano_message_001",
"(",
"self",
")",
"->",
"None",
":",
"expected_topic",
"=",
"\"build update\"",
"expected_message",
"=",
"\"\"\"\nBuild update (see [build log](https://ci.solanolabs.com:443/reports/3316175)):\n* **Author**: solano-ci[bot]@users.noreply.github.com\n* **Com... | [
8,
4
] | [
25,
9
] | python | en | ['en', 'error', 'th'] | False |
SolanoHookTests.test_solano_message_002 | (self) |
Build notifications are generated by Solano Labs after build completes.
|
Build notifications are generated by Solano Labs after build completes.
| def test_solano_message_002(self) -> None:
"""
Build notifications are generated by Solano Labs after build completes.
"""
expected_topic = "build update"
expected_message = """
Build update (see [build log](https://ci.solanolabs.com:443/reports/3316723)):
* **Author**: Unknown
*... | [
"def",
"test_solano_message_002",
"(",
"self",
")",
"->",
"None",
":",
"expected_topic",
"=",
"\"build update\"",
"expected_message",
"=",
"\"\"\"\nBuild update (see [build log](https://ci.solanolabs.com:443/reports/3316723)):\n* **Author**: Unknown\n* **Commit**: [5d0b92e](bitbucket.org/f... | [
27,
4
] | [
44,
9
] | python | en | ['en', 'error', 'th'] | False |
SolanoHookTests.test_solano_message_received | (self) |
Build notifications are generated by Solano Labs after build completes.
|
Build notifications are generated by Solano Labs after build completes.
| def test_solano_message_received(self) -> None:
"""
Build notifications are generated by Solano Labs after build completes.
"""
expected_topic = "build update"
expected_message = """
Build update (see [build log](https://ci.solanolabs.com:443/reports/3317799)):
* **Author**: sola... | [
"def",
"test_solano_message_received",
"(",
"self",
")",
"->",
"None",
":",
"expected_topic",
"=",
"\"build update\"",
"expected_message",
"=",
"\"\"\"\nBuild update (see [build log](https://ci.solanolabs.com:443/reports/3317799)):\n* **Author**: solano-ci[bot]@users.noreply.github.com\n* ... | [
46,
4
] | [
63,
9
] | python | en | ['en', 'error', 'th'] | False |
ExpressionsTests.test_F_object_deepcopy | (self) |
Make sure F objects can be deepcopied (#23492)
|
Make sure F objects can be deepcopied (#23492)
| def test_F_object_deepcopy(self):
"""
Make sure F objects can be deepcopied (#23492)
"""
f = F("foo")
g = deepcopy(f)
self.assertEqual(f.name, g.name) | [
"def",
"test_F_object_deepcopy",
"(",
"self",
")",
":",
"f",
"=",
"F",
"(",
"\"foo\"",
")",
"g",
"=",
"deepcopy",
"(",
"f",
")",
"self",
".",
"assertEqual",
"(",
"f",
".",
"name",
",",
"g",
".",
"name",
")"
] | [
290,
4
] | [
296,
40
] | python | en | ['en', 'error', 'th'] | False |
ExpressionsNumericTests.test_fill_with_value_from_same_object | (self) |
We can fill a value in all objects with an other value of the
same object.
|
We can fill a value in all objects with an other value of the
same object.
| def test_fill_with_value_from_same_object(self):
"""
We can fill a value in all objects with an other value of the
same object.
"""
self.assertQuerysetEqual(
Number.objects.all(),
[
'<Number: -1, -1.000>',
'<Number: 42, 42.0... | [
"def",
"test_fill_with_value_from_same_object",
"(",
"self",
")",
":",
"self",
".",
"assertQuerysetEqual",
"(",
"Number",
".",
"objects",
".",
"all",
"(",
")",
",",
"[",
"'<Number: -1, -1.000>'",
",",
"'<Number: 42, 42.000>'",
",",
"'<Number: 1337, 1337.000>'",
"]",
... | [
307,
4
] | [
320,
9
] | python | en | ['en', 'error', 'th'] | False |
ExpressionsNumericTests.test_increment_value | (self) |
We can increment a value of all objects in a query set.
|
We can increment a value of all objects in a query set.
| def test_increment_value(self):
"""
We can increment a value of all objects in a query set.
"""
self.assertEqual(
Number.objects.filter(integer__gt=0)
.update(integer=F('integer') + 1),
2)
self.assertQuerysetEqual(
Number.obj... | [
"def",
"test_increment_value",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"Number",
".",
"objects",
".",
"filter",
"(",
"integer__gt",
"=",
"0",
")",
".",
"update",
"(",
"integer",
"=",
"F",
"(",
"'integer'",
")",
"+",
"1",
")",
",",
"2"... | [
322,
4
] | [
339,
9
] | python | en | ['en', 'error', 'th'] | False |
ExpressionsNumericTests.test_filter_not_equals_other_field | (self) |
We can filter for objects, where a value is not equals the value
of an other field.
|
We can filter for objects, where a value is not equals the value
of an other field.
| def test_filter_not_equals_other_field(self):
"""
We can filter for objects, where a value is not equals the value
of an other field.
"""
self.assertEqual(
Number.objects.filter(integer__gt=0)
.update(integer=F('integer') + 1),
2)
... | [
"def",
"test_filter_not_equals_other_field",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"Number",
".",
"objects",
".",
"filter",
"(",
"integer__gt",
"=",
"0",
")",
".",
"update",
"(",
"integer",
"=",
"F",
"(",
"'integer'",
")",
"+",
"1",
")"... | [
341,
4
] | [
357,
9
] | python | en | ['en', 'error', 'th'] | False |
ExpressionsNumericTests.test_complex_expressions | (self) |
Complex expressions of different connection types are possible.
|
Complex expressions of different connection types are possible.
| def test_complex_expressions(self):
"""
Complex expressions of different connection types are possible.
"""
n = Number.objects.create(integer=10, float=123.45)
self.assertEqual(Number.objects.filter(pk=n.pk)
.update(float=F('integer') + F('float') * 2), 1)
se... | [
"def",
"test_complex_expressions",
"(",
"self",
")",
":",
"n",
"=",
"Number",
".",
"objects",
".",
"create",
"(",
"integer",
"=",
"10",
",",
"float",
"=",
"123.45",
")",
"self",
".",
"assertEqual",
"(",
"Number",
".",
"objects",
".",
"filter",
"(",
"pk... | [
359,
4
] | [
368,
91
] | python | en | ['en', 'error', 'th'] | False |
HomeTest._sanity_check | (self, result: HttpResponse) |
Use this for tests that are geared toward specific edge cases, but
which still want the home page to load properly.
|
Use this for tests that are geared toward specific edge cases, but
which still want the home page to load properly.
| def _sanity_check(self, result: HttpResponse) -> None:
"""
Use this for tests that are geared toward specific edge cases, but
which still want the home page to load properly.
"""
html = result.content.decode("utf-8")
if "Compose your message" not in html:
rais... | [
"def",
"_sanity_check",
"(",
"self",
",",
"result",
":",
"HttpResponse",
")",
"->",
"None",
":",
"html",
"=",
"result",
".",
"content",
".",
"decode",
"(",
"\"utf-8\"",
")",
"if",
"\"Compose your message\"",
"not",
"in",
"html",
":",
"raise",
"AssertionError... | [
390,
4
] | [
397,
68
] | python | en | ['en', 'error', 'th'] | False |
HomeTest.test_people | (self) |
We send three lists of users. The first two below are disjoint
lists of users, and the records we send for them have identical
structure.
The realm_bots bucket is somewhat redundant, since all bots will
be in one of the first two buckets. They do include fields, however,
... |
We send three lists of users. The first two below are disjoint
lists of users, and the records we send for them have identical
structure. | def test_people(self) -> None:
hamlet = self.example_user("hamlet")
realm = get_realm("zulip")
self.login_user(hamlet)
bots = {}
for i in range(3):
bots[i] = self.create_bot(
owner=hamlet,
bot_email=f"bot-{i}@zulip.com",
... | [
"def",
"test_people",
"(",
"self",
")",
"->",
"None",
":",
"hamlet",
"=",
"self",
".",
"example_user",
"(",
"\"hamlet\"",
")",
"realm",
"=",
"get_realm",
"(",
"\"zulip\"",
")",
"self",
".",
"login_user",
"(",
"hamlet",
")",
"bots",
"=",
"{",
"}",
"for"... | [
525,
4
] | [
656,
9
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_bad_httprequest_repr | (self) |
If an exception occurs when parsing GET, POST, COOKIES, or META, the
repr of the request should show it.
|
If an exception occurs when parsing GET, POST, COOKIES, or META, the
repr of the request should show it.
| def test_bad_httprequest_repr(self):
"""
If an exception occurs when parsing GET, POST, COOKIES, or META, the
repr of the request should show it.
"""
class Bomb(object):
"""An object that raises an exception when printed out."""
def __repr__(self):
... | [
"def",
"test_bad_httprequest_repr",
"(",
"self",
")",
":",
"class",
"Bomb",
"(",
"object",
")",
":",
"\"\"\"An object that raises an exception when printed out.\"\"\"",
"def",
"__repr__",
"(",
"self",
")",
":",
"raise",
"Exception",
"(",
"'boom!'",
")",
"bomb",
"=",... | [
49,
4
] | [
63,
71
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_wsgirequest_with_script_name | (self) |
Ensure that the request's path is correctly assembled, regardless of
whether or not the SCRIPT_NAME has a trailing slash.
Refs #20169.
|
Ensure that the request's path is correctly assembled, regardless of
whether or not the SCRIPT_NAME has a trailing slash.
Refs #20169.
| def test_wsgirequest_with_script_name(self):
"""
Ensure that the request's path is correctly assembled, regardless of
whether or not the SCRIPT_NAME has a trailing slash.
Refs #20169.
"""
# With trailing slash
request = WSGIRequest({'PATH_INFO': '/somepath/', 'SCR... | [
"def",
"test_wsgirequest_with_script_name",
"(",
"self",
")",
":",
"# With trailing slash",
"request",
"=",
"WSGIRequest",
"(",
"{",
"'PATH_INFO'",
":",
"'/somepath/'",
",",
"'SCRIPT_NAME'",
":",
"'/PREFIX/'",
",",
"'REQUEST_METHOD'",
":",
"'get'",
",",
"'wsgi.input'"... | [
75,
4
] | [
86,
59
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_wsgirequest_with_force_script_name | (self) |
Ensure that the FORCE_SCRIPT_NAME setting takes precedence over the
request's SCRIPT_NAME environment parameter.
Refs #20169.
|
Ensure that the FORCE_SCRIPT_NAME setting takes precedence over the
request's SCRIPT_NAME environment parameter.
Refs #20169.
| def test_wsgirequest_with_force_script_name(self):
"""
Ensure that the FORCE_SCRIPT_NAME setting takes precedence over the
request's SCRIPT_NAME environment parameter.
Refs #20169.
"""
with override_settings(FORCE_SCRIPT_NAME='/FORCED_PREFIX/'):
request = WSGI... | [
"def",
"test_wsgirequest_with_force_script_name",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"FORCE_SCRIPT_NAME",
"=",
"'/FORCED_PREFIX/'",
")",
":",
"request",
"=",
"WSGIRequest",
"(",
"{",
"'PATH_INFO'",
":",
"'/somepath/'",
",",
"'SCRIPT_NAME'",
":",
... | [
88,
4
] | [
96,
70
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_wsgirequest_path_with_force_script_name_trailing_slash | (self) |
Ensure that the request's path is correctly assembled, regardless of
whether or not the FORCE_SCRIPT_NAME setting has a trailing slash.
Refs #20169.
|
Ensure that the request's path is correctly assembled, regardless of
whether or not the FORCE_SCRIPT_NAME setting has a trailing slash.
Refs #20169.
| def test_wsgirequest_path_with_force_script_name_trailing_slash(self):
"""
Ensure that the request's path is correctly assembled, regardless of
whether or not the FORCE_SCRIPT_NAME setting has a trailing slash.
Refs #20169.
"""
# With trailing slash
with override_... | [
"def",
"test_wsgirequest_path_with_force_script_name_trailing_slash",
"(",
"self",
")",
":",
"# With trailing slash",
"with",
"override_settings",
"(",
"FORCE_SCRIPT_NAME",
"=",
"'/FORCED_PREFIX/'",
")",
":",
"request",
"=",
"WSGIRequest",
"(",
"{",
"'PATH_INFO'",
":",
"'... | [
98,
4
] | [
111,
70
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_near_expiration | (self) | Cookie will expire when an near expiration time is provided | Cookie will expire when an near expiration time is provided | def test_near_expiration(self):
"Cookie will expire when an near expiration time is provided"
response = HttpResponse()
# There is a timing weakness in this test; The
# expected result for max-age requires that there be
# a very slight difference between the evaluated expiration
... | [
"def",
"test_near_expiration",
"(",
"self",
")",
":",
"response",
"=",
"HttpResponse",
"(",
")",
"# There is a timing weakness in this test; The",
"# expected result for max-age requires that there be",
"# a very slight difference between the evaluated expiration",
"# time, and the time ... | [
147,
4
] | [
161,
56
] | python | en | ['en', 'en', 'en'] | True |
RequestsTests.test_aware_expiration | (self) | Cookie accepts an aware datetime as expiration time | Cookie accepts an aware datetime as expiration time | def test_aware_expiration(self):
"Cookie accepts an aware datetime as expiration time"
response = HttpResponse()
expires = (datetime.utcnow() + timedelta(seconds=10)).replace(tzinfo=utc)
time.sleep(0.001)
response.set_cookie('datetime', expires=expires)
datetime_cookie = ... | [
"def",
"test_aware_expiration",
"(",
"self",
")",
":",
"response",
"=",
"HttpResponse",
"(",
")",
"expires",
"=",
"(",
"datetime",
".",
"utcnow",
"(",
")",
"+",
"timedelta",
"(",
"seconds",
"=",
"10",
")",
")",
".",
"replace",
"(",
"tzinfo",
"=",
"utc"... | [
163,
4
] | [
170,
56
] | python | en | ['en', 'en', 'en'] | True |
RequestsTests.test_far_expiration | (self) | Cookie will expire when an distant expiration time is provided | Cookie will expire when an distant expiration time is provided | def test_far_expiration(self):
"Cookie will expire when an distant expiration time is provided"
response = HttpResponse()
response.set_cookie('datetime', expires=datetime(2028, 1, 1, 4, 5, 6))
datetime_cookie = response.cookies['datetime']
self.assertEqual(datetime_cookie['expire... | [
"def",
"test_far_expiration",
"(",
"self",
")",
":",
"response",
"=",
"HttpResponse",
"(",
")",
"response",
".",
"set_cookie",
"(",
"'datetime'",
",",
"expires",
"=",
"datetime",
"(",
"2028",
",",
"1",
",",
"1",
",",
"4",
",",
"5",
",",
"6",
")",
")"... | [
172,
4
] | [
177,
85
] | python | en | ['en', 'en', 'en'] | True |
RequestsTests.test_max_age_expiration | (self) | Cookie will expire if max_age is provided | Cookie will expire if max_age is provided | def test_max_age_expiration(self):
"Cookie will expire if max_age is provided"
response = HttpResponse()
response.set_cookie('max_age', max_age=10)
max_age_cookie = response.cookies['max_age']
self.assertEqual(max_age_cookie['max-age'], 10)
self.assertEqual(max_age_cookie... | [
"def",
"test_max_age_expiration",
"(",
"self",
")",
":",
"response",
"=",
"HttpResponse",
"(",
")",
"response",
".",
"set_cookie",
"(",
"'max_age'",
",",
"max_age",
"=",
"10",
")",
"max_age_cookie",
"=",
"response",
".",
"cookies",
"[",
"'max_age'",
"]",
"se... | [
179,
4
] | [
185,
82
] | python | en | ['en', 'en', 'en'] | True |
RequestsTests.test_unicode_cookie | (self) | Verify HttpResponse.set_cookie() works with unicode data. | Verify HttpResponse.set_cookie() works with unicode data. | def test_unicode_cookie(self):
"Verify HttpResponse.set_cookie() works with unicode data."
response = HttpResponse()
cookie_value = '清風'
response.set_cookie('test', cookie_value)
self.assertEqual(force_str(cookie_value), response.cookies['test'].value) | [
"def",
"test_unicode_cookie",
"(",
"self",
")",
":",
"response",
"=",
"HttpResponse",
"(",
")",
"cookie_value",
"=",
"'清風'",
"response",
".",
"set_cookie",
"(",
"'test'",
",",
"cookie_value",
")",
"self",
".",
"assertEqual",
"(",
"force_str",
"(",
"cookie_valu... | [
196,
4
] | [
201,
81
] | python | en | ['en', 'en', 'en'] | True |
RequestsTests.test_read_after_value | (self) |
Reading from request is allowed after accessing request contents as
POST or body.
|
Reading from request is allowed after accessing request contents as
POST or body.
| def test_read_after_value(self):
"""
Reading from request is allowed after accessing request contents as
POST or body.
"""
payload = FakePayload('name=value')
request = WSGIRequest({'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'application/x-ww... | [
"def",
"test_read_after_value",
"(",
"self",
")",
":",
"payload",
"=",
"FakePayload",
"(",
"'name=value'",
")",
"request",
"=",
"WSGIRequest",
"(",
"{",
"'REQUEST_METHOD'",
":",
"'POST'",
",",
"'CONTENT_TYPE'",
":",
"'application/x-www-form-urlencoded'",
",",
"'CONT... | [
268,
4
] | [
280,
55
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_value_after_read | (self) |
Construction of POST or body is not allowed after reading
from request.
|
Construction of POST or body is not allowed after reading
from request.
| def test_value_after_read(self):
"""
Construction of POST or body is not allowed after reading
from request.
"""
payload = FakePayload('name=value')
request = WSGIRequest({'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'application/x-www-form-url... | [
"def",
"test_value_after_read",
"(",
"self",
")",
":",
"payload",
"=",
"FakePayload",
"(",
"'name=value'",
")",
"request",
"=",
"WSGIRequest",
"(",
"{",
"'REQUEST_METHOD'",
":",
"'POST'",
",",
"'CONTENT_TYPE'",
":",
"'application/x-www-form-urlencoded'",
",",
"'CONT... | [
282,
4
] | [
294,
42
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_alternate_charset_POST | (self) |
Test a POST with non-utf-8 payload encoding.
|
Test a POST with non-utf-8 payload encoding.
| def test_alternate_charset_POST(self):
"""
Test a POST with non-utf-8 payload encoding.
"""
payload = FakePayload(original_urlencode({'key': 'España'.encode('latin-1')}))
request = WSGIRequest({
'REQUEST_METHOD': 'POST',
'CONTENT_LENGTH': len(payload),
... | [
"def",
"test_alternate_charset_POST",
"(",
"self",
")",
":",
"payload",
"=",
"FakePayload",
"(",
"original_urlencode",
"(",
"{",
"'key'",
":",
"'España'.",
"e",
"ncode(",
"'",
"latin-1')",
"}",
")",
")",
"",
"request",
"=",
"WSGIRequest",
"(",
"{",
"'REQUEST... | [
306,
4
] | [
317,
60
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_body_after_POST_multipart_form_data | (self) |
Reading body after parsing multipart/form-data is not allowed
|
Reading body after parsing multipart/form-data is not allowed
| def test_body_after_POST_multipart_form_data(self):
"""
Reading body after parsing multipart/form-data is not allowed
"""
# Because multipart is used for large amounts fo data i.e. file uploads,
# we don't want the data held in memory twice, and we don't want to
# silence... | [
"def",
"test_body_after_POST_multipart_form_data",
"(",
"self",
")",
":",
"# Because multipart is used for large amounts fo data i.e. file uploads,",
"# we don't want the data held in memory twice, and we don't want to",
"# silence the error by setting body = '' either.",
"payload",
"=",
"Fake... | [
319,
4
] | [
338,
69
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_body_after_POST_multipart_related | (self) |
Reading body after parsing multipart that isn't form-data is allowed
|
Reading body after parsing multipart that isn't form-data is allowed
| def test_body_after_POST_multipart_related(self):
"""
Reading body after parsing multipart that isn't form-data is allowed
"""
# Ticket #9054
# There are cases in which the multipart data is related instead of
# being a binary upload, in which case it should still be acce... | [
"def",
"test_body_after_POST_multipart_related",
"(",
"self",
")",
":",
"# Ticket #9054",
"# There are cases in which the multipart data is related instead of",
"# being a binary upload, in which case it should still be accessible",
"# via body.",
"payload_data",
"=",
"b\"\\r\\n\"",
".",
... | [
340,
4
] | [
361,
52
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_POST_multipart_with_content_length_zero | (self) |
Multipart POST requests with Content-Length >= 0 are valid and need to be handled.
|
Multipart POST requests with Content-Length >= 0 are valid and need to be handled.
| def test_POST_multipart_with_content_length_zero(self):
"""
Multipart POST requests with Content-Length >= 0 are valid and need to be handled.
"""
# According to:
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13
# Every request.POST with Content-Length >=... | [
"def",
"test_POST_multipart_with_content_length_zero",
"(",
"self",
")",
":",
"# According to:",
"# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.13",
"# Every request.POST with Content-Length >= 0 is a valid request,",
"# this test ensures that we handle Content-Length == 0.",
"p... | [
363,
4
] | [
382,
42
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_POST_after_body_read | (self) |
POST should be populated even if body is read first
|
POST should be populated even if body is read first
| def test_POST_after_body_read(self):
"""
POST should be populated even if body is read first
"""
payload = FakePayload('name=value')
request = WSGIRequest({'REQUEST_METHOD': 'POST',
'CONTENT_TYPE': 'application/x-www-form-urlencoded',
... | [
"def",
"test_POST_after_body_read",
"(",
"self",
")",
":",
"payload",
"=",
"FakePayload",
"(",
"'name=value'",
")",
"request",
"=",
"WSGIRequest",
"(",
"{",
"'REQUEST_METHOD'",
":",
"'POST'",
",",
"'CONTENT_TYPE'",
":",
"'application/x-www-form-urlencoded'",
",",
"'... | [
410,
4
] | [
420,
59
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_POST_after_body_read_and_stream_read | (self) |
POST should be populated even if body is read first, and then
the stream is read second.
|
POST should be populated even if body is read first, and then
the stream is read second.
| def test_POST_after_body_read_and_stream_read(self):
"""
POST should be populated even if body is read first, and then
the stream is read second.
"""
payload = FakePayload('name=value')
request = WSGIRequest({'REQUEST_METHOD': 'POST',
'CONTE... | [
"def",
"test_POST_after_body_read_and_stream_read",
"(",
"self",
")",
":",
"payload",
"=",
"FakePayload",
"(",
"'name=value'",
")",
"request",
"=",
"WSGIRequest",
"(",
"{",
"'REQUEST_METHOD'",
":",
"'POST'",
",",
"'CONTENT_TYPE'",
":",
"'application/x-www-form-urlencode... | [
422,
4
] | [
434,
59
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_POST_after_body_read_and_stream_read_multipart | (self) |
POST should be populated even if body is read first, and then
the stream is read second. Using multipart/form-data instead of urlencoded.
|
POST should be populated even if body is read first, and then
the stream is read second. Using multipart/form-data instead of urlencoded.
| def test_POST_after_body_read_and_stream_read_multipart(self):
"""
POST should be populated even if body is read first, and then
the stream is read second. Using multipart/form-data instead of urlencoded.
"""
payload = FakePayload("\r\n".join([
'--boundary',
... | [
"def",
"test_POST_after_body_read_and_stream_read_multipart",
"(",
"self",
")",
":",
"payload",
"=",
"FakePayload",
"(",
"\"\\r\\n\"",
".",
"join",
"(",
"[",
"'--boundary'",
",",
"'Content-Disposition: form-data; name=\"name\"'",
",",
"''",
",",
"'value'",
",",
"'--boun... | [
436,
4
] | [
455,
59
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_POST_connection_error | (self) |
If wsgi.input.read() raises an exception while trying to read() the
POST, the exception should be identifiable (not a generic IOError).
|
If wsgi.input.read() raises an exception while trying to read() the
POST, the exception should be identifiable (not a generic IOError).
| def test_POST_connection_error(self):
"""
If wsgi.input.read() raises an exception while trying to read() the
POST, the exception should be identifiable (not a generic IOError).
"""
class ExplodingBytesIO(BytesIO):
def read(self, len=0):
raise IOError(... | [
"def",
"test_POST_connection_error",
"(",
"self",
")",
":",
"class",
"ExplodingBytesIO",
"(",
"BytesIO",
")",
":",
"def",
"read",
"(",
"self",
",",
"len",
"=",
"0",
")",
":",
"raise",
"IOError",
"(",
"\"kaboom!\"",
")",
"payload",
"=",
"b'name=value'",
"re... | [
457,
4
] | [
473,
24
] | python | en | ['en', 'error', 'th'] | False |
RequestsTests.test_FILES_connection_error | (self) |
If wsgi.input.read() raises an exception while trying to read() the
FILES, the exception should be identifiable (not a generic IOError).
|
If wsgi.input.read() raises an exception while trying to read() the
FILES, the exception should be identifiable (not a generic IOError).
| def test_FILES_connection_error(self):
"""
If wsgi.input.read() raises an exception while trying to read() the
FILES, the exception should be identifiable (not a generic IOError).
"""
class ExplodingBytesIO(BytesIO):
def read(self, len=0):
raise IOErro... | [
"def",
"test_FILES_connection_error",
"(",
"self",
")",
":",
"class",
"ExplodingBytesIO",
"(",
"BytesIO",
")",
":",
"def",
"read",
"(",
"self",
",",
"len",
"=",
"0",
")",
":",
"raise",
"IOError",
"(",
"\"kaboom!\"",
")",
"payload",
"=",
"b'x'",
"request",
... | [
475,
4
] | [
491,
25
] | python | en | ['en', 'error', 'th'] | False |
HostValidationTests.test_host_validation_disabled_in_debug_mode | (self) | If ALLOWED_HOSTS is empty and DEBUG is True, all hosts pass. | If ALLOWED_HOSTS is empty and DEBUG is True, all hosts pass. | def test_host_validation_disabled_in_debug_mode(self):
"""If ALLOWED_HOSTS is empty and DEBUG is True, all hosts pass."""
request = HttpRequest()
request.META = {
'HTTP_HOST': 'example.com',
}
self.assertEqual(request.get_host(), 'example.com')
# Invalid host... | [
"def",
"test_host_validation_disabled_in_debug_mode",
"(",
"self",
")",
":",
"request",
"=",
"HttpRequest",
"(",
")",
"request",
".",
"META",
"=",
"{",
"'HTTP_HOST'",
":",
"'example.com'",
",",
"}",
"self",
".",
"assertEqual",
"(",
"request",
".",
"get_host",
... | [
643,
4
] | [
657,
68
] | python | en | ['en', 'en', 'en'] | True |
HostValidationTests.test_get_host_suggestion_of_allowed_host | (self) | get_host() makes helpful suggestions if a valid-looking host is not in ALLOWED_HOSTS. | get_host() makes helpful suggestions if a valid-looking host is not in ALLOWED_HOSTS. | def test_get_host_suggestion_of_allowed_host(self):
"""get_host() makes helpful suggestions if a valid-looking host is not in ALLOWED_HOSTS."""
msg_invalid_host = "Invalid HTTP_HOST header: %r."
msg_suggestion = msg_invalid_host + " You may need to add %r to ALLOWED_HOSTS."
msg_suggestio... | [
"def",
"test_get_host_suggestion_of_allowed_host",
"(",
"self",
")",
":",
"msg_invalid_host",
"=",
"\"Invalid HTTP_HOST header: %r.\"",
"msg_suggestion",
"=",
"msg_invalid_host",
"+",
"\" You may need to add %r to ALLOWED_HOSTS.\"",
"msg_suggestion2",
"=",
"msg_invalid_host",
"+",
... | [
660,
4
] | [
709,
9
] | python | en | ['en', 'en', 'en'] | True |
BuildAbsoluteURITestCase.test_build_absolute_uri_no_location | (self) |
Ensures that ``request.build_absolute_uri()`` returns the proper value
when the ``location`` argument is not provided, and ``request.path``
begins with //.
|
Ensures that ``request.build_absolute_uri()`` returns the proper value
when the ``location`` argument is not provided, and ``request.path``
begins with //.
| def test_build_absolute_uri_no_location(self):
"""
Ensures that ``request.build_absolute_uri()`` returns the proper value
when the ``location`` argument is not provided, and ``request.path``
begins with //.
"""
# //// is needed to create a request with a path beginning wi... | [
"def",
"test_build_absolute_uri_no_location",
"(",
"self",
")",
":",
"# //// is needed to create a request with a path beginning with //",
"request",
"=",
"self",
".",
"factory",
".",
"get",
"(",
"'////absolute-uri'",
")",
"self",
".",
"assertEqual",
"(",
"request",
".",
... | [
720,
4
] | [
731,
9
] | python | en | ['en', 'error', 'th'] | False |
BuildAbsoluteURITestCase.test_build_absolute_uri_absolute_location | (self) |
Ensures that ``request.build_absolute_uri()`` returns the proper value
when an absolute URL ``location`` argument is provided, and
``request.path`` begins with //.
|
Ensures that ``request.build_absolute_uri()`` returns the proper value
when an absolute URL ``location`` argument is provided, and
``request.path`` begins with //.
| def test_build_absolute_uri_absolute_location(self):
"""
Ensures that ``request.build_absolute_uri()`` returns the proper value
when an absolute URL ``location`` argument is provided, and
``request.path`` begins with //.
"""
# //// is needed to create a request with a pat... | [
"def",
"test_build_absolute_uri_absolute_location",
"(",
"self",
")",
":",
"# //// is needed to create a request with a path beginning with //",
"request",
"=",
"self",
".",
"factory",
".",
"get",
"(",
"'////absolute-uri'",
")",
"self",
".",
"assertEqual",
"(",
"request",
... | [
733,
4
] | [
744,
9
] | python | en | ['en', 'error', 'th'] | False |
BuildAbsoluteURITestCase.test_build_absolute_uri_schema_relative_location | (self) |
Ensures that ``request.build_absolute_uri()`` returns the proper value
when a schema-relative URL ``location`` argument is provided, and
``request.path`` begins with //.
|
Ensures that ``request.build_absolute_uri()`` returns the proper value
when a schema-relative URL ``location`` argument is provided, and
``request.path`` begins with //.
| def test_build_absolute_uri_schema_relative_location(self):
"""
Ensures that ``request.build_absolute_uri()`` returns the proper value
when a schema-relative URL ``location`` argument is provided, and
``request.path`` begins with //.
"""
# //// is needed to create a reque... | [
"def",
"test_build_absolute_uri_schema_relative_location",
"(",
"self",
")",
":",
"# //// is needed to create a request with a path beginning with //",
"request",
"=",
"self",
".",
"factory",
".",
"get",
"(",
"'////absolute-uri'",
")",
"self",
".",
"assertEqual",
"(",
"requ... | [
746,
4
] | [
757,
9
] | python | en | ['en', 'error', 'th'] | False |
BuildAbsoluteURITestCase.test_build_absolute_uri_relative_location | (self) |
Ensures that ``request.build_absolute_uri()`` returns the proper value
when a relative URL ``location`` argument is provided, and
``request.path`` begins with //.
|
Ensures that ``request.build_absolute_uri()`` returns the proper value
when a relative URL ``location`` argument is provided, and
``request.path`` begins with //.
| def test_build_absolute_uri_relative_location(self):
"""
Ensures that ``request.build_absolute_uri()`` returns the proper value
when a relative URL ``location`` argument is provided, and
``request.path`` begins with //.
"""
# //// is needed to create a request with a path... | [
"def",
"test_build_absolute_uri_relative_location",
"(",
"self",
")",
":",
"# //// is needed to create a request with a path beginning with //",
"request",
"=",
"self",
".",
"factory",
".",
"get",
"(",
"'////absolute-uri'",
")",
"self",
".",
"assertEqual",
"(",
"request",
... | [
759,
4
] | [
770,
9
] | python | en | ['en', 'error', 'th'] | False |
OnDeleteTests.test_do_nothing_qscount | (self) |
Test that a models.DO_NOTHING relation doesn't trigger a query.
|
Test that a models.DO_NOTHING relation doesn't trigger a query.
| def test_do_nothing_qscount(self):
"""
Test that a models.DO_NOTHING relation doesn't trigger a query.
"""
b = Base.objects.create()
with self.assertNumQueries(1):
# RelToBase should not be queried.
b.delete()
self.assertEqual(Base.objects.count(),... | [
"def",
"test_do_nothing_qscount",
"(",
"self",
")",
":",
"b",
"=",
"Base",
".",
"objects",
".",
"create",
"(",
")",
"with",
"self",
".",
"assertNumQueries",
"(",
"1",
")",
":",
"# RelToBase should not be queried.",
"b",
".",
"delete",
"(",
")",
"self",
"."... | [
81,
4
] | [
89,
49
] | python | en | ['en', 'error', 'th'] | False |
TestSparseL1Descent.test_do_not_reach_lp_boundary | (self) |
Make sure that iterative attack don't reach boundary of Lp
neighbourhood if nb_iter * eps_iter is relatively small compared to
epsilon.
|
Make sure that iterative attack don't reach boundary of Lp
neighbourhood if nb_iter * eps_iter is relatively small compared to
epsilon.
| def test_do_not_reach_lp_boundary(self):
"""
Make sure that iterative attack don't reach boundary of Lp
neighbourhood if nb_iter * eps_iter is relatively small compared to
epsilon.
"""
_, delta, _ = self.generate_adversarial_examples(
eps=0.5, clip_min=-5, cli... | [
"def",
"test_do_not_reach_lp_boundary",
"(",
"self",
")",
":",
"_",
",",
"delta",
",",
"_",
"=",
"self",
".",
"generate_adversarial_examples",
"(",
"eps",
"=",
"0.5",
",",
"clip_min",
"=",
"-",
"5",
",",
"clip_max",
"=",
"5",
",",
"nb_iter",
"=",
"10",
... | [
940,
4
] | [
949,
54
] | python | en | ['en', 'error', 'th'] | False |
TestSparseL1Descent.test_grad_clip | (self) |
With clipped gradients, we achieve
np.mean(orig_labels == new_labels) == 0.0
|
With clipped gradients, we achieve
np.mean(orig_labels == new_labels) == 0.0
| def test_grad_clip(self):
"""
With clipped gradients, we achieve
np.mean(orig_labels == new_labels) == 0.0
"""
# sanity checks turned off because this test initializes outside
# the valid range.
_, _, adv_acc = self.generate_adversarial_examples(
eps=... | [
"def",
"test_grad_clip",
"(",
"self",
")",
":",
"# sanity checks turned off because this test initializes outside",
"# the valid range.",
"_",
",",
"_",
",",
"adv_acc",
"=",
"self",
".",
"generate_adversarial_examples",
"(",
"eps",
"=",
"10",
",",
"rand_init",
"=",
"T... | [
986,
4
] | [
1003,
37
] | python | en | ['en', 'error', 'th'] | False |
default_storage | (request) |
Callable with the same interface as the storage classes.
This isn't just default_storage = import_string(settings.MESSAGE_STORAGE)
to avoid accessing the settings at the module level.
|
Callable with the same interface as the storage classes. | def default_storage(request):
"""
Callable with the same interface as the storage classes.
This isn't just default_storage = import_string(settings.MESSAGE_STORAGE)
to avoid accessing the settings at the module level.
"""
return import_string(settings.MESSAGE_STORAGE)(request) | [
"def",
"default_storage",
"(",
"request",
")",
":",
"return",
"import_string",
"(",
"settings",
".",
"MESSAGE_STORAGE",
")",
"(",
"request",
")"
] | [
4,
0
] | [
11,
59
] | python | en | ['en', 'error', 'th'] | False |
TimesinceTests.test_equal_datetimes | (self) | equal datetimes. | equal datetimes. | def test_equal_datetimes(self):
""" equal datetimes. """
# NOTE: \xa0 avoids wrapping between value and unit
self.assertEqual(timesince(self.t, self.t), '0\xa0minutes') | [
"def",
"test_equal_datetimes",
"(",
"self",
")",
":",
"# NOTE: \\xa0 avoids wrapping between value and unit",
"self",
".",
"assertEqual",
"(",
"timesince",
"(",
"self",
".",
"t",
",",
"self",
".",
"t",
")",
",",
"'0\\xa0minutes'",
")"
] | [
23,
4
] | [
26,
67
] | python | da | ['es', 'da', 'en'] | False |
TimesinceTests.test_ignore_microseconds_and_seconds | (self) | Microseconds and seconds are ignored. | Microseconds and seconds are ignored. | def test_ignore_microseconds_and_seconds(self):
""" Microseconds and seconds are ignored. """
self.assertEqual(timesince(self.t, self.t + self.onemicrosecond),
'0\xa0minutes')
self.assertEqual(timesince(self.t, self.t + self.onesecond),
'0\xa0minutes') | [
"def",
"test_ignore_microseconds_and_seconds",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"timesince",
"(",
"self",
".",
"t",
",",
"self",
".",
"t",
"+",
"self",
".",
"onemicrosecond",
")",
",",
"'0\\xa0minutes'",
")",
"self",
".",
"assertEqual"... | [
28,
4
] | [
33,
27
] | python | en | ['en', 'en', 'en'] | True |
TimesinceTests.test_other_units | (self) | Test other units. | Test other units. | def test_other_units(self):
""" Test other units. """
self.assertEqual(timesince(self.t, self.t + self.oneminute),
'1\xa0minute')
self.assertEqual(timesince(self.t, self.t + self.onehour), '1\xa0hour')
self.assertEqual(timesince(self.t, self.t + self.oneday), '1\xa0day')
... | [
"def",
"test_other_units",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"timesince",
"(",
"self",
".",
"t",
",",
"self",
".",
"t",
"+",
"self",
".",
"oneminute",
")",
",",
"'1\\xa0minute'",
")",
"self",
".",
"assertEqual",
"(",
"timesince",
... | [
35,
4
] | [
44,
79
] | python | en | ['en', 'en', 'en'] | True |
TimesinceTests.test_multiple_units | (self) | Test multiple units. | Test multiple units. | def test_multiple_units(self):
""" Test multiple units. """
self.assertEqual(timesince(self.t,
self.t + 2 * self.oneday + 6 * self.onehour), '2\xa0days, 6\xa0hours')
self.assertEqual(timesince(self.t,
self.t + 2 * self.oneweek + 2 * self.oneday), '2\xa0weeks, 2\xa0days') | [
"def",
"test_multiple_units",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"timesince",
"(",
"self",
".",
"t",
",",
"self",
".",
"t",
"+",
"2",
"*",
"self",
".",
"oneday",
"+",
"6",
"*",
"self",
".",
"onehour",
")",
",",
"'2\\xa0days, 6\\x... | [
46,
4
] | [
51,
82
] | python | en | ['es', 'et', 'en'] | False |
TimesinceTests.test_display_first_unit | (self) |
If the two differing units aren't adjacent, only the first unit is
displayed.
|
If the two differing units aren't adjacent, only the first unit is
displayed.
| def test_display_first_unit(self):
"""
If the two differing units aren't adjacent, only the first unit is
displayed.
"""
self.assertEqual(timesince(self.t,
self.t + 2 * self.oneweek + 3 * self.onehour + 4 * self.oneminute),
'2\xa0weeks')
self.asse... | [
"def",
"test_display_first_unit",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"timesince",
"(",
"self",
".",
"t",
",",
"self",
".",
"t",
"+",
"2",
"*",
"self",
".",
"oneweek",
"+",
"3",
"*",
"self",
".",
"onehour",
"+",
"4",
"*",
"self"... | [
53,
4
] | [
63,
72
] | python | en | ['en', 'error', 'th'] | False |
TimesinceTests.test_display_second_before_first | (self) |
When the second date occurs before the first, we should always
get 0 minutes.
|
When the second date occurs before the first, we should always
get 0 minutes.
| def test_display_second_before_first(self):
"""
When the second date occurs before the first, we should always
get 0 minutes.
"""
self.assertEqual(timesince(self.t, self.t - self.onemicrosecond),
'0\xa0minutes')
self.assertEqual(timesince(self.t, self.t - self... | [
"def",
"test_display_second_before_first",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"timesince",
"(",
"self",
".",
"t",
",",
"self",
".",
"t",
"-",
"self",
".",
"onemicrosecond",
")",
",",
"'0\\xa0minutes'",
")",
"self",
".",
"assertEqual",
... | [
65,
4
] | [
94,
75
] | python | en | ['en', 'error', 'th'] | False |
TimesinceTests.test_different_timezones | (self) | When using two different timezones. | When using two different timezones. | def test_different_timezones(self):
""" When using two different timezones. """
now = datetime.datetime.now()
now_tz = timezone.make_aware(now, timezone.get_default_timezone())
now_tz_i = timezone.localtime(now_tz, timezone.get_fixed_timezone(195))
self.assertEqual(timesince(now... | [
"def",
"test_different_timezones",
"(",
"self",
")",
":",
"now",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"now_tz",
"=",
"timezone",
".",
"make_aware",
"(",
"now",
",",
"timezone",
".",
"get_default_timezone",
"(",
")",
")",
"now_tz_i",
"=",... | [
97,
4
] | [
110,
69
] | python | en | ['en', 'en', 'en'] | True |
TimesinceTests.test_date_objects | (self) | Both timesince and timeuntil should work on date objects (#17937). | Both timesince and timeuntil should work on date objects (#17937). | def test_date_objects(self):
""" Both timesince and timeuntil should work on date objects (#17937). """
today = datetime.date.today()
self.assertEqual(timesince(today + self.oneday), '0\xa0minutes')
self.assertEqual(timeuntil(today - self.oneday), '0\xa0minutes') | [
"def",
"test_date_objects",
"(",
"self",
")",
":",
"today",
"=",
"datetime",
".",
"date",
".",
"today",
"(",
")",
"self",
".",
"assertEqual",
"(",
"timesince",
"(",
"today",
"+",
"self",
".",
"oneday",
")",
",",
"'0\\xa0minutes'",
")",
"self",
".",
"as... | [
112,
4
] | [
116,
72
] | python | en | ['en', 'en', 'en'] | True |
TimesinceTests.test_both_date_objects | (self) | Timesince should work with both date objects (#9672) | Timesince should work with both date objects (#9672) | def test_both_date_objects(self):
""" Timesince should work with both date objects (#9672) """
today = datetime.date.today()
self.assertEqual(timeuntil(today + self.oneday, today), '1\xa0day')
self.assertEqual(timeuntil(today - self.oneday, today), '0\xa0minutes')
self.assertEqua... | [
"def",
"test_both_date_objects",
"(",
"self",
")",
":",
"today",
"=",
"datetime",
".",
"date",
".",
"today",
"(",
")",
"self",
".",
"assertEqual",
"(",
"timeuntil",
"(",
"today",
"+",
"self",
".",
"oneday",
",",
"today",
")",
",",
"'1\\xa0day'",
")",
"... | [
118,
4
] | [
123,
77
] | python | en | ['en', 'en', 'en'] | True |
SDNML.length | (self, x) | Calculate SDNML code-length.
Parameters
----------
x : float
Sample.
Returns
-------
code_length : float
Code length of the sample.
| Calculate SDNML code-length. | def length(self, x):
"""Calculate SDNML code-length.
Parameters
----------
x : float
Sample.
Returns
-------
code_length : float
Code length of the sample.
"""
self._xs.pop(0)
self._xs.append(x)
xs = np.atl... | [
"def",
"length",
"(",
"self",
",",
"x",
")",
":",
"self",
".",
"_xs",
".",
"pop",
"(",
"0",
")",
"self",
".",
"_xs",
".",
"append",
"(",
"x",
")",
"xs",
"=",
"np",
".",
"atleast_2d",
"(",
"self",
".",
"_xs",
")",
".",
"T",
"self",
".",
"_up... | [
52,
4
] | [
82,
26
] | python | en | ['en', 'en', 'en'] | True |
fix_help_options | (options) | Convert a 4-tuple 'help_options' list as found in various command
classes to the 3-tuple form required by FancyGetopt.
| Convert a 4-tuple 'help_options' list as found in various command
classes to the 3-tuple form required by FancyGetopt.
| def fix_help_options(options):
"""Convert a 4-tuple 'help_options' list as found in various command
classes to the 3-tuple form required by FancyGetopt.
"""
new_options = []
for help_tuple in options:
new_options.append(help_tuple[0:3])
return new_options | [
"def",
"fix_help_options",
"(",
"options",
")",
":",
"new_options",
"=",
"[",
"]",
"for",
"help_tuple",
"in",
"options",
":",
"new_options",
".",
"append",
"(",
"help_tuple",
"[",
"0",
":",
"3",
"]",
")",
"return",
"new_options"
] | [
1249,
0
] | [
1256,
22
] | python | en | ['en', 'en', 'en'] | True |
Distribution.__init__ | (self, attrs=None) | Construct a new Distribution instance: initialize all the
attributes of a Distribution, and then use 'attrs' (a dictionary
mapping attribute names to values) to assign some of those
attributes their "real" values. (Any attributes not mentioned in
'attrs' will be assigned to some null va... | Construct a new Distribution instance: initialize all the
attributes of a Distribution, and then use 'attrs' (a dictionary
mapping attribute names to values) to assign some of those
attributes their "real" values. (Any attributes not mentioned in
'attrs' will be assigned to some null va... | def __init__(self, attrs=None):
"""Construct a new Distribution instance: initialize all the
attributes of a Distribution, and then use 'attrs' (a dictionary
mapping attribute names to values) to assign some of those
attributes their "real" values. (Any attributes not mentioned in
... | [
"def",
"__init__",
"(",
"self",
",",
"attrs",
"=",
"None",
")",
":",
"# Default values for our command-line options",
"self",
".",
"verbose",
"=",
"1",
"self",
".",
"dry_run",
"=",
"0",
"self",
".",
"help",
"=",
"0",
"for",
"attr",
"in",
"self",
".",
"di... | [
136,
4
] | [
292,
31
] | python | en | ['en', 'en', 'en'] | True |
Distribution.get_option_dict | (self, command) | Get the option dictionary for a given command. If that
command's option dictionary hasn't been created yet, then create it
and return the new dictionary; otherwise, return the existing
option dictionary.
| Get the option dictionary for a given command. If that
command's option dictionary hasn't been created yet, then create it
and return the new dictionary; otherwise, return the existing
option dictionary.
| def get_option_dict(self, command):
"""Get the option dictionary for a given command. If that
command's option dictionary hasn't been created yet, then create it
and return the new dictionary; otherwise, return the existing
option dictionary.
"""
dict = self.command_opti... | [
"def",
"get_option_dict",
"(",
"self",
",",
"command",
")",
":",
"dict",
"=",
"self",
".",
"command_options",
".",
"get",
"(",
"command",
")",
"if",
"dict",
"is",
"None",
":",
"dict",
"=",
"self",
".",
"command_options",
"[",
"command",
"]",
"=",
"{",
... | [
294,
4
] | [
303,
19
] | python | en | ['en', 'en', 'en'] | True |
Distribution.find_config_files | (self) | Find as many configuration files as should be processed for this
platform, and return a list of filenames in the order in which they
should be parsed. The filenames returned are guaranteed to exist
(modulo nasty race conditions).
There are three possible config files: distutils.cfg in ... | Find as many configuration files as should be processed for this
platform, and return a list of filenames in the order in which they
should be parsed. The filenames returned are guaranteed to exist
(modulo nasty race conditions). | def find_config_files(self):
"""Find as many configuration files as should be processed for this
platform, and return a list of filenames in the order in which they
should be parsed. The filenames returned are guaranteed to exist
(modulo nasty race conditions).
There are three ... | [
"def",
"find_config_files",
"(",
"self",
")",
":",
"files",
"=",
"[",
"]",
"check_environ",
"(",
")",
"# Where to look for the system-wide Distutils config file",
"sys_dir",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"sys",
".",
"modules",
"[",
"'distutils'",
... | [
333,
4
] | [
379,
20
] | python | en | ['en', 'en', 'en'] | True |
Distribution.parse_command_line | (self) | Parse the setup script's command line, taken from the
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
-- see 'setup()' in core.py). This list is first processed for
"global options" -- options that set attributes of the Distribution
instance. Then, it is alternately ... | Parse the setup script's command line, taken from the
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
-- see 'setup()' in core.py). This list is first processed for
"global options" -- options that set attributes of the Distribution
instance. Then, it is alternately ... | def parse_command_line(self):
"""Parse the setup script's command line, taken from the
'script_args' instance attribute (which defaults to 'sys.argv[1:]'
-- see 'setup()' in core.py). This list is first processed for
"global options" -- options that set attributes of the Distribution
... | [
"def",
"parse_command_line",
"(",
"self",
")",
":",
"#",
"# We now have enough information to show the Macintosh dialog",
"# that allows the user to interactively specify the \"command line\".",
"#",
"toplevel_options",
"=",
"self",
".",
"_get_toplevel_options",
"(",
")",
"# We hav... | [
439,
4
] | [
504,
19
] | python | en | ['en', 'en', 'en'] | True |
Distribution._get_toplevel_options | (self) | Return the non-display options recognized at the top level.
This includes options that are recognized *only* at the top
level as well as options recognized for commands.
| Return the non-display options recognized at the top level. | def _get_toplevel_options(self):
"""Return the non-display options recognized at the top level.
This includes options that are recognized *only* at the top
level as well as options recognized for commands.
"""
return self.global_options + [
("command-packages=", None... | [
"def",
"_get_toplevel_options",
"(",
"self",
")",
":",
"return",
"self",
".",
"global_options",
"+",
"[",
"(",
"\"command-packages=\"",
",",
"None",
",",
"\"list of packages that provide distutils commands\"",
")",
",",
"]"
] | [
506,
4
] | [
515,
13
] | 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.