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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
MakeMigrationsTests.test_makemigrations_empty_migration | (self) |
Makes sure that makemigrations properly constructs an empty migration.
|
Makes sure that makemigrations properly constructs an empty migration.
| def test_makemigrations_empty_migration(self):
"""
Makes sure that makemigrations properly constructs an empty migration.
"""
with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
try:
call_command("makemigrations", "migrations", empty=... | [
"def",
"test_makemigrations_empty_migration",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"MIGRATION_MODULES",
"=",
"{",
"\"migrations\"",
":",
"self",
".",
"migration_pkg",
"}",
")",
":",
"try",
":",
"call_command",
"(",
"\"makemigrations\"",
",",
"\... | [
279,
4
] | [
301,
53
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_no_changes_no_apps | (self) |
Makes sure that makemigrations exits when there are no changes and no apps are specified.
|
Makes sure that makemigrations exits when there are no changes and no apps are specified.
| def test_makemigrations_no_changes_no_apps(self):
"""
Makes sure that makemigrations exits when there are no changes and no apps are specified.
"""
stdout = six.StringIO()
call_command("makemigrations", stdout=stdout)
self.assertIn("No changes detected", stdout.getvalue()... | [
"def",
"test_makemigrations_no_changes_no_apps",
"(",
"self",
")",
":",
"stdout",
"=",
"six",
".",
"StringIO",
"(",
")",
"call_command",
"(",
"\"makemigrations\"",
",",
"stdout",
"=",
"stdout",
")",
"self",
".",
"assertIn",
"(",
"\"No changes detected\"",
",",
"... | [
304,
4
] | [
310,
63
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_no_changes | (self) |
Makes sure that makemigrations exits when there are no changes to an app.
|
Makes sure that makemigrations exits when there are no changes to an app.
| def test_makemigrations_no_changes(self):
"""
Makes sure that makemigrations exits when there are no changes to an app.
"""
stdout = six.StringIO()
call_command("makemigrations", "migrations", stdout=stdout)
self.assertIn("No changes detected in app 'migrations'", stdout.... | [
"def",
"test_makemigrations_no_changes",
"(",
"self",
")",
":",
"stdout",
"=",
"six",
".",
"StringIO",
"(",
")",
"call_command",
"(",
"\"makemigrations\"",
",",
"\"migrations\"",
",",
"stdout",
"=",
"stdout",
")",
"self",
".",
"assertIn",
"(",
"\"No changes dete... | [
314,
4
] | [
320,
83
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_migrations_announce | (self) |
Makes sure that makemigrations announces the migration at the default verbosity level.
|
Makes sure that makemigrations announces the migration at the default verbosity level.
| def test_makemigrations_migrations_announce(self):
"""
Makes sure that makemigrations announces the migration at the default verbosity level.
"""
stdout = six.StringIO()
with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
call_command("makemi... | [
"def",
"test_makemigrations_migrations_announce",
"(",
"self",
")",
":",
"stdout",
"=",
"six",
".",
"StringIO",
"(",
")",
"with",
"override_settings",
"(",
"MIGRATION_MODULES",
"=",
"{",
"\"migrations\"",
":",
"self",
".",
"migration_pkg",
"}",
")",
":",
"call_c... | [
323,
4
] | [
330,
71
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_no_common_ancestor | (self) |
Makes sure that makemigrations fails to merge migrations with no common ancestor.
|
Makes sure that makemigrations fails to merge migrations with no common ancestor.
| def test_makemigrations_no_common_ancestor(self):
"""
Makes sure that makemigrations fails to merge migrations with no common ancestor.
"""
with self.assertRaises(ValueError) as context:
call_command("makemigrations", "migrations", merge=True)
exception_message = str(... | [
"def",
"test_makemigrations_no_common_ancestor",
"(",
"self",
")",
":",
"with",
"self",
".",
"assertRaises",
"(",
"ValueError",
")",
"as",
"context",
":",
"call_command",
"(",
"\"makemigrations\"",
",",
"\"migrations\"",
",",
"merge",
"=",
"True",
")",
"exception_... | [
334,
4
] | [
343,
67
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_interactive_reject | (self) |
Makes sure that makemigrations enters and exits interactive mode properly.
|
Makes sure that makemigrations enters and exits interactive mode properly.
| def test_makemigrations_interactive_reject(self):
"""
Makes sure that makemigrations enters and exits interactive mode properly.
"""
# Monkeypatch interactive questioner to auto reject
old_input = questioner.input
questioner.input = lambda _: "N"
try:
... | [
"def",
"test_makemigrations_interactive_reject",
"(",
"self",
")",
":",
"# Monkeypatch interactive questioner to auto reject",
"old_input",
"=",
"questioner",
".",
"input",
"questioner",
".",
"input",
"=",
"lambda",
"_",
":",
"\"N\"",
"try",
":",
"call_command",
"(",
... | [
347,
4
] | [
361,
40
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_interactive_accept | (self) |
Makes sure that makemigrations enters interactive mode and merges properly.
|
Makes sure that makemigrations enters interactive mode and merges properly.
| def test_makemigrations_interactive_accept(self):
"""
Makes sure that makemigrations enters interactive mode and merges properly.
"""
# Monkeypatch interactive questioner to auto accept
old_input = questioner.input
questioner.input = lambda _: "y"
stdout = six.Str... | [
"def",
"test_makemigrations_interactive_accept",
"(",
"self",
")",
":",
"# Monkeypatch interactive questioner to auto accept",
"old_input",
"=",
"questioner",
".",
"input",
"questioner",
".",
"input",
"=",
"lambda",
"_",
":",
"\"y\"",
"stdout",
"=",
"six",
".",
"Strin... | [
365,
4
] | [
383,
71
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_handle_merge | (self) |
Makes sure that makemigrations properly merges the conflicting migrations with --noinput.
|
Makes sure that makemigrations properly merges the conflicting migrations with --noinput.
| def test_makemigrations_handle_merge(self):
"""
Makes sure that makemigrations properly merges the conflicting migrations with --noinput.
"""
stdout = six.StringIO()
call_command("makemigrations", "migrations", merge=True, interactive=False, stdout=stdout)
self.assertIn("... | [
"def",
"test_makemigrations_handle_merge",
"(",
"self",
")",
":",
"stdout",
"=",
"six",
".",
"StringIO",
"(",
")",
"call_command",
"(",
"\"makemigrations\"",
",",
"\"migrations\"",
",",
"merge",
"=",
"True",
",",
"interactive",
"=",
"False",
",",
"stdout",
"="... | [
387,
4
] | [
400,
71
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_dry_run | (self) |
Ticket #22676 -- `makemigrations --dry-run` should not ask for defaults.
|
Ticket #22676 -- `makemigrations --dry-run` should not ask for defaults.
| def test_makemigrations_dry_run(self):
"""
Ticket #22676 -- `makemigrations --dry-run` should not ask for defaults.
"""
class SillyModel(models.Model):
silly_field = models.BooleanField(default=False)
silly_date = models.DateField() # Added field without a defau... | [
"def",
"test_makemigrations_dry_run",
"(",
"self",
")",
":",
"class",
"SillyModel",
"(",
"models",
".",
"Model",
")",
":",
"silly_field",
"=",
"models",
".",
"BooleanField",
"(",
"default",
"=",
"False",
")",
"silly_date",
"=",
"models",
".",
"DateField",
"(... | [
404,
4
] | [
419,
78
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_dry_run_verbosity_3 | (self) |
Ticket #22675 -- Allow `makemigrations --dry-run` to output the
migrations file to stdout (with verbosity == 3).
|
Ticket #22675 -- Allow `makemigrations --dry-run` to output the
migrations file to stdout (with verbosity == 3).
| def test_makemigrations_dry_run_verbosity_3(self):
"""
Ticket #22675 -- Allow `makemigrations --dry-run` to output the
migrations file to stdout (with verbosity == 3).
"""
class SillyModel(models.Model):
silly_field = models.BooleanField(default=False)
si... | [
"def",
"test_makemigrations_dry_run_verbosity_3",
"(",
"self",
")",
":",
"class",
"SillyModel",
"(",
"models",
".",
"Model",
")",
":",
"silly_field",
"=",
"models",
".",
"BooleanField",
"(",
"default",
"=",
"False",
")",
"silly_char",
"=",
"models",
".",
"Char... | [
423,
4
] | [
450,
62
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_migrations_modules_path_not_exist | (self) |
Ticket #22682 -- Makemigrations fails when specifying custom location
for migration files (using MIGRATION_MODULES) if the custom path
doesn't already exist.
|
Ticket #22682 -- Makemigrations fails when specifying custom location
for migration files (using MIGRATION_MODULES) if the custom path
doesn't already exist.
| def test_makemigrations_migrations_modules_path_not_exist(self):
"""
Ticket #22682 -- Makemigrations fails when specifying custom location
for migration files (using MIGRATION_MODULES) if the custom path
doesn't already exist.
"""
class SillyModel(models.Model):
... | [
"def",
"test_makemigrations_migrations_modules_path_not_exist",
"(",
"self",
")",
":",
"class",
"SillyModel",
"(",
"models",
".",
"Model",
")",
":",
"silly_field",
"=",
"models",
".",
"BooleanField",
"(",
"default",
"=",
"False",
")",
"class",
"Meta",
":",
"app_... | [
454,
4
] | [
476,
43
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_interactive_by_default | (self) |
Makes sure that the user is prompted to merge by default if there are
conflicts and merge is True. Answer negative to differentiate it from
behavior when --noinput is specified.
|
Makes sure that the user is prompted to merge by default if there are
conflicts and merge is True. Answer negative to differentiate it from
behavior when --noinput is specified.
| def test_makemigrations_interactive_by_default(self):
"""
Makes sure that the user is prompted to merge by default if there are
conflicts and merge is True. Answer negative to differentiate it from
behavior when --noinput is specified.
"""
# Monkeypatch interactive questi... | [
"def",
"test_makemigrations_interactive_by_default",
"(",
"self",
")",
":",
"# Monkeypatch interactive questioner to auto reject",
"old_input",
"=",
"questioner",
".",
"input",
"questioner",
".",
"input",
"=",
"lambda",
"_",
":",
"\"N\"",
"stdout",
"=",
"six",
".",
"S... | [
480,
4
] | [
501,
74
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_unspecified_app_with_conflict_no_merge | (self) |
Makes sure that makemigrations does not raise a CommandError when an
unspecified app has conflicting migrations.
|
Makes sure that makemigrations does not raise a CommandError when an
unspecified app has conflicting migrations.
| def test_makemigrations_unspecified_app_with_conflict_no_merge(self):
"""
Makes sure that makemigrations does not raise a CommandError when an
unspecified app has conflicting migrations.
"""
try:
call_command("makemigrations", "migrations", merge=False, verbosity=0)
... | [
"def",
"test_makemigrations_unspecified_app_with_conflict_no_merge",
"(",
"self",
")",
":",
"try",
":",
"call_command",
"(",
"\"makemigrations\"",
",",
"\"migrations\"",
",",
"merge",
"=",
"False",
",",
"verbosity",
"=",
"0",
")",
"except",
"CommandError",
":",
"sel... | [
509,
4
] | [
517,
87
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_unspecified_app_with_conflict_merge | (self) |
Makes sure that makemigrations does not create a merge for an
unspecified app even if it has conflicting migrations.
|
Makes sure that makemigrations does not create a merge for an
unspecified app even if it has conflicting migrations.
| def test_makemigrations_unspecified_app_with_conflict_merge(self):
"""
Makes sure that makemigrations does not create a merge for an
unspecified app even if it has conflicting migrations.
"""
# Monkeypatch interactive questioner to auto accept
old_input = questioner.input... | [
"def",
"test_makemigrations_unspecified_app_with_conflict_merge",
"(",
"self",
")",
":",
"# Monkeypatch interactive questioner to auto accept",
"old_input",
"=",
"questioner",
".",
"input",
"questioner",
".",
"input",
"=",
"lambda",
"_",
":",
"\"y\"",
"stdout",
"=",
"six"... | [
524,
4
] | [
547,
37
] | python | en | ['en', 'error', 'th'] | False |
MakeMigrationsTests.test_makemigrations_with_custom_name | (self) |
Makes sure that makemigrations generate a custom migration.
|
Makes sure that makemigrations generate a custom migration.
| def test_makemigrations_with_custom_name(self):
"""
Makes sure that makemigrations generate a custom migration.
"""
def cmd(migration_count, migration_name, *args):
with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
try:
... | [
"def",
"test_makemigrations_with_custom_name",
"(",
"self",
")",
":",
"def",
"cmd",
"(",
"migration_count",
",",
"migration_name",
",",
"*",
"args",
")",
":",
"with",
"override_settings",
"(",
"MIGRATION_MODULES",
"=",
"{",
"\"migrations\"",
":",
"self",
".",
"m... | [
550,
4
] | [
578,
49
] | python | en | ['en', 'error', 'th'] | False |
Noise.generate | (self, x, **kwargs) |
Generate symbolic graph for adversarial examples and return.
:param x: The model's symbolic inputs.
:param kwargs: See `parse_params`
|
Generate symbolic graph for adversarial examples and return. | def generate(self, x, **kwargs):
"""
Generate symbolic graph for adversarial examples and return.
:param x: The model's symbolic inputs.
:param kwargs: See `parse_params`
"""
# Parse and save attack-specific parameters
assert self.parse_params(**kwargs)
... | [
"def",
"generate",
"(",
"self",
",",
"x",
",",
"*",
"*",
"kwargs",
")",
":",
"# Parse and save attack-specific parameters",
"assert",
"self",
".",
"parse_params",
"(",
"*",
"*",
"kwargs",
")",
"if",
"self",
".",
"ord",
"!=",
"np",
".",
"inf",
":",
"raise... | [
36,
4
] | [
54,
20
] | python | en | ['en', 'error', 'th'] | False |
Noise.parse_params | (self, eps=0.3, ord=np.inf, clip_min=None, clip_max=None, **kwargs) |
Take in a dictionary of parameters and applies attack-specific checks
before saving them as attributes.
Attack-specific parameters:
:param eps: (optional float) maximum distortion of adversarial example
compared to original input
:param ord: (optional) Orde... |
Take in a dictionary of parameters and applies attack-specific checks
before saving them as attributes. | def parse_params(self, eps=0.3, ord=np.inf, clip_min=None, clip_max=None, **kwargs):
"""
Take in a dictionary of parameters and applies attack-specific checks
before saving them as attributes.
Attack-specific parameters:
:param eps: (optional float) maximum distortion of advers... | [
"def",
"parse_params",
"(",
"self",
",",
"eps",
"=",
"0.3",
",",
"ord",
"=",
"np",
".",
"inf",
",",
"clip_min",
"=",
"None",
",",
"clip_max",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# Save attack-specific parameters",
"self",
".",
"eps",
"=",
... | [
56,
4
] | [
85,
19
] | python | en | ['en', 'error', 'th'] | False |
get_files_to_package | (input_files) | Find files to be added to the distribution.
input_files: list of pairs (package_path, real_path)
| Find files to be added to the distribution. | def get_files_to_package(input_files):
"""Find files to be added to the distribution.
input_files: list of pairs (package_path, real_path)
"""
files = {}
for package_path, real_path in input_files:
files[package_path] = real_path
return files | [
"def",
"get_files_to_package",
"(",
"input_files",
")",
":",
"files",
"=",
"{",
"}",
"for",
"package_path",
",",
"real_path",
"in",
"input_files",
":",
"files",
"[",
"package_path",
"]",
"=",
"real_path",
"return",
"files"
] | [
179,
0
] | [
187,
16
] | python | en | ['en', 'en', 'en'] | True |
WheelMaker.add_string | (self, filename, contents) | Add given 'contents' as filename to the distribution. | Add given 'contents' as filename to the distribution. | def add_string(self, filename, contents):
"""Add given 'contents' as filename to the distribution."""
if sys.version_info[0] > 2 and isinstance(contents, str):
contents = contents.encode('utf-8', 'surrogateescape')
self._zipfile.writestr(filename, contents)
hash = hashlib.sha... | [
"def",
"add_string",
"(",
"self",
",",
"filename",
",",
"contents",
")",
":",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
">",
"2",
"and",
"isinstance",
"(",
"contents",
",",
"str",
")",
":",
"contents",
"=",
"contents",
".",
"encode",
"(",
"'ut... | [
82,
4
] | [
90,
42
] | python | en | ['en', 'en', 'en'] | True |
WheelMaker.add_file | (self, package_filename, real_filename) | Add given file to the distribution. | Add given file to the distribution. | def add_file(self, package_filename, real_filename):
"""Add given file to the distribution."""
def arcname_from(name):
# Always use unix path separators.
normalized_arcname = name.replace(os.path.sep, '/')
for prefix in self._strip_path_prefixes:
if n... | [
"def",
"add_file",
"(",
"self",
",",
"package_filename",
",",
"real_filename",
")",
":",
"def",
"arcname_from",
"(",
"name",
")",
":",
"# Always use unix path separators.",
"normalized_arcname",
"=",
"name",
".",
"replace",
"(",
"os",
".",
"path",
".",
"sep",
... | [
92,
4
] | [
117,
72
] | python | en | ['en', 'en', 'en'] | True |
WheelMaker.add_wheelfile | (self) | Write WHEEL file to the distribution | Write WHEEL file to the distribution | def add_wheelfile(self):
"""Write WHEEL file to the distribution"""
# TODO(pstradomski): Support non-purelib wheels.
wheel_contents = """\
Wheel-Version: 1.0
Generator: bazel-wheelmaker 1.0
Root-Is-Purelib: true
"""
for tag in self.disttags():
wheel_contents += "Tag: %s\n" % ... | [
"def",
"add_wheelfile",
"(",
"self",
")",
":",
"# TODO(pstradomski): Support non-purelib wheels.",
"wheel_contents",
"=",
"\"\"\"\\\nWheel-Version: 1.0\nGenerator: bazel-wheelmaker 1.0\nRoot-Is-Purelib: true\n\"\"\"",
"for",
"tag",
"in",
"self",
".",
"disttags",
"(",
")",
":",
... | [
119,
4
] | [
129,
68
] | python | en | ['en', 'en', 'en'] | True |
WheelMaker.add_metadata | (self, extra_headers, description, classifiers, python_requires,
requires, extra_requires) | Write METADATA file to the distribution. | Write METADATA file to the distribution. | def add_metadata(self, extra_headers, description, classifiers, python_requires,
requires, extra_requires):
"""Write METADATA file to the distribution."""
# https://www.python.org/dev/peps/pep-0566/
# https://packaging.python.org/specifications/core-metadata/
metadat... | [
"def",
"add_metadata",
"(",
"self",
",",
"extra_headers",
",",
"description",
",",
"classifiers",
",",
"python_requires",
",",
"requires",
",",
"extra_requires",
")",
":",
"# https://www.python.org/dev/peps/pep-0566/",
"# https://packaging.python.org/specifications/core-metadat... | [
131,
4
] | [
160,
65
] | python | en | ['en', 'lt', 'en'] | True |
WheelMaker.add_recordfile | (self) | Write RECORD file to the distribution. | Write RECORD file to the distribution. | def add_recordfile(self):
"""Write RECORD file to the distribution."""
record_path = self.distinfo_path('RECORD')
entries = self._record + [(record_path, b'', b'')]
entries.sort()
contents = b''
for filename, digest, size in entries:
if sys.version_info[0] > 2... | [
"def",
"add_recordfile",
"(",
"self",
")",
":",
"record_path",
"=",
"self",
".",
"distinfo_path",
"(",
"'RECORD'",
")",
"entries",
"=",
"self",
".",
"_record",
"+",
"[",
"(",
"record_path",
",",
"b''",
",",
"b''",
")",
"]",
"entries",
".",
"sort",
"(",... | [
162,
4
] | [
172,
46
] | python | en | ['en', 'en', 'en'] | True |
create_tensorflow_neuropod | (
neuropod_path,
input_spec,
output_spec,
node_name_mapping,
frozen_graph_path=None,
graph_def=None,
init_op_names=[],
**kwargs
) |
Packages a TensorFlow model as a neuropod package.
{common_doc_pre}
:param node_name_mapping: Mapping from a neuropod input/output name to a node in the graph. The `:0` is
optional.
!!! note ""
***Examp... |
Packages a TensorFlow model as a neuropod package. | def create_tensorflow_neuropod(
neuropod_path,
input_spec,
output_spec,
node_name_mapping,
frozen_graph_path=None,
graph_def=None,
init_op_names=[],
**kwargs
):
"""
Packages a TensorFlow model as a neuropod package.
{common_doc_pre}
:param node_name_mapping: Mapping f... | [
"def",
"create_tensorflow_neuropod",
"(",
"neuropod_path",
",",
"input_spec",
",",
"output_spec",
",",
"node_name_mapping",
",",
"frozen_graph_path",
"=",
"None",
",",
"graph_def",
"=",
"None",
",",
"init_op_names",
"=",
"[",
"]",
",",
"*",
"*",
"kwargs",
")",
... | [
23,
0
] | [
110,
9
] | python | en | ['en', 'error', 'th'] | False |
SearchScope.create | (
cls,
find_links, # type: List[str]
index_urls, # type: List[str]
) |
Create a SearchScope object after normalizing the `find_links`.
|
Create a SearchScope object after normalizing the `find_links`.
| def create(
cls,
find_links, # type: List[str]
index_urls, # type: List[str]
):
# type: (...) -> SearchScope
"""
Create a SearchScope object after normalizing the `find_links`.
"""
# Build find_links. If an argument starts with ~, it may be
#... | [
"def",
"create",
"(",
"cls",
",",
"find_links",
",",
"# type: List[str]",
"index_urls",
",",
"# type: List[str]",
")",
":",
"# type: (...) -> SearchScope",
"# Build find_links. If an argument starts with ~, it may be",
"# a local file relative to a home directory. So try normalizing",
... | [
27,
4
] | [
65,
9
] | python | en | ['en', 'error', 'th'] | False |
SearchScope.get_index_urls_locations | (self, project_name) | Returns the locations found via self.index_urls
Checks the url_name on the main (first in the list) index and
use this url_name to produce all locations
| Returns the locations found via self.index_urls | def get_index_urls_locations(self, project_name):
# type: (str) -> List[str]
"""Returns the locations found via self.index_urls
Checks the url_name on the main (first in the list) index and
use this url_name to produce all locations
"""
def mkurl_pypi_url(url):
... | [
"def",
"get_index_urls_locations",
"(",
"self",
",",
"project_name",
")",
":",
"# type: (str) -> List[str]",
"def",
"mkurl_pypi_url",
"(",
"url",
")",
":",
"# type: (str) -> str",
"loc",
"=",
"posixpath",
".",
"join",
"(",
"url",
",",
"urllib_parse",
".",
"quote",... | [
110,
4
] | [
132,
63
] | python | en | ['en', 'la', 'en'] | True |
Reservation._save_dt | (self, attr, dt) |
Any DateTime object is converted to UTC time zone aware DateTime
before save
If there is no time zone on the object, resource's time zone will
be assumed through its unit's time zone
|
Any DateTime object is converted to UTC time zone aware DateTime
before save | def _save_dt(self, attr, dt):
"""
Any DateTime object is converted to UTC time zone aware DateTime
before save
If there is no time zone on the object, resource's time zone will
be assumed through its unit's time zone
"""
save_dt(self, attr, dt, self.resource.unit... | [
"def",
"_save_dt",
"(",
"self",
",",
"attr",
",",
"dt",
")",
":",
"save_dt",
"(",
"self",
",",
"attr",
",",
"dt",
",",
"self",
".",
"resource",
".",
"unit",
".",
"time_zone",
")"
] | [
164,
4
] | [
172,
61
] | python | en | ['en', 'error', 'th'] | False |
Reservation.end_tz | (self, dt) |
Any DateTime object is converted to UTC time zone aware DateTime
before save
If there is no time zone on the object, resource's time zone will
be assumed through its unit's time zone
|
Any DateTime object is converted to UTC time zone aware DateTime
before save | def end_tz(self, dt):
"""
Any DateTime object is converted to UTC time zone aware DateTime
before save
If there is no time zone on the object, resource's time zone will
be assumed through its unit's time zone
"""
self._save_dt('end', dt) | [
"def",
"end_tz",
"(",
"self",
",",
"dt",
")",
":",
"self",
".",
"_save_dt",
"(",
"'end'",
",",
"dt",
")"
] | [
193,
4
] | [
201,
32
] | python | en | ['en', 'error', 'th'] | False |
Reservation.clean | (self, **kwargs) |
Check restrictions that are common to all reservations.
If this reservation isn't yet saved and it will modify an existing reservation,
the original reservation need to be provided in kwargs as 'original_reservation', so
that it can be excluded when checking if the resource is availabl... |
Check restrictions that are common to all reservations. | def clean(self, **kwargs):
"""
Check restrictions that are common to all reservations.
If this reservation isn't yet saved and it will modify an existing reservation,
the original reservation need to be provided in kwargs as 'original_reservation', so
that it can be excluded whe... | [
"def",
"clean",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"'user'",
"in",
"kwargs",
":",
"user",
"=",
"kwargs",
"[",
"'user'",
"]",
"else",
":",
"user",
"=",
"self",
".",
"user",
"user_is_admin",
"=",
"user",
"and",
"self",
".",
"resour... | [
350,
4
] | [
410,
82
] | python | en | ['en', 'error', 'th'] | False |
Reservation.send_reservation_mail | (self, notification_type, user=None, attachments=None) |
Stuff common to all reservation related mails.
If user isn't given use self.user.
|
Stuff common to all reservation related mails. | def send_reservation_mail(self, notification_type, user=None, attachments=None):
"""
Stuff common to all reservation related mails.
If user isn't given use self.user.
"""
try:
notification_template = NotificationTemplate.objects.get(type=notification_type)
ex... | [
"def",
"send_reservation_mail",
"(",
"self",
",",
"notification_type",
",",
"user",
"=",
"None",
",",
"attachments",
"=",
"None",
")",
":",
"try",
":",
"notification_template",
"=",
"NotificationTemplate",
".",
"objects",
".",
"get",
"(",
"type",
"=",
"notific... | [
491,
4
] | [
527,
9
] | python | en | ['en', 'error', 'th'] | False |
decoder | (conv_func) |
Convert bytestrings from Python's sqlite3 interface to a regular string.
|
Convert bytestrings from Python's sqlite3 interface to a regular string.
| def decoder(conv_func):
"""
Convert bytestrings from Python's sqlite3 interface to a regular string.
"""
return lambda s: conv_func(s.decode()) | [
"def",
"decoder",
"(",
"conv_func",
")",
":",
"return",
"lambda",
"s",
":",
"conv_func",
"(",
"s",
".",
"decode",
"(",
")",
")"
] | [
34,
0
] | [
38,
42
] | python | en | ['en', 'error', 'th'] | False |
none_guard | (func) |
Decorator that returns None if any of the arguments to the decorated
function are None. Many SQL functions return NULL if any of their arguments
are NULL. This decorator simplifies the implementation of this for the
custom functions registered below.
|
Decorator that returns None if any of the arguments to the decorated
function are None. Many SQL functions return NULL if any of their arguments
are NULL. This decorator simplifies the implementation of this for the
custom functions registered below.
| def none_guard(func):
"""
Decorator that returns None if any of the arguments to the decorated
function are None. Many SQL functions return NULL if any of their arguments
are NULL. This decorator simplifies the implementation of this for the
custom functions registered below.
"""
@functools.... | [
"def",
"none_guard",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"None",
"if",
"None",
"in",
"args",
"else",
"func",
"(",
"*",
"args",
"... | [
41,
0
] | [
51,
18
] | python | en | ['en', 'error', 'th'] | False |
list_aggregate | (function) |
Return an aggregate class that accumulates values in a list and applies
the provided function to the data.
|
Return an aggregate class that accumulates values in a list and applies
the provided function to the data.
| def list_aggregate(function):
"""
Return an aggregate class that accumulates values in a list and applies
the provided function to the data.
"""
return type('ListAggregate', (list,), {'finalize': function, 'step': list.append}) | [
"def",
"list_aggregate",
"(",
"function",
")",
":",
"return",
"type",
"(",
"'ListAggregate'",
",",
"(",
"list",
",",
")",
",",
"{",
"'finalize'",
":",
"function",
",",
"'step'",
":",
"list",
".",
"append",
"}",
")"
] | [
54,
0
] | [
59,
86
] | python | en | ['en', 'error', 'th'] | False |
_sqlite_format_dtdelta | (conn, lhs, rhs) |
LHS and RHS can be either:
- An integer number of microseconds
- A string representing a datetime
|
LHS and RHS can be either:
- An integer number of microseconds
- A string representing a datetime
| def _sqlite_format_dtdelta(conn, lhs, rhs):
"""
LHS and RHS can be either:
- An integer number of microseconds
- A string representing a datetime
"""
try:
real_lhs = datetime.timedelta(0, 0, lhs) if isinstance(lhs, int) else backend_utils.typecast_timestamp(lhs)
real_rhs = dateti... | [
"def",
"_sqlite_format_dtdelta",
"(",
"conn",
",",
"lhs",
",",
"rhs",
")",
":",
"try",
":",
"real_lhs",
"=",
"datetime",
".",
"timedelta",
"(",
"0",
",",
"0",
",",
"lhs",
")",
"if",
"isinstance",
"(",
"lhs",
",",
"int",
")",
"else",
"backend_utils",
... | [
525,
0
] | [
542,
19
] | python | en | ['en', 'error', 'th'] | False |
DatabaseWrapper.check_constraints | (self, table_names=None) |
Check each table name in `table_names` for rows with invalid foreign
key references. This method is intended to be used in conjunction with
`disable_constraint_checking()` and `enable_constraint_checking()`, to
determine if rows with invalid references were entered while constraint
... |
Check each table name in `table_names` for rows with invalid foreign
key references. This method is intended to be used in conjunction with
`disable_constraint_checking()` and `enable_constraint_checking()`, to
determine if rows with invalid references were entered while constraint
... | def check_constraints(self, table_names=None):
"""
Check each table name in `table_names` for rows with invalid foreign
key references. This method is intended to be used in conjunction with
`disable_constraint_checking()` and `enable_constraint_checking()`, to
determine if rows ... | [
"def",
"check_constraints",
"(",
"self",
",",
"table_names",
"=",
"None",
")",
":",
"if",
"self",
".",
"features",
".",
"supports_pragma_foreign_key_check",
":",
"with",
"self",
".",
"cursor",
"(",
")",
"as",
"cursor",
":",
"if",
"table_names",
"is",
"None",... | [
295,
4
] | [
364,
29
] | python | en | ['en', 'error', 'th'] | False |
DatabaseWrapper._start_transaction_under_autocommit | (self) |
Start a transaction explicitly in autocommit mode.
Staying in autocommit mode works around a bug of sqlite3 that breaks
savepoints when autocommit is disabled.
|
Start a transaction explicitly in autocommit mode. | def _start_transaction_under_autocommit(self):
"""
Start a transaction explicitly in autocommit mode.
Staying in autocommit mode works around a bug of sqlite3 that breaks
savepoints when autocommit is disabled.
"""
self.cursor().execute("BEGIN") | [
"def",
"_start_transaction_under_autocommit",
"(",
"self",
")",
":",
"self",
".",
"cursor",
"(",
")",
".",
"execute",
"(",
"\"BEGIN\"",
")"
] | [
369,
4
] | [
376,
38
] | python | en | ['en', 'error', 'th'] | False |
dispatch_hook | (key, hooks, hook_data, **kwargs) | Dispatches a hook dictionary on a given piece of data. | Dispatches a hook dictionary on a given piece of data. | def dispatch_hook(key, hooks, hook_data, **kwargs):
"""Dispatches a hook dictionary on a given piece of data."""
hooks = hooks or {}
hooks = hooks.get(key)
if hooks:
if hasattr(hooks, '__call__'):
hooks = [hooks]
for hook in hooks:
_hook_data = hook(hook_data, **k... | [
"def",
"dispatch_hook",
"(",
"key",
",",
"hooks",
",",
"hook_data",
",",
"*",
"*",
"kwargs",
")",
":",
"hooks",
"=",
"hooks",
"or",
"{",
"}",
"hooks",
"=",
"hooks",
".",
"get",
"(",
"key",
")",
"if",
"hooks",
":",
"if",
"hasattr",
"(",
"hooks",
"... | [
22,
0
] | [
33,
20
] | python | en | ['en', 'en', 'en'] | True |
PackageIndex.__init__ | (self, url=None) |
Initialise an instance.
:param url: The URL of the index. If not specified, the URL for PyPI is
used.
|
Initialise an instance. | def __init__(self, url=None):
"""
Initialise an instance.
:param url: The URL of the index. If not specified, the URL for PyPI is
used.
"""
self.url = url or DEFAULT_INDEX
self.read_configuration()
scheme, netloc, path, params, query, frag = u... | [
"def",
"__init__",
"(",
"self",
",",
"url",
"=",
"None",
")",
":",
"self",
".",
"url",
"=",
"url",
"or",
"DEFAULT_INDEX",
"self",
".",
"read_configuration",
"(",
")",
"scheme",
",",
"netloc",
",",
"path",
",",
"params",
",",
"query",
",",
"frag",
"="... | [
35,
4
] | [
62,
24
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex._get_pypirc_command | (self) |
Get the distutils command for interacting with PyPI configurations.
:return: the command.
|
Get the distutils command for interacting with PyPI configurations.
:return: the command.
| def _get_pypirc_command(self):
"""
Get the distutils command for interacting with PyPI configurations.
:return: the command.
"""
from distutils.core import Distribution
from distutils.config import PyPIRCCommand
d = Distribution()
return PyPIRCCommand(d) | [
"def",
"_get_pypirc_command",
"(",
"self",
")",
":",
"from",
"distutils",
".",
"core",
"import",
"Distribution",
"from",
"distutils",
".",
"config",
"import",
"PyPIRCCommand",
"d",
"=",
"Distribution",
"(",
")",
"return",
"PyPIRCCommand",
"(",
"d",
")"
] | [
64,
4
] | [
72,
31
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.read_configuration | (self) |
Read the PyPI access configuration as supported by distutils, getting
PyPI to do the actual work. This populates ``username``, ``password``,
``realm`` and ``url`` attributes from the configuration.
|
Read the PyPI access configuration as supported by distutils, getting
PyPI to do the actual work. This populates ``username``, ``password``,
``realm`` and ``url`` attributes from the configuration.
| def read_configuration(self):
"""
Read the PyPI access configuration as supported by distutils, getting
PyPI to do the actual work. This populates ``username``, ``password``,
``realm`` and ``url`` attributes from the configuration.
"""
# get distutils to do the work
... | [
"def",
"read_configuration",
"(",
"self",
")",
":",
"# get distutils to do the work",
"c",
"=",
"self",
".",
"_get_pypirc_command",
"(",
")",
"c",
".",
"repository",
"=",
"self",
".",
"url",
"cfg",
"=",
"c",
".",
"_read_pypirc",
"(",
")",
"self",
".",
"use... | [
74,
4
] | [
87,
50
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.save_configuration | (self) |
Save the PyPI access configuration. You must have set ``username`` and
``password`` attributes before calling this method.
Again, distutils is used to do the actual work.
|
Save the PyPI access configuration. You must have set ``username`` and
``password`` attributes before calling this method. | def save_configuration(self):
"""
Save the PyPI access configuration. You must have set ``username`` and
``password`` attributes before calling this method.
Again, distutils is used to do the actual work.
"""
self.check_credentials()
# get distutils to do the wor... | [
"def",
"save_configuration",
"(",
"self",
")",
":",
"self",
".",
"check_credentials",
"(",
")",
"# get distutils to do the work",
"c",
"=",
"self",
".",
"_get_pypirc_command",
"(",
")",
"c",
".",
"_store_pypirc",
"(",
"self",
".",
"username",
",",
"self",
".",... | [
89,
4
] | [
99,
53
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.check_credentials | (self) |
Check that ``username`` and ``password`` have been set, and raise an
exception if not.
|
Check that ``username`` and ``password`` have been set, and raise an
exception if not.
| def check_credentials(self):
"""
Check that ``username`` and ``password`` have been set, and raise an
exception if not.
"""
if self.username is None or self.password is None:
raise DistlibException('username and password must be set')
pm = HTTPPasswordMgr()
... | [
"def",
"check_credentials",
"(",
"self",
")",
":",
"if",
"self",
".",
"username",
"is",
"None",
"or",
"self",
".",
"password",
"is",
"None",
":",
"raise",
"DistlibException",
"(",
"'username and password must be set'",
")",
"pm",
"=",
"HTTPPasswordMgr",
"(",
"... | [
101,
4
] | [
111,
56
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.register | (self, metadata) |
Register a distribution on PyPI, using the provided metadata.
:param metadata: A :class:`Metadata` instance defining at least a name
and version number for the distribution to be
registered.
:return: The HTTP response received from PyPI upon su... |
Register a distribution on PyPI, using the provided metadata. | def register(self, metadata):
"""
Register a distribution on PyPI, using the provided metadata.
:param metadata: A :class:`Metadata` instance defining at least a name
and version number for the distribution to be
registered.
:return: The... | [
"def",
"register",
"(",
"self",
",",
"metadata",
")",
":",
"self",
".",
"check_credentials",
"(",
")",
"metadata",
".",
"validate",
"(",
")",
"d",
"=",
"metadata",
".",
"todict",
"(",
")",
"d",
"[",
"':action'",
"]",
"=",
"'verify'",
"request",
"=",
... | [
113,
4
] | [
131,
41
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex._reader | (self, name, stream, outbuf) |
Thread runner for reading lines of from a subprocess into a buffer.
:param name: The logical name of the stream (used for logging only).
:param stream: The stream to read from. This will typically a pipe
connected to the output stream of a subprocess.
:param outb... |
Thread runner for reading lines of from a subprocess into a buffer. | def _reader(self, name, stream, outbuf):
"""
Thread runner for reading lines of from a subprocess into a buffer.
:param name: The logical name of the stream (used for logging only).
:param stream: The stream to read from. This will typically a pipe
connected to th... | [
"def",
"_reader",
"(",
"self",
",",
"name",
",",
"stream",
",",
"outbuf",
")",
":",
"while",
"True",
":",
"s",
"=",
"stream",
".",
"readline",
"(",
")",
"if",
"not",
"s",
":",
"break",
"s",
"=",
"s",
".",
"decode",
"(",
"'utf-8'",
")",
".",
"rs... | [
133,
4
] | [
149,
22
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.get_sign_command | (self, filename, signer, sign_password,
keystore=None) |
Return a suitable command for signing a file.
:param filename: The pathname to the file to be signed.
:param signer: The identifier of the signer of the file.
:param sign_password: The passphrase for the signer's
private key used for signing.
:para... |
Return a suitable command for signing a file. | def get_sign_command(self, filename, signer, sign_password,
keystore=None):
"""
Return a suitable command for signing a file.
:param filename: The pathname to the file to be signed.
:param signer: The identifier of the signer of the file.
:param sign_pas... | [
"def",
"get_sign_command",
"(",
"self",
",",
"filename",
",",
"signer",
",",
"sign_password",
",",
"keystore",
"=",
"None",
")",
":",
"cmd",
"=",
"[",
"self",
".",
"gpg",
",",
"'--status-fd'",
",",
"'2'",
",",
"'--no-tty'",
"]",
"if",
"keystore",
"is",
... | [
151,
4
] | [
178,
22
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.run_command | (self, cmd, input_data=None) |
Run a command in a child process , passing it any input data specified.
:param cmd: The command to run.
:param input_data: If specified, this must be a byte string containing
data to be sent to the child process.
:return: A tuple consisting of the subprocess'... |
Run a command in a child process , passing it any input data specified. | def run_command(self, cmd, input_data=None):
"""
Run a command in a child process , passing it any input data specified.
:param cmd: The command to run.
:param input_data: If specified, this must be a byte string containing
data to be sent to the child process... | [
"def",
"run_command",
"(",
"self",
",",
"cmd",
",",
"input_data",
"=",
"None",
")",
":",
"kwargs",
"=",
"{",
"'stdout'",
":",
"subprocess",
".",
"PIPE",
",",
"'stderr'",
":",
"subprocess",
".",
"PIPE",
",",
"}",
"if",
"input_data",
"is",
"not",
"None",... | [
180,
4
] | [
213,
43
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.sign_file | (self, filename, signer, sign_password, keystore=None) |
Sign a file.
:param filename: The pathname to the file to be signed.
:param signer: The identifier of the signer of the file.
:param sign_password: The passphrase for the signer's
private key used for signing.
:param keystore: The path to a directo... |
Sign a file. | def sign_file(self, filename, signer, sign_password, keystore=None):
"""
Sign a file.
:param filename: The pathname to the file to be signed.
:param signer: The identifier of the signer of the file.
:param sign_password: The passphrase for the signer's
... | [
"def",
"sign_file",
"(",
"self",
",",
"filename",
",",
"signer",
",",
"sign_password",
",",
"keystore",
"=",
"None",
")",
":",
"cmd",
",",
"sig_file",
"=",
"self",
".",
"get_sign_command",
"(",
"filename",
",",
"signer",
",",
"sign_password",
",",
"keystor... | [
215,
4
] | [
236,
23
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.upload_file | (self, metadata, filename, signer=None, sign_password=None,
filetype='sdist', pyversion='source', keystore=None) |
Upload a release file to the index.
:param metadata: A :class:`Metadata` instance defining at least a name
and version number for the file to be uploaded.
:param filename: The pathname of the file to be uploaded.
:param signer: The identifier of the signer of t... |
Upload a release file to the index. | def upload_file(self, metadata, filename, signer=None, sign_password=None,
filetype='sdist', pyversion='source', keystore=None):
"""
Upload a release file to the index.
:param metadata: A :class:`Metadata` instance defining at least a name
and versio... | [
"def",
"upload_file",
"(",
"self",
",",
"metadata",
",",
"filename",
",",
"signer",
"=",
"None",
",",
"sign_password",
"=",
"None",
",",
"filetype",
"=",
"'sdist'",
",",
"pyversion",
"=",
"'source'",
",",
"keystore",
"=",
"None",
")",
":",
"self",
".",
... | [
238,
4
] | [
293,
41
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.upload_documentation | (self, metadata, doc_dir) |
Upload documentation to the index.
:param metadata: A :class:`Metadata` instance defining at least a name
and version number for the documentation to be
uploaded.
:param doc_dir: The pathname of the directory which contains the
... |
Upload documentation to the index. | def upload_documentation(self, metadata, doc_dir):
"""
Upload documentation to the index.
:param metadata: A :class:`Metadata` instance defining at least a name
and version number for the documentation to be
uploaded.
:param doc_dir: The... | [
"def",
"upload_documentation",
"(",
"self",
",",
"metadata",
",",
"doc_dir",
")",
":",
"self",
".",
"check_credentials",
"(",
")",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"doc_dir",
")",
":",
"raise",
"DistlibException",
"(",
"'not a directory: %r... | [
295,
4
] | [
321,
41
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.get_verify_command | (self, signature_filename, data_filename,
keystore=None) |
Return a suitable command for verifying a file.
:param signature_filename: The pathname to the file containing the
signature.
:param data_filename: The pathname to the file containing the
signed data.
:param keystore: The... |
Return a suitable command for verifying a file. | def get_verify_command(self, signature_filename, data_filename,
keystore=None):
"""
Return a suitable command for verifying a file.
:param signature_filename: The pathname to the file containing the
signature.
:param data_fil... | [
"def",
"get_verify_command",
"(",
"self",
",",
"signature_filename",
",",
"data_filename",
",",
"keystore",
"=",
"None",
")",
":",
"cmd",
"=",
"[",
"self",
".",
"gpg",
",",
"'--status-fd'",
",",
"'2'",
",",
"'--no-tty'",
"]",
"if",
"keystore",
"is",
"None"... | [
323,
4
] | [
345,
18
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.verify_signature | (self, signature_filename, data_filename,
keystore=None) |
Verify a signature for a file.
:param signature_filename: The pathname to the file containing the
signature.
:param data_filename: The pathname to the file containing the
signed data.
:param keystore: The path to a direct... |
Verify a signature for a file. | def verify_signature(self, signature_filename, data_filename,
keystore=None):
"""
Verify a signature for a file.
:param signature_filename: The pathname to the file containing the
signature.
:param data_filename: The pathname t... | [
"def",
"verify_signature",
"(",
"self",
",",
"signature_filename",
",",
"data_filename",
",",
"keystore",
"=",
"None",
")",
":",
"if",
"not",
"self",
".",
"gpg",
":",
"raise",
"DistlibException",
"(",
"'verification unavailable because gpg '",
"'unavailable'",
")",
... | [
347,
4
] | [
370,
22
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.download_file | (self, url, destfile, digest=None, reporthook=None) |
This is a convenience method for downloading a file from an URL.
Normally, this will be a file from the index, though currently
no check is made for this (i.e. a file can be downloaded from
anywhere).
The method is just like the :func:`urlretrieve` function in the
stand... |
This is a convenience method for downloading a file from an URL.
Normally, this will be a file from the index, though currently
no check is made for this (i.e. a file can be downloaded from
anywhere). | def download_file(self, url, destfile, digest=None, reporthook=None):
"""
This is a convenience method for downloading a file from an URL.
Normally, this will be a file from the index, though currently
no check is made for this (i.e. a file can be downloaded from
anywhere).
... | [
"def",
"download_file",
"(",
"self",
",",
"url",
",",
"destfile",
",",
"digest",
"=",
"None",
",",
"reporthook",
"=",
"None",
")",
":",
"if",
"digest",
"is",
"None",
":",
"digester",
"=",
"None",
"logger",
".",
"debug",
"(",
"'No digest specified'",
")",... | [
372,
4
] | [
447,
55
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.send_request | (self, req) |
Send a standard library :class:`Request` to PyPI and return its
response.
:param req: The request to send.
:return: The HTTP response from PyPI (a standard library HTTPResponse).
|
Send a standard library :class:`Request` to PyPI and return its
response. | def send_request(self, req):
"""
Send a standard library :class:`Request` to PyPI and return its
response.
:param req: The request to send.
:return: The HTTP response from PyPI (a standard library HTTPResponse).
"""
handlers = []
if self.password_handler:... | [
"def",
"send_request",
"(",
"self",
",",
"req",
")",
":",
"handlers",
"=",
"[",
"]",
"if",
"self",
".",
"password_handler",
":",
"handlers",
".",
"append",
"(",
"self",
".",
"password_handler",
")",
"if",
"self",
".",
"ssl_verifier",
":",
"handlers",
"."... | [
449,
4
] | [
463,
31
] | python | en | ['en', 'error', 'th'] | False |
PackageIndex.encode_request | (self, fields, files) |
Encode fields and files for posting to an HTTP server.
:param fields: The fields to send as a list of (fieldname, value)
tuples.
:param files: The files to send as a list of (fieldname, filename,
file_bytes) tuple.
|
Encode fields and files for posting to an HTTP server. | def encode_request(self, fields, files):
"""
Encode fields and files for posting to an HTTP server.
:param fields: The fields to send as a list of (fieldname, value)
tuples.
:param files: The files to send as a list of (fieldname, filename,
f... | [
"def",
"encode_request",
"(",
"self",
",",
"fields",
",",
"files",
")",
":",
"# Adapted from packaging, which in turn was adapted from",
"# http://code.activestate.com/recipes/146306",
"parts",
"=",
"[",
"]",
"boundary",
"=",
"self",
".",
"boundary",
"for",
"k",
",",
... | [
465,
4
] | [
506,
47
] | python | en | ['en', 'error', 'th'] | False |
AutocompleteJsonView.get | (self, request, *args, **kwargs) |
Return a JsonResponse with search results of the form:
{
results: [{id: "123" text: "foo"}],
pagination: {more: true}
}
|
Return a JsonResponse with search results of the form:
{
results: [{id: "123" text: "foo"}],
pagination: {more: true}
}
| def get(self, request, *args, **kwargs):
"""
Return a JsonResponse with search results of the form:
{
results: [{id: "123" text: "foo"}],
pagination: {more: true}
}
"""
if not self.model_admin.get_search_fields(request):
raise Http404(
... | [
"def",
"get",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"model_admin",
".",
"get_search_fields",
"(",
"request",
")",
":",
"raise",
"Http404",
"(",
"'%s must have search_fields for the autocom... | [
9,
4
] | [
34,
10
] | python | en | ['en', 'error', 'th'] | False |
AutocompleteJsonView.get_paginator | (self, *args, **kwargs) | Use the ModelAdmin's paginator. | Use the ModelAdmin's paginator. | def get_paginator(self, *args, **kwargs):
"""Use the ModelAdmin's paginator."""
return self.model_admin.get_paginator(self.request, *args, **kwargs) | [
"def",
"get_paginator",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"model_admin",
".",
"get_paginator",
"(",
"self",
".",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | [
36,
4
] | [
38,
76
] | python | en | ['en', 'en', 'en'] | True |
AutocompleteJsonView.get_queryset | (self) | Return queryset based on ModelAdmin.get_search_results(). | Return queryset based on ModelAdmin.get_search_results(). | def get_queryset(self):
"""Return queryset based on ModelAdmin.get_search_results()."""
qs = self.model_admin.get_queryset(self.request)
qs, search_use_distinct = self.model_admin.get_search_results(self.request, qs, self.term)
if search_use_distinct:
qs = qs.distinct()
... | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"qs",
"=",
"self",
".",
"model_admin",
".",
"get_queryset",
"(",
"self",
".",
"request",
")",
"qs",
",",
"search_use_distinct",
"=",
"self",
".",
"model_admin",
".",
"get_search_results",
"(",
"self",
".",
"req... | [
40,
4
] | [
46,
17
] | python | en | ['en', 'en', 'en'] | True |
AutocompleteJsonView.has_perm | (self, request, obj=None) | Check if user has permission to access the related model. | Check if user has permission to access the related model. | def has_perm(self, request, obj=None):
"""Check if user has permission to access the related model."""
return self.model_admin.has_view_permission(request, obj=obj) | [
"def",
"has_perm",
"(",
"self",
",",
"request",
",",
"obj",
"=",
"None",
")",
":",
"return",
"self",
".",
"model_admin",
".",
"has_view_permission",
"(",
"request",
",",
"obj",
"=",
"obj",
")"
] | [
48,
4
] | [
50,
69
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.get_config_template | () | Keys and value types what Bambora requires from environment | Keys and value types what Bambora requires from environment | def get_config_template() -> dict:
"""Keys and value types what Bambora requires from environment"""
return {
RESPA_PAYMENTS_BAMBORA_API_URL: (str, 'https://payform.bambora.com/pbwapi'),
RESPA_PAYMENTS_BAMBORA_API_KEY: str,
RESPA_PAYMENTS_BAMBORA_API_SECRET: str,
... | [
"def",
"get_config_template",
"(",
")",
"->",
"dict",
":",
"return",
"{",
"RESPA_PAYMENTS_BAMBORA_API_URL",
":",
"(",
"str",
",",
"'https://payform.bambora.com/pbwapi'",
")",
",",
"RESPA_PAYMENTS_BAMBORA_API_KEY",
":",
"str",
",",
"RESPA_PAYMENTS_BAMBORA_API_SECRET",
":",... | [
41,
4
] | [
49,
9
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.initiate_payment | (self, order) | Initiate payment by constructing the payload with necessary items | Initiate payment by constructing the payload with necessary items | def initiate_payment(self, order) -> str:
"""Initiate payment by constructing the payload with necessary items"""
token_valid_days = self.config.get(RESPA_PAYMENTS_BAMBORA_TOKEN_VALID_DAYS)
token_valid_until = now() + timedelta(days=token_valid_days)
payload = {
'version': ... | [
"def",
"initiate_payment",
"(",
"self",
",",
"order",
")",
"->",
"str",
":",
"token_valid_days",
"=",
"self",
".",
"config",
".",
"get",
"(",
"RESPA_PAYMENTS_BAMBORA_TOKEN_VALID_DAYS",
")",
"token_valid_until",
"=",
"now",
"(",
")",
"+",
"timedelta",
"(",
"day... | [
51,
4
] | [
80,
82
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.handle_initiate_payment | (self, response) | Handling the Bambora payment auth response | Handling the Bambora payment auth response | def handle_initiate_payment(self, response) -> str:
"""Handling the Bambora payment auth response"""
result = response['result']
if result == 0:
# Create the URL where user is redirected to complete the payment
# Append "?minified" to get a stripped version of the payment... | [
"def",
"handle_initiate_payment",
"(",
"self",
",",
"response",
")",
"->",
"str",
":",
"result",
"=",
"response",
"[",
"'result'",
"]",
"if",
"result",
"==",
"0",
":",
"# Create the URL where user is redirected to complete the payment",
"# Append \"?minified\" to get a st... | [
82,
4
] | [
97,
93
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.payload_add_products | (self, payload, order) | Attach info of bought products to payload
Order lines that contain bought products are retrieved through order | Attach info of bought products to payload | def payload_add_products(self, payload, order):
"""Attach info of bought products to payload
Order lines that contain bought products are retrieved through order"""
reservation = order.reservation
order_lines = OrderLine.objects.filter(order=order.id)
items = []
for orde... | [
"def",
"payload_add_products",
"(",
"self",
",",
"payload",
",",
"order",
")",
":",
"reservation",
"=",
"order",
".",
"reservation",
"order_lines",
"=",
"OrderLine",
".",
"objects",
".",
"filter",
"(",
"order",
"=",
"order",
".",
"id",
")",
"items",
"=",
... | [
99,
4
] | [
120,
35
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.payload_add_customer | (self, payload, order) | Attach customer data to payload | Attach customer data to payload | def payload_add_customer(self, payload, order):
"""Attach customer data to payload"""
reservation = order.reservation
payload.update({
'email': reservation.billing_email_address,
'customer': {
'firstname': reservation.billing_first_name,
'l... | [
"def",
"payload_add_customer",
"(",
"self",
",",
"payload",
",",
"order",
")",
":",
"reservation",
"=",
"order",
".",
"reservation",
"payload",
".",
"update",
"(",
"{",
"'email'",
":",
"reservation",
".",
"billing_email_address",
",",
"'customer'",
":",
"{",
... | [
122,
4
] | [
135,
10
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.payload_add_auth_code | (self, payload) | Construct auth code string and hash it into payload | Construct auth code string and hash it into payload | def payload_add_auth_code(self, payload):
"""Construct auth code string and hash it into payload"""
data = '{}|{}'.format(payload['api_key'], payload['order_number'])
payload.update(authcode=self.calculate_auth_code(data)) | [
"def",
"payload_add_auth_code",
"(",
"self",
",",
"payload",
")",
":",
"data",
"=",
"'{}|{}'",
".",
"format",
"(",
"payload",
"[",
"'api_key'",
"]",
",",
"payload",
"[",
"'order_number'",
"]",
")",
"payload",
".",
"update",
"(",
"authcode",
"=",
"self",
... | [
137,
4
] | [
140,
63
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.calculate_auth_code | (self, data) | Calculate a hmac sha256 out of some data string | Calculate a hmac sha256 out of some data string | def calculate_auth_code(self, data) -> str:
"""Calculate a hmac sha256 out of some data string"""
return hmac.new(bytes(self.config.get(RESPA_PAYMENTS_BAMBORA_API_SECRET), 'latin-1'),
msg=bytes(data, 'latin-1'),
digestmod=hashlib.sha256).hexdigest().upper(... | [
"def",
"calculate_auth_code",
"(",
"self",
",",
"data",
")",
"->",
"str",
":",
"return",
"hmac",
".",
"new",
"(",
"bytes",
"(",
"self",
".",
"config",
".",
"get",
"(",
"RESPA_PAYMENTS_BAMBORA_API_SECRET",
")",
",",
"'latin-1'",
")",
",",
"msg",
"=",
"byt... | [
142,
4
] | [
146,
69
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.check_new_payment_authcode | (self, request) | Validate that success/notify payload authcode matches | Validate that success/notify payload authcode matches | def check_new_payment_authcode(self, request):
"""Validate that success/notify payload authcode matches"""
is_valid = True
auth_code_calculation_values = [
request.GET[param_name]
for param_name in ('RETURN_CODE', 'ORDER_NUMBER', 'SETTLED', 'CONTACT_ID', 'INCIDENT_ID')
... | [
"def",
"check_new_payment_authcode",
"(",
"self",
",",
"request",
")",
":",
"is_valid",
"=",
"True",
"auth_code_calculation_values",
"=",
"[",
"request",
".",
"GET",
"[",
"param_name",
"]",
"for",
"param_name",
"in",
"(",
"'RETURN_CODE'",
",",
"'ORDER_NUMBER'",
... | [
148,
4
] | [
161,
23
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.handle_success_request | (self) | Handle the payform response after user has completed the payment flow in normal fashion | Handle the payform response after user has completed the payment flow in normal fashion | def handle_success_request(self): # noqa: C901
"""Handle the payform response after user has completed the payment flow in normal fashion"""
request = self.request
logger.debug('Handling Bambora user return request, params: {}.'.format(request.GET))
if not self.check_new_payment_authco... | [
"def",
"handle_success_request",
"(",
"self",
")",
":",
"# noqa: C901",
"request",
"=",
"self",
".",
"request",
"logger",
".",
"debug",
"(",
"'Handling Bambora user return request, params: {}.'",
".",
"format",
"(",
"request",
".",
"GET",
")",
")",
"if",
"not",
... | [
163,
4
] | [
209,
50
] | python | en | ['en', 'en', 'en'] | True |
BamboraPayformProvider.handle_notify_request | (self) | Handle the asynchronous part of payform response
Arrives some time after user has completed the payment flow or stopped it abruptly.
Skips changing order state if it has been previously set. Although, according to
Bambora's documentation, there are some cases where payment state might change
... | Handle the asynchronous part of payform response | def handle_notify_request(self):
"""Handle the asynchronous part of payform response
Arrives some time after user has completed the payment flow or stopped it abruptly.
Skips changing order state if it has been previously set. Although, according to
Bambora's documentation, there are so... | [
"def",
"handle_notify_request",
"(",
"self",
")",
":",
"request",
"=",
"self",
".",
"request",
"logger",
".",
"debug",
"(",
"'Handling Bambora notify request, params: {}.'",
".",
"format",
"(",
"request",
".",
"GET",
")",
")",
"if",
"not",
"self",
".",
"check_... | [
211,
4
] | [
250,
39
] | python | en | ['en', 'en', 'en'] | True |
_check_lazy_references | (apps, ignore=None) |
Ensure all lazy (i.e. string) model references have been resolved.
Lazy references are used in various places throughout Django, primarily in
related fields and model signals. Identify those common cases and provide
more helpful error messages for them.
The ignore parameter is used by StateApps t... |
Ensure all lazy (i.e. string) model references have been resolved. | def _check_lazy_references(apps, ignore=None):
"""
Ensure all lazy (i.e. string) model references have been resolved.
Lazy references are used in various places throughout Django, primarily in
related fields and model signals. Identify those common cases and provide
more helpful error messages for ... | [
"def",
"_check_lazy_references",
"(",
"apps",
",",
"ignore",
"=",
"None",
")",
":",
"pending_models",
"=",
"set",
"(",
"apps",
".",
"_pending_operations",
")",
"-",
"(",
"ignore",
"or",
"set",
"(",
")",
")",
"# Short circuit if there aren't any errors.",
"if",
... | [
88,
0
] | [
204,
36
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_rest_endpoint | (self) |
Tests the /api/v1/user_uploads API endpoint. Here a single file is uploaded
and downloaded using a username and api_key
|
Tests the /api/v1/user_uploads API endpoint. Here a single file is uploaded
and downloaded using a username and api_key
| def test_rest_endpoint(self) -> None:
"""
Tests the /api/v1/user_uploads API endpoint. Here a single file is uploaded
and downloaded using a username and api_key
"""
fp = StringIO("zulip!")
fp.name = "zulip.txt"
# Upload file via API
result = self.api_pos... | [
"def",
"test_rest_endpoint",
"(",
"self",
")",
"->",
"None",
":",
"fp",
"=",
"StringIO",
"(",
"\"zulip!\"",
")",
"fp",
".",
"name",
"=",
"\"zulip.txt\"",
"# Upload file via API",
"result",
"=",
"self",
".",
"api_post",
"(",
"self",
".",
"example_user",
"(",
... | [
82,
4
] | [
106,
63
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_mobile_api_endpoint | (self) |
Tests the /api/v1/user_uploads API endpoint with ?api_key
auth. Here a single file is uploaded and downloaded using a
username and api_key
|
Tests the /api/v1/user_uploads API endpoint with ?api_key
auth. Here a single file is uploaded and downloaded using a
username and api_key
| def test_mobile_api_endpoint(self) -> None:
"""
Tests the /api/v1/user_uploads API endpoint with ?api_key
auth. Here a single file is uploaded and downloaded using a
username and api_key
"""
fp = StringIO("zulip!")
fp.name = "zulip.txt"
# Upload file via ... | [
"def",
"test_mobile_api_endpoint",
"(",
"self",
")",
"->",
"None",
":",
"fp",
"=",
"StringIO",
"(",
"\"zulip!\"",
")",
"fp",
".",
"name",
"=",
"\"zulip.txt\"",
"# Upload file via API",
"result",
"=",
"self",
".",
"api_post",
"(",
"self",
".",
"example_user",
... | [
108,
4
] | [
135,
41
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_upload_file_with_supplied_mimetype | (self) |
When files are copied into the system clipboard and pasted for upload
the filename may not be supplied so the extension is determined from a
query string parameter.
|
When files are copied into the system clipboard and pasted for upload
the filename may not be supplied so the extension is determined from a
query string parameter.
| def test_upload_file_with_supplied_mimetype(self) -> None:
"""
When files are copied into the system clipboard and pasted for upload
the filename may not be supplied so the extension is determined from a
query string parameter.
"""
fp = StringIO("zulip!")
fp.name ... | [
"def",
"test_upload_file_with_supplied_mimetype",
"(",
"self",
")",
"->",
"None",
":",
"fp",
"=",
"StringIO",
"(",
"\"zulip!\"",
")",
"fp",
".",
"name",
"=",
"\"pasted_file\"",
"result",
"=",
"self",
".",
"api_post",
"(",
"self",
".",
"example_user",
"(",
"\... | [
137,
4
] | [
150,
56
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_file_too_big_failure | (self) |
Attempting to upload big files should fail.
|
Attempting to upload big files should fail.
| def test_file_too_big_failure(self) -> None:
"""
Attempting to upload big files should fail.
"""
self.login("hamlet")
fp = StringIO("bah!")
fp.name = "a.txt"
# Use MAX_FILE_UPLOAD_SIZE of 0, because the next increment
# would be 1MB.
with self.set... | [
"def",
"test_file_too_big_failure",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"fp",
"=",
"StringIO",
"(",
"\"bah!\"",
")",
"fp",
".",
"name",
"=",
"\"a.txt\"",
"# Use MAX_FILE_UPLOAD_SIZE of 0, because the next increment",
... | [
152,
4
] | [
164,
97
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_multiple_upload_failure | (self) |
Attempting to upload two files should fail.
|
Attempting to upload two files should fail.
| def test_multiple_upload_failure(self) -> None:
"""
Attempting to upload two files should fail.
"""
self.login("hamlet")
fp = StringIO("bah!")
fp.name = "a.txt"
fp2 = StringIO("pshaw!")
fp2.name = "b.txt"
result = self.client_post("/json/user_uplo... | [
"def",
"test_multiple_upload_failure",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"fp",
"=",
"StringIO",
"(",
"\"bah!\"",
")",
"fp",
".",
"name",
"=",
"\"a.txt\"",
"fp2",
"=",
"StringIO",
"(",
"\"pshaw!\"",
")",
"f... | [
166,
4
] | [
177,
80
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_no_file_upload_failure | (self) |
Calling this endpoint with no files should fail.
|
Calling this endpoint with no files should fail.
| def test_no_file_upload_failure(self) -> None:
"""
Calling this endpoint with no files should fail.
"""
self.login("hamlet")
result = self.client_post("/json/user_uploads")
self.assert_json_error(result, "You must specify a file to upload") | [
"def",
"test_no_file_upload_failure",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"result",
"=",
"self",
".",
"client_post",
"(",
"\"/json/user_uploads\"",
")",
"self",
".",
"assert_json_error",
"(",
"result",
",",
"\"You... | [
179,
4
] | [
186,
75
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_file_upload_authed | (self) |
A call to /json/user_uploads should return a uri and actually create an
entry in the database. This entry will be marked unclaimed till a message
refers it.
|
A call to /json/user_uploads should return a uri and actually create an
entry in the database. This entry will be marked unclaimed till a message
refers it.
| def test_file_upload_authed(self) -> None:
"""
A call to /json/user_uploads should return a uri and actually create an
entry in the database. This entry will be marked unclaimed till a message
refers it.
"""
self.login("hamlet")
fp = StringIO("zulip!")
fp.... | [
"def",
"test_file_upload_authed",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"fp",
"=",
"StringIO",
"(",
"\"zulip!\"",
")",
"fp",
".",
"name",
"=",
"\"zulip.txt\"",
"result",
"=",
"self",
".",
"client_post",
"(",
"... | [
190,
4
] | [
235,
49
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_removed_file_download | (self) |
Trying to download deleted files should return 404 error
|
Trying to download deleted files should return 404 error
| def test_removed_file_download(self) -> None:
"""
Trying to download deleted files should return 404 error
"""
self.login("hamlet")
fp = StringIO("zulip!")
fp.name = "zulip.txt"
result = self.client_post("/json/user_uploads", {"file": fp})
destroy_uploads... | [
"def",
"test_removed_file_download",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"fp",
"=",
"StringIO",
"(",
"\"zulip!\"",
")",
"fp",
".",
"name",
"=",
"\"zulip.txt\"",
"result",
"=",
"self",
".",
"client_post",
"(",
... | [
293,
4
] | [
305,
51
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_non_existing_file_download | (self) |
Trying to download a file that was never uploaded will return a json_error
|
Trying to download a file that was never uploaded will return a json_error
| def test_non_existing_file_download(self) -> None:
"""
Trying to download a file that was never uploaded will return a json_error
"""
hamlet = self.example_user("hamlet")
self.login_user(hamlet)
response = self.client_get(
f"http://localhost:9991/user_uploads/... | [
"def",
"test_non_existing_file_download",
"(",
"self",
")",
"->",
"None",
":",
"hamlet",
"=",
"self",
".",
"example_user",
"(",
"\"hamlet\"",
")",
"self",
".",
"login_user",
"(",
"hamlet",
")",
"response",
"=",
"self",
".",
"client_get",
"(",
"f\"http://localh... | [
307,
4
] | [
317,
60
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_multiple_claim_attachments | (self) |
This test tries to claim the same attachment twice. The messages field in
the Attachment model should have both the messages in its entry.
|
This test tries to claim the same attachment twice. The messages field in
the Attachment model should have both the messages in its entry.
| def test_multiple_claim_attachments(self) -> None:
"""
This test tries to claim the same attachment twice. The messages field in
the Attachment model should have both the messages in its entry.
"""
self.login("hamlet")
d1 = StringIO("zulip!")
d1.name = "dummy_1.tx... | [
"def",
"test_multiple_claim_attachments",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"d1",
"=",
"StringIO",
"(",
"\"zulip!\"",
")",
"d1",
".",
"name",
"=",
"\"dummy_1.txt\"",
"result",
"=",
"self",
".",
"client_post",
... | [
365,
4
] | [
383,
88
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_multiple_claim_attachments_different_owners | (self) | This test tries to claim the same attachment more than once, first
with a private stream and then with different recipients. | This test tries to claim the same attachment more than once, first
with a private stream and then with different recipients. | def test_multiple_claim_attachments_different_owners(self) -> None:
"""This test tries to claim the same attachment more than once, first
with a private stream and then with different recipients."""
self.login("hamlet")
d1 = StringIO("zulip!")
d1.name = "dummy_1.txt"
resu... | [
"def",
"test_multiple_claim_attachments_different_owners",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"d1",
"=",
"StringIO",
"(",
"\"zulip!\"",
")",
"d1",
".",
"name",
"=",
"\"dummy_1.txt\"",
"result",
"=",
"self",
".",
... | [
385,
4
] | [
435,
81
] | python | en | ['en', 'en', 'en'] | True |
FileUploadTest.test_file_name | (self) |
Unicode filenames should be processed correctly.
|
Unicode filenames should be processed correctly.
| def test_file_name(self) -> None:
"""
Unicode filenames should be processed correctly.
"""
self.login("hamlet")
for expected in ["Здравейте.txt", "test"]:
fp = StringIO("bah!")
fp.name = urllib.parse.quote(expected)
result = self.client_post(... | [
"def",
"test_file_name",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"for",
"expected",
"in",
"[",
"\"Здравейте.txt\", \"test\"]:",
"",
"",
"",
"",
"fp",
"=",
"StringIO",
"(",
"\"bah!\"",
")",
"fp",
".",
"name",
... | [
505,
4
] | [
515,
66
] | python | en | ['en', 'error', 'th'] | False |
FileUploadTest.test_realm_quota | (self) |
Realm quota for uploading should not be exceeded.
|
Realm quota for uploading should not be exceeded.
| def test_realm_quota(self) -> None:
"""
Realm quota for uploading should not be exceeded.
"""
self.login("hamlet")
d1 = StringIO("zulip!")
d1.name = "dummy_1.txt"
result = self.client_post("/json/user_uploads", {"file": d1})
d1_path_id = re.sub("/user_upl... | [
"def",
"test_realm_quota",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"d1",
"=",
"StringIO",
"(",
"\"zulip!\"",
")",
"d1",
".",
"name",
"=",
"\"dummy_1.txt\"",
"result",
"=",
"self",
".",
"client_post",
"(",
"\"/js... | [
517,
4
] | [
555,
40
] | python | en | ['en', 'error', 'th'] | False |
AvatarTest.test_avatar_url | (self) | Verifies URL schemes for avatars and realm icons. | Verifies URL schemes for avatars and realm icons. | def test_avatar_url(self) -> None:
"""Verifies URL schemes for avatars and realm icons."""
backend: ZulipUploadBackend = LocalUploadBackend()
self.assertEqual(backend.get_avatar_url("hash", False), "/user_avatars/hash.png?x=x")
self.assertEqual(backend.get_avatar_url("hash", True), "/use... | [
"def",
"test_avatar_url",
"(",
"self",
")",
"->",
"None",
":",
"backend",
":",
"ZulipUploadBackend",
"=",
"LocalUploadBackend",
"(",
")",
"self",
".",
"assertEqual",
"(",
"backend",
".",
"get_avatar_url",
"(",
"\"hash\"",
",",
"False",
")",
",",
"\"/user_avata... | [
910,
4
] | [
946,
13
] | python | en | ['en', 'en', 'en'] | True |
AvatarTest.test_multiple_upload_failure | (self) |
Attempting to upload two files should fail.
|
Attempting to upload two files should fail.
| def test_multiple_upload_failure(self) -> None:
"""
Attempting to upload two files should fail.
"""
self.login("hamlet")
with get_test_image_file("img.png") as fp1, get_test_image_file("img.png") as fp2:
result = self.client_post("/json/users/me/avatar", {"f1": fp1, "... | [
"def",
"test_multiple_upload_failure",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"with",
"get_test_image_file",
"(",
"\"img.png\"",
")",
"as",
"fp1",
",",
"get_test_image_file",
"(",
"\"img.png\"",
")",
"as",
"fp2",
":"... | [
948,
4
] | [
955,
77
] | python | en | ['en', 'error', 'th'] | False |
AvatarTest.test_no_file_upload_failure | (self) |
Calling this endpoint with no files should fail.
|
Calling this endpoint with no files should fail.
| def test_no_file_upload_failure(self) -> None:
"""
Calling this endpoint with no files should fail.
"""
self.login("hamlet")
result = self.client_post("/json/users/me/avatar")
self.assert_json_error(result, "You must upload exactly one avatar.") | [
"def",
"test_no_file_upload_failure",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"result",
"=",
"self",
".",
"client_post",
"(",
"\"/json/users/me/avatar\"",
")",
"self",
".",
"assert_json_error",
"(",
"result",
",",
"\"... | [
957,
4
] | [
964,
77
] | python | en | ['en', 'error', 'th'] | False |
AvatarTest.test_avatar_changes_disabled_failure | (self) |
Attempting to upload avatar on a realm with avatar changes disabled should fail.
|
Attempting to upload avatar on a realm with avatar changes disabled should fail.
| def test_avatar_changes_disabled_failure(self) -> None:
"""
Attempting to upload avatar on a realm with avatar changes disabled should fail.
"""
self.login("cordelia")
do_set_realm_property(
self.example_user("cordelia").realm,
"avatar_changes_disabled",
... | [
"def",
"test_avatar_changes_disabled_failure",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"cordelia\"",
")",
"do_set_realm_property",
"(",
"self",
".",
"example_user",
"(",
"\"cordelia\"",
")",
".",
"realm",
",",
"\"avatar_changes_disabled\"",... | [
966,
4
] | [
980,
91
] | python | en | ['en', 'error', 'th'] | False |
AvatarTest.test_valid_avatars | (self) |
A PUT request to /json/users/me/avatar with a valid file should return a URL and actually create an avatar.
|
A PUT request to /json/users/me/avatar with a valid file should return a URL and actually create an avatar.
| def test_valid_avatars(self) -> None:
"""
A PUT request to /json/users/me/avatar with a valid file should return a URL and actually create an avatar.
"""
version = 2
for fname, rfname in self.correct_files:
# TODO: use self.subTest once we're exclusively on python 3 b... | [
"def",
"test_valid_avatars",
"(",
"self",
")",
"->",
"None",
":",
"version",
"=",
"2",
"for",
"fname",
",",
"rfname",
"in",
"self",
".",
"correct_files",
":",
"# TODO: use self.subTest once we're exclusively on python 3 by uncommenting the line below.",
"# with self.subTest... | [
1101,
4
] | [
1143,
24
] | python | en | ['en', 'error', 'th'] | False |
AvatarTest.test_invalid_avatars | (self) |
A PUT request to /json/users/me/avatar with an invalid file should fail.
|
A PUT request to /json/users/me/avatar with an invalid file should fail.
| def test_invalid_avatars(self) -> None:
"""
A PUT request to /json/users/me/avatar with an invalid file should fail.
"""
for fname in self.corrupt_files:
# with self.subTest(fname=fname):
self.login("hamlet")
with get_test_image_file(fname) as fp:
... | [
"def",
"test_invalid_avatars",
"(",
"self",
")",
"->",
"None",
":",
"for",
"fname",
"in",
"self",
".",
"corrupt_files",
":",
"# with self.subTest(fname=fname):",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"with",
"get_test_image_file",
"(",
"fname",
")",
"as"... | [
1198,
4
] | [
1210,
60
] | python | en | ['en', 'error', 'th'] | False |
AvatarTest.test_delete_avatar | (self) |
A DELETE request to /json/users/me/avatar should delete the profile picture and return gravatar URL
|
A DELETE request to /json/users/me/avatar should delete the profile picture and return gravatar URL
| def test_delete_avatar(self) -> None:
"""
A DELETE request to /json/users/me/avatar should delete the profile picture and return gravatar URL
"""
self.login("cordelia")
cordelia = self.example_user("cordelia")
cordelia.avatar_source = UserProfile.AVATAR_FROM_USER
... | [
"def",
"test_delete_avatar",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"cordelia\"",
")",
"cordelia",
"=",
"self",
".",
"example_user",
"(",
"\"cordelia\"",
")",
"cordelia",
".",
"avatar_source",
"=",
"UserProfile",
".",
"AVATAR_FROM_US... | [
1212,
4
] | [
1234,
56
] | python | en | ['en', 'error', 'th'] | False |
RealmIconTest.test_multiple_upload_failure | (self) |
Attempting to upload two files should fail.
|
Attempting to upload two files should fail.
| def test_multiple_upload_failure(self) -> None:
"""
Attempting to upload two files should fail.
"""
# Log in as admin
self.login("iago")
with get_test_image_file("img.png") as fp1, get_test_image_file("img.png") as fp2:
result = self.client_post("/json/realm/i... | [
"def",
"test_multiple_upload_failure",
"(",
"self",
")",
"->",
"None",
":",
"# Log in as admin",
"self",
".",
"login",
"(",
"\"iago\"",
")",
"with",
"get_test_image_file",
"(",
"\"img.png\"",
")",
"as",
"fp1",
",",
"get_test_image_file",
"(",
"\"img.png\"",
")",
... | [
1296,
4
] | [
1304,
75
] | python | en | ['en', 'error', 'th'] | False |
RealmIconTest.test_no_file_upload_failure | (self) |
Calling this endpoint with no files should fail.
|
Calling this endpoint with no files should fail.
| def test_no_file_upload_failure(self) -> None:
"""
Calling this endpoint with no files should fail.
"""
self.login("iago")
result = self.client_post("/json/realm/icon")
self.assert_json_error(result, "You must upload exactly one icon.") | [
"def",
"test_no_file_upload_failure",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"iago\"",
")",
"result",
"=",
"self",
".",
"client_post",
"(",
"\"/json/realm/icon\"",
")",
"self",
".",
"assert_json_error",
"(",
"result",
",",
"\"You mus... | [
1306,
4
] | [
1313,
75
] | python | en | ['en', 'error', 'th'] | False |
RealmIconTest.test_valid_icons | (self) |
A PUT request to /json/realm/icon with a valid file should return a URL
and actually create an realm icon.
|
A PUT request to /json/realm/icon with a valid file should return a URL
and actually create an realm icon.
| def test_valid_icons(self) -> None:
"""
A PUT request to /json/realm/icon with a valid file should return a URL
and actually create an realm icon.
"""
for fname, rfname in self.correct_files:
# TODO: use self.subTest once we're exclusively on python 3 by uncommenting ... | [
"def",
"test_valid_icons",
"(",
"self",
")",
"->",
"None",
":",
"for",
"fname",
",",
"rfname",
"in",
"self",
".",
"correct_files",
":",
"# TODO: use self.subTest once we're exclusively on python 3 by uncommenting the line below.",
"# with self.subTest(fname=fname):",
"self",
... | [
1353,
4
] | [
1374,
79
] | python | en | ['en', 'error', 'th'] | False |
RealmIconTest.test_invalid_icons | (self) |
A PUT request to /json/realm/icon with an invalid file should fail.
|
A PUT request to /json/realm/icon with an invalid file should fail.
| def test_invalid_icons(self) -> None:
"""
A PUT request to /json/realm/icon with an invalid file should fail.
"""
for fname in self.corrupt_files:
# with self.subTest(fname=fname):
self.login("iago")
with get_test_image_file(fname) as fp:
... | [
"def",
"test_invalid_icons",
"(",
"self",
")",
"->",
"None",
":",
"for",
"fname",
"in",
"self",
".",
"corrupt_files",
":",
"# with self.subTest(fname=fname):",
"self",
".",
"login",
"(",
"\"iago\"",
")",
"with",
"get_test_image_file",
"(",
"fname",
")",
"as",
... | [
1376,
4
] | [
1386,
99
] | python | en | ['en', 'error', 'th'] | False |
RealmIconTest.test_delete_icon | (self) |
A DELETE request to /json/realm/icon should delete the realm icon and return gravatar URL
|
A DELETE request to /json/realm/icon should delete the realm icon and return gravatar URL
| def test_delete_icon(self) -> None:
"""
A DELETE request to /json/realm/icon should delete the realm icon and return gravatar URL
"""
self.login("iago")
realm = get_realm("zulip")
do_change_icon_source(realm, Realm.ICON_UPLOADED, acting_user=None)
result = self.c... | [
"def",
"test_delete_icon",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"iago\"",
")",
"realm",
"=",
"get_realm",
"(",
"\"zulip\"",
")",
"do_change_icon_source",
"(",
"realm",
",",
"Realm",
".",
"ICON_UPLOADED",
",",
"acting_user",
"=",
... | [
1388,
4
] | [
1402,
69
] | python | en | ['en', 'error', 'th'] | False |
RealmLogoTest.test_multiple_upload_failure | (self) |
Attempting to upload two files should fail.
|
Attempting to upload two files should fail.
| def test_multiple_upload_failure(self) -> None:
"""
Attempting to upload two files should fail.
"""
# Log in as admin
self.login("iago")
with get_test_image_file("img.png") as fp1, get_test_image_file("img.png") as fp2:
result = self.client_post(
... | [
"def",
"test_multiple_upload_failure",
"(",
"self",
")",
"->",
"None",
":",
"# Log in as admin",
"self",
".",
"login",
"(",
"\"iago\"",
")",
"with",
"get_test_image_file",
"(",
"\"img.png\"",
")",
"as",
"fp1",
",",
"get_test_image_file",
"(",
"\"img.png\"",
")",
... | [
1429,
4
] | [
1440,
75
] | python | en | ['en', 'error', 'th'] | False |
RealmLogoTest.test_no_file_upload_failure | (self) |
Calling this endpoint with no files should fail.
|
Calling this endpoint with no files should fail.
| def test_no_file_upload_failure(self) -> None:
"""
Calling this endpoint with no files should fail.
"""
self.login("iago")
result = self.client_post("/json/realm/logo", {"night": orjson.dumps(self.night).decode()})
self.assert_json_error(result, "You must upload exactly ... | [
"def",
"test_no_file_upload_failure",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"iago\"",
")",
"result",
"=",
"self",
".",
"client_post",
"(",
"\"/json/realm/logo\"",
",",
"{",
"\"night\"",
":",
"orjson",
".",
"dumps",
"(",
"self",
... | [
1442,
4
] | [
1449,
75
] | python | en | ['en', 'error', 'th'] | False |
RealmLogoTest.test_valid_logos | (self) |
A PUT request to /json/realm/logo with a valid file should return a URL
and actually create an realm logo.
|
A PUT request to /json/realm/logo with a valid file should return a URL
and actually create an realm logo.
| def test_valid_logos(self) -> None:
"""
A PUT request to /json/realm/logo with a valid file should return a URL
and actually create an realm logo.
"""
for fname, rfname in self.correct_files:
# TODO: use self.subTest once we're exclusively on python 3 by uncommenting ... | [
"def",
"test_valid_logos",
"(",
"self",
")",
"->",
"None",
":",
"for",
"fname",
",",
"rfname",
"in",
"self",
".",
"correct_files",
":",
"# TODO: use self.subTest once we're exclusively on python 3 by uncommenting the line below.",
"# with self.subTest(fname=fname):",
"self",
... | [
1525,
4
] | [
1547,
79
] | python | en | ['en', 'error', 'th'] | False |
RealmLogoTest.test_invalid_logo_upload | (self) |
A PUT request to /json/realm/logo with an invalid file should fail.
|
A PUT request to /json/realm/logo with an invalid file should fail.
| def test_invalid_logo_upload(self) -> None:
"""
A PUT request to /json/realm/logo with an invalid file should fail.
"""
for fname in self.corrupt_files:
# with self.subTest(fname=fname):
self.login("iago")
with get_test_image_file(fname) as fp:
... | [
"def",
"test_invalid_logo_upload",
"(",
"self",
")",
"->",
"None",
":",
"for",
"fname",
"in",
"self",
".",
"corrupt_files",
":",
"# with self.subTest(fname=fname):",
"self",
".",
"login",
"(",
"\"iago\"",
")",
"with",
"get_test_image_file",
"(",
"fname",
")",
"a... | [
1549,
4
] | [
1561,
99
] | python | en | ['en', 'error', 'th'] | False |
RealmLogoTest.test_delete_logo | (self) |
A DELETE request to /json/realm/logo should delete the realm logo and return gravatar URL
|
A DELETE request to /json/realm/logo should delete the realm logo and return gravatar URL
| def test_delete_logo(self) -> None:
"""
A DELETE request to /json/realm/logo should delete the realm logo and return gravatar URL
"""
user_profile = self.example_user("iago")
self.login_user(user_profile)
realm = user_profile.realm
do_change_logo_source(realm, Rea... | [
"def",
"test_delete_logo",
"(",
"self",
")",
"->",
"None",
":",
"user_profile",
"=",
"self",
".",
"example_user",
"(",
"\"iago\"",
")",
"self",
".",
"login_user",
"(",
"user_profile",
")",
"realm",
"=",
"user_profile",
".",
"realm",
"do_change_logo_source",
"(... | [
1563,
4
] | [
1579,
67
] | python | en | ['en', 'error', 'th'] | False |
S3Test.test_file_upload_authed | (self) |
A call to /json/user_uploads should return a uri and actually create an object.
|
A call to /json/user_uploads should return a uri and actually create an object.
| def test_file_upload_authed(self) -> None:
"""
A call to /json/user_uploads should return a uri and actually create an object.
"""
bucket = create_s3_buckets(settings.S3_AUTH_UPLOADS_BUCKET)[0]
self.login("hamlet")
fp = StringIO("zulip!")
fp.name = "zulip.txt"
... | [
"def",
"test_file_upload_authed",
"(",
"self",
")",
"->",
"None",
":",
"bucket",
"=",
"create_s3_buckets",
"(",
"settings",
".",
"S3_AUTH_UPLOADS_BUCKET",
")",
"[",
"0",
"]",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"fp",
"=",
"StringIO",
"(",
"\"zulip!... | [
1773,
4
] | [
1814,
86
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.