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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
send_rate_limited_pm_notification_to_bot_owner | (
sender: UserProfile, realm: Realm, content: str
) |
Sends a PM error notification to a bot's owner if one hasn't already
been sent in the last 5 minutes.
|
Sends a PM error notification to a bot's owner if one hasn't already
been sent in the last 5 minutes.
| def send_rate_limited_pm_notification_to_bot_owner(
sender: UserProfile, realm: Realm, content: str
) -> None:
"""
Sends a PM error notification to a bot's owner if one hasn't already
been sent in the last 5 minutes.
"""
if sender.realm.is_zephyr_mirror_realm or sender.realm.deactivated:
... | [
"def",
"send_rate_limited_pm_notification_to_bot_owner",
"(",
"sender",
":",
"UserProfile",
",",
"realm",
":",
"Realm",
",",
"content",
":",
"str",
")",
"->",
"None",
":",
"if",
"sender",
".",
"realm",
".",
"is_zephyr_mirror_realm",
"or",
"sender",
".",
"realm",... | [
2611,
0
] | [
2644,
48
] | python | en | ['en', 'error', 'th'] | False |
send_pm_if_empty_stream | (
stream: Optional[Stream],
realm: Realm,
sender: UserProfile,
stream_name: Optional[str] = None,
stream_id: Optional[int] = None,
) | If a bot sends a message to a stream that doesn't exist or has no
subscribers, sends a notification to the bot owner (if not a
cross-realm bot) so that the owner can correct the issue. | If a bot sends a message to a stream that doesn't exist or has no
subscribers, sends a notification to the bot owner (if not a
cross-realm bot) so that the owner can correct the issue. | def send_pm_if_empty_stream(
stream: Optional[Stream],
realm: Realm,
sender: UserProfile,
stream_name: Optional[str] = None,
stream_id: Optional[int] = None,
) -> None:
"""If a bot sends a message to a stream that doesn't exist or has no
subscribers, sends a notification to the bot owner (if... | [
"def",
"send_pm_if_empty_stream",
"(",
"stream",
":",
"Optional",
"[",
"Stream",
"]",
",",
"realm",
":",
"Realm",
",",
"sender",
":",
"UserProfile",
",",
"stream_name",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"stream_id",
":",
"Optional",
"[",
... | [
2647,
0
] | [
2690,
78
] | python | en | ['en', 'en', 'en'] | True |
direct_url_as_pep440_direct_reference | (direct_url, name) | Convert a DirectUrl to a pip requirement string. | Convert a DirectUrl to a pip requirement string. | def direct_url_as_pep440_direct_reference(direct_url, name):
# type: (DirectUrl, str) -> str
"""Convert a DirectUrl to a pip requirement string."""
direct_url.validate() # if invalid, this is a pip bug
requirement = name + " @ "
fragments = []
if isinstance(direct_url.info, VcsInfo):
re... | [
"def",
"direct_url_as_pep440_direct_reference",
"(",
"direct_url",
",",
"name",
")",
":",
"# type: (DirectUrl, str) -> str",
"direct_url",
".",
"validate",
"(",
")",
"# if invalid, this is a pip bug",
"requirement",
"=",
"name",
"+",
"\" @ \"",
"fragments",
"=",
"[",
"]... | [
29,
0
] | [
54,
22
] | python | en | ['en', 'en', 'en'] | True |
dist_get_direct_url | (dist) | Obtain a DirectUrl from a pkg_resource.Distribution.
Returns None if the distribution has no `direct_url.json` metadata,
or if `direct_url.json` is invalid.
| Obtain a DirectUrl from a pkg_resource.Distribution. | def dist_get_direct_url(dist):
# type: (Distribution) -> Optional[DirectUrl]
"""Obtain a DirectUrl from a pkg_resource.Distribution.
Returns None if the distribution has no `direct_url.json` metadata,
or if `direct_url.json` is invalid.
"""
if not dist.has_metadata(DIRECT_URL_METADATA_NAME):
... | [
"def",
"dist_get_direct_url",
"(",
"dist",
")",
":",
"# type: (Distribution) -> Optional[DirectUrl]",
"if",
"not",
"dist",
".",
"has_metadata",
"(",
"DIRECT_URL_METADATA_NAME",
")",
":",
"return",
"None",
"try",
":",
"return",
"DirectUrl",
".",
"from_json",
"(",
"di... | [
107,
0
] | [
129,
19
] | python | en | ['en', 'en', 'en'] | True |
testing_view | (request) |
Testing various ways of getting to resources by their availability time
This function gets you active period for all resources in given date range
TODO: filter depending on closed state, but this depends on weekday state as well and this needs additional work
TODO: -> exclude end before my start and s... |
Testing various ways of getting to resources by their availability time
This function gets you active period for all resources in given date range | def testing_view(request):
"""
Testing various ways of getting to resources by their availability time
This function gets you active period for all resources in given date range
TODO: filter depending on closed state, but this depends on weekday state as well and this needs additional work
TODO: ->... | [
"def",
"testing_view",
"(",
"request",
")",
":",
"start_date",
"=",
"request",
".",
"GET",
".",
"get",
"(",
"'start_date'",
",",
"'2015-03-02'",
")",
"end_date",
"=",
"request",
".",
"GET",
".",
"get",
"(",
"'end_date'",
",",
"'2015-03-07'",
")",
"duration... | [
9,
0
] | [
29,
90
] | python | en | ['en', 'error', 'th'] | False |
DatabaseSchemaEditor._remake_table | (self, model, create_fields=[], delete_fields=[], alter_fields=[], override_uniques=None) |
Shortcut to transform a model from old_model into new_model
|
Shortcut to transform a model from old_model into new_model
| def _remake_table(self, model, create_fields=[], delete_fields=[], alter_fields=[], override_uniques=None):
"""
Shortcut to transform a model from old_model into new_model
"""
# Work out the new fields dict / mapping
body = dict((f.name, f) for f in model._meta.local_fields)
... | [
"def",
"_remake_table",
"(",
"self",
",",
"model",
",",
"create_fields",
"=",
"[",
"]",
",",
"delete_fields",
"=",
"[",
"]",
",",
"alter_fields",
"=",
"[",
"]",
",",
"override_uniques",
"=",
"None",
")",
":",
"# Work out the new fields dict / mapping",
"body",... | [
45,
4
] | [
146,
47
] | python | en | ['en', 'error', 'th'] | False |
DatabaseSchemaEditor.add_field | (self, model, field) |
Creates a field on a model.
Usually involves adding a column, but may involve adding a
table instead (for M2M fields)
|
Creates a field on a model.
Usually involves adding a column, but may involve adding a
table instead (for M2M fields)
| def add_field(self, model, field):
"""
Creates a field on a model.
Usually involves adding a column, but may involve adding a
table instead (for M2M fields)
"""
# Special-case implicit M2M tables
if isinstance(field, ManyToManyField) and field.rel.through._meta.au... | [
"def",
"add_field",
"(",
"self",
",",
"model",
",",
"field",
")",
":",
"# Special-case implicit M2M tables",
"if",
"isinstance",
"(",
"field",
",",
"ManyToManyField",
")",
"and",
"field",
".",
"rel",
".",
"through",
".",
"_meta",
".",
"auto_created",
":",
"r... | [
157,
4
] | [
166,
56
] | python | en | ['en', 'error', 'th'] | False |
DatabaseSchemaEditor.remove_field | (self, model, field) |
Removes a field from a model. Usually involves deleting a column,
but for M2Ms may involve deleting a table.
|
Removes a field from a model. Usually involves deleting a column,
but for M2Ms may involve deleting a table.
| def remove_field(self, model, field):
"""
Removes a field from a model. Usually involves deleting a column,
but for M2Ms may involve deleting a table.
"""
# M2M fields are a special case
if isinstance(field, ManyToManyField):
# For implicit M2M tables, delete ... | [
"def",
"remove_field",
"(",
"self",
",",
"model",
",",
"field",
")",
":",
"# M2M fields are a special case",
"if",
"isinstance",
"(",
"field",
",",
"ManyToManyField",
")",
":",
"# For implicit M2M tables, delete the auto-created table",
"if",
"field",
".",
"rel",
".",... | [
168,
4
] | [
184,
60
] | python | en | ['en', 'error', 'th'] | False |
DatabaseSchemaEditor._alter_field | (self, model, old_field, new_field, old_type, new_type,
old_db_params, new_db_params, strict=False) | Actually perform a "physical" (non-ManyToMany) field update. | Actually perform a "physical" (non-ManyToMany) field update. | def _alter_field(self, model, old_field, new_field, old_type, new_type,
old_db_params, new_db_params, strict=False):
"""Actually perform a "physical" (non-ManyToMany) field update."""
# Alter by remaking table
self._remake_table(model, alter_fields=[(old_field, new_field)]) | [
"def",
"_alter_field",
"(",
"self",
",",
"model",
",",
"old_field",
",",
"new_field",
",",
"old_type",
",",
"new_type",
",",
"old_db_params",
",",
"new_db_params",
",",
"strict",
"=",
"False",
")",
":",
"# Alter by remaking table",
"self",
".",
"_remake_table",
... | [
186,
4
] | [
190,
72
] | python | en | ['en', 'en', 'en'] | True |
DatabaseSchemaEditor.alter_unique_together | (self, model, old_unique_together, new_unique_together) |
Deals with a model changing its unique_together.
Note: The input unique_togethers must be doubly-nested, not the single-
nested ["foo", "bar"] format.
|
Deals with a model changing its unique_together.
Note: The input unique_togethers must be doubly-nested, not the single-
nested ["foo", "bar"] format.
| def alter_unique_together(self, model, old_unique_together, new_unique_together):
"""
Deals with a model changing its unique_together.
Note: The input unique_togethers must be doubly-nested, not the single-
nested ["foo", "bar"] format.
"""
self._remake_table(model, overr... | [
"def",
"alter_unique_together",
"(",
"self",
",",
"model",
",",
"old_unique_together",
",",
"new_unique_together",
")",
":",
"self",
".",
"_remake_table",
"(",
"model",
",",
"override_uniques",
"=",
"new_unique_together",
")"
] | [
192,
4
] | [
198,
71
] | python | en | ['en', 'error', 'th'] | False |
DatabaseSchemaEditor._alter_many_to_many | (self, model, old_field, new_field, strict) |
Alters M2Ms to repoint their to= endpoints.
|
Alters M2Ms to repoint their to= endpoints.
| def _alter_many_to_many(self, model, old_field, new_field, strict):
"""
Alters M2Ms to repoint their to= endpoints.
"""
if old_field.rel.through._meta.db_table == new_field.rel.through._meta.db_table:
# The field name didn't change, but some options did; we have to propagate ... | [
"def",
"_alter_many_to_many",
"(",
"self",
",",
"model",
",",
"old_field",
",",
"new_field",
",",
"strict",
")",
":",
"if",
"old_field",
".",
"rel",
".",
"through",
".",
"_meta",
".",
"db_table",
"==",
"new_field",
".",
"rel",
".",
"through",
".",
"_meta... | [
200,
4
] | [
236,
48
] | python | en | ['en', 'error', 'th'] | False |
api_zendesk_webhook | (
request: HttpRequest,
user_profile: UserProfile,
ticket_title: str = REQ(),
ticket_id: str = REQ(),
message: str = REQ(),
) |
Zendesk uses triggers with message templates. This webhook uses the
ticket_id and ticket_title to create a subject. And passes with zendesk
user's configured message to zulip.
|
Zendesk uses triggers with message templates. This webhook uses the
ticket_id and ticket_title to create a subject. And passes with zendesk
user's configured message to zulip.
| def api_zendesk_webhook(
request: HttpRequest,
user_profile: UserProfile,
ticket_title: str = REQ(),
ticket_id: str = REQ(),
message: str = REQ(),
) -> HttpResponse:
"""
Zendesk uses triggers with message templates. This webhook uses the
ticket_id and ticket_title to create a subject. An... | [
"def",
"api_zendesk_webhook",
"(",
"request",
":",
"HttpRequest",
",",
"user_profile",
":",
"UserProfile",
",",
"ticket_title",
":",
"str",
"=",
"REQ",
"(",
")",
",",
"ticket_id",
":",
"str",
"=",
"REQ",
"(",
")",
",",
"message",
":",
"str",
"=",
"REQ",
... | [
18,
0
] | [
32,
25
] | python | en | ['en', 'error', 'th'] | False |
_hash_of_file | (path, algorithm) | Return the hash digest of a file. | Return the hash digest of a file. | def _hash_of_file(path, algorithm):
"""Return the hash digest of a file."""
with open(path, 'rb') as archive:
hash = hashlib.new(algorithm)
for chunk in read_chunks(archive):
hash.update(chunk)
return hash.hexdigest() | [
"def",
"_hash_of_file",
"(",
"path",
",",
"algorithm",
")",
":",
"with",
"open",
"(",
"path",
",",
"'rb'",
")",
"as",
"archive",
":",
"hash",
"=",
"hashlib",
".",
"new",
"(",
"algorithm",
")",
"for",
"chunk",
"in",
"read_chunks",
"(",
"archive",
")",
... | [
51,
0
] | [
57,
27
] | python | en | ['en', 'en', 'en'] | True |
random_shift | (x, pad=(4, 4), mode="REFLECT") | Pad a single image and then crop to the original size with a random
offset. | Pad a single image and then crop to the original size with a random
offset. | def random_shift(x, pad=(4, 4), mode="REFLECT"):
"""Pad a single image and then crop to the original size with a random
offset."""
assert mode in "REFLECT SYMMETRIC CONSTANT".split()
assert x.get_shape().ndims == 3
xp = tf.pad(x, [[pad[0], pad[0]], [pad[1], pad[1]], [0, 0]], mode)
return tf.rand... | [
"def",
"random_shift",
"(",
"x",
",",
"pad",
"=",
"(",
"4",
",",
"4",
")",
",",
"mode",
"=",
"\"REFLECT\"",
")",
":",
"assert",
"mode",
"in",
"\"REFLECT SYMMETRIC CONSTANT\"",
".",
"split",
"(",
")",
"assert",
"x",
".",
"get_shape",
"(",
")",
".",
"n... | [
18,
0
] | [
24,
42
] | python | en | ['en', 'en', 'en'] | True |
batch_augment | (x, func, device="/CPU:0") |
Apply dataset augmentation to a batch of exmaples.
:param x: Tensor representing a batch of examples.
:param func: Callable implementing dataset augmentation, operating on
a single image.
:param device: String specifying which device to use.
|
Apply dataset augmentation to a batch of exmaples.
:param x: Tensor representing a batch of examples.
:param func: Callable implementing dataset augmentation, operating on
a single image.
:param device: String specifying which device to use.
| def batch_augment(x, func, device="/CPU:0"):
"""
Apply dataset augmentation to a batch of exmaples.
:param x: Tensor representing a batch of examples.
:param func: Callable implementing dataset augmentation, operating on
a single image.
:param device: String specifying which device to use.
... | [
"def",
"batch_augment",
"(",
"x",
",",
"func",
",",
"device",
"=",
"\"/CPU:0\"",
")",
":",
"with",
"tf",
".",
"device",
"(",
"device",
")",
":",
"return",
"tf",
".",
"map_fn",
"(",
"func",
",",
"x",
")"
] | [
27,
0
] | [
36,
33
] | python | en | ['en', 'error', 'th'] | False |
random_crop_and_flip | (x, pad_rows=4, pad_cols=4) | Augment a batch by randomly cropping and horizontally flipping it. | Augment a batch by randomly cropping and horizontally flipping it. | def random_crop_and_flip(x, pad_rows=4, pad_cols=4):
"""Augment a batch by randomly cropping and horizontally flipping it."""
rows = tf.shape(x)[1]
cols = tf.shape(x)[2]
channels = x.get_shape()[3]
def _rand_crop_img(img):
"""Randomly crop an individual image"""
return tf.random_cro... | [
"def",
"random_crop_and_flip",
"(",
"x",
",",
"pad_rows",
"=",
"4",
",",
"pad_cols",
"=",
"4",
")",
":",
"rows",
"=",
"tf",
".",
"shape",
"(",
"x",
")",
"[",
"1",
"]",
"cols",
"=",
"tf",
".",
"shape",
"(",
"x",
")",
"[",
"2",
"]",
"channels",
... | [
39,
0
] | [
56,
12
] | python | en | ['en', 'en', 'en'] | True |
store_rendered_templates | (store, signal, sender, template, context, **kwargs) |
Stores templates and contexts that are rendered.
The context is copied so that it is an accurate representation at the time
of rendering.
|
Stores templates and contexts that are rendered. | def store_rendered_templates(store, signal, sender, template, context, **kwargs):
"""
Stores templates and contexts that are rendered.
The context is copied so that it is an accurate representation at the time
of rendering.
"""
store.setdefault('templates', []).append(template)
store.setdef... | [
"def",
"store_rendered_templates",
"(",
"store",
",",
"signal",
",",
"sender",
",",
"template",
",",
"context",
",",
"*",
"*",
"kwargs",
")",
":",
"store",
".",
"setdefault",
"(",
"'templates'",
",",
"[",
"]",
")",
".",
"append",
"(",
"template",
")",
... | [
128,
0
] | [
136,
68
] | python | en | ['en', 'error', 'th'] | False |
encode_multipart | (boundary, data) |
Encodes multipart POST data from a dictionary of form values.
The key will be used as the form data name; the value will be transmitted
as content. If the value is a file, the contents of the file will be sent
as an application/octet-stream; otherwise, str(value) will be sent.
|
Encodes multipart POST data from a dictionary of form values. | def encode_multipart(boundary, data):
"""
Encodes multipart POST data from a dictionary of form values.
The key will be used as the form data name; the value will be transmitted
as content. If the value is a file, the contents of the file will be sent
as an application/octet-stream; otherwise, str(... | [
"def",
"encode_multipart",
"(",
"boundary",
",",
"data",
")",
":",
"lines",
"=",
"[",
"]",
"to_bytes",
"=",
"lambda",
"s",
":",
"force_bytes",
"(",
"s",
",",
"settings",
".",
"DEFAULT_CHARSET",
")",
"# Not by any means perfect, but good enough for our purposes.",
... | [
139,
0
] | [
182,
30
] | python | en | ['en', 'error', 'th'] | False |
RequestFactory._base_environ | (self, **request) |
The base environment for a request.
|
The base environment for a request.
| def _base_environ(self, **request):
"""
The base environment for a request.
"""
# This is a minimal valid WSGI environ dictionary, plus:
# - HTTP_COOKIE: for cookie support,
# - REMOTE_ADDR: often useful, see #8551.
# See http://www.python.org/dev/peps/pep-3333/#e... | [
"def",
"_base_environ",
"(",
"self",
",",
"*",
"*",
"request",
")",
":",
"# This is a minimal valid WSGI environ dictionary, plus:",
"# - HTTP_COOKIE: for cookie support,",
"# - REMOTE_ADDR: often useful, see #8551.",
"# See http://www.python.org/dev/peps/pep-3333/#environ-variables",
"e... | [
222,
4
] | [
249,
22
] | python | en | ['en', 'error', 'th'] | False |
RequestFactory.request | (self, **request) | Construct a generic request object. | Construct a generic request object. | def request(self, **request):
"Construct a generic request object."
return WSGIRequest(self._base_environ(**request)) | [
"def",
"request",
"(",
"self",
",",
"*",
"*",
"request",
")",
":",
"return",
"WSGIRequest",
"(",
"self",
".",
"_base_environ",
"(",
"*",
"*",
"request",
")",
")"
] | [
251,
4
] | [
253,
57
] | python | en | ['en', 'en', 'en'] | True |
RequestFactory.get | (self, path, data=None, secure=False, **extra) | Construct a GET request. | Construct a GET request. | def get(self, path, data=None, secure=False, **extra):
"Construct a GET request."
r = {
'QUERY_STRING': urlencode(data or {}, doseq=True),
}
r.update(extra)
return self.generic('GET', path, secure=secure, **r) | [
"def",
"get",
"(",
"self",
",",
"path",
",",
"data",
"=",
"None",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"r",
"=",
"{",
"'QUERY_STRING'",
":",
"urlencode",
"(",
"data",
"or",
"{",
"}",
",",
"doseq",
"=",
"True",
")",
","... | [
278,
4
] | [
285,
60
] | python | en | ['en', 'en', 'en'] | True |
RequestFactory.post | (self, path, data=None, content_type=MULTIPART_CONTENT,
secure=False, **extra) | Construct a POST request. | Construct a POST request. | def post(self, path, data=None, content_type=MULTIPART_CONTENT,
secure=False, **extra):
"Construct a POST request."
post_data = self._encode_data(data or {}, content_type)
return self.generic('POST', path, post_data, content_type,
secure=secure, **extra... | [
"def",
"post",
"(",
"self",
",",
"path",
",",
"data",
"=",
"None",
",",
"content_type",
"=",
"MULTIPART_CONTENT",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"post_data",
"=",
"self",
".",
"_encode_data",
"(",
"data",
"or",
"{",
"}... | [
287,
4
] | [
294,
51
] | python | en | ['en', 'en', 'en'] | True |
RequestFactory.head | (self, path, data=None, secure=False, **extra) | Construct a HEAD request. | Construct a HEAD request. | def head(self, path, data=None, secure=False, **extra):
"Construct a HEAD request."
r = {
'QUERY_STRING': urlencode(data or {}, doseq=True),
}
r.update(extra)
return self.generic('HEAD', path, secure=secure, **r) | [
"def",
"head",
"(",
"self",
",",
"path",
",",
"data",
"=",
"None",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"r",
"=",
"{",
"'QUERY_STRING'",
":",
"urlencode",
"(",
"data",
"or",
"{",
"}",
",",
"doseq",
"=",
"True",
")",
",... | [
296,
4
] | [
303,
61
] | python | en | ['en', 'en', 'en'] | True |
RequestFactory.options | (self, path, data='', content_type='application/octet-stream',
secure=False, **extra) | Construct an OPTIONS request. | Construct an OPTIONS request. | def options(self, path, data='', content_type='application/octet-stream',
secure=False, **extra):
"Construct an OPTIONS request."
return self.generic('OPTIONS', path, data, content_type,
secure=secure, **extra) | [
"def",
"options",
"(",
"self",
",",
"path",
",",
"data",
"=",
"''",
",",
"content_type",
"=",
"'application/octet-stream'",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"return",
"self",
".",
"generic",
"(",
"'OPTIONS'",
",",
"path",
... | [
305,
4
] | [
309,
51
] | python | en | ['en', 'en', 'en'] | True |
RequestFactory.put | (self, path, data='', content_type='application/octet-stream',
secure=False, **extra) | Construct a PUT request. | Construct a PUT request. | def put(self, path, data='', content_type='application/octet-stream',
secure=False, **extra):
"Construct a PUT request."
return self.generic('PUT', path, data, content_type,
secure=secure, **extra) | [
"def",
"put",
"(",
"self",
",",
"path",
",",
"data",
"=",
"''",
",",
"content_type",
"=",
"'application/octet-stream'",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"return",
"self",
".",
"generic",
"(",
"'PUT'",
",",
"path",
",",
"... | [
311,
4
] | [
315,
51
] | python | en | ['en', 'en', 'en'] | True |
RequestFactory.patch | (self, path, data='', content_type='application/octet-stream',
secure=False, **extra) | Construct a PATCH request. | Construct a PATCH request. | def patch(self, path, data='', content_type='application/octet-stream',
secure=False, **extra):
"Construct a PATCH request."
return self.generic('PATCH', path, data, content_type,
secure=secure, **extra) | [
"def",
"patch",
"(",
"self",
",",
"path",
",",
"data",
"=",
"''",
",",
"content_type",
"=",
"'application/octet-stream'",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"return",
"self",
".",
"generic",
"(",
"'PATCH'",
",",
"path",
",",... | [
317,
4
] | [
321,
51
] | python | en | ['en', 'en', 'en'] | True |
RequestFactory.delete | (self, path, data='', content_type='application/octet-stream',
secure=False, **extra) | Construct a DELETE request. | Construct a DELETE request. | def delete(self, path, data='', content_type='application/octet-stream',
secure=False, **extra):
"Construct a DELETE request."
return self.generic('DELETE', path, data, content_type,
secure=secure, **extra) | [
"def",
"delete",
"(",
"self",
",",
"path",
",",
"data",
"=",
"''",
",",
"content_type",
"=",
"'application/octet-stream'",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"return",
"self",
".",
"generic",
"(",
"'DELETE'",
",",
"path",
",... | [
323,
4
] | [
327,
51
] | python | en | ['en', 'it', 'en'] | True |
RequestFactory.generic | (self, method, path, data='',
content_type='application/octet-stream', secure=False,
**extra) | Constructs an arbitrary HTTP request. | Constructs an arbitrary HTTP request. | def generic(self, method, path, data='',
content_type='application/octet-stream', secure=False,
**extra):
"""Constructs an arbitrary HTTP request."""
parsed = urlparse(path)
data = force_bytes(data, settings.DEFAULT_CHARSET)
r = {
'PATH_INFO': ... | [
"def",
"generic",
"(",
"self",
",",
"method",
",",
"path",
",",
"data",
"=",
"''",
",",
"content_type",
"=",
"'application/octet-stream'",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"parsed",
"=",
"urlparse",
"(",
"path",
")",
"data... | [
329,
4
] | [
355,
32
] | python | en | ['en', 'en', 'en'] | True |
Client.store_exc_info | (self, **kwargs) |
Stores exceptions when they are generated by a view.
|
Stores exceptions when they are generated by a view.
| def store_exc_info(self, **kwargs):
"""
Stores exceptions when they are generated by a view.
"""
self.exc_info = sys.exc_info() | [
"def",
"store_exc_info",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"exc_info",
"=",
"sys",
".",
"exc_info",
"(",
")"
] | [
381,
4
] | [
385,
38
] | python | en | ['en', 'error', 'th'] | False |
Client._session | (self) |
Obtains the current session variables.
|
Obtains the current session variables.
| def _session(self):
"""
Obtains the current session variables.
"""
if apps.is_installed('django.contrib.sessions'):
engine = import_module(settings.SESSION_ENGINE)
cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
if cookie:
... | [
"def",
"_session",
"(",
"self",
")",
":",
"if",
"apps",
".",
"is_installed",
"(",
"'django.contrib.sessions'",
")",
":",
"engine",
"=",
"import_module",
"(",
"settings",
".",
"SESSION_ENGINE",
")",
"cookie",
"=",
"self",
".",
"cookies",
".",
"get",
"(",
"s... | [
387,
4
] | [
401,
17
] | python | en | ['en', 'error', 'th'] | False |
Client.request | (self, **request) |
The master request method. Composes the environment dictionary
and passes to the handler, returning the result of the handler.
Assumes defaults for the query environment, which can be overridden
using the arguments to the request.
|
The master request method. Composes the environment dictionary
and passes to the handler, returning the result of the handler.
Assumes defaults for the query environment, which can be overridden
using the arguments to the request.
| def request(self, **request):
"""
The master request method. Composes the environment dictionary
and passes to the handler, returning the result of the handler.
Assumes defaults for the query environment, which can be overridden
using the arguments to the request.
"""
... | [
"def",
"request",
"(",
"self",
",",
"*",
"*",
"request",
")",
":",
"environ",
"=",
"self",
".",
"_base_environ",
"(",
"*",
"*",
"request",
")",
"# Curry a data dictionary into an instance of the template renderer",
"# callback function.",
"data",
"=",
"{",
"}",
"o... | [
404,
4
] | [
469,
78
] | python | en | ['en', 'error', 'th'] | False |
Client.get | (self, path, data=None, follow=False, secure=False, **extra) |
Requests a response from the server using GET.
|
Requests a response from the server using GET.
| def get(self, path, data=None, follow=False, secure=False, **extra):
"""
Requests a response from the server using GET.
"""
response = super(Client, self).get(path, data=data, secure=secure,
**extra)
if follow:
response = sel... | [
"def",
"get",
"(",
"self",
",",
"path",
",",
"data",
"=",
"None",
",",
"follow",
"=",
"False",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"response",
"=",
"super",
"(",
"Client",
",",
"self",
")",
".",
"get",
"(",
"path",
",... | [
471,
4
] | [
479,
23
] | python | en | ['en', 'error', 'th'] | False |
Client.post | (self, path, data=None, content_type=MULTIPART_CONTENT,
follow=False, secure=False, **extra) |
Requests a response from the server using POST.
|
Requests a response from the server using POST.
| def post(self, path, data=None, content_type=MULTIPART_CONTENT,
follow=False, secure=False, **extra):
"""
Requests a response from the server using POST.
"""
response = super(Client, self).post(path, data=data,
content_type=content... | [
"def",
"post",
"(",
"self",
",",
"path",
",",
"data",
"=",
"None",
",",
"content_type",
"=",
"MULTIPART_CONTENT",
",",
"follow",
"=",
"False",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"response",
"=",
"super",
"(",
"Client",
","... | [
481,
4
] | [
491,
23
] | python | en | ['en', 'error', 'th'] | False |
Client.head | (self, path, data=None, follow=False, secure=False, **extra) |
Request a response from the server using HEAD.
|
Request a response from the server using HEAD.
| def head(self, path, data=None, follow=False, secure=False, **extra):
"""
Request a response from the server using HEAD.
"""
response = super(Client, self).head(path, data=data, secure=secure,
**extra)
if follow:
response = ... | [
"def",
"head",
"(",
"self",
",",
"path",
",",
"data",
"=",
"None",
",",
"follow",
"=",
"False",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"response",
"=",
"super",
"(",
"Client",
",",
"self",
")",
".",
"head",
"(",
"path",
... | [
493,
4
] | [
501,
23
] | python | en | ['en', 'error', 'th'] | False |
Client.options | (self, path, data='', content_type='application/octet-stream',
follow=False, secure=False, **extra) |
Request a response from the server using OPTIONS.
|
Request a response from the server using OPTIONS.
| def options(self, path, data='', content_type='application/octet-stream',
follow=False, secure=False, **extra):
"""
Request a response from the server using OPTIONS.
"""
response = super(Client, self).options(path, data=data,
... | [
"def",
"options",
"(",
"self",
",",
"path",
",",
"data",
"=",
"''",
",",
"content_type",
"=",
"'application/octet-stream'",
",",
"follow",
"=",
"False",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"response",
"=",
"super",
"(",
"Clie... | [
503,
4
] | [
513,
23
] | python | en | ['en', 'error', 'th'] | False |
Client.put | (self, path, data='', content_type='application/octet-stream',
follow=False, secure=False, **extra) |
Send a resource to the server using PUT.
|
Send a resource to the server using PUT.
| def put(self, path, data='', content_type='application/octet-stream',
follow=False, secure=False, **extra):
"""
Send a resource to the server using PUT.
"""
response = super(Client, self).put(path, data=data,
content_type=content_typ... | [
"def",
"put",
"(",
"self",
",",
"path",
",",
"data",
"=",
"''",
",",
"content_type",
"=",
"'application/octet-stream'",
",",
"follow",
"=",
"False",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"response",
"=",
"super",
"(",
"Client",... | [
515,
4
] | [
525,
23
] | python | en | ['en', 'error', 'th'] | False |
Client.patch | (self, path, data='', content_type='application/octet-stream',
follow=False, secure=False, **extra) |
Send a resource to the server using PATCH.
|
Send a resource to the server using PATCH.
| def patch(self, path, data='', content_type='application/octet-stream',
follow=False, secure=False, **extra):
"""
Send a resource to the server using PATCH.
"""
response = super(Client, self).patch(path, data=data,
content_type=c... | [
"def",
"patch",
"(",
"self",
",",
"path",
",",
"data",
"=",
"''",
",",
"content_type",
"=",
"'application/octet-stream'",
",",
"follow",
"=",
"False",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"response",
"=",
"super",
"(",
"Client... | [
527,
4
] | [
537,
23
] | python | en | ['en', 'error', 'th'] | False |
Client.delete | (self, path, data='', content_type='application/octet-stream',
follow=False, secure=False, **extra) |
Send a DELETE request to the server.
|
Send a DELETE request to the server.
| def delete(self, path, data='', content_type='application/octet-stream',
follow=False, secure=False, **extra):
"""
Send a DELETE request to the server.
"""
response = super(Client, self).delete(path, data=data,
content_type=con... | [
"def",
"delete",
"(",
"self",
",",
"path",
",",
"data",
"=",
"''",
",",
"content_type",
"=",
"'application/octet-stream'",
",",
"follow",
"=",
"False",
",",
"secure",
"=",
"False",
",",
"*",
"*",
"extra",
")",
":",
"response",
"=",
"super",
"(",
"Clien... | [
539,
4
] | [
549,
23
] | python | en | ['en', 'error', 'th'] | False |
Client.login | (self, **credentials) |
Sets the Factory to appear as if it has successfully logged into a site.
Returns True if login is possible; False if the provided credentials
are incorrect, or the user is inactive, or if the sessions framework is
not available.
|
Sets the Factory to appear as if it has successfully logged into a site. | def login(self, **credentials):
"""
Sets the Factory to appear as if it has successfully logged into a site.
Returns True if login is possible; False if the provided credentials
are incorrect, or the user is inactive, or if the sessions framework is
not available.
"""
... | [
"def",
"login",
"(",
"self",
",",
"*",
"*",
"credentials",
")",
":",
"from",
"django",
".",
"contrib",
".",
"auth",
"import",
"authenticate",
",",
"login",
"user",
"=",
"authenticate",
"(",
"*",
"*",
"credentials",
")",
"if",
"(",
"user",
"and",
"user"... | [
551,
4
] | [
591,
24
] | python | en | ['en', 'error', 'th'] | False |
Client.logout | (self) |
Removes the authenticated user's cookies and session object.
Causes the authenticated user to be logged out.
|
Removes the authenticated user's cookies and session object. | def logout(self):
"""
Removes the authenticated user's cookies and session object.
Causes the authenticated user to be logged out.
"""
from django.contrib.auth import get_user, logout
request = HttpRequest()
engine = import_module(settings.SESSION_ENGINE)
... | [
"def",
"logout",
"(",
"self",
")",
":",
"from",
"django",
".",
"contrib",
".",
"auth",
"import",
"get_user",
",",
"logout",
"request",
"=",
"HttpRequest",
"(",
")",
"engine",
"=",
"import_module",
"(",
"settings",
".",
"SESSION_ENGINE",
")",
"if",
"self",
... | [
593,
4
] | [
609,
37
] | python | en | ['en', 'error', 'th'] | False |
Client._handle_redirects | (self, response, **extra) | Follows any redirects by requesting responses from the server using GET. | Follows any redirects by requesting responses from the server using GET. | def _handle_redirects(self, response, **extra):
"Follows any redirects by requesting responses from the server using GET."
response.redirect_chain = []
while response.status_code in (301, 302, 303, 307):
url = response.url
redirect_chain = response.redirect_chain
... | [
"def",
"_handle_redirects",
"(",
"self",
",",
"response",
",",
"*",
"*",
"extra",
")",
":",
"response",
".",
"redirect_chain",
"=",
"[",
"]",
"while",
"response",
".",
"status_code",
"in",
"(",
"301",
",",
"302",
",",
"303",
",",
"307",
")",
":",
"ur... | [
611,
4
] | [
634,
23
] | python | en | ['en', 'en', 'en'] | True |
test_resource_with_access_code | (test_driver, monkeypatch, ac_resource) | Test that Respa resource pre_save hook and AC resource hooks are working | Test that Respa resource pre_save hook and AC resource hooks are working | def test_resource_with_access_code(test_driver, monkeypatch, ac_resource):
"""Test that Respa resource pre_save hook and AC resource hooks are working"""
resource = ac_resource.resource
resource.access_code_type = Resource.ACCESS_CODE_TYPE_PIN4
resource.generate_access_codes = True
resource.save()
... | [
"def",
"test_resource_with_access_code",
"(",
"test_driver",
",",
"monkeypatch",
",",
"ac_resource",
")",
":",
"resource",
"=",
"ac_resource",
".",
"resource",
"resource",
".",
"access_code_type",
"=",
"Resource",
".",
"ACCESS_CODE_TYPE_PIN4",
"resource",
".",
"genera... | [
11,
0
] | [
44,
50
] | python | en | ['en', 'en', 'en'] | True |
SpatialTransformationMethod.__init__ | (self, model, sess=None, dtypestr="float32", **kwargs) |
Create a SpatialTransformationMethod instance.
Note: the model parameter should be an instance of the
cleverhans.model.Model abstraction provided by CleverHans.
:param model: cleverhans.model.Model
:param sess: optional tf.Session
:param dtypestr: dtype of the dat... |
Create a SpatialTransformationMethod instance.
Note: the model parameter should be an instance of the
cleverhans.model.Model abstraction provided by CleverHans. | def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
"""
Create a SpatialTransformationMethod instance.
Note: the model parameter should be an instance of the
cleverhans.model.Model abstraction provided by CleverHans.
:param model: cleverhans.model.Model
... | [
"def",
"__init__",
"(",
"self",
",",
"model",
",",
"sess",
"=",
"None",
",",
"dtypestr",
"=",
"\"float32\"",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
"SpatialTransformationMethod",
",",
"self",
")",
".",
"__init__",
"(",
"model",
",",
"sess",
"... | [
12,
4
] | [
39,
9
] | python | en | ['en', 'error', 'th'] | False |
SpatialTransformationMethod.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.
:param x: The model's symbolic inputs.
:param kwargs: See `parse_params`
| 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)
f... | [
"def",
"generate",
"(",
"self",
",",
"x",
",",
"*",
"*",
"kwargs",
")",
":",
"# Parse and save attack-specific parameters",
"assert",
"self",
".",
"parse_params",
"(",
"*",
"*",
"kwargs",
")",
"from",
"cleverhans",
".",
"attacks_tf",
"import",
"spm",
"labels",... | [
41,
4
] | [
69,
9
] | python | en | ['en', 'error', 'th'] | False |
SpatialTransformationMethod.parse_params | (
self,
n_samples=None,
dx_min=-0.1,
dx_max=0.1,
n_dxs=2,
dy_min=-0.1,
dy_max=0.1,
n_dys=2,
angle_min=-30,
angle_max=30,
n_angles=6,
black_border_size=0,
**kwargs
) |
Take in a dictionary of parameters and applies attack-specific checks
before saving them as attributes.
:param n_samples: (optional) The number of transformations sampled to
construct the attack. Set it to None to run
full grid attack.
... |
Take in a dictionary of parameters and applies attack-specific checks
before saving them as attributes.
:param n_samples: (optional) The number of transformations sampled to
construct the attack. Set it to None to run
full grid attack.
... | def parse_params(
self,
n_samples=None,
dx_min=-0.1,
dx_max=0.1,
n_dxs=2,
dy_min=-0.1,
dy_max=0.1,
n_dys=2,
angle_min=-30,
angle_max=30,
n_angles=6,
black_border_size=0,
**kwargs
):
"""
Take in a ... | [
"def",
"parse_params",
"(",
"self",
",",
"n_samples",
"=",
"None",
",",
"dx_min",
"=",
"-",
"0.1",
",",
"dx_max",
"=",
"0.1",
",",
"n_dxs",
"=",
"2",
",",
"dy_min",
"=",
"-",
"0.1",
",",
"dy_max",
"=",
"0.1",
",",
"n_dys",
"=",
"2",
",",
"angle_m... | [
71,
4
] | [
126,
19
] | python | en | ['en', 'error', 'th'] | False |
delete_old_scheduled_jobs | (apps: StateApps, schema_editor: DatabaseSchemaEditor) | Delete any old scheduled jobs, to handle changes in the format of
that table. Ideally, we'd translate the jobs, but it's not really
worth the development effort to save a few invitation reminders
and day2 followup emails.
| Delete any old scheduled jobs, to handle changes in the format of
that table. Ideally, we'd translate the jobs, but it's not really
worth the development effort to save a few invitation reminders
and day2 followup emails.
| def delete_old_scheduled_jobs(apps: StateApps, schema_editor: DatabaseSchemaEditor) -> None:
"""Delete any old scheduled jobs, to handle changes in the format of
that table. Ideally, we'd translate the jobs, but it's not really
worth the development effort to save a few invitation reminders
and day2 fo... | [
"def",
"delete_old_scheduled_jobs",
"(",
"apps",
":",
"StateApps",
",",
"schema_editor",
":",
"DatabaseSchemaEditor",
")",
"->",
"None",
":",
"ScheduledJob",
"=",
"apps",
".",
"get_model",
"(",
"\"zerver\"",
",",
"\"ScheduledJob\"",
")",
"ScheduledJob",
".",
"obje... | [
6,
0
] | [
13,
39
] | python | en | ['en', 'en', 'en'] | True |
MultiColumnFKTests.test_batch_create_foreign_object | (self) | See: https://code.djangoproject.com/ticket/21566 | See: https://code.djangoproject.com/ticket/21566 | def test_batch_create_foreign_object(self):
""" See: https://code.djangoproject.com/ticket/21566 """
objs = [Person(name="abcd_%s" % i, person_country=self.usa) for i in range(0, 5)]
Person.objects.bulk_create(objs, 10) | [
"def",
"test_batch_create_foreign_object",
"(",
"self",
")",
":",
"objs",
"=",
"[",
"Person",
"(",
"name",
"=",
"\"abcd_%s\"",
"%",
"i",
",",
"person_country",
"=",
"self",
".",
"usa",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"5",
")",
"]",
"Pe... | [
383,
4
] | [
386,
44
] | python | en | ['en', 'nl', 'sw'] | False |
BaseDatabaseCreation._nodb_connection | (self) |
Used to be defined here, now moved to DatabaseWrapper.
|
Used to be defined here, now moved to DatabaseWrapper.
| def _nodb_connection(self):
"""
Used to be defined here, now moved to DatabaseWrapper.
"""
return self.connection._nodb_connection | [
"def",
"_nodb_connection",
"(",
"self",
")",
":",
"return",
"self",
".",
"connection",
".",
"_nodb_connection"
] | [
23,
4
] | [
27,
47
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.create_test_db | (self, verbosity=1, autoclobber=False, serialize=True, keepdb=False) |
Create a test database, prompting the user for confirmation if the
database already exists. Return the name of the test database created.
|
Create a test database, prompting the user for confirmation if the
database already exists. Return the name of the test database created.
| def create_test_db(self, verbosity=1, autoclobber=False, serialize=True, keepdb=False):
"""
Create a test database, prompting the user for confirmation if the
database already exists. Return the name of the test database created.
"""
# Don't import django.core.management if it is... | [
"def",
"create_test_db",
"(",
"self",
",",
"verbosity",
"=",
"1",
",",
"autoclobber",
"=",
"False",
",",
"serialize",
"=",
"True",
",",
"keepdb",
"=",
"False",
")",
":",
"# Don't import django.core.management if it isn't needed.",
"from",
"django",
".",
"core",
... | [
32,
4
] | [
86,
33
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.set_as_test_mirror | (self, primary_settings_dict) |
Set this database up to be used in testing as a mirror of a primary
database whose settings are given.
|
Set this database up to be used in testing as a mirror of a primary
database whose settings are given.
| def set_as_test_mirror(self, primary_settings_dict):
"""
Set this database up to be used in testing as a mirror of a primary
database whose settings are given.
"""
self.connection.settings_dict['NAME'] = primary_settings_dict['NAME'] | [
"def",
"set_as_test_mirror",
"(",
"self",
",",
"primary_settings_dict",
")",
":",
"self",
".",
"connection",
".",
"settings_dict",
"[",
"'NAME'",
"]",
"=",
"primary_settings_dict",
"[",
"'NAME'",
"]"
] | [
88,
4
] | [
93,
77
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.serialize_db_to_string | (self) |
Serialize all data in the database into a JSON string.
Designed only for test runner usage; will not handle large
amounts of data.
|
Serialize all data in the database into a JSON string.
Designed only for test runner usage; will not handle large
amounts of data.
| def serialize_db_to_string(self):
"""
Serialize all data in the database into a JSON string.
Designed only for test runner usage; will not handle large
amounts of data.
"""
# Build list of all apps to serialize
from django.db.migrations.loader import MigrationLoad... | [
"def",
"serialize_db_to_string",
"(",
"self",
")",
":",
"# Build list of all apps to serialize",
"from",
"django",
".",
"db",
".",
"migrations",
".",
"loader",
"import",
"MigrationLoader",
"loader",
"=",
"MigrationLoader",
"(",
"self",
".",
"connection",
")",
"app_l... | [
95,
4
] | [
123,
29
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.deserialize_db_from_string | (self, data) |
Reload the database with data from a string generated by
the serialize_db_to_string() method.
|
Reload the database with data from a string generated by
the serialize_db_to_string() method.
| def deserialize_db_from_string(self, data):
"""
Reload the database with data from a string generated by
the serialize_db_to_string() method.
"""
data = StringIO(data)
for obj in serializers.deserialize("json", data, using=self.connection.alias):
obj.save() | [
"def",
"deserialize_db_from_string",
"(",
"self",
",",
"data",
")",
":",
"data",
"=",
"StringIO",
"(",
"data",
")",
"for",
"obj",
"in",
"serializers",
".",
"deserialize",
"(",
"\"json\"",
",",
"data",
",",
"using",
"=",
"self",
".",
"connection",
".",
"a... | [
125,
4
] | [
132,
22
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._get_database_display_str | (self, verbosity, database_name) |
Return display string for a database for use in various actions.
|
Return display string for a database for use in various actions.
| def _get_database_display_str(self, verbosity, database_name):
"""
Return display string for a database for use in various actions.
"""
return "'%s'%s" % (
self.connection.alias,
(" ('%s')" % database_name) if verbosity >= 2 else '',
) | [
"def",
"_get_database_display_str",
"(",
"self",
",",
"verbosity",
",",
"database_name",
")",
":",
"return",
"\"'%s'%s\"",
"%",
"(",
"self",
".",
"connection",
".",
"alias",
",",
"(",
"\" ('%s')\"",
"%",
"database_name",
")",
"if",
"verbosity",
">=",
"2",
"e... | [
134,
4
] | [
141,
9
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._get_test_db_name | (self) |
Internal implementation - return the name of the test DB that will be
created. Only useful when called from create_test_db() and
_create_test_db() and when no external munging is done with the 'NAME'
settings.
|
Internal implementation - return the name of the test DB that will be
created. Only useful when called from create_test_db() and
_create_test_db() and when no external munging is done with the 'NAME'
settings.
| def _get_test_db_name(self):
"""
Internal implementation - return the name of the test DB that will be
created. Only useful when called from create_test_db() and
_create_test_db() and when no external munging is done with the 'NAME'
settings.
"""
if self.connectio... | [
"def",
"_get_test_db_name",
"(",
"self",
")",
":",
"if",
"self",
".",
"connection",
".",
"settings_dict",
"[",
"'TEST'",
"]",
"[",
"'NAME'",
"]",
":",
"return",
"self",
".",
"connection",
".",
"settings_dict",
"[",
"'TEST'",
"]",
"[",
"'NAME'",
"]",
"ret... | [
143,
4
] | [
152,
75
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._create_test_db | (self, verbosity, autoclobber, keepdb=False) |
Internal implementation - create the test db tables.
|
Internal implementation - create the test db tables.
| def _create_test_db(self, verbosity, autoclobber, keepdb=False):
"""
Internal implementation - create the test db tables.
"""
test_database_name = self._get_test_db_name()
test_db_params = {
'dbname': self.connection.ops.quote_name(test_database_name),
'su... | [
"def",
"_create_test_db",
"(",
"self",
",",
"verbosity",
",",
"autoclobber",
",",
"keepdb",
"=",
"False",
")",
":",
"test_database_name",
"=",
"self",
".",
"_get_test_db_name",
"(",
")",
"test_db_params",
"=",
"{",
"'dbname'",
":",
"self",
".",
"connection",
... | [
157,
4
] | [
196,
33
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.clone_test_db | (self, suffix, verbosity=1, autoclobber=False, keepdb=False) |
Clone a test database.
|
Clone a test database.
| def clone_test_db(self, suffix, verbosity=1, autoclobber=False, keepdb=False):
"""
Clone a test database.
"""
source_database_name = self.connection.settings_dict['NAME']
if verbosity >= 1:
action = 'Cloning test database'
if keepdb:
actio... | [
"def",
"clone_test_db",
"(",
"self",
",",
"suffix",
",",
"verbosity",
"=",
"1",
",",
"autoclobber",
"=",
"False",
",",
"keepdb",
"=",
"False",
")",
":",
"source_database_name",
"=",
"self",
".",
"connection",
".",
"settings_dict",
"[",
"'NAME'",
"]",
"if",... | [
198,
4
] | [
215,
54
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.get_test_db_clone_settings | (self, suffix) |
Return a modified connection settings dict for the n-th clone of a DB.
|
Return a modified connection settings dict for the n-th clone of a DB.
| def get_test_db_clone_settings(self, suffix):
"""
Return a modified connection settings dict for the n-th clone of a DB.
"""
# When this function is called, the test database has been created
# already and its name has been copied to settings_dict['NAME'] so
# we don't ne... | [
"def",
"get_test_db_clone_settings",
"(",
"self",
",",
"suffix",
")",
":",
"# When this function is called, the test database has been created",
"# already and its name has been copied to settings_dict['NAME'] so",
"# we don't need to call _get_test_db_name.",
"orig_settings_dict",
"=",
"s... | [
217,
4
] | [
225,
97
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._clone_test_db | (self, suffix, verbosity, keepdb=False) |
Internal implementation - duplicate the test db tables.
|
Internal implementation - duplicate the test db tables.
| def _clone_test_db(self, suffix, verbosity, keepdb=False):
"""
Internal implementation - duplicate the test db tables.
"""
raise NotImplementedError(
"The database backend doesn't support cloning databases. "
"Disable the option to run tests in parallel processes.... | [
"def",
"_clone_test_db",
"(",
"self",
",",
"suffix",
",",
"verbosity",
",",
"keepdb",
"=",
"False",
")",
":",
"raise",
"NotImplementedError",
"(",
"\"The database backend doesn't support cloning databases. \"",
"\"Disable the option to run tests in parallel processes.\"",
")"
] | [
227,
4
] | [
233,
69
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.destroy_test_db | (self, old_database_name=None, verbosity=1, keepdb=False, suffix=None) |
Destroy a test database, prompting the user for confirmation if the
database already exists.
|
Destroy a test database, prompting the user for confirmation if the
database already exists.
| def destroy_test_db(self, old_database_name=None, verbosity=1, keepdb=False, suffix=None):
"""
Destroy a test database, prompting the user for confirmation if the
database already exists.
"""
self.connection.close()
if suffix is None:
test_database_name = self... | [
"def",
"destroy_test_db",
"(",
"self",
",",
"old_database_name",
"=",
"None",
",",
"verbosity",
"=",
"1",
",",
"keepdb",
"=",
"False",
",",
"suffix",
"=",
"None",
")",
":",
"self",
".",
"connection",
".",
"close",
"(",
")",
"if",
"suffix",
"is",
"None"... | [
235,
4
] | [
263,
69
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._destroy_test_db | (self, test_database_name, verbosity) |
Internal implementation - remove the test db tables.
|
Internal implementation - remove the test db tables.
| def _destroy_test_db(self, test_database_name, verbosity):
"""
Internal implementation - remove the test db tables.
"""
# Remove the test database to clean up after
# ourselves. Connect to the previous database (not the test database)
# to do so, because it's not allowed ... | [
"def",
"_destroy_test_db",
"(",
"self",
",",
"test_database_name",
",",
"verbosity",
")",
":",
"# Remove the test database to clean up after",
"# ourselves. Connect to the previous database (not the test database)",
"# to do so, because it's not allowed to delete a database while being",
"... | [
265,
4
] | [
275,
80
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.sql_table_creation_suffix | (self) |
SQL to append to the end of the test table creation statements.
|
SQL to append to the end of the test table creation statements.
| def sql_table_creation_suffix(self):
"""
SQL to append to the end of the test table creation statements.
"""
return '' | [
"def",
"sql_table_creation_suffix",
"(",
"self",
")",
":",
"return",
"''"
] | [
277,
4
] | [
281,
17
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.test_db_signature | (self) |
Return a tuple with elements of self.connection.settings_dict (a
DATABASES setting value) that uniquely identify a database
accordingly to the RDBMS particularities.
|
Return a tuple with elements of self.connection.settings_dict (a
DATABASES setting value) that uniquely identify a database
accordingly to the RDBMS particularities.
| def test_db_signature(self):
"""
Return a tuple with elements of self.connection.settings_dict (a
DATABASES setting value) that uniquely identify a database
accordingly to the RDBMS particularities.
"""
settings_dict = self.connection.settings_dict
return (
... | [
"def",
"test_db_signature",
"(",
"self",
")",
":",
"settings_dict",
"=",
"self",
".",
"connection",
".",
"settings_dict",
"return",
"(",
"settings_dict",
"[",
"'HOST'",
"]",
",",
"settings_dict",
"[",
"'PORT'",
"]",
",",
"settings_dict",
"[",
"'ENGINE'",
"]",
... | [
283,
4
] | [
295,
9
] | python | en | ['en', 'error', 'th'] | False |
path_to_url | (path) |
Convert a path to a file: URL. The path will be made absolute and have
quoted path parts.
|
Convert a path to a file: URL. The path will be made absolute and have
quoted path parts.
| def path_to_url(path):
# type: (Union[str, Text]) -> str
"""
Convert a path to a file: URL. The path will be made absolute and have
quoted path parts.
"""
path = os.path.normpath(os.path.abspath(path))
url = urllib_parse.urljoin('file:', urllib_request.pathname2url(path))
return url | [
"def",
"path_to_url",
"(",
"path",
")",
":",
"# type: (Union[str, Text]) -> str",
"path",
"=",
"os",
".",
"path",
".",
"normpath",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"path",
")",
")",
"url",
"=",
"urllib_parse",
".",
"urljoin",
"(",
"'file:'",
... | [
19,
0
] | [
27,
14
] | python | en | ['en', 'error', 'th'] | False |
url_to_path | (url) |
Convert a file: URL to a path.
|
Convert a file: URL to a path.
| def url_to_path(url):
# type: (str) -> str
"""
Convert a file: URL to a path.
"""
assert url.startswith('file:'), (
"You can only turn file: urls into filenames (not {url!r})"
.format(**locals()))
_, netloc, path, _, _ = urllib_parse.urlsplit(url)
if not netloc or netloc ==... | [
"def",
"url_to_path",
"(",
"url",
")",
":",
"# type: (str) -> str",
"assert",
"url",
".",
"startswith",
"(",
"'file:'",
")",
",",
"(",
"\"You can only turn file: urls into filenames (not {url!r})\"",
".",
"format",
"(",
"*",
"*",
"locals",
"(",
")",
")",
")",
"_... | [
30,
0
] | [
54,
15
] | python | en | ['en', 'error', 'th'] | False |
parse | (version) |
Parse the given version string and return either a :class:`Version` object
or a :class:`LegacyVersion` object depending on if the given version is
a valid PEP 440 version or a legacy version.
|
Parse the given version string and return either a :class:`Version` object
or a :class:`LegacyVersion` object depending on if the given version is
a valid PEP 440 version or a legacy version.
| def parse(version):
# type: (str) -> Union[LegacyVersion, Version]
"""
Parse the given version string and return either a :class:`Version` object
or a :class:`LegacyVersion` object depending on if the given version is
a valid PEP 440 version or a legacy version.
"""
try:
return Versi... | [
"def",
"parse",
"(",
"version",
")",
":",
"# type: (str) -> Union[LegacyVersion, Version]",
"try",
":",
"return",
"Version",
"(",
"version",
")",
"except",
"InvalidVersion",
":",
"return",
"LegacyVersion",
"(",
"version",
")"
] | [
47,
0
] | [
57,
37
] | python | en | ['en', 'error', 'th'] | False |
_parse_local_version | (local) |
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
|
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
| def _parse_local_version(local):
# type: (str) -> Optional[LocalType]
"""
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
"""
if local is not None:
return tuple(
part.lower() if not part.isdigit() else int(part)
for part in _local_version_sepa... | [
"def",
"_parse_local_version",
"(",
"local",
")",
":",
"# type: (str) -> Optional[LocalType]",
"if",
"local",
"is",
"not",
"None",
":",
"return",
"tuple",
"(",
"part",
".",
"lower",
"(",
")",
"if",
"not",
"part",
".",
"isdigit",
"(",
")",
"else",
"int",
"(... | [
460,
0
] | [
470,
15
] | python | en | ['en', 'error', 'th'] | False |
BaseUserManager.normalize_email | (cls, email) |
Normalize the email address by lowercasing the domain part of it.
|
Normalize the email address by lowercasing the domain part of it.
| def normalize_email(cls, email):
"""
Normalize the email address by lowercasing the domain part of it.
"""
email = email or ''
try:
email_name, domain_part = email.strip().rsplit('@', 1)
except ValueError:
pass
else:
email = ema... | [
"def",
"normalize_email",
"(",
"cls",
",",
"email",
")",
":",
"email",
"=",
"email",
"or",
"''",
"try",
":",
"email_name",
",",
"domain_part",
"=",
"email",
".",
"strip",
"(",
")",
".",
"rsplit",
"(",
"'@'",
",",
"1",
")",
"except",
"ValueError",
":"... | [
18,
4
] | [
29,
20
] | python | en | ['en', 'error', 'th'] | False |
BaseUserManager.make_random_password | (self, length=10,
allowed_chars='abcdefghjkmnpqrstuvwxyz'
'ABCDEFGHJKLMNPQRSTUVWXYZ'
'23456789') |
Generate a random password with the given length and given
allowed_chars. The default value of allowed_chars does not have "I" or
"O" or letters and digits that look similar -- just to avoid confusion.
|
Generate a random password with the given length and given
allowed_chars. The default value of allowed_chars does not have "I" or
"O" or letters and digits that look similar -- just to avoid confusion.
| def make_random_password(self, length=10,
allowed_chars='abcdefghjkmnpqrstuvwxyz'
'ABCDEFGHJKLMNPQRSTUVWXYZ'
'23456789'):
"""
Generate a random password with the given length and given
... | [
"def",
"make_random_password",
"(",
"self",
",",
"length",
"=",
"10",
",",
"allowed_chars",
"=",
"'abcdefghjkmnpqrstuvwxyz'",
"'ABCDEFGHJKLMNPQRSTUVWXYZ'",
"'23456789'",
")",
":",
"return",
"get_random_string",
"(",
"length",
",",
"allowed_chars",
")"
] | [
31,
4
] | [
40,
55
] | python | en | ['en', 'error', 'th'] | False |
AbstractBaseUser.get_username | (self) | Return the username for this User. | Return the username for this User. | def get_username(self):
"""Return the username for this User."""
return getattr(self, self.USERNAME_FIELD) | [
"def",
"get_username",
"(",
"self",
")",
":",
"return",
"getattr",
"(",
"self",
",",
"self",
".",
"USERNAME_FIELD",
")"
] | [
70,
4
] | [
72,
49
] | python | en | ['en', 'en', 'en'] | True |
AbstractBaseUser.is_anonymous | (self) |
Always return False. This is a way of comparing User objects to
anonymous users.
|
Always return False. This is a way of comparing User objects to
anonymous users.
| def is_anonymous(self):
"""
Always return False. This is a way of comparing User objects to
anonymous users.
"""
return False | [
"def",
"is_anonymous",
"(",
"self",
")",
":",
"return",
"False"
] | [
81,
4
] | [
86,
20
] | python | en | ['en', 'error', 'th'] | False |
AbstractBaseUser.is_authenticated | (self) |
Always return True. This is a way to tell if the user has been
authenticated in templates.
|
Always return True. This is a way to tell if the user has been
authenticated in templates.
| def is_authenticated(self):
"""
Always return True. This is a way to tell if the user has been
authenticated in templates.
"""
return True | [
"def",
"is_authenticated",
"(",
"self",
")",
":",
"return",
"True"
] | [
89,
4
] | [
94,
19
] | python | en | ['en', 'error', 'th'] | False |
AbstractBaseUser.check_password | (self, raw_password) |
Return a boolean of whether the raw_password was correct. Handles
hashing formats behind the scenes.
|
Return a boolean of whether the raw_password was correct. Handles
hashing formats behind the scenes.
| def check_password(self, raw_password):
"""
Return a boolean of whether the raw_password was correct. Handles
hashing formats behind the scenes.
"""
def setter(raw_password):
self.set_password(raw_password)
# Password hash upgrades shouldn't be considered ... | [
"def",
"check_password",
"(",
"self",
",",
"raw_password",
")",
":",
"def",
"setter",
"(",
"raw_password",
")",
":",
"self",
".",
"set_password",
"(",
"raw_password",
")",
"# Password hash upgrades shouldn't be considered password changes.",
"self",
".",
"_password",
... | [
100,
4
] | [
110,
66
] | python | en | ['en', 'error', 'th'] | False |
AbstractBaseUser.has_usable_password | (self) |
Return False if set_unusable_password() has been called for this user.
|
Return False if set_unusable_password() has been called for this user.
| def has_usable_password(self):
"""
Return False if set_unusable_password() has been called for this user.
"""
return is_password_usable(self.password) | [
"def",
"has_usable_password",
"(",
"self",
")",
":",
"return",
"is_password_usable",
"(",
"self",
".",
"password",
")"
] | [
116,
4
] | [
120,
48
] | python | en | ['en', 'error', 'th'] | False |
AbstractBaseUser.get_session_auth_hash | (self) |
Return an HMAC of the password field.
|
Return an HMAC of the password field.
| def get_session_auth_hash(self):
"""
Return an HMAC of the password field.
"""
key_salt = "django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash"
return salted_hmac(key_salt, self.password).hexdigest() | [
"def",
"get_session_auth_hash",
"(",
"self",
")",
":",
"key_salt",
"=",
"\"django.contrib.auth.models.AbstractBaseUser.get_session_auth_hash\"",
"return",
"salted_hmac",
"(",
"key_salt",
",",
"self",
".",
"password",
")",
".",
"hexdigest",
"(",
")"
] | [
122,
4
] | [
127,
63
] | python | en | ['en', 'error', 'th'] | False |
prefix_validation_error | (error, prefix, code, params) |
Prefix a validation error message while maintaining the existing
validation data structure.
|
Prefix a validation error message while maintaining the existing
validation data structure.
| def prefix_validation_error(error, prefix, code, params):
"""
Prefix a validation error message while maintaining the existing
validation data structure.
"""
if error.error_list == [error]:
error_params = error.params or {}
return ValidationError(
# We can't simply concat... | [
"def",
"prefix_validation_error",
"(",
"error",
",",
"prefix",
",",
"code",
",",
"params",
")",
":",
"if",
"error",
".",
"error_list",
"==",
"[",
"error",
"]",
":",
"error_params",
"=",
"error",
".",
"params",
"or",
"{",
"}",
"return",
"ValidationError",
... | [
5,
0
] | [
28,
6
] | python | en | ['en', 'error', 'th'] | False |
binary_predicate | (func, *args) | For GEOS binary predicate functions. | For GEOS binary predicate functions. | def binary_predicate(func, *args):
"For GEOS binary predicate functions."
argtypes = [GEOM_PTR, GEOM_PTR]
if args:
argtypes += args
func.argtypes = argtypes
func.restype = c_char
func.errcheck = check_predicate
return func | [
"def",
"binary_predicate",
"(",
"func",
",",
"*",
"args",
")",
":",
"argtypes",
"=",
"[",
"GEOM_PTR",
",",
"GEOM_PTR",
"]",
"if",
"args",
":",
"argtypes",
"+=",
"args",
"func",
".",
"argtypes",
"=",
"argtypes",
"func",
".",
"restype",
"=",
"c_char",
"f... | [
11,
0
] | [
19,
15
] | python | en | ['en', 'en', 'en'] | True |
unary_predicate | (func) | For GEOS unary predicate functions. | For GEOS unary predicate functions. | def unary_predicate(func):
"For GEOS unary predicate functions."
func.argtypes = [GEOM_PTR]
func.restype = c_char
func.errcheck = check_predicate
return func | [
"def",
"unary_predicate",
"(",
"func",
")",
":",
"func",
".",
"argtypes",
"=",
"[",
"GEOM_PTR",
"]",
"func",
".",
"restype",
"=",
"c_char",
"func",
".",
"errcheck",
"=",
"check_predicate",
"return",
"func"
] | [
22,
0
] | [
27,
15
] | python | en | ['en', 'en', 'it'] | True |
OracleOperations.geo_db_type | (self, f) |
Return the geometry database type for Oracle. Unlike other spatial
backends, no stored procedure is necessary and it's the same for all
geometry types.
|
Return the geometry database type for Oracle. Unlike other spatial
backends, no stored procedure is necessary and it's the same for all
geometry types.
| def geo_db_type(self, f):
"""
Return the geometry database type for Oracle. Unlike other spatial
backends, no stored procedure is necessary and it's the same for all
geometry types.
"""
return 'MDSYS.SDO_GEOMETRY' | [
"def",
"geo_db_type",
"(",
"self",
",",
"f",
")",
":",
"return",
"'MDSYS.SDO_GEOMETRY'"
] | [
138,
4
] | [
144,
35
] | python | en | ['en', 'error', 'th'] | False |
OracleOperations.get_distance | (self, f, value, lookup_type) |
Return the distance parameters given the value and the lookup type.
On Oracle, geometry columns with a geodetic coordinate system behave
implicitly like a geography column, and thus meters will be used as
the distance parameter on them.
|
Return the distance parameters given the value and the lookup type.
On Oracle, geometry columns with a geodetic coordinate system behave
implicitly like a geography column, and thus meters will be used as
the distance parameter on them.
| def get_distance(self, f, value, lookup_type):
"""
Return the distance parameters given the value and the lookup type.
On Oracle, geometry columns with a geodetic coordinate system behave
implicitly like a geography column, and thus meters will be used as
the distance parameter o... | [
"def",
"get_distance",
"(",
"self",
",",
"f",
",",
"value",
",",
"lookup_type",
")",
":",
"if",
"not",
"value",
":",
"return",
"[",
"]",
"value",
"=",
"value",
"[",
"0",
"]",
"if",
"isinstance",
"(",
"value",
",",
"Distance",
")",
":",
"if",
"f",
... | [
146,
4
] | [
169,
27
] | python | en | ['en', 'error', 'th'] | False |
OracleOperations.spatial_aggregate_name | (self, agg_name) |
Return the spatial aggregate SQL name.
|
Return the spatial aggregate SQL name.
| def spatial_aggregate_name(self, agg_name):
"""
Return the spatial aggregate SQL name.
"""
agg_name = 'unionagg' if agg_name.lower() == 'union' else agg_name.lower()
return getattr(self, agg_name) | [
"def",
"spatial_aggregate_name",
"(",
"self",
",",
"agg_name",
")",
":",
"agg_name",
"=",
"'unionagg'",
"if",
"agg_name",
".",
"lower",
"(",
")",
"==",
"'union'",
"else",
"agg_name",
".",
"lower",
"(",
")",
"return",
"getattr",
"(",
"self",
",",
"agg_name"... | [
176,
4
] | [
181,
38
] | python | en | ['en', 'error', 'th'] | False |
OracleOperations.modify_insert_params | (self, placeholder, params) | Drop out insert parameters for NULL placeholder. Needed for Oracle Spatial
backend due to #10888.
| Drop out insert parameters for NULL placeholder. Needed for Oracle Spatial
backend due to #10888.
| def modify_insert_params(self, placeholder, params):
"""Drop out insert parameters for NULL placeholder. Needed for Oracle Spatial
backend due to #10888.
"""
if placeholder == 'NULL':
return []
return super().modify_insert_params(placeholder, params) | [
"def",
"modify_insert_params",
"(",
"self",
",",
"placeholder",
",",
"params",
")",
":",
"if",
"placeholder",
"==",
"'NULL'",
":",
"return",
"[",
"]",
"return",
"super",
"(",
")",
".",
"modify_insert_params",
"(",
"placeholder",
",",
"params",
")"
] | [
192,
4
] | [
198,
64
] | python | en | ['en', 'en', 'en'] | True |
TensorflowNeuropodExecutor.__init__ | (self, neuropod_path, load_custom_ops=True) |
Load a Tensorflow neuropod
:param neuropod_path: The path to a python neuropod package
|
Load a Tensorflow neuropod | def __init__(self, neuropod_path, load_custom_ops=True):
"""
Load a Tensorflow neuropod
:param neuropod_path: The path to a python neuropod package
"""
super(TensorflowNeuropodExecutor, self).__init__(neuropod_path)
# Load custom ops (if any)
if load_custom_op... | [
"def",
"__init__",
"(",
"self",
",",
"neuropod_path",
",",
"load_custom_ops",
"=",
"True",
")",
":",
"super",
"(",
"TensorflowNeuropodExecutor",
",",
"self",
")",
".",
"__init__",
"(",
"neuropod_path",
")",
"# Load custom ops (if any)",
"if",
"load_custom_ops",
"a... | [
33,
4
] | [
85,
31
] | python | en | ['en', 'error', 'th'] | False |
TensorflowNeuropodExecutor.forward | (self, inputs) |
Run inference using the specifed inputs.
:param inputs: A dict mapping input names to values. This must match the input
spec in the neuropod config for the loaded model.
Ex: {'x1': np.array([5]), 'x2': np.array([6])}
... |
Run inference using the specifed inputs. | def forward(self, inputs):
"""
Run inference using the specifed inputs.
:param inputs: A dict mapping input names to values. This must match the input
spec in the neuropod config for the loaded model.
Ex: {'x1': np.array([5]), 'x2': n... | [
"def",
"forward",
"(",
"self",
",",
"inputs",
")",
":",
"# get the input and output nodes",
"output_dict",
"=",
"{",
"}",
"feed_dict",
"=",
"{",
"}",
"# Get the output nodes",
"for",
"node",
"in",
"self",
".",
"neuropod_config",
"[",
"\"output_spec\"",
"]",
":",... | [
87,
4
] | [
147,
22
] | python | en | ['en', 'error', 'th'] | False |
BulkCreateTests.test_zero_as_autoval | (self) |
Zero as id for AutoField should raise exception in MySQL, because MySQL
does not allow zero for automatic primary key.
|
Zero as id for AutoField should raise exception in MySQL, because MySQL
does not allow zero for automatic primary key.
| def test_zero_as_autoval(self):
"""
Zero as id for AutoField should raise exception in MySQL, because MySQL
does not allow zero for automatic primary key.
"""
valid_country = Country(name='Germany', iso_two_letter='DE')
invalid_country = Country(id=0, name='Poland', iso_t... | [
"def",
"test_zero_as_autoval",
"(",
"self",
")",
":",
"valid_country",
"=",
"Country",
"(",
"name",
"=",
"'Germany'",
",",
"iso_two_letter",
"=",
"'DE'",
")",
"invalid_country",
"=",
"Country",
"(",
"id",
"=",
"0",
",",
"name",
"=",
"'Poland'",
",",
"iso_t... | [
73,
4
] | [
81,
73
] | python | en | ['en', 'error', 'th'] | False |
BulkCreateTests.test_large_batch_mixed | (self) |
Test inserting a large batch with objects having primary key set
mixed together with objects without PK set.
|
Test inserting a large batch with objects having primary key set
mixed together with objects without PK set.
| def test_large_batch_mixed(self):
"""
Test inserting a large batch with objects having primary key set
mixed together with objects without PK set.
"""
with override_settings(DEBUG=True):
connection.queries_log.clear()
TwoFields.objects.bulk_create([
... | [
"def",
"test_large_batch_mixed",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"DEBUG",
"=",
"True",
")",
":",
"connection",
".",
"queries_log",
".",
"clear",
"(",
")",
"TwoFields",
".",
"objects",
".",
"bulk_create",
"(",
"[",
"TwoFields",
"(",
... | [
120,
4
] | [
135,
81
] | python | en | ['en', 'error', 'th'] | False |
BulkCreateTests.test_large_batch_mixed_efficiency | (self) |
Test inserting a large batch with objects having primary key set
mixed together with objects without PK set.
|
Test inserting a large batch with objects having primary key set
mixed together with objects without PK set.
| def test_large_batch_mixed_efficiency(self):
"""
Test inserting a large batch with objects having primary key set
mixed together with objects without PK set.
"""
with override_settings(DEBUG=True):
connection.queries_log.clear()
TwoFields.objects.bulk_crea... | [
"def",
"test_large_batch_mixed_efficiency",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"DEBUG",
"=",
"True",
")",
":",
"connection",
".",
"queries_log",
".",
"clear",
"(",
")",
"TwoFields",
".",
"objects",
".",
"bulk_create",
"(",
"[",
"TwoFields... | [
138,
4
] | [
148,
57
] | python | en | ['en', 'error', 'th'] | False |
short_replace | (match, file, line_number) | Replace a Short: ... cobra command description with an internationalization
| Replace a Short: ... cobra command description with an internationalization
| def short_replace(match, file, line_number):
"""Replace a Short: ... cobra command description with an internationalization
"""
sys.stdout.write('{}i18n.T({}),\n'.format(match.group(1), match.group(2))) | [
"def",
"short_replace",
"(",
"match",
",",
"file",
",",
"line_number",
")",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"'{}i18n.T({}),\\n'",
".",
"format",
"(",
"match",
".",
"group",
"(",
"1",
")",
",",
"match",
".",
"group",
"(",
"2",
")",
")",
... | [
36,
0
] | [
39,
78
] | python | en | ['en', 'en', 'en'] | True |
import_replace | (match, file, line_number) | Add an extra import for the i18n library.
Doesn't try to be smart and detect if it's already present, assumes a
gofmt round wil fix things.
| Add an extra import for the i18n library.
Doesn't try to be smart and detect if it's already present, assumes a
gofmt round wil fix things.
| def import_replace(match, file, line_number):
"""Add an extra import for the i18n library.
Doesn't try to be smart and detect if it's already present, assumes a
gofmt round wil fix things.
"""
sys.stdout.write('{}\n"k8s.io/kubectl/pkg/util/i18n"\n'.format(match.group(1))) | [
"def",
"import_replace",
"(",
"match",
",",
"file",
",",
"line_number",
")",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"'{}\\n\"k8s.io/kubectl/pkg/util/i18n\"\\n'",
".",
"format",
"(",
"match",
".",
"group",
"(",
"1",
")",
")",
")"
] | [
43,
0
] | [
48,
83
] | python | en | ['en', 'en', 'en'] | True |
string_flag_replace | (match, file, line_number) | Replace a cmd.Flags().String("...", "", "...") with an internationalization
| Replace a cmd.Flags().String("...", "", "...") with an internationalization
| def string_flag_replace(match, file, line_number):
"""Replace a cmd.Flags().String("...", "", "...") with an internationalization
"""
sys.stdout.write('{}i18n.T("{})"))\n'.format(match.group(1), match.group(2))) | [
"def",
"string_flag_replace",
"(",
"match",
",",
"file",
",",
"line_number",
")",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"'{}i18n.T(\"{})\"))\\n'",
".",
"format",
"(",
"match",
".",
"group",
"(",
"1",
")",
",",
"match",
".",
"group",
"(",
"2",
"... | [
53,
0
] | [
56,
81
] | python | en | ['en', 'en', 'en'] | True |
replace | (filename, matchers, multiline_matchers) | Given a file and a set of matchers, run those matchers
across the file and replace it with the results.
| Given a file and a set of matchers, run those matchers
across the file and replace it with the results.
| def replace(filename, matchers, multiline_matchers):
"""Given a file and a set of matchers, run those matchers
across the file and replace it with the results.
"""
# Run all the matchers
line_number = 0
for line in fileinput.input(filename, inplace=True):
line_number += 1
matched... | [
"def",
"replace",
"(",
"filename",
",",
"matchers",
",",
"multiline_matchers",
")",
":",
"# Run all the matchers",
"line_number",
"=",
"0",
"for",
"line",
"in",
"fileinput",
".",
"input",
"(",
"filename",
",",
"inplace",
"=",
"True",
")",
":",
"line_number",
... | [
68,
0
] | [
102,
39
] | python | en | ['en', 'ny', 'en'] | True |
to_sax | (walker, handler) | Call SAX-like content handler based on treewalker walker
:arg walker: the treewalker to use to walk the tree to convert it
:arg handler: SAX handler to use
| Call SAX-like content handler based on treewalker walker | def to_sax(walker, handler):
"""Call SAX-like content handler based on treewalker walker
:arg walker: the treewalker to use to walk the tree to convert it
:arg handler: SAX handler to use
"""
handler.startDocument()
for prefix, namespace in prefix_mapping.items():
handler.startPrefixM... | [
"def",
"to_sax",
"(",
"walker",
",",
"handler",
")",
":",
"handler",
".",
"startDocument",
"(",
")",
"for",
"prefix",
",",
"namespace",
"in",
"prefix_mapping",
".",
"items",
"(",
")",
":",
"handler",
".",
"startPrefixMapping",
"(",
"prefix",
",",
"namespac... | [
12,
0
] | [
49,
25
] | python | en | ['en', 'no', 'en'] | True |
get_app_template_dirs | (dirname) |
Return an iterable of paths of directories to load app templates from.
dirname is the name of the subdirectory containing templates inside
installed applications.
|
Return an iterable of paths of directories to load app templates from. | def get_app_template_dirs(dirname):
"""
Return an iterable of paths of directories to load app templates from.
dirname is the name of the subdirectory containing templates inside
installed applications.
"""
template_dirs = [
str(Path(app_config.path) / dirname)
for app_config in... | [
"def",
"get_app_template_dirs",
"(",
"dirname",
")",
":",
"template_dirs",
"=",
"[",
"str",
"(",
"Path",
"(",
"app_config",
".",
"path",
")",
"/",
"dirname",
")",
"for",
"app_config",
"in",
"apps",
".",
"get_app_configs",
"(",
")",
"if",
"app_config",
".",... | [
93,
0
] | [
106,
31
] | python | en | ['en', 'error', 'th'] | False |
EngineHandler.__init__ | (self, templates=None) |
templates is an optional list of template engine definitions
(structured like settings.TEMPLATES).
|
templates is an optional list of template engine definitions
(structured like settings.TEMPLATES).
| def __init__(self, templates=None):
"""
templates is an optional list of template engine definitions
(structured like settings.TEMPLATES).
"""
self._templates = templates
self._engines = {} | [
"def",
"__init__",
"(",
"self",
",",
"templates",
"=",
"None",
")",
":",
"self",
".",
"_templates",
"=",
"templates",
"self",
".",
"_engines",
"=",
"{",
"}"
] | [
16,
4
] | [
22,
26
] | python | en | ['en', 'error', 'th'] | False |
Command.get_handler | (self, *args, **options) | Return the default WSGI handler for the runner. | Return the default WSGI handler for the runner. | def get_handler(self, *args, **options):
"""Return the default WSGI handler for the runner."""
return get_internal_wsgi_application() | [
"def",
"get_handler",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"options",
")",
":",
"return",
"get_internal_wsgi_application",
"(",
")"
] | [
61,
4
] | [
63,
46
] | python | en | ['en', 'no', 'en'] | True |
Command.run | (self, **options) | Run the server, using the autoreloader if needed. | Run the server, using the autoreloader if needed. | def run(self, **options):
"""Run the server, using the autoreloader if needed."""
use_reloader = options['use_reloader']
if use_reloader:
autoreload.run_with_reloader(self.inner_run, **options)
else:
self.inner_run(None, **options) | [
"def",
"run",
"(",
"self",
",",
"*",
"*",
"options",
")",
":",
"use_reloader",
"=",
"options",
"[",
"'use_reloader'",
"]",
"if",
"use_reloader",
":",
"autoreload",
".",
"run_with_reloader",
"(",
"self",
".",
"inner_run",
",",
"*",
"*",
"options",
")",
"e... | [
96,
4
] | [
103,
43
] | python | en | ['en', 'en', 'en'] | True |
parse_anchor_value | (anchor_val: Optional[str], use_first_unread_anchor: bool) | Given the anchor and use_first_unread_anchor parameters passed by
the client, computes what anchor value the client requested,
handling backwards-compatibility and the various string-valued
fields. We encode use_first_unread_anchor as anchor=None.
| Given the anchor and use_first_unread_anchor parameters passed by
the client, computes what anchor value the client requested,
handling backwards-compatibility and the various string-valued
fields. We encode use_first_unread_anchor as anchor=None.
| def parse_anchor_value(anchor_val: Optional[str], use_first_unread_anchor: bool) -> Optional[int]:
"""Given the anchor and use_first_unread_anchor parameters passed by
the client, computes what anchor value the client requested,
handling backwards-compatibility and the various string-valued
fields. We ... | [
"def",
"parse_anchor_value",
"(",
"anchor_val",
":",
"Optional",
"[",
"str",
"]",
",",
"use_first_unread_anchor",
":",
"bool",
")",
"->",
"Optional",
"[",
"int",
"]",
":",
"if",
"use_first_unread_anchor",
":",
"# Backwards-compatibility: Before we added support for the"... | [
882,
0
] | [
917,
48
] | python | en | ['en', 'en', 'en'] | True |
limit_query_to_range | (
query: Select,
num_before: int,
num_after: int,
anchor: int,
anchored_to_left: bool,
anchored_to_right: bool,
id_col: "ColumnElement[int]",
first_visible_message_id: int,
) |
This code is actually generic enough that we could move it to a
library, but our only caller for now is message search.
|
This code is actually generic enough that we could move it to a
library, but our only caller for now is message search.
| def limit_query_to_range(
query: Select,
num_before: int,
num_after: int,
anchor: int,
anchored_to_left: bool,
anchored_to_right: bool,
id_col: "ColumnElement[int]",
first_visible_message_id: int,
) -> FromClause:
"""
This code is actually generic enough that we could move it to ... | [
"def",
"limit_query_to_range",
"(",
"query",
":",
"Select",
",",
"num_before",
":",
"int",
",",
"num_after",
":",
"int",
",",
"anchor",
":",
"int",
",",
"anchored_to_left",
":",
"bool",
",",
"anchored_to_right",
":",
"bool",
",",
"id_col",
":",
"\"ColumnElem... | [
1148,
0
] | [
1226,
44
] | python | en | ['en', 'error', 'th'] | False |
NarrowBuilder.add_term | (self, query: Select, term: Dict[str, Any]) |
Extend the given query to one narrowed by the given term, and return the result.
This method satisfies an important security property: the returned
query never includes a message that the given query didn't. In
particular, if the given query will only find messages that a given
... |
Extend the given query to one narrowed by the given term, and return the result. | def add_term(self, query: Select, term: Dict[str, Any]) -> Select:
"""
Extend the given query to one narrowed by the given term, and return the result.
This method satisfies an important security property: the returned
query never includes a message that the given query didn't. In
... | [
"def",
"add_term",
"(",
"self",
",",
"query",
":",
"Select",
",",
"term",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"Select",
":",
"# To maintain the security property, we hold all the `by_*`",
"# methods to the same criterion. See the class's block comment",
... | [
161,
4
] | [
192,
51
] | python | en | ['en', 'error', 'th'] | False |
NarrowBuilder._pg_re_escape | (self, pattern: str) |
Escape user input to place in a regex
Python's re.escape escapes Unicode characters in a way which PostgreSQL
fails on, '\u03bb' to '\\\u03bb'. This function will correctly escape
them for PostgreSQL, '\u03bb' to '\\u03bb'.
|
Escape user input to place in a regex | def _pg_re_escape(self, pattern: str) -> str:
"""
Escape user input to place in a regex
Python's re.escape escapes Unicode characters in a way which PostgreSQL
fails on, '\u03bb' to '\\\u03bb'. This function will correctly escape
them for PostgreSQL, '\u03bb' to '\\u03bb'.
... | [
"def",
"_pg_re_escape",
"(",
"self",
",",
"pattern",
":",
"str",
")",
"->",
"str",
":",
"s",
"=",
"list",
"(",
"pattern",
")",
"for",
"i",
",",
"c",
"in",
"enumerate",
"(",
"s",
")",
":",
"if",
"c",
"not",
"in",
"self",
".",
"_alphanum",
":",
"... | [
240,
4
] | [
257,
25
] | python | en | ['en', 'error', 'th'] | False |
cache_page | (*args, **kwargs) |
Decorator for views that tries getting the page from the cache and
populates the cache if the page isn't in the cache yet.
The cache is keyed by the URL and some data from the headers.
Additionally there is the key prefix that is used to distinguish different
cache areas in a multi-site setup. You... |
Decorator for views that tries getting the page from the cache and
populates the cache if the page isn't in the cache yet. | def cache_page(*args, **kwargs):
"""
Decorator for views that tries getting the page from the cache and
populates the cache if the page isn't in the cache yet.
The cache is keyed by the URL and some data from the headers.
Additionally there is the key prefix that is used to distinguish different
... | [
"def",
"cache_page",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"# We also add some asserts to give better error messages in case people are",
"# using other ways to call cache_page that no longer work.",
"if",
"len",
"(",
"args",
")",
"!=",
"1",
"or",
"callable",... | [
6,
0
] | [
32,
5
] | 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.