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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
FileStorageTests.test_file_save_without_name | (self) |
File storage extracts the filename from the content object if no
name is given explicitly.
|
File storage extracts the filename from the content object if no
name is given explicitly.
| def test_file_save_without_name(self):
"""
File storage extracts the filename from the content object if no
name is given explicitly.
"""
self.assertFalse(self.storage.exists('test.file'))
f = ContentFile('custom contents')
f.name = 'test.file'
storage_f... | [
"def",
"test_file_save_without_name",
"(",
"self",
")",
":",
"self",
".",
"assertFalse",
"(",
"self",
".",
"storage",
".",
"exists",
"(",
"'test.file'",
")",
")",
"f",
"=",
"ContentFile",
"(",
"'custom contents'",
")",
"f",
".",
"name",
"=",
"'test.file'",
... | [
177,
4
] | [
193,
43
] | python | en | ['en', 'error', 'th'] | False |
FileStorageTests.test_file_save_with_path | (self) |
Saving a pathname should create intermediate directories as necessary.
|
Saving a pathname should create intermediate directories as necessary.
| def test_file_save_with_path(self):
"""
Saving a pathname should create intermediate directories as necessary.
"""
self.assertFalse(self.storage.exists('path/to'))
self.storage.save('path/to/test.file',
ContentFile('file saved with path'))
self.assertTrue(sel... | [
"def",
"test_file_save_with_path",
"(",
"self",
")",
":",
"self",
".",
"assertFalse",
"(",
"self",
".",
"storage",
".",
"exists",
"(",
"'path/to'",
")",
")",
"self",
".",
"storage",
".",
"save",
"(",
"'path/to/test.file'",
",",
"ContentFile",
"(",
"'file sav... | [
195,
4
] | [
210,
48
] | python | en | ['en', 'error', 'th'] | False |
FileStorageTests.test_file_path | (self) |
File storage returns the full path of a file
|
File storage returns the full path of a file
| def test_file_path(self):
"""
File storage returns the full path of a file
"""
self.assertFalse(self.storage.exists('test.file'))
f = ContentFile('custom contents')
f_name = self.storage.save('test.file', f)
self.assertEqual(self.storage.path(f_name),
... | [
"def",
"test_file_path",
"(",
"self",
")",
":",
"self",
".",
"assertFalse",
"(",
"self",
".",
"storage",
".",
"exists",
"(",
"'test.file'",
")",
")",
"f",
"=",
"ContentFile",
"(",
"'custom contents'",
")",
"f_name",
"=",
"self",
".",
"storage",
".",
"sav... | [
229,
4
] | [
241,
35
] | python | en | ['en', 'error', 'th'] | False |
FileStorageTests.test_file_url | (self) |
File storage returns a url to access a given file from the Web.
|
File storage returns a url to access a given file from the Web.
| def test_file_url(self):
"""
File storage returns a url to access a given file from the Web.
"""
self.assertEqual(self.storage.url('test.file'),
'%s%s' % (self.storage.base_url, 'test.file'))
# should encode special chars except ~!*()'
# like encodeURICompone... | [
"def",
"test_file_url",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"self",
".",
"storage",
".",
"url",
"(",
"'test.file'",
")",
",",
"'%s%s'",
"%",
"(",
"self",
".",
"storage",
".",
"base_url",
",",
"'test.file'",
")",
")",
"# should encode ... | [
243,
4
] | [
268,
9
] | python | en | ['en', 'error', 'th'] | False |
FileStorageTests.test_listdir | (self) |
File storage returns a tuple containing directories and files.
|
File storage returns a tuple containing directories and files.
| def test_listdir(self):
"""
File storage returns a tuple containing directories and files.
"""
self.assertFalse(self.storage.exists('storage_test_1'))
self.assertFalse(self.storage.exists('storage_test_2'))
self.assertFalse(self.storage.exists('storage_dir_1'))
s... | [
"def",
"test_listdir",
"(",
"self",
")",
":",
"self",
".",
"assertFalse",
"(",
"self",
".",
"storage",
".",
"exists",
"(",
"'storage_test_1'",
")",
")",
"self",
".",
"assertFalse",
"(",
"self",
".",
"storage",
".",
"exists",
"(",
"'storage_test_2'",
")",
... | [
270,
4
] | [
289,
62
] | python | en | ['en', 'error', 'th'] | False |
FileStorageTests.test_file_storage_prevents_directory_traversal | (self) |
File storage prevents directory traversal (files can only be accessed if
they're below the storage location).
|
File storage prevents directory traversal (files can only be accessed if
they're below the storage location).
| def test_file_storage_prevents_directory_traversal(self):
"""
File storage prevents directory traversal (files can only be accessed if
they're below the storage location).
"""
self.assertRaises(SuspiciousOperation, self.storage.exists, '..')
self.assertRaises(SuspiciousOp... | [
"def",
"test_file_storage_prevents_directory_traversal",
"(",
"self",
")",
":",
"self",
".",
"assertRaises",
"(",
"SuspiciousOperation",
",",
"self",
".",
"storage",
".",
"exists",
",",
"'..'",
")",
"self",
".",
"assertRaises",
"(",
"SuspiciousOperation",
",",
"se... | [
291,
4
] | [
297,
82
] | python | en | ['en', 'error', 'th'] | False |
FileStorageTests.test_file_storage_preserves_filename_case | (self) | The storage backend should preserve case of filenames. | The storage backend should preserve case of filenames. | def test_file_storage_preserves_filename_case(self):
"""The storage backend should preserve case of filenames."""
# Create a storage backend associated with the mixed case name
# directory.
other_temp_storage = self.storage_class(location=self.temp_dir2)
# Ask that storage backen... | [
"def",
"test_file_storage_preserves_filename_case",
"(",
"self",
")",
":",
"# Create a storage backend associated with the mixed case name",
"# directory.",
"other_temp_storage",
"=",
"self",
".",
"storage_class",
"(",
"location",
"=",
"self",
".",
"temp_dir2",
")",
"# Ask th... | [
299,
4
] | [
311,
45
] | python | en | ['en', 'en', 'en'] | True |
FileStorageTests.test_makedirs_race_handling | (self) |
File storage should be robust against directory creation race conditions.
|
File storage should be robust against directory creation race conditions.
| def test_makedirs_race_handling(self):
"""
File storage should be robust against directory creation race conditions.
"""
real_makedirs = os.makedirs
# Monkey-patch os.makedirs, to simulate a normal call, a raced call,
# and an error.
def fake_makedirs(path):
... | [
"def",
"test_makedirs_race_handling",
"(",
"self",
")",
":",
"real_makedirs",
"=",
"os",
".",
"makedirs",
"# Monkey-patch os.makedirs, to simulate a normal call, a raced call,",
"# and an error.",
"def",
"fake_makedirs",
"(",
"path",
")",
":",
"if",
"path",
"==",
"os",
... | [
313,
4
] | [
349,
39
] | python | en | ['en', 'error', 'th'] | False |
FileStorageTests.test_remove_race_handling | (self) |
File storage should be robust against file removal race conditions.
|
File storage should be robust against file removal race conditions.
| def test_remove_race_handling(self):
"""
File storage should be robust against file removal race conditions.
"""
real_remove = os.remove
# Monkey-patch os.remove, to simulate a normal call, a raced call,
# and an error.
def fake_remove(path):
if path ... | [
"def",
"test_remove_race_handling",
"(",
"self",
")",
":",
"real_remove",
"=",
"os",
".",
"remove",
"# Monkey-patch os.remove, to simulate a normal call, a raced call,",
"# and an error.",
"def",
"fake_remove",
"(",
"path",
")",
":",
"if",
"path",
"==",
"os",
".",
"pa... | [
351,
4
] | [
385,
35
] | python | en | ['en', 'error', 'th'] | False |
FileStorageTests.test_file_chunks_error | (self) |
Test behavior when file.chunks() is raising an error
|
Test behavior when file.chunks() is raising an error
| def test_file_chunks_error(self):
"""
Test behavior when file.chunks() is raising an error
"""
f1 = ContentFile('chunks fails')
def failing_chunks():
raise IOError
f1.chunks = failing_chunks
with self.assertRaises(IOError):
self.storage.sa... | [
"def",
"test_file_chunks_error",
"(",
"self",
")",
":",
"f1",
"=",
"ContentFile",
"(",
"'chunks fails'",
")",
"def",
"failing_chunks",
"(",
")",
":",
"raise",
"IOError",
"f1",
".",
"chunks",
"=",
"failing_chunks",
"with",
"self",
".",
"assertRaises",
"(",
"I... | [
387,
4
] | [
397,
47
] | python | en | ['en', 'error', 'th'] | False |
FileStorageTests.test_delete_no_name | (self) |
Calling delete with an empty name should not try to remove the base
storage directory, but fail loudly (#20660).
|
Calling delete with an empty name should not try to remove the base
storage directory, but fail loudly (#20660).
| def test_delete_no_name(self):
"""
Calling delete with an empty name should not try to remove the base
storage directory, but fail loudly (#20660).
"""
with self.assertRaises(AssertionError):
self.storage.delete('') | [
"def",
"test_delete_no_name",
"(",
"self",
")",
":",
"with",
"self",
".",
"assertRaises",
"(",
"AssertionError",
")",
":",
"self",
".",
"storage",
".",
"delete",
"(",
"''",
")"
] | [
399,
4
] | [
405,
35
] | python | en | ['en', 'error', 'th'] | False |
CustomStorage.get_available_name | (self, name) |
Append numbers to duplicate files rather than underscores, like Trac.
|
Append numbers to duplicate files rather than underscores, like Trac.
| def get_available_name(self, name):
"""
Append numbers to duplicate files rather than underscores, like Trac.
"""
parts = name.split('.')
basename, ext = parts[0], parts[1:]
number = 2
while self.exists(name):
name = '.'.join([basename, str(number)] + ... | [
"def",
"get_available_name",
"(",
"self",
",",
"name",
")",
":",
"parts",
"=",
"name",
".",
"split",
"(",
"'.'",
")",
"basename",
",",
"ext",
"=",
"parts",
"[",
"0",
"]",
",",
"parts",
"[",
"1",
":",
"]",
"number",
"=",
"2",
"while",
"self",
".",... | [
409,
4
] | [
420,
19
] | python | en | ['en', 'error', 'th'] | False |
FileStoragePathParsing.test_directory_with_dot | (self) | Regression test for #9610.
If the directory name contains a dot and the file name doesn't, make
sure we still mangle the file name instead of the directory name.
| Regression test for #9610. | def test_directory_with_dot(self):
"""Regression test for #9610.
If the directory name contains a dot and the file name doesn't, make
sure we still mangle the file name instead of the directory name.
"""
self.storage.save('dotted.path/test', ContentFile("1"))
self.stora... | [
"def",
"test_directory_with_dot",
"(",
"self",
")",
":",
"self",
".",
"storage",
".",
"save",
"(",
"'dotted.path/test'",
",",
"ContentFile",
"(",
"\"1\"",
")",
")",
"self",
".",
"storage",
".",
"save",
"(",
"'dotted.path/test'",
",",
"ContentFile",
"(",
"\"2... | [
648,
4
] | [
661,
70
] | python | en | ['en', 'en', 'en'] | True |
FileStoragePathParsing.test_first_character_dot | (self) |
File names with a dot as their first character don't have an extension,
and the underscore should get added to the end.
|
File names with a dot as their first character don't have an extension,
and the underscore should get added to the end.
| def test_first_character_dot(self):
"""
File names with a dot as their first character don't have an extension,
and the underscore should get added to the end.
"""
self.storage.save('dotted.path/.test', ContentFile("1"))
self.storage.save('dotted.path/.test', ContentFile(... | [
"def",
"test_first_character_dot",
"(",
"self",
")",
":",
"self",
".",
"storage",
".",
"save",
"(",
"'dotted.path/.test'",
",",
"ContentFile",
"(",
"\"1\"",
")",
")",
"self",
".",
"storage",
".",
"save",
"(",
"'dotted.path/.test'",
",",
"ContentFile",
"(",
"... | [
663,
4
] | [
674,
71
] | python | en | ['en', 'error', 'th'] | False |
ContentFileStorageTestCase.test_content_saving | (self) |
Test that ContentFile can be saved correctly with the filesystem storage,
both if it was initialized with string or unicode content |
Test that ContentFile can be saved correctly with the filesystem storage,
both if it was initialized with string or unicode content | def test_content_saving(self):
"""
Test that ContentFile can be saved correctly with the filesystem storage,
both if it was initialized with string or unicode content"""
self.storage.save('bytes.txt', ContentFile(b"content"))
self.storage.save('unicode.txt', ContentFile("español"... | [
"def",
"test_content_saving",
"(",
"self",
")",
":",
"self",
".",
"storage",
".",
"save",
"(",
"'bytes.txt'",
",",
"ContentFile",
"(",
"b\"content\"",
")",
")",
"self",
".",
"storage",
".",
"save",
"(",
"'unicode.txt'",
",",
"ContentFile",
"(",
"\"español\")... | [
686,
4
] | [
691,
65
] | python | en | ['en', 'error', 'th'] | False |
VendorImporter.search_path | (self) |
Search first the vendor package then as a natural package.
|
Search first the vendor package then as a natural package.
| def search_path(self):
"""
Search first the vendor package then as a natural package.
"""
yield self.vendor_pkg + '.'
yield '' | [
"def",
"search_path",
"(",
"self",
")",
":",
"yield",
"self",
".",
"vendor_pkg",
"+",
"'.'",
"yield",
"''"
] | [
15,
4
] | [
20,
16
] | python | en | ['en', 'error', 'th'] | False |
VendorImporter.find_module | (self, fullname, path=None) |
Return self when fullname starts with root_name and the
target module is one vendored through this importer.
|
Return self when fullname starts with root_name and the
target module is one vendored through this importer.
| def find_module(self, fullname, path=None):
"""
Return self when fullname starts with root_name and the
target module is one vendored through this importer.
"""
root, base, target = fullname.partition(self.root_name + '.')
if root:
return
if not any(ma... | [
"def",
"find_module",
"(",
"self",
",",
"fullname",
",",
"path",
"=",
"None",
")",
":",
"root",
",",
"base",
",",
"target",
"=",
"fullname",
".",
"partition",
"(",
"self",
".",
"root_name",
"+",
"'.'",
")",
"if",
"root",
":",
"return",
"if",
"not",
... | [
22,
4
] | [
32,
19
] | python | en | ['en', 'error', 'th'] | False |
VendorImporter.load_module | (self, fullname) |
Iterate over the search path to locate and load fullname.
|
Iterate over the search path to locate and load fullname.
| def load_module(self, fullname):
"""
Iterate over the search path to locate and load fullname.
"""
root, base, target = fullname.partition(self.root_name + '.')
for prefix in self.search_path:
try:
extant = prefix + target
__import__(ex... | [
"def",
"load_module",
"(",
"self",
",",
"fullname",
")",
":",
"root",
",",
"base",
",",
"target",
"=",
"fullname",
".",
"partition",
"(",
"self",
".",
"root_name",
"+",
"'.'",
")",
"for",
"prefix",
"in",
"self",
".",
"search_path",
":",
"try",
":",
"... | [
34,
4
] | [
54,
13
] | python | en | ['en', 'error', 'th'] | False |
VendorImporter.install | (self) |
Install this importer into sys.meta_path if not already present.
|
Install this importer into sys.meta_path if not already present.
| def install(self):
"""
Install this importer into sys.meta_path if not already present.
"""
if self not in sys.meta_path:
sys.meta_path.append(self) | [
"def",
"install",
"(",
"self",
")",
":",
"if",
"self",
"not",
"in",
"sys",
".",
"meta_path",
":",
"sys",
".",
"meta_path",
".",
"append",
"(",
"self",
")"
] | [
56,
4
] | [
61,
38
] | python | en | ['en', 'error', 'th'] | False |
check_emoji_admin | (user_profile: UserProfile, emoji_name: Optional[str] = None) | Raises an exception if the user cannot administer the target realm
emoji name in their organization. | Raises an exception if the user cannot administer the target realm
emoji name in their organization. | def check_emoji_admin(user_profile: UserProfile, emoji_name: Optional[str] = None) -> None:
"""Raises an exception if the user cannot administer the target realm
emoji name in their organization."""
# Realm administrators can always administer emoji
if user_profile.is_realm_admin:
return
if... | [
"def",
"check_emoji_admin",
"(",
"user_profile",
":",
"UserProfile",
",",
"emoji_name",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"None",
":",
"# Realm administrators can always administer emoji",
"if",
"user_profile",
".",
"is_realm_admin",
":",
"re... | [
87,
0
] | [
109,
87
] | python | en | ['en', 'en', 'en'] | True |
FormsRegressionsTestCase.test_regression_14234 | (self) |
Re-cleaning an instance that was added via a ModelForm should not raise
a pk uniqueness error.
|
Re-cleaning an instance that was added via a ModelForm should not raise
a pk uniqueness error. | def test_regression_14234(self):
"""
Re-cleaning an instance that was added via a ModelForm should not raise
a pk uniqueness error.
"""
class CheeseForm(ModelForm):
class Meta:
model = Cheese
fields = '__all__'
form = CheeseFo... | [
"def",
"test_regression_14234",
"(",
"self",
")",
":",
"class",
"CheeseForm",
"(",
"ModelForm",
")",
":",
"class",
"Meta",
":",
"model",
"=",
"Cheese",
"fields",
"=",
"'__all__'",
"form",
"=",
"CheeseForm",
"(",
"{",
"'name'",
":",
"'Brie'",
",",
"}",
")... | [
135,
4
] | [
154,
24
] | python | en | ['en', 'error', 'th'] | False |
TestUtilsText.test_normalize_newlines_bytes | (self) | normalize_newlines should be able to handle bytes too | normalize_newlines should be able to handle bytes too | def test_normalize_newlines_bytes(self):
"""normalize_newlines should be able to handle bytes too"""
normalized = text.normalize_newlines(b"abc\ndef\rghi\r\n")
self.assertEqual(normalized, "abc\ndef\nghi\n")
self.assertIsInstance(normalized, six.text_type) | [
"def",
"test_normalize_newlines_bytes",
"(",
"self",
")",
":",
"normalized",
"=",
"text",
".",
"normalize_newlines",
"(",
"b\"abc\\ndef\\rghi\\r\\n\"",
")",
"self",
".",
"assertEqual",
"(",
"normalized",
",",
"\"abc\\ndef\\nghi\\n\"",
")",
"self",
".",
"assertIsInstan... | [
168,
4
] | [
172,
56
] | python | en | ['en', 'en', 'en'] | True |
fast_gradient_method | (
model_fn,
x,
eps,
norm,
loss_fn=None,
clip_min=None,
clip_max=None,
y=None,
targeted=False,
sanity_checks=False,
) |
Tensorflow 2.0 implementation of the Fast Gradient Method.
:param model_fn: a callable that takes an input tensor and returns the model logits.
:param x: input tensor.
:param eps: epsilon (input variation parameter); see https://arxiv.org/abs/1412.6572.
:param norm: Order of the norm (mimics NumPy)... |
Tensorflow 2.0 implementation of the Fast Gradient Method.
:param model_fn: a callable that takes an input tensor and returns the model logits.
:param x: input tensor.
:param eps: epsilon (input variation parameter); see https://arxiv.org/abs/1412.6572.
:param norm: Order of the norm (mimics NumPy)... | def fast_gradient_method(
model_fn,
x,
eps,
norm,
loss_fn=None,
clip_min=None,
clip_max=None,
y=None,
targeted=False,
sanity_checks=False,
):
"""
Tensorflow 2.0 implementation of the Fast Gradient Method.
:param model_fn: a callable that takes an input tensor and retu... | [
"def",
"fast_gradient_method",
"(",
"model_fn",
",",
"x",
",",
"eps",
",",
"norm",
",",
"loss_fn",
"=",
"None",
",",
"clip_min",
"=",
"None",
",",
"clip_max",
"=",
"None",
",",
"y",
"=",
"None",
",",
"targeted",
"=",
"False",
",",
"sanity_checks",
"=",... | [
8,
0
] | [
78,
16
] | python | en | ['en', 'error', 'th'] | False |
Layer.__init__ | (self, layer_ptr, ds) |
Initialize on an OGR C pointer to the Layer and the `DataSource` object
that owns this layer. The `DataSource` object is required so that a
reference to it is kept with this Layer. This prevents garbage
collection of the `DataSource` while this Layer is still active.
|
Initialize on an OGR C pointer to the Layer and the `DataSource` object
that owns this layer. The `DataSource` object is required so that a
reference to it is kept with this Layer. This prevents garbage
collection of the `DataSource` while this Layer is still active.
| def __init__(self, layer_ptr, ds):
"""
Initialize on an OGR C pointer to the Layer and the `DataSource` object
that owns this layer. The `DataSource` object is required so that a
reference to it is kept with this Layer. This prevents garbage
collection of the `DataSource` while... | [
"def",
"__init__",
"(",
"self",
",",
"layer_ptr",
",",
"ds",
")",
":",
"if",
"not",
"layer_ptr",
":",
"raise",
"GDALException",
"(",
"'Cannot create Layer, invalid pointer given'",
")",
"self",
".",
"ptr",
"=",
"layer_ptr",
"self",
".",
"_ds",
"=",
"ds",
"se... | [
23,
4
] | [
36,
63
] | python | en | ['en', 'error', 'th'] | False |
Layer.__getitem__ | (self, index) | Get the Feature at the specified index. | Get the Feature at the specified index. | def __getitem__(self, index):
"Get the Feature at the specified index."
if isinstance(index, int):
# An integer index was given -- we cannot do a check based on the
# number of features because the beginning and ending feature IDs
# are not guaranteed to be 0 and len(... | [
"def",
"__getitem__",
"(",
"self",
",",
"index",
")",
":",
"if",
"isinstance",
"(",
"index",
",",
"int",
")",
":",
"# An integer index was given -- we cannot do a check based on the",
"# number of features because the beginning and ending feature IDs",
"# are not guaranteed to be... | [
38,
4
] | [
52,
93
] | python | en | ['en', 'en', 'en'] | True |
Layer.__iter__ | (self) | Iterate over each Feature in the Layer. | Iterate over each Feature in the Layer. | def __iter__(self):
"Iterate over each Feature in the Layer."
# ResetReading() must be called before iteration is to begin.
capi.reset_reading(self._ptr)
for i in range(self.num_feat):
yield Feature(capi.get_next_feature(self._ptr), self) | [
"def",
"__iter__",
"(",
"self",
")",
":",
"# ResetReading() must be called before iteration is to begin.",
"capi",
".",
"reset_reading",
"(",
"self",
".",
"_ptr",
")",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"num_feat",
")",
":",
"yield",
"Feature",
"(",
... | [
54,
4
] | [
59,
65
] | python | en | ['en', 'en', 'en'] | True |
Layer.__len__ | (self) | The length is the number of features. | The length is the number of features. | def __len__(self):
"The length is the number of features."
return self.num_feat | [
"def",
"__len__",
"(",
"self",
")",
":",
"return",
"self",
".",
"num_feat"
] | [
61,
4
] | [
63,
28
] | python | en | ['en', 'en', 'en'] | True |
Layer.__str__ | (self) | The string name of the layer. | The string name of the layer. | def __str__(self):
"The string name of the layer."
return self.name | [
"def",
"__str__",
"(",
"self",
")",
":",
"return",
"self",
".",
"name"
] | [
65,
4
] | [
67,
24
] | python | en | ['en', 'en', 'en'] | True |
Layer._make_feature | (self, feat_id) |
Helper routine for __getitem__ that constructs a Feature from the given
Feature ID. If the OGR Layer does not support random-access reading,
then each feature of the layer will be incremented through until the
a Feature is found matching the given feature ID.
|
Helper routine for __getitem__ that constructs a Feature from the given
Feature ID. If the OGR Layer does not support random-access reading,
then each feature of the layer will be incremented through until the
a Feature is found matching the given feature ID.
| def _make_feature(self, feat_id):
"""
Helper routine for __getitem__ that constructs a Feature from the given
Feature ID. If the OGR Layer does not support random-access reading,
then each feature of the layer will be incremented through until the
a Feature is found matching the... | [
"def",
"_make_feature",
"(",
"self",
",",
"feat_id",
")",
":",
"if",
"self",
".",
"_random_read",
":",
"# If the Layer supports random reading, return.",
"try",
":",
"return",
"Feature",
"(",
"capi",
".",
"get_feature",
"(",
"self",
".",
"ptr",
",",
"feat_id",
... | [
69,
4
] | [
89,
61
] | python | en | ['en', 'error', 'th'] | False |
Layer.extent | (self) | Return the extent (an Envelope) of this layer. | Return the extent (an Envelope) of this layer. | def extent(self):
"Return the extent (an Envelope) of this layer."
env = OGREnvelope()
capi.get_extent(self.ptr, byref(env), 1)
return Envelope(env) | [
"def",
"extent",
"(",
"self",
")",
":",
"env",
"=",
"OGREnvelope",
"(",
")",
"capi",
".",
"get_extent",
"(",
"self",
".",
"ptr",
",",
"byref",
"(",
"env",
")",
",",
"1",
")",
"return",
"Envelope",
"(",
"env",
")"
] | [
93,
4
] | [
97,
28
] | python | en | ['en', 'en', 'en'] | True |
Layer.name | (self) | Return the name of this layer in the Data Source. | Return the name of this layer in the Data Source. | def name(self):
"Return the name of this layer in the Data Source."
name = capi.get_fd_name(self._ldefn)
return force_str(name, self._ds.encoding, strings_only=True) | [
"def",
"name",
"(",
"self",
")",
":",
"name",
"=",
"capi",
".",
"get_fd_name",
"(",
"self",
".",
"_ldefn",
")",
"return",
"force_str",
"(",
"name",
",",
"self",
".",
"_ds",
".",
"encoding",
",",
"strings_only",
"=",
"True",
")"
] | [
100,
4
] | [
103,
68
] | python | en | ['en', 'en', 'en'] | True |
Layer.num_feat | (self, force=1) | Return the number of features in the Layer. | Return the number of features in the Layer. | def num_feat(self, force=1):
"Return the number of features in the Layer."
return capi.get_feature_count(self.ptr, force) | [
"def",
"num_feat",
"(",
"self",
",",
"force",
"=",
"1",
")",
":",
"return",
"capi",
".",
"get_feature_count",
"(",
"self",
".",
"ptr",
",",
"force",
")"
] | [
106,
4
] | [
108,
54
] | python | en | ['en', 'en', 'en'] | True |
Layer.num_fields | (self) | Return the number of fields in the Layer. | Return the number of fields in the Layer. | def num_fields(self):
"Return the number of fields in the Layer."
return capi.get_field_count(self._ldefn) | [
"def",
"num_fields",
"(",
"self",
")",
":",
"return",
"capi",
".",
"get_field_count",
"(",
"self",
".",
"_ldefn",
")"
] | [
111,
4
] | [
113,
48
] | python | en | ['en', 'en', 'en'] | True |
Layer.geom_type | (self) | Return the geometry type (OGRGeomType) of the Layer. | Return the geometry type (OGRGeomType) of the Layer. | def geom_type(self):
"Return the geometry type (OGRGeomType) of the Layer."
return OGRGeomType(capi.get_fd_geom_type(self._ldefn)) | [
"def",
"geom_type",
"(",
"self",
")",
":",
"return",
"OGRGeomType",
"(",
"capi",
".",
"get_fd_geom_type",
"(",
"self",
".",
"_ldefn",
")",
")"
] | [
116,
4
] | [
118,
62
] | python | en | ['en', 'en', 'en'] | True |
Layer.srs | (self) | Return the Spatial Reference used in this Layer. | Return the Spatial Reference used in this Layer. | def srs(self):
"Return the Spatial Reference used in this Layer."
try:
ptr = capi.get_layer_srs(self.ptr)
return SpatialReference(srs_api.clone_srs(ptr))
except SRSException:
return None | [
"def",
"srs",
"(",
"self",
")",
":",
"try",
":",
"ptr",
"=",
"capi",
".",
"get_layer_srs",
"(",
"self",
".",
"ptr",
")",
"return",
"SpatialReference",
"(",
"srs_api",
".",
"clone_srs",
"(",
"ptr",
")",
")",
"except",
"SRSException",
":",
"return",
"Non... | [
121,
4
] | [
127,
23
] | python | en | ['en', 'en', 'en'] | True |
Layer.fields | (self) |
Return a list of string names corresponding to each of the Fields
available in this Layer.
|
Return a list of string names corresponding to each of the Fields
available in this Layer.
| def fields(self):
"""
Return a list of string names corresponding to each of the Fields
available in this Layer.
"""
return [force_str(
capi.get_field_name(capi.get_field_defn(self._ldefn, i)),
self._ds.encoding, strings_only=True,
) for i in range... | [
"def",
"fields",
"(",
"self",
")",
":",
"return",
"[",
"force_str",
"(",
"capi",
".",
"get_field_name",
"(",
"capi",
".",
"get_field_defn",
"(",
"self",
".",
"_ldefn",
",",
"i",
")",
")",
",",
"self",
".",
"_ds",
".",
"encoding",
",",
"strings_only",
... | [
130,
4
] | [
138,
42
] | python | en | ['en', 'error', 'th'] | False |
Layer.field_types | (self) |
Return a list of the types of fields in this Layer. For example,
return the list [OFTInteger, OFTReal, OFTString] for an OGR layer that
has an integer, a floating-point, and string fields.
|
Return a list of the types of fields in this Layer. For example,
return the list [OFTInteger, OFTReal, OFTString] for an OGR layer that
has an integer, a floating-point, and string fields.
| def field_types(self):
"""
Return a list of the types of fields in this Layer. For example,
return the list [OFTInteger, OFTReal, OFTString] for an OGR layer that
has an integer, a floating-point, and string fields.
"""
return [OGRFieldTypes[capi.get_field_type(capi.get_... | [
"def",
"field_types",
"(",
"self",
")",
":",
"return",
"[",
"OGRFieldTypes",
"[",
"capi",
".",
"get_field_type",
"(",
"capi",
".",
"get_field_defn",
"(",
"self",
".",
"_ldefn",
",",
"i",
")",
")",
"]",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"nu... | [
141,
4
] | [
148,
48
] | python | en | ['en', 'error', 'th'] | False |
Layer.field_widths | (self) | Return a list of the maximum field widths for the features. | Return a list of the maximum field widths for the features. | def field_widths(self):
"Return a list of the maximum field widths for the features."
return [capi.get_field_width(capi.get_field_defn(self._ldefn, i))
for i in range(self.num_fields)] | [
"def",
"field_widths",
"(",
"self",
")",
":",
"return",
"[",
"capi",
".",
"get_field_width",
"(",
"capi",
".",
"get_field_defn",
"(",
"self",
".",
"_ldefn",
",",
"i",
")",
")",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"num_fields",
")",
"]"
] | [
151,
4
] | [
154,
48
] | python | en | ['en', 'en', 'en'] | True |
Layer.field_precisions | (self) | Return the field precisions for the features. | Return the field precisions for the features. | def field_precisions(self):
"Return the field precisions for the features."
return [capi.get_field_precision(capi.get_field_defn(self._ldefn, i))
for i in range(self.num_fields)] | [
"def",
"field_precisions",
"(",
"self",
")",
":",
"return",
"[",
"capi",
".",
"get_field_precision",
"(",
"capi",
".",
"get_field_defn",
"(",
"self",
".",
"_ldefn",
",",
"i",
")",
")",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"num_fields",
")",
"]"... | [
157,
4
] | [
160,
48
] | python | en | ['en', 'en', 'en'] | True |
Layer.get_fields | (self, field_name) |
Return a list containing the given field name for every Feature
in the Layer.
|
Return a list containing the given field name for every Feature
in the Layer.
| def get_fields(self, field_name):
"""
Return a list containing the given field name for every Feature
in the Layer.
"""
if field_name not in self.fields:
raise GDALException('invalid field name: %s' % field_name)
return [feat.get(field_name) for feat in self] | [
"def",
"get_fields",
"(",
"self",
",",
"field_name",
")",
":",
"if",
"field_name",
"not",
"in",
"self",
".",
"fields",
":",
"raise",
"GDALException",
"(",
"'invalid field name: %s'",
"%",
"field_name",
")",
"return",
"[",
"feat",
".",
"get",
"(",
"field_name... | [
186,
4
] | [
193,
54
] | python | en | ['en', 'error', 'th'] | False |
Layer.get_geoms | (self, geos=False) |
Return a list containing the OGRGeometry for every Feature in
the Layer.
|
Return a list containing the OGRGeometry for every Feature in
the Layer.
| def get_geoms(self, geos=False):
"""
Return a list containing the OGRGeometry for every Feature in
the Layer.
"""
if geos:
from django.contrib.gis.geos import GEOSGeometry
return [GEOSGeometry(feat.geom.wkb) for feat in self]
else:
retu... | [
"def",
"get_geoms",
"(",
"self",
",",
"geos",
"=",
"False",
")",
":",
"if",
"geos",
":",
"from",
"django",
".",
"contrib",
".",
"gis",
".",
"geos",
"import",
"GEOSGeometry",
"return",
"[",
"GEOSGeometry",
"(",
"feat",
".",
"geom",
".",
"wkb",
")",
"f... | [
195,
4
] | [
204,
47
] | python | en | ['en', 'error', 'th'] | False |
Layer.test_capability | (self, capability) |
Return a bool indicating whether the this Layer supports the given
capability (a string). Valid capability strings include:
'RandomRead', 'SequentialWrite', 'RandomWrite', 'FastSpatialFilter',
'FastFeatureCount', 'FastGetExtent', 'CreateField', 'Transactions',
'DeleteFeat... |
Return a bool indicating whether the this Layer supports the given
capability (a string). Valid capability strings include:
'RandomRead', 'SequentialWrite', 'RandomWrite', 'FastSpatialFilter',
'FastFeatureCount', 'FastGetExtent', 'CreateField', 'Transactions',
'DeleteFeat... | def test_capability(self, capability):
"""
Return a bool indicating whether the this Layer supports the given
capability (a string). Valid capability strings include:
'RandomRead', 'SequentialWrite', 'RandomWrite', 'FastSpatialFilter',
'FastFeatureCount', 'FastGetExtent', 'C... | [
"def",
"test_capability",
"(",
"self",
",",
"capability",
")",
":",
"return",
"bool",
"(",
"capi",
".",
"test_capability",
"(",
"self",
".",
"ptr",
",",
"force_bytes",
"(",
"capability",
")",
")",
")"
] | [
206,
4
] | [
214,
76
] | python | en | ['en', 'error', 'th'] | False |
ChangeSettingsTest.test_successful_change_settings | (self) |
A call to /json/settings with valid parameters changes the user's
settings correctly and returns correct values.
|
A call to /json/settings with valid parameters changes the user's
settings correctly and returns correct values.
| def test_successful_change_settings(self) -> None:
"""
A call to /json/settings with valid parameters changes the user's
settings correctly and returns correct values.
"""
user = self.example_user("hamlet")
self.login_user(user)
json_result = self.client_patch(
... | [
"def",
"test_successful_change_settings",
"(",
"self",
")",
"->",
"None",
":",
"user",
"=",
"self",
".",
"example_user",
"(",
"\"hamlet\"",
")",
"self",
".",
"login_user",
"(",
"user",
")",
"json_result",
"=",
"self",
".",
"client_patch",
"(",
"\"/json/setting... | [
54,
4
] | [
90,
46
] | python | en | ['en', 'error', 'th'] | False |
ChangeSettingsTest.test_toggling_boolean_user_display_settings | (self) | Test updating each boolean setting in UserProfile property_types | Test updating each boolean setting in UserProfile property_types | def test_toggling_boolean_user_display_settings(self) -> None:
"""Test updating each boolean setting in UserProfile property_types"""
boolean_settings = (
s for s in UserProfile.property_types if UserProfile.property_types[s] is bool
)
for display_setting in boolean_settings:... | [
"def",
"test_toggling_boolean_user_display_settings",
"(",
"self",
")",
"->",
"None",
":",
"boolean_settings",
"=",
"(",
"s",
"for",
"s",
"in",
"UserProfile",
".",
"property_types",
"if",
"UserProfile",
".",
"property_types",
"[",
"s",
"]",
"is",
"bool",
")",
... | [
192,
4
] | [
198,
88
] | python | en | ['en', 'en', 'en'] | True |
ChangeSettingsTest.test_changing_nothing_returns_error | (self) |
We need to supply at least one non-empty parameter
to this API, or it should fail. (Eventually, we should
probably use a patch interface for these changes.)
|
We need to supply at least one non-empty parameter
to this API, or it should fail. (Eventually, we should
probably use a patch interface for these changes.)
| def test_changing_nothing_returns_error(self) -> None:
"""
We need to supply at least one non-empty parameter
to this API, or it should fail. (Eventually, we should
probably use a patch interface for these changes.)
"""
self.login("hamlet")
result = self.client_p... | [
"def",
"test_changing_nothing_returns_error",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"login",
"(",
"\"hamlet\"",
")",
"result",
"=",
"self",
".",
"client_patch",
"(",
"\"/json/settings\"",
",",
"dict",
"(",
"old_password",
"=",
"\"ignored\"",
")",
"... | [
324,
4
] | [
332,
69
] | python | en | ['en', 'error', 'th'] | False |
ChangeSettingsTest.test_change_user_display_setting | (self) | Test updating each non-boolean setting in UserProfile property_types | Test updating each non-boolean setting in UserProfile property_types | def test_change_user_display_setting(self) -> None:
"""Test updating each non-boolean setting in UserProfile property_types"""
user_settings = (
s for s in UserProfile.property_types if UserProfile.property_types[s] is not bool
)
for setting in user_settings:
self... | [
"def",
"test_change_user_display_setting",
"(",
"self",
")",
"->",
"None",
":",
"user_settings",
"=",
"(",
"s",
"for",
"s",
"in",
"UserProfile",
".",
"property_types",
"if",
"UserProfile",
".",
"property_types",
"[",
"s",
"]",
"is",
"not",
"bool",
")",
"for"... | [
374,
4
] | [
380,
61
] | python | en | ['en', 'en', 'en'] | True |
ChangeSettingsTest.test_emojiset | (self) | Test banned emojisets are not accepted. | Test banned emojisets are not accepted. | def test_emojiset(self) -> None:
"""Test banned emojisets are not accepted."""
banned_emojisets = ["apple", "emojione"]
valid_emojisets = ["google", "google-blob", "text", "twitter"]
for emojiset in banned_emojisets:
result = self.do_change_emojiset(emojiset)
sel... | [
"def",
"test_emojiset",
"(",
"self",
")",
"->",
"None",
":",
"banned_emojisets",
"=",
"[",
"\"apple\"",
",",
"\"emojione\"",
"]",
"valid_emojisets",
"=",
"[",
"\"google\"",
",",
"\"google-blob\"",
",",
"\"text\"",
",",
"\"twitter\"",
"]",
"for",
"emojiset",
"i... | [
388,
4
] | [
399,
44
] | python | en | ['en', 'en', 'en'] | True |
Command.get_new_strings | (
self, old_strings: Mapping[str, str], translation_strings: List[str], locale: str
) |
Missing strings are removed, new strings are added and already
translated strings are not touched.
|
Missing strings are removed, new strings are added and already
translated strings are not touched.
| def get_new_strings(
self, old_strings: Mapping[str, str], translation_strings: List[str], locale: str
) -> Dict[str, str]:
"""
Missing strings are removed, new strings are added and already
translated strings are not touched.
"""
new_strings = {} # Dict[str, str]
... | [
"def",
"get_new_strings",
"(",
"self",
",",
"old_strings",
":",
"Mapping",
"[",
"str",
",",
"str",
"]",
",",
"translation_strings",
":",
"List",
"[",
"str",
"]",
",",
"locale",
":",
"str",
")",
"->",
"Dict",
"[",
"str",
",",
"str",
"]",
":",
"new_str... | [
240,
4
] | [
263,
26
] | python | en | ['en', 'error', 'th'] | False |
fast_gradient_method | (
model_fn, x, eps, norm, clip_min=None, clip_max=None, y=None, targeted=False
) |
JAX implementation of the Fast Gradient Method.
:param model_fn: a callable that takes an input tensor and returns the model logits.
:param x: input tensor.
:param eps: epsilon (input variation parameter); see https://arxiv.org/abs/1412.6572.
:param norm: Order of the norm (mimics NumPy). Possible ... |
JAX implementation of the Fast Gradient Method.
:param model_fn: a callable that takes an input tensor and returns the model logits.
:param x: input tensor.
:param eps: epsilon (input variation parameter); see https://arxiv.org/abs/1412.6572.
:param norm: Order of the norm (mimics NumPy). Possible ... | def fast_gradient_method(
model_fn, x, eps, norm, clip_min=None, clip_max=None, y=None, targeted=False
):
"""
JAX implementation of the Fast Gradient Method.
:param model_fn: a callable that takes an input tensor and returns the model logits.
:param x: input tensor.
:param eps: epsilon (input va... | [
"def",
"fast_gradient_method",
"(",
"model_fn",
",",
"x",
",",
"eps",
",",
"norm",
",",
"clip_min",
"=",
"None",
",",
"clip_max",
"=",
"None",
",",
"y",
"=",
"None",
",",
"targeted",
"=",
"False",
")",
":",
"if",
"norm",
"not",
"in",
"[",
"np",
"."... | [
7,
0
] | [
68,
16
] | python | en | ['en', 'error', 'th'] | False |
ConditionalGetMiddleware.needs_etag | (self, response) | Return True if an ETag header should be added to response. | Return True if an ETag header should be added to response. | def needs_etag(self, response):
"""Return True if an ETag header should be added to response."""
cache_control_headers = cc_delim_re.split(response.get('Cache-Control', ''))
return all(header.lower() != 'no-store' for header in cache_control_headers) | [
"def",
"needs_etag",
"(",
"self",
",",
"response",
")",
":",
"cache_control_headers",
"=",
"cc_delim_re",
".",
"split",
"(",
"response",
".",
"get",
"(",
"'Cache-Control'",
",",
"''",
")",
")",
"return",
"all",
"(",
"header",
".",
"lower",
"(",
")",
"!="... | [
37,
4
] | [
40,
84
] | python | en | ['en', 'en', 'en'] | True |
paginator_number | (cl, i) |
Generate an individual page index link in a paginated list.
|
Generate an individual page index link in a paginated list.
| def paginator_number(cl, i):
"""
Generate an individual page index link in a paginated list.
"""
if i == DOT:
return '… '
elif i == cl.page_num:
return format_html('<span class="this-page">{}</span> ', i + 1)
else:
return format_html(
'<a href="{}"{}>{}</a> ',... | [
"def",
"paginator_number",
"(",
"cl",
",",
"i",
")",
":",
"if",
"i",
"==",
"DOT",
":",
"return",
"'… '",
"elif",
"i",
"==",
"cl",
".",
"page_num",
":",
"return",
"format_html",
"(",
"'<span class=\"this-page\">{}</span> '",
",",
"i",
"+",
"1",
")",
"else... | [
29,
0
] | [
43,
9
] | python | en | ['en', 'error', 'th'] | False |
pagination | (cl) |
Generate the series of links to the pages in a paginated list.
|
Generate the series of links to the pages in a paginated list.
| def pagination(cl):
"""
Generate the series of links to the pages in a paginated list.
"""
paginator, page_num = cl.paginator, cl.page_num
pagination_required = (not cl.show_all or not cl.can_show_all) and cl.multi_page
if not pagination_required:
page_range = []
else:
ON_EA... | [
"def",
"pagination",
"(",
"cl",
")",
":",
"paginator",
",",
"page_num",
"=",
"cl",
".",
"paginator",
",",
"cl",
".",
"page_num",
"pagination_required",
"=",
"(",
"not",
"cl",
".",
"show_all",
"or",
"not",
"cl",
".",
"can_show_all",
")",
"and",
"cl",
".... | [
46,
0
] | [
91,
5
] | python | en | ['en', 'error', 'th'] | False |
result_headers | (cl) |
Generate the list column headers.
|
Generate the list column headers.
| def result_headers(cl):
"""
Generate the list column headers.
"""
ordering_field_columns = cl.get_ordering_field_columns()
for i, field_name in enumerate(cl.list_display):
text, attr = label_for_field(
field_name, cl.model,
model_admin=cl.model_admin,
retu... | [
"def",
"result_headers",
"(",
"cl",
")",
":",
"ordering_field_columns",
"=",
"cl",
".",
"get_ordering_field_columns",
"(",
")",
"for",
"i",
",",
"field_name",
"in",
"enumerate",
"(",
"cl",
".",
"list_display",
")",
":",
"text",
",",
"attr",
"=",
"label_for_f... | [
104,
0
] | [
193,
9
] | python | en | ['en', 'error', 'th'] | False |
_coerce_field_name | (field_name, field_index) |
Coerce a field_name (which may be a callable) to a string.
|
Coerce a field_name (which may be a callable) to a string.
| def _coerce_field_name(field_name, field_index):
"""
Coerce a field_name (which may be a callable) to a string.
"""
if callable(field_name):
if field_name.__name__ == '<lambda>':
return 'lambda' + str(field_index)
else:
return field_name.__name__
return field_... | [
"def",
"_coerce_field_name",
"(",
"field_name",
",",
"field_index",
")",
":",
"if",
"callable",
"(",
"field_name",
")",
":",
"if",
"field_name",
".",
"__name__",
"==",
"'<lambda>'",
":",
"return",
"'lambda'",
"+",
"str",
"(",
"field_index",
")",
"else",
":",... | [
201,
0
] | [
210,
21
] | python | en | ['en', 'error', 'th'] | False |
items_for_result | (cl, result, form) |
Generate the actual list of data.
|
Generate the actual list of data.
| def items_for_result(cl, result, form):
"""
Generate the actual list of data.
"""
def link_in_col(is_first, field_name, cl):
if cl.list_display_links is None:
return False
if is_first and not cl.list_display_links:
return True
return field_name in cl.list... | [
"def",
"items_for_result",
"(",
"cl",
",",
"result",
",",
"form",
")",
":",
"def",
"link_in_col",
"(",
"is_first",
",",
"field_name",
",",
"cl",
")",
":",
"if",
"cl",
".",
"list_display_links",
"is",
"None",
":",
"return",
"False",
"if",
"is_first",
"and... | [
213,
0
] | [
297,
70
] | python | en | ['en', 'error', 'th'] | False |
result_list | (cl) |
Display the headers and data list together.
|
Display the headers and data list together.
| def result_list(cl):
"""
Display the headers and data list together.
"""
headers = list(result_headers(cl))
num_sorted_fields = 0
for h in headers:
if h['sortable'] and h['sorted']:
num_sorted_fields += 1
return {
'cl': cl,
'result_hidden_fields': list(res... | [
"def",
"result_list",
"(",
"cl",
")",
":",
"headers",
"=",
"list",
"(",
"result_headers",
"(",
"cl",
")",
")",
"num_sorted_fields",
"=",
"0",
"for",
"h",
"in",
"headers",
":",
"if",
"h",
"[",
"'sortable'",
"]",
"and",
"h",
"[",
"'sorted'",
"]",
":",
... | [
327,
0
] | [
342,
5
] | python | en | ['en', 'error', 'th'] | False |
date_hierarchy | (cl) |
Display the date hierarchy for date drill-down functionality.
|
Display the date hierarchy for date drill-down functionality.
| def date_hierarchy(cl):
"""
Display the date hierarchy for date drill-down functionality.
"""
if cl.date_hierarchy:
field_name = cl.date_hierarchy
year_field = '%s__year' % field_name
month_field = '%s__month' % field_name
day_field = '%s__day' % field_name
field_... | [
"def",
"date_hierarchy",
"(",
"cl",
")",
":",
"if",
"cl",
".",
"date_hierarchy",
":",
"field_name",
"=",
"cl",
".",
"date_hierarchy",
"year_field",
"=",
"'%s__year'",
"%",
"field_name",
"month_field",
"=",
"'%s__month'",
"%",
"field_name",
"day_field",
"=",
"'... | [
355,
0
] | [
427,
13
] | python | en | ['en', 'error', 'th'] | False |
search_form | (cl) |
Display a search form for searching the list.
|
Display a search form for searching the list.
| def search_form(cl):
"""
Display a search form for searching the list.
"""
return {
'cl': cl,
'show_result_count': cl.result_count != cl.full_result_count,
'search_var': SEARCH_VAR
} | [
"def",
"search_form",
"(",
"cl",
")",
":",
"return",
"{",
"'cl'",
":",
"cl",
",",
"'show_result_count'",
":",
"cl",
".",
"result_count",
"!=",
"cl",
".",
"full_result_count",
",",
"'search_var'",
":",
"SEARCH_VAR",
"}"
] | [
440,
0
] | [
448,
5
] | python | en | ['en', 'error', 'th'] | False |
admin_actions | (context) |
Track the number of times the action field has been rendered on the page,
so we know which value to use.
|
Track the number of times the action field has been rendered on the page,
so we know which value to use.
| def admin_actions(context):
"""
Track the number of times the action field has been rendered on the page,
so we know which value to use.
"""
context['action_index'] = context.get('action_index', -1) + 1
return context | [
"def",
"admin_actions",
"(",
"context",
")",
":",
"context",
"[",
"'action_index'",
"]",
"=",
"context",
".",
"get",
"(",
"'action_index'",
",",
"-",
"1",
")",
"+",
"1",
"return",
"context"
] | [
466,
0
] | [
472,
18
] | python | en | ['en', 'error', 'th'] | False |
change_list_object_tools_tag | (parser, token) | Display the row of change list object tools. | Display the row of change list object tools. | def change_list_object_tools_tag(parser, token):
"""Display the row of change list object tools."""
return InclusionAdminNode(
parser, token,
func=lambda context: context,
template_name='change_list_object_tools.html',
) | [
"def",
"change_list_object_tools_tag",
"(",
"parser",
",",
"token",
")",
":",
"return",
"InclusionAdminNode",
"(",
"parser",
",",
"token",
",",
"func",
"=",
"lambda",
"context",
":",
"context",
",",
"template_name",
"=",
"'change_list_object_tools.html'",
",",
")"... | [
481,
0
] | [
487,
5
] | python | en | ['en', 'en', 'en'] | True |
space_resource_type | () |
A ResourceType denoting a space
|
A ResourceType denoting a space
| def space_resource_type():
"""
A ResourceType denoting a space
"""
return ResourceType.objects.get_or_create(id="test_space", name="test_space", main_type="space")[0] | [
"def",
"space_resource_type",
"(",
")",
":",
"return",
"ResourceType",
".",
"objects",
".",
"get_or_create",
"(",
"id",
"=",
"\"test_space\"",
",",
"name",
"=",
"\"test_space\"",
",",
"main_type",
"=",
"\"space\"",
")",
"[",
"0",
"]"
] | [
9,
0
] | [
13,
103
] | python | en | ['en', 'error', 'th'] | False |
space_resource | (space_resource_type) |
An arbitrary space resource
|
An arbitrary space resource
| def space_resource(space_resource_type):
"""
An arbitrary space resource
"""
unit = Unit.objects.create(name='unit 1')
return Resource.objects.create(
unit=unit, type=space_resource_type, authentication="none", name="resource"
) | [
"def",
"space_resource",
"(",
"space_resource_type",
")",
":",
"unit",
"=",
"Unit",
".",
"objects",
".",
"create",
"(",
"name",
"=",
"'unit 1'",
")",
"return",
"Resource",
".",
"objects",
".",
"create",
"(",
"unit",
"=",
"unit",
",",
"type",
"=",
"space_... | [
18,
0
] | [
25,
5
] | python | en | ['en', 'error', 'th'] | False |
exchange | () |
An Exchange configuration for testing
|
An Exchange configuration for testing
| def exchange():
"""
An Exchange configuration for testing
"""
return ExchangeConfiguration.objects.create(
url="https://127.0.0.1:8000/%s.asmx" % get_random_string(),
password=get_random_string(),
username=get_random_string(),
) | [
"def",
"exchange",
"(",
")",
":",
"return",
"ExchangeConfiguration",
".",
"objects",
".",
"create",
"(",
"url",
"=",
"\"https://127.0.0.1:8000/%s.asmx\"",
"%",
"get_random_string",
"(",
")",
",",
"password",
"=",
"get_random_string",
"(",
")",
",",
"username",
"... | [
30,
0
] | [
38,
5
] | python | en | ['en', 'error', 'th'] | False |
get_wsgi_application | () |
The public interface to Django's WSGI support. Should return a WSGI
callable.
Allows us to avoid making django.core.handlers.WSGIHandler public API, in
case the internal WSGI implementation changes or moves in the future.
|
The public interface to Django's WSGI support. Should return a WSGI
callable. | def get_wsgi_application():
"""
The public interface to Django's WSGI support. Should return a WSGI
callable.
Allows us to avoid making django.core.handlers.WSGIHandler public API, in
case the internal WSGI implementation changes or moves in the future.
"""
django.setup()
return WSGIHa... | [
"def",
"get_wsgi_application",
"(",
")",
":",
"django",
".",
"setup",
"(",
")",
"return",
"WSGIHandler",
"(",
")"
] | [
4,
0
] | [
14,
24
] | python | en | ['en', 'error', 'th'] | False |
get_path_info | (environ) |
Returns the HTTP request's PATH_INFO as a unicode string.
|
Returns the HTTP request's PATH_INFO as a unicode string.
| def get_path_info(environ):
"""
Returns the HTTP request's PATH_INFO as a unicode string.
"""
path_info = get_bytes_from_wsgi(environ, 'PATH_INFO', '/')
# It'd be better to implement URI-to-IRI decoding, see #19508.
return path_info.decode(UTF_8) | [
"def",
"get_path_info",
"(",
"environ",
")",
":",
"path_info",
"=",
"get_bytes_from_wsgi",
"(",
"environ",
",",
"'PATH_INFO'",
",",
"'/'",
")",
"# It'd be better to implement URI-to-IRI decoding, see #19508.",
"return",
"path_info",
".",
"decode",
"(",
"UTF_8",
")"
] | [
202,
0
] | [
209,
34
] | python | en | ['en', 'error', 'th'] | False |
get_script_name | (environ) |
Returns the equivalent of the HTTP request's SCRIPT_NAME environment
variable. If Apache mod_rewrite has been used, returns what would have been
the script name prior to any rewriting (so it's the script name as seen
from the client's perspective), unless the FORCE_SCRIPT_NAME setting is
set (to an... |
Returns the equivalent of the HTTP request's SCRIPT_NAME environment
variable. If Apache mod_rewrite has been used, returns what would have been
the script name prior to any rewriting (so it's the script name as seen
from the client's perspective), unless the FORCE_SCRIPT_NAME setting is
set (to an... | def get_script_name(environ):
"""
Returns the equivalent of the HTTP request's SCRIPT_NAME environment
variable. If Apache mod_rewrite has been used, returns what would have been
the script name prior to any rewriting (so it's the script name as seen
from the client's perspective), unless the FORCE_... | [
"def",
"get_script_name",
"(",
"environ",
")",
":",
"if",
"settings",
".",
"FORCE_SCRIPT_NAME",
"is",
"not",
"None",
":",
"return",
"force_text",
"(",
"settings",
".",
"FORCE_SCRIPT_NAME",
")",
"# If Apache's mod_rewrite had a whack at the URL, Apache set either",
"# SCRI... | [
212,
0
] | [
239,
36
] | python | en | ['en', 'error', 'th'] | False |
get_bytes_from_wsgi | (environ, key, default) |
Get a value from the WSGI environ dictionary as bytes.
key and default should be str objects. Under Python 2 they may also be
unicode objects provided they only contain ASCII characters.
|
Get a value from the WSGI environ dictionary as bytes. | def get_bytes_from_wsgi(environ, key, default):
"""
Get a value from the WSGI environ dictionary as bytes.
key and default should be str objects. Under Python 2 they may also be
unicode objects provided they only contain ASCII characters.
"""
value = environ.get(str(key), str(default))
# Un... | [
"def",
"get_bytes_from_wsgi",
"(",
"environ",
",",
"key",
",",
"default",
")",
":",
"value",
"=",
"environ",
".",
"get",
"(",
"str",
"(",
"key",
")",
",",
"str",
"(",
"default",
")",
")",
"# Under Python 3, non-ASCII values in the WSGI environ are arbitrarily",
... | [
242,
0
] | [
253,
57
] | python | en | ['en', 'error', 'th'] | False |
get_str_from_wsgi | (environ, key, default) |
Get a value from the WSGI environ dictionary as bytes.
key and default should be str objects. Under Python 2 they may also be
unicode objects provided they only contain ASCII characters.
|
Get a value from the WSGI environ dictionary as bytes. | def get_str_from_wsgi(environ, key, default):
"""
Get a value from the WSGI environ dictionary as bytes.
key and default should be str objects. Under Python 2 they may also be
unicode objects provided they only contain ASCII characters.
"""
value = environ.get(str(key), str(default))
# Same... | [
"def",
"get_str_from_wsgi",
"(",
"environ",
",",
"key",
",",
"default",
")",
":",
"value",
"=",
"environ",
".",
"get",
"(",
"str",
"(",
"key",
")",
",",
"str",
"(",
"default",
")",
")",
"# Same comment as above",
"return",
"value",
"if",
"six",
".",
"P... | [
256,
0
] | [
265,
71
] | python | en | ['en', 'error', 'th'] | False |
_string_concat | (*strings) |
Lazy variant of string concatenation, needed for translations that are
constructed from multiple parts.
|
Lazy variant of string concatenation, needed for translations that are
constructed from multiple parts.
| def _string_concat(*strings):
"""
Lazy variant of string concatenation, needed for translations that are
constructed from multiple parts.
"""
return ''.join(force_text(s) for s in strings) | [
"def",
"_string_concat",
"(",
"*",
"strings",
")",
":",
"return",
"''",
".",
"join",
"(",
"force_text",
"(",
"s",
")",
"for",
"s",
"in",
"strings",
")"
] | [
203,
0
] | [
208,
50
] | python | en | ['en', 'error', 'th'] | False |
SampleTestCase.testClassFixtures | (self) | Test cases can load fixture objects into models defined in packages | Test cases can load fixture objects into models defined in packages | def testClassFixtures(self):
"Test cases can load fixture objects into models defined in packages"
self.assertEqual(Article.objects.count(), 3)
self.assertQuerysetEqual(
Article.objects.all(), [
"Django conquers world!",
"Copyright is fine the way it i... | [
"def",
"testClassFixtures",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"Article",
".",
"objects",
".",
"count",
"(",
")",
",",
"3",
")",
"self",
".",
"assertQuerysetEqual",
"(",
"Article",
".",
"objects",
".",
"all",
"(",
")",
",",
"[",
... | [
16,
4
] | [
26,
9
] | python | en | ['en', 'en', 'en'] | True |
FixtureTestCase.test_initial_data | (self) | Fixtures can load initial data into models defined in packages | Fixtures can load initial data into models defined in packages | def test_initial_data(self):
"Fixtures can load initial data into models defined in packages"
# migrate introduces 1 initial data object from initial_data.json
# this behavior is deprecated and will be removed in Django 1.9
self.assertQuerysetEqual(
Book.objects.all(), [
... | [
"def",
"test_initial_data",
"(",
"self",
")",
":",
"# migrate introduces 1 initial data object from initial_data.json",
"# this behavior is deprecated and will be removed in Django 1.9",
"self",
".",
"assertQuerysetEqual",
"(",
"Book",
".",
"objects",
".",
"all",
"(",
")",
",",... | [
66,
4
] | [
75,
9
] | python | en | ['en', 'en', 'en'] | True |
FixtureTestCase.test_loaddata | (self) | Fixtures can load data into models defined in packages | Fixtures can load data into models defined in packages | def test_loaddata(self):
"Fixtures can load data into models defined in packages"
# Load fixture 1. Single JSON file, with two objects
management.call_command("loaddata", "fixture1.json", verbosity=0)
self.assertQuerysetEqual(
Article.objects.all(), [
"Time to... | [
"def",
"test_loaddata",
"(",
"self",
")",
":",
"# Load fixture 1. Single JSON file, with two objects",
"management",
".",
"call_command",
"(",
"\"loaddata\"",
",",
"\"fixture1.json\"",
",",
"verbosity",
"=",
"0",
")",
"self",
".",
"assertQuerysetEqual",
"(",
"Article",
... | [
77,
4
] | [
115,
9
] | python | en | ['en', 'en', 'en'] | True |
InitialSQLTests.test_custom_sql | (self) |
#14300 -- Verify that custom_sql_for_model searches `app/sql` and not
`app/models/sql` (the old location will work until Django 1.9)
|
#14300 -- Verify that custom_sql_for_model searches `app/sql` and not
`app/models/sql` (the old location will work until Django 1.9)
| def test_custom_sql(self):
"""
#14300 -- Verify that custom_sql_for_model searches `app/sql` and not
`app/models/sql` (the old location will work until Django 1.9)
"""
out = StringIO()
management.call_command("sqlcustom", "fixtures_model_package", stdout=out)
outp... | [
"def",
"test_custom_sql",
"(",
"self",
")",
":",
"out",
"=",
"StringIO",
"(",
")",
"management",
".",
"call_command",
"(",
"\"sqlcustom\"",
",",
"\"fixtures_model_package\"",
",",
"stdout",
"=",
"out",
")",
"output",
"=",
"out",
".",
"getvalue",
"(",
")",
... | [
120,
4
] | [
131,
52
] | python | en | ['en', 'error', 'th'] | False |
get_connection | (using=None) |
Get a database connection by name, or the default database connection
if no name is provided. This is a private API.
|
Get a database connection by name, or the default database connection
if no name is provided. This is a private API.
| def get_connection(using=None):
"""
Get a database connection by name, or the default database connection
if no name is provided. This is a private API.
"""
if using is None:
using = DEFAULT_DB_ALIAS
return connections[using] | [
"def",
"get_connection",
"(",
"using",
"=",
"None",
")",
":",
"if",
"using",
"is",
"None",
":",
"using",
"=",
"DEFAULT_DB_ALIAS",
"return",
"connections",
"[",
"using",
"]"
] | [
12,
0
] | [
19,
29
] | python | en | ['en', 'error', 'th'] | False |
get_autocommit | (using=None) | Get the autocommit status of the connection. | Get the autocommit status of the connection. | def get_autocommit(using=None):
"""Get the autocommit status of the connection."""
return get_connection(using).get_autocommit() | [
"def",
"get_autocommit",
"(",
"using",
"=",
"None",
")",
":",
"return",
"get_connection",
"(",
"using",
")",
".",
"get_autocommit",
"(",
")"
] | [
22,
0
] | [
24,
49
] | python | en | ['en', 'en', 'en'] | True |
set_autocommit | (autocommit, using=None) | Set the autocommit status of the connection. | Set the autocommit status of the connection. | def set_autocommit(autocommit, using=None):
"""Set the autocommit status of the connection."""
return get_connection(using).set_autocommit(autocommit) | [
"def",
"set_autocommit",
"(",
"autocommit",
",",
"using",
"=",
"None",
")",
":",
"return",
"get_connection",
"(",
"using",
")",
".",
"set_autocommit",
"(",
"autocommit",
")"
] | [
27,
0
] | [
29,
59
] | python | en | ['en', 'en', 'en'] | True |
commit | (using=None) | Commit a transaction. | Commit a transaction. | def commit(using=None):
"""Commit a transaction."""
get_connection(using).commit() | [
"def",
"commit",
"(",
"using",
"=",
"None",
")",
":",
"get_connection",
"(",
"using",
")",
".",
"commit",
"(",
")"
] | [
32,
0
] | [
34,
34
] | python | en | ['en', 'en', 'en'] | True |
rollback | (using=None) | Roll back a transaction. | Roll back a transaction. | def rollback(using=None):
"""Roll back a transaction."""
get_connection(using).rollback() | [
"def",
"rollback",
"(",
"using",
"=",
"None",
")",
":",
"get_connection",
"(",
"using",
")",
".",
"rollback",
"(",
")"
] | [
37,
0
] | [
39,
36
] | python | en | ['en', 'en', 'en'] | True |
savepoint | (using=None) |
Create a savepoint (if supported and required by the backend) inside the
current transaction. Return an identifier for the savepoint that will be
used for the subsequent rollback or commit.
|
Create a savepoint (if supported and required by the backend) inside the
current transaction. Return an identifier for the savepoint that will be
used for the subsequent rollback or commit.
| def savepoint(using=None):
"""
Create a savepoint (if supported and required by the backend) inside the
current transaction. Return an identifier for the savepoint that will be
used for the subsequent rollback or commit.
"""
return get_connection(using).savepoint() | [
"def",
"savepoint",
"(",
"using",
"=",
"None",
")",
":",
"return",
"get_connection",
"(",
"using",
")",
".",
"savepoint",
"(",
")"
] | [
42,
0
] | [
48,
44
] | python | en | ['en', 'error', 'th'] | False |
savepoint_rollback | (sid, using=None) |
Roll back the most recent savepoint (if one exists). Do nothing if
savepoints are not supported.
|
Roll back the most recent savepoint (if one exists). Do nothing if
savepoints are not supported.
| def savepoint_rollback(sid, using=None):
"""
Roll back the most recent savepoint (if one exists). Do nothing if
savepoints are not supported.
"""
get_connection(using).savepoint_rollback(sid) | [
"def",
"savepoint_rollback",
"(",
"sid",
",",
"using",
"=",
"None",
")",
":",
"get_connection",
"(",
"using",
")",
".",
"savepoint_rollback",
"(",
"sid",
")"
] | [
51,
0
] | [
56,
49
] | python | en | ['en', 'error', 'th'] | False |
savepoint_commit | (sid, using=None) |
Commit the most recent savepoint (if one exists). Do nothing if
savepoints are not supported.
|
Commit the most recent savepoint (if one exists). Do nothing if
savepoints are not supported.
| def savepoint_commit(sid, using=None):
"""
Commit the most recent savepoint (if one exists). Do nothing if
savepoints are not supported.
"""
get_connection(using).savepoint_commit(sid) | [
"def",
"savepoint_commit",
"(",
"sid",
",",
"using",
"=",
"None",
")",
":",
"get_connection",
"(",
"using",
")",
".",
"savepoint_commit",
"(",
"sid",
")"
] | [
59,
0
] | [
64,
47
] | python | en | ['en', 'error', 'th'] | False |
clean_savepoints | (using=None) |
Reset the counter used to generate unique savepoint ids in this thread.
|
Reset the counter used to generate unique savepoint ids in this thread.
| def clean_savepoints(using=None):
"""
Reset the counter used to generate unique savepoint ids in this thread.
"""
get_connection(using).clean_savepoints() | [
"def",
"clean_savepoints",
"(",
"using",
"=",
"None",
")",
":",
"get_connection",
"(",
"using",
")",
".",
"clean_savepoints",
"(",
")"
] | [
67,
0
] | [
71,
44
] | python | en | ['en', 'error', 'th'] | False |
get_rollback | (using=None) | Get the "needs rollback" flag -- for *advanced use* only. | Get the "needs rollback" flag -- for *advanced use* only. | def get_rollback(using=None):
"""Get the "needs rollback" flag -- for *advanced use* only."""
return get_connection(using).get_rollback() | [
"def",
"get_rollback",
"(",
"using",
"=",
"None",
")",
":",
"return",
"get_connection",
"(",
"using",
")",
".",
"get_rollback",
"(",
")"
] | [
74,
0
] | [
76,
47
] | python | en | ['en', 'en', 'en'] | True |
set_rollback | (rollback, using=None) |
Set or unset the "needs rollback" flag -- for *advanced use* only.
When `rollback` is `True`, trigger a rollback when exiting the innermost
enclosing atomic block that has `savepoint=True` (that's the default). Use
this to force a rollback without raising an exception.
When `rollback` is `False`,... |
Set or unset the "needs rollback" flag -- for *advanced use* only. | def set_rollback(rollback, using=None):
"""
Set or unset the "needs rollback" flag -- for *advanced use* only.
When `rollback` is `True`, trigger a rollback when exiting the innermost
enclosing atomic block that has `savepoint=True` (that's the default). Use
this to force a rollback without raising... | [
"def",
"set_rollback",
"(",
"rollback",
",",
"using",
"=",
"None",
")",
":",
"return",
"get_connection",
"(",
"using",
")",
".",
"set_rollback",
"(",
"rollback",
")"
] | [
79,
0
] | [
91,
55
] | python | en | ['en', 'error', 'th'] | False |
mark_for_rollback_on_error | (using=None) |
Internal low-level utility to mark a transaction as "needs rollback" when
an exception is raised while not enforcing the enclosed block to be in a
transaction. This is needed by Model.save() and friends to avoid starting a
transaction when in autocommit mode and a single query is executed.
It's eq... |
Internal low-level utility to mark a transaction as "needs rollback" when
an exception is raised while not enforcing the enclosed block to be in a
transaction. This is needed by Model.save() and friends to avoid starting a
transaction when in autocommit mode and a single query is executed. | def mark_for_rollback_on_error(using=None):
"""
Internal low-level utility to mark a transaction as "needs rollback" when
an exception is raised while not enforcing the enclosed block to be in a
transaction. This is needed by Model.save() and friends to avoid starting a
transaction when in autocommi... | [
"def",
"mark_for_rollback_on_error",
"(",
"using",
"=",
"None",
")",
":",
"try",
":",
"yield",
"except",
"Exception",
":",
"connection",
"=",
"get_connection",
"(",
"using",
")",
"if",
"connection",
".",
"in_atomic_block",
":",
"connection",
".",
"needs_rollback... | [
95,
0
] | [
119,
13
] | python | en | ['en', 'error', 'th'] | False |
on_commit | (func, using=None) |
Register `func` to be called when the current transaction is committed.
If the current transaction is rolled back, `func` will not be called.
|
Register `func` to be called when the current transaction is committed.
If the current transaction is rolled back, `func` will not be called.
| def on_commit(func, using=None):
"""
Register `func` to be called when the current transaction is committed.
If the current transaction is rolled back, `func` will not be called.
"""
get_connection(using).on_commit(func) | [
"def",
"on_commit",
"(",
"func",
",",
"using",
"=",
"None",
")",
":",
"get_connection",
"(",
"using",
")",
".",
"on_commit",
"(",
"func",
")"
] | [
122,
0
] | [
127,
41
] | python | en | ['en', 'error', 'th'] | False |
hide_right_and_top_spine | (ax) | Hide the right and top spines
Args:
ax: axes of plot
| Hide the right and top spines | def hide_right_and_top_spine(ax):
"""Hide the right and top spines
Args:
ax: axes of plot
"""
ax.spines["right"].set_visible(False)
ax.spines["top"].set_visible(False) | [
"def",
"hide_right_and_top_spine",
"(",
"ax",
")",
":",
"ax",
".",
"spines",
"[",
"\"right\"",
"]",
".",
"set_visible",
"(",
"False",
")",
"ax",
".",
"spines",
"[",
"\"top\"",
"]",
".",
"set_visible",
"(",
"False",
")"
] | [
12,
0
] | [
19,
39
] | python | en | ['en', 'en', 'en'] | True |
plot_human_rec_gap_as_horizonal_bar | (n_experimental_conditions) | plot the human data as a horizontal bar
Args:
n_experimental_conditions: value to determine the width of the horizontal bar
| plot the human data as a horizontal bar | def plot_human_rec_gap_as_horizonal_bar(n_experimental_conditions):
"""plot the human data as a horizontal bar
Args:
n_experimental_conditions: value to determine the width of the horizontal bar
"""
plt.plot(
[0 - 0.5, n_experimental_conditions - 1 + 0.5],
[data_csv_utils.recog... | [
"def",
"plot_human_rec_gap_as_horizonal_bar",
"(",
"n_experimental_conditions",
")",
":",
"plt",
".",
"plot",
"(",
"[",
"0",
"-",
"0.5",
",",
"n_experimental_conditions",
"-",
"1",
"+",
"0.5",
"]",
",",
"[",
"data_csv_utils",
".",
"recognitionGapsHuman",
",",
"d... | [
41,
0
] | [
66,
5
] | python | en | ['en', 'su', 'en'] | True |
get_dict_of_dict_with_imagenet_number_wordnetID_word | () | Create a dictionary with the following information:
imagenetnumber, wordnetID, word.
The structure is as follows:
0: {"word": "tench, Tinca tinca", "wordnetID": "n01440764"},
1: {"word": "goldfish, Carassius auratus", "wordnetID": "n01443537"}, ...
| Create a dictionary with the following information:
imagenetnumber, wordnetID, word.
The structure is as follows:
0: {"word": "tench, Tinca tinca", "wordnetID": "n01440764"},
1: {"word": "goldfish, Carassius auratus", "wordnetID": "n01443537"}, ...
| def get_dict_of_dict_with_imagenet_number_wordnetID_word():
"""Create a dictionary with the following information:
imagenetnumber, wordnetID, word.
The structure is as follows:
0: {"word": "tench, Tinca tinca", "wordnetID": "n01440764"},
1: {"word": "goldfish, Carassius auratus", "wordnetID": "n0144... | [
"def",
"get_dict_of_dict_with_imagenet_number_wordnetID_word",
"(",
")",
":",
"imagenetnumber_wordnetID_word_dict",
"=",
"{",
"}",
"for",
"imagenetnumber",
",",
"line",
"in",
"enumerate",
"(",
"open",
"(",
"\"categories.txt\"",
",",
"\"r\"",
")",
")",
":",
"wordnetID"... | [
78,
0
] | [
94,
45
] | python | en | ['en', 'en', 'en'] | True |
customize_axes | (ax, crop_probability, xaxis_label_coord_x, orig_px_size) | Adjust the axes for the figure showing probability vs crop.
Args:
ax: axes of plot
crop_probability: list of each crop's probability that should be plotted
xaxis_label_coord_x: position of x-coordinate for x-axis label
orig_px_size: list of original pixel ... | Adjust the axes for the figure showing probability vs crop. | def customize_axes(ax, crop_probability, xaxis_label_coord_x, orig_px_size):
"""Adjust the axes for the figure showing probability vs crop.
Args:
ax: axes of plot
crop_probability: list of each crop's probability that should be plotted
xaxis_label_coord_x: position o... | [
"def",
"customize_axes",
"(",
"ax",
",",
"crop_probability",
",",
"xaxis_label_coord_x",
",",
"orig_px_size",
")",
":",
"ax",
".",
"set_ylim",
"(",
"[",
"-",
"0.07",
",",
"1.07",
"]",
")",
"ax",
".",
"set_ylabel",
"(",
"\"p(correct class)\"",
")",
"ax",
".... | [
97,
0
] | [
112,
36
] | python | en | ['en', 'en', 'en'] | True |
plot_recognition_criterion | (ax, crop_probability) | plot the recognition criterion
Arg:
crop_probability: list of each crop's probability that should be plotted
| plot the recognition criterion | def plot_recognition_criterion(ax, crop_probability):
"""plot the recognition criterion
Arg:
crop_probability: list of each crop's probability that should be plotted
"""
ax.plot(
[0, len(crop_probability) - 1],
[0.5, 0.5],
color="gray",
linestyle="--",
l... | [
"def",
"plot_recognition_criterion",
"(",
"ax",
",",
"crop_probability",
")",
":",
"ax",
".",
"plot",
"(",
"[",
"0",
",",
"len",
"(",
"crop_probability",
")",
"-",
"1",
"]",
",",
"[",
"0.5",
",",
"0.5",
"]",
",",
"color",
"=",
"\"gray\"",
",",
"lines... | [
115,
0
] | [
128,
5
] | python | en | ['en', 'en', 'en'] | True |
plot_crops_below_xaxis | (
fig,
ax,
img_class_dict,
y_offset=0,
space_between_ticks=0.037,
color_counter=0,
list_of_keys_for_plotting=[]) | add images below x-axis
Args:
fig: figure
ax: axes of plot
img_class_dict: dictionary with all data, e.g. a key: "glasses_INclass836_224_0"
y_offset: offset in y-direction. Only non-zero, when several datapoint... | add images below x-axis | def plot_crops_below_xaxis(
fig,
ax,
img_class_dict,
y_offset=0,
space_between_ticks=0.037,
color_counter=0,
list_of_keys_for_plotting=[]):
"""add images below x-axis
Args:
fig: figure
ax: axes ... | [
"def",
"plot_crops_below_xaxis",
"(",
"fig",
",",
"ax",
",",
"img_class_dict",
",",
"y_offset",
"=",
"0",
",",
"space_between_ticks",
"=",
"0.037",
",",
"color_counter",
"=",
"0",
",",
"list_of_keys_for_plotting",
"=",
"[",
"]",
")",
":",
"# in case no list_of_k... | [
131,
0
] | [
177,
30
] | python | en | ['en', 'en', 'en'] | True |
plot_probabilities | (
ax,
crop_probability,
probability_label,
color_counter=0) | plot the probabilities of the crops
Args:
ax: axes of plot
crop_probability: list of each crop's probability that should be plotted
probability_label: label that corresponds to the crop's probability of a certain datapoint
color_counter: counter to index the colo... | plot the probabilities of the crops | def plot_probabilities(
ax,
crop_probability,
probability_label,
color_counter=0):
"""plot the probabilities of the crops
Args:
ax: axes of plot
crop_probability: list of each crop's probability that should be plotted
probability_label: la... | [
"def",
"plot_probabilities",
"(",
"ax",
",",
"crop_probability",
",",
"probability_label",
",",
"color_counter",
"=",
"0",
")",
":",
"ax",
".",
"plot",
"(",
"crop_probability",
",",
"label",
"=",
"probability_label",
",",
"color",
"=",
"color",
"[",
"color_cou... | [
180,
0
] | [
196,
35
] | python | en | ['en', 'en', 'en'] | True |
get_list_of_keys_for_plotting | (img_class_dict) | obtain list that contains the zero'th entry of a new pixel size,
except for the last pixel size. For the last pixel size, pick the last entry.
Args:
img_class_dict: dictionary with all data, e.g. a key: "glasses_INclass836_224_0"
Returns:
list_of_keys_for_plotting: list of keys ... | obtain list that contains the zero'th entry of a new pixel size,
except for the last pixel size. For the last pixel size, pick the last entry. | def get_list_of_keys_for_plotting(img_class_dict):
"""obtain list that contains the zero'th entry of a new pixel size,
except for the last pixel size. For the last pixel size, pick the last entry.
Args:
img_class_dict: dictionary with all data, e.g. a key: "glasses_INclass836_224_0"
... | [
"def",
"get_list_of_keys_for_plotting",
"(",
"img_class_dict",
")",
":",
"key_list",
"=",
"list",
"(",
"img_class_dict",
".",
"keys",
"(",
")",
")",
"# get last pixel size",
"last_px_size",
"=",
"key_list",
"[",
"-",
"1",
"]",
".",
"split",
"(",
"\"_\"",
")",
... | [
199,
0
] | [
224,
36
] | python | en | ['en', 'en', 'en'] | True |
plot_and_save_singe_crop | (
crop,
exp_dir_MIRCs_and_original_images,
img_identifier,
original_or_MIRC) | Plot and save original or MIRC image
Args:
crop: image to be plotted
exp_dir_MIRCs_and_original_images: path to directory of the original images and the final MIRCs
img_identifier: string to identify an image and its correct class
... | Plot and save original or MIRC image | def plot_and_save_singe_crop(
crop,
exp_dir_MIRCs_and_original_images,
img_identifier,
original_or_MIRC):
"""Plot and save original or MIRC image
Args:
crop: image to be plotted
exp_dir_MIRCs_and_original_images: path to directory of ... | [
"def",
"plot_and_save_singe_crop",
"(",
"crop",
",",
"exp_dir_MIRCs_and_original_images",
",",
"img_identifier",
",",
"original_or_MIRC",
")",
":",
"fig",
",",
"ax",
"=",
"plt",
".",
"subplots",
"(",
"1",
",",
"1",
")",
"ax",
".",
"imshow",
"(",
"util",
".",... | [
232,
0
] | [
263,
18
] | python | en | ['en', 'id', 'en'] | True |
Stat.__getattr__ | (self, id) | Calculate missing attribute | Calculate missing attribute | def __getattr__(self, id):
"""Calculate missing attribute"""
if id[:4] == "_get":
raise AttributeError(id)
# calculate missing attribute
v = getattr(self, "_get" + id)()
setattr(self, id, v)
return v | [
"def",
"__getattr__",
"(",
"self",
",",
"id",
")",
":",
"if",
"id",
"[",
":",
"4",
"]",
"==",
"\"_get\"",
":",
"raise",
"AttributeError",
"(",
"id",
")",
"# calculate missing attribute",
"v",
"=",
"getattr",
"(",
"self",
",",
"\"_get\"",
"+",
"id",
")"... | [
41,
4
] | [
48,
16
] | python | en | ['en', 'co', 'en'] | True |
Stat._getextrema | (self) | Get min/max values for each band in the image | Get min/max values for each band in the image | def _getextrema(self):
"""Get min/max values for each band in the image"""
def minmax(histogram):
n = 255
x = 0
for i in range(256):
if histogram[i]:
n = min(n, i)
x = max(x, i)
return n, x # return... | [
"def",
"_getextrema",
"(",
"self",
")",
":",
"def",
"minmax",
"(",
"histogram",
")",
":",
"n",
"=",
"255",
"x",
"=",
"0",
"for",
"i",
"in",
"range",
"(",
"256",
")",
":",
"if",
"histogram",
"[",
"i",
"]",
":",
"n",
"=",
"min",
"(",
"n",
",",
... | [
50,
4
] | [
65,
16
] | python | en | ['en', 'en', 'en'] | True |
Stat._getcount | (self) | Get total number of pixels in each layer | Get total number of pixels in each layer | def _getcount(self):
"""Get total number of pixels in each layer"""
v = []
for i in range(0, len(self.h), 256):
v.append(functools.reduce(operator.add, self.h[i : i + 256]))
return v | [
"def",
"_getcount",
"(",
"self",
")",
":",
"v",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"self",
".",
"h",
")",
",",
"256",
")",
":",
"v",
".",
"append",
"(",
"functools",
".",
"reduce",
"(",
"operator",
".",
"add"... | [
67,
4
] | [
73,
16
] | python | en | ['en', 'en', 'en'] | True |
Stat._getsum | (self) | Get sum of all pixels in each layer | Get sum of all pixels in each layer | def _getsum(self):
"""Get sum of all pixels in each layer"""
v = []
for i in range(0, len(self.h), 256):
layerSum = 0.0
for j in range(256):
layerSum += j * self.h[i + j]
v.append(layerSum)
return v | [
"def",
"_getsum",
"(",
"self",
")",
":",
"v",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"self",
".",
"h",
")",
",",
"256",
")",
":",
"layerSum",
"=",
"0.0",
"for",
"j",
"in",
"range",
"(",
"256",
")",
":",
"layerS... | [
75,
4
] | [
84,
16
] | python | en | ['en', 'en', 'en'] | True |
Stat._getsum2 | (self) | Get squared sum of all pixels in each layer | Get squared sum of all pixels in each layer | def _getsum2(self):
"""Get squared sum of all pixels in each layer"""
v = []
for i in range(0, len(self.h), 256):
sum2 = 0.0
for j in range(256):
sum2 += (j ** 2) * float(self.h[i + j])
v.append(sum2)
return v | [
"def",
"_getsum2",
"(",
"self",
")",
":",
"v",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"len",
"(",
"self",
".",
"h",
")",
",",
"256",
")",
":",
"sum2",
"=",
"0.0",
"for",
"j",
"in",
"range",
"(",
"256",
")",
":",
"sum2",
... | [
86,
4
] | [
95,
16
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.