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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
TestLoadSettingsProcessor.test_CTG_prop_rs | (self) | ConcurrencyThreadGroup: properties in ramp-up, steps | ConcurrencyThreadGroup: properties in ramp-up, steps | def test_CTG_prop_rs(self):
""" ConcurrencyThreadGroup: properties in ramp-up, steps """
self.configure(load={'ramp-up': '${__P(r)}', 'steps': '${__P(s)}'},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/threadgroups.jmx')
self.assertEqual(LoadSettingsProcessor.CTG, self.obj.tg)
... | [
"def",
"test_CTG_prop_rs",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'ramp-up'",
":",
"'${__P(r)}'",
",",
"'steps'",
":",
"'${__P(s)}'",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"+",
"'jmeter/jmx/threadgroups.jmx'",
")",
"self... | [
158,
4
] | [
175,
102
] | python | en | ['en', 'en', 'en'] | True |
TestLoadSettingsProcessor.test_CTG_prop_trh | (self) | ConcurrencyThreadGroup: properties in throughput, ramp-up, hold-for | ConcurrencyThreadGroup: properties in throughput, ramp-up, hold-for | def test_CTG_prop_trh(self):
""" ConcurrencyThreadGroup: properties in throughput, ramp-up, hold-for """
self.configure(load={'ramp-up': '${__P(r)}', 'throughput': '${__P(t)}', 'hold-for': '${__P(h)}'},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/threadgroups.jmx')
self.assertEqu... | [
"def",
"test_CTG_prop_trh",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'ramp-up'",
":",
"'${__P(r)}'",
",",
"'throughput'",
":",
"'${__P(t)}'",
",",
"'hold-for'",
":",
"'${__P(h)}'",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"... | [
177,
4
] | [
186,
108
] | python | en | ['en', 'en', 'en'] | True |
TestLoadSettingsProcessor.test_TST_low_val | (self) | ConcurrencyThreadGroup: properties in throughput, ramp-up, hold-for | ConcurrencyThreadGroup: properties in throughput, ramp-up, hold-for | def test_TST_low_val(self):
""" ConcurrencyThreadGroup: properties in throughput, ramp-up, hold-for """
self.configure(load={'ramp-up': '300', 'throughput': '2', 'hold-for': '6900'},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/threadgroups.jmx')
self.assertEqual(LoadSettingsProce... | [
"def",
"test_TST_low_val",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'ramp-up'",
":",
"'300'",
",",
"'throughput'",
":",
"'2'",
",",
"'hold-for'",
":",
"'6900'",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"+",
"'jmeter/jmx/t... | [
188,
4
] | [
197,
81
] | python | en | ['en', 'en', 'en'] | True |
TestLoadSettingsProcessor.test_TG_prop_cih | (self) | ThreadGroup: properties in concurrency, hold-for, iterations | ThreadGroup: properties in concurrency, hold-for, iterations | def test_TG_prop_cih(self):
""" ThreadGroup: properties in concurrency, hold-for, iterations """
self.configure(load={'concurrency': '${__P(c)}', 'hold-for': '${__P(h)}', 'iterations': '${__P(i)}'},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/threadgroups.jmx')
self.assertEqual(L... | [
"def",
"test_TG_prop_cih",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'concurrency'",
":",
"'${__P(c)}'",
",",
"'hold-for'",
":",
"'${__P(h)}'",
",",
"'iterations'",
":",
"'${__P(i)}'",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
... | [
215,
4
] | [
227,
104
] | python | en | ['en', 'en', 'en'] | True |
TestLoadSettingsProcessor.test_TG_prop_rh | (self) | ThreadGroup: properties in ramp-up, hold-for | ThreadGroup: properties in ramp-up, hold-for | def test_TG_prop_rh(self):
""" ThreadGroup: properties in ramp-up, hold-for """
self.configure(load={'ramp-up': '${__P(r)}', 'hold-for': '${__P(h)}'},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/threadgroups.jmx', has_ctg=False)
self.assertEqual(LoadSettingsProcessor.TG, self.obj... | [
"def",
"test_TG_prop_rh",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'ramp-up'",
":",
"'${__P(r)}'",
",",
"'hold-for'",
":",
"'${__P(h)}'",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"+",
"'jmeter/jmx/threadgroups.jmx'",
",",
"ha... | [
229,
4
] | [
246,
91
] | python | en | ['en', 'en', 'en'] | True |
TestLoadSettingsProcessor.test_CTG_h | (self) | ConcurrencyThreadGroup: hold-for | ConcurrencyThreadGroup: hold-for | def test_CTG_h(self):
""" ConcurrencyThreadGroup: hold-for """
self.configure(load={'hold-for': 70.5}, jmx_file=RESOURCES_DIR + 'jmeter/jmx/threadgroups.jmx')
self.assertEqual(LoadSettingsProcessor.CTG, self.obj.tg)
self.obj.modify(self.jmx)
res_values = {}
for group in... | [
"def",
"test_CTG_h",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'hold-for'",
":",
"70.5",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"+",
"'jmeter/jmx/threadgroups.jmx'",
")",
"self",
".",
"assertEqual",
"(",
"LoadSettingsProcess... | [
248,
4
] | [
266,
55
] | python | en | ['da', 'en', 'en'] | False |
TestLoadSettingsProcessor.test_TG_ci | (self) | ThreadGroup: concurrency, iterations | ThreadGroup: concurrency, iterations | def test_TG_ci(self):
""" ThreadGroup: concurrency, iterations """
self.configure(load={'concurrency': 1, 'iterations': 7},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/threadgroups.jmx')
self.assertEqual(LoadSettingsProcessor.TG, self.obj.tg)
self.obj.modify(self.jmx)
... | [
"def",
"test_TG_ci",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'concurrency'",
":",
"1",
",",
"'iterations'",
":",
"7",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"+",
"'jmeter/jmx/threadgroups.jmx'",
")",
"self",
".",
"asse... | [
268,
4
] | [
280,
96
] | python | en | ['en', 'en', 'en'] | True |
TestLoadSettingsProcessor.test_TG_hr | (self) | ThreadGroup: hold-for, ramp-up, no plugin | ThreadGroup: hold-for, ramp-up, no plugin | def test_TG_hr(self):
""" ThreadGroup: hold-for, ramp-up, no plugin """
self.configure(load={'ramp-up': 10, 'hold-for': 20},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/threadgroups.jmx',
has_ctg=False)
self.assertEqual(LoadSettingsProcessor.TG, self.obj.tg... | [
"def",
"test_TG_hr",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'ramp-up'",
":",
"10",
",",
"'hold-for'",
":",
"20",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"+",
"'jmeter/jmx/threadgroups.jmx'",
",",
"has_ctg",
"=",
"False... | [
282,
4
] | [
300,
102
] | python | en | ['en', 'en', 'en'] | True |
TestLoadSettingsProcessor.test_TG_cr | (self) | ThreadGroup: concurrency, ramp-up | ThreadGroup: concurrency, ramp-up | def test_TG_cr(self):
"""ThreadGroup: concurrency, ramp-up"""
self.configure(load={'concurrency': 76, 'ramp-up': 4},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/UTG_dummy.jmx',
settings={'force-ctg': False})
self.assertEqual(LoadSettingsProcessor.TG, self.... | [
"def",
"test_TG_cr",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'concurrency'",
":",
"76",
",",
"'ramp-up'",
":",
"4",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"+",
"'jmeter/jmx/UTG_dummy.jmx'",
",",
"settings",
"=",
"{",
... | [
302,
4
] | [
311,
97
] | python | en | ['en', 'en', 'en'] | True |
TestLoadSettingsProcessor.test_TG_iterations_from_load | (self) | ThreadGroup: concurrency, ramp-up, iterations | ThreadGroup: concurrency, ramp-up, iterations | def test_TG_iterations_from_load(self):
"""ThreadGroup: concurrency, ramp-up, iterations"""
self.configure(load={'concurrency': 76, 'ramp-up': 4, 'iterations': 5},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/iterations-TG.jmx',
settings={'keep-iterations': False})... | [
"def",
"test_TG_iterations_from_load",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'concurrency'",
":",
"76",
",",
"'ramp-up'",
":",
"4",
",",
"'iterations'",
":",
"5",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"+",
"'jmeter/... | [
313,
4
] | [
322,
96
] | python | en | ['en', 'en', 'en'] | True |
TestLoadSettingsProcessor.test_TG_iterations_from_jmx | (self) | ThreadGroup: concurrency, ramp-up, iterations | ThreadGroup: concurrency, ramp-up, iterations | def test_TG_iterations_from_jmx(self):
"""ThreadGroup: concurrency, ramp-up, iterations"""
self.configure(load={'concurrency': 76, 'steps': 5, 'throughput': 20},
jmx_file=RESOURCES_DIR + 'jmeter/jmx/iterations-TG.jmx',
settings={'force-ctg': False})
... | [
"def",
"test_TG_iterations_from_jmx",
"(",
"self",
")",
":",
"self",
".",
"configure",
"(",
"load",
"=",
"{",
"'concurrency'",
":",
"76",
",",
"'steps'",
":",
"5",
",",
"'throughput'",
":",
"20",
"}",
",",
"jmx_file",
"=",
"RESOURCES_DIR",
"+",
"'jmeter/jm... | [
324,
4
] | [
333,
97
] | python | en | ['en', 'en', 'en'] | True |
_test_credentials | (authfile, key, testurl) | Helper function to test the credentials
| Helper function to test the credentials
| def _test_credentials(authfile, key, testurl):
""" Helper function to test the credentials
"""
if 'ftps://' in testurl:
# FTP_TLS needs some extra workflow
try:
upar = urlparse(testurl)
# Decide if Implicit or Explicit FTPS
if upar.port == 990:
... | [
"def",
"_test_credentials",
"(",
"authfile",
",",
"key",
",",
"testurl",
")",
":",
"if",
"'ftps://'",
"in",
"testurl",
":",
"# FTP_TLS needs some extra workflow",
"try",
":",
"upar",
"=",
"urlparse",
"(",
"testurl",
")",
"# Decide if Implicit or Explicit FTPS",
"if"... | [
11,
0
] | [
56,
21
] | python | en | ['en', 'en', 'en'] | True |
read_credentials | (key, testurl) | Generic function to read credentials and attach them to a .netrc file
Parameters
----------
key : str
credentials identifier
testurl : str
a filelink to test the credentials against
| Generic function to read credentials and attach them to a .netrc file | def read_credentials(key, testurl):
""" Generic function to read credentials and attach them to a .netrc file
Parameters
----------
key : str
credentials identifier
testurl : str
a filelink to test the credentials against
"""
# the .netrc file
authfile = os.path.expandus... | [
"def",
"read_credentials",
"(",
"key",
",",
"testurl",
")",
":",
"# the .netrc file",
"authfile",
"=",
"os",
".",
"path",
".",
"expanduser",
"(",
"\"~/.netrc\"",
")",
"# check if file and credentials already exist",
"try",
":",
"netrc",
"(",
"authfile",
")",
".",
... | [
59,
0
] | [
122,
55
] | python | en | ['en', 'en', 'en'] | True |
cli | () | command line interface to store different NETRC credentials
call via 'oggm_netrc_credentials'
| command line interface to store different NETRC credentials
call via 'oggm_netrc_credentials'
| def cli():
""" command line interface to store different NETRC credentials
call via 'oggm_netrc_credentials'
"""
print('This will store login credentials in a local .netrc file.\n'
'Enter the number or the service you want to add credentials for, '
'this might override existing cred... | [
"def",
"cli",
"(",
")",
":",
"print",
"(",
"'This will store login credentials in a local .netrc file.\\n'",
"'Enter the number or the service you want to add credentials for, '",
"'this might override existing credentials in the .netrc file!\\n\\n'",
"'[0] urs.earthdata.nasa.gov, ASTER DEM\\n'"... | [
125,
0
] | [
156,
34
] | python | en | ['en', 'en', 'en'] | True |
getTreeWalker | (treeType, implementation=None, **kwargs) | Get a TreeWalker class for various types of tree with built-in support
:arg str treeType: the name of the tree type required (case-insensitive).
Supported values are:
* "dom": The xml.dom.minidom DOM implementation
* "etree": A generic walker for tree implementations exposing an
... | Get a TreeWalker class for various types of tree with built-in support | def getTreeWalker(treeType, implementation=None, **kwargs):
"""Get a TreeWalker class for various types of tree with built-in support
:arg str treeType: the name of the tree type required (case-insensitive).
Supported values are:
* "dom": The xml.dom.minidom DOM implementation
* "etree... | [
"def",
"getTreeWalker",
"(",
"treeType",
",",
"implementation",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"treeType",
"=",
"treeType",
".",
"lower",
"(",
")",
"if",
"treeType",
"not",
"in",
"treeWalkerCache",
":",
"if",
"treeType",
"==",
"\"dom\"",
... | [
20,
0
] | [
61,
40
] | python | en | ['en', 'en', 'en'] | True |
pprint | (walker) | Pretty printer for tree walkers
Takes a TreeWalker instance and pretty prints the output of walking the tree.
:arg walker: a TreeWalker instance
| Pretty printer for tree walkers | def pprint(walker):
"""Pretty printer for tree walkers
Takes a TreeWalker instance and pretty prints the output of walking the tree.
:arg walker: a TreeWalker instance
"""
output = []
indent = 0
for token in concatenateCharacterTokens(walker):
type = token["type"]
if type ... | [
"def",
"pprint",
"(",
"walker",
")",
":",
"output",
"=",
"[",
"]",
"indent",
"=",
"0",
"for",
"token",
"in",
"concatenateCharacterTokens",
"(",
"walker",
")",
":",
"type",
"=",
"token",
"[",
"\"type\"",
"]",
"if",
"type",
"in",
"(",
"\"StartTag\"",
","... | [
79,
0
] | [
153,
28
] | python | en | ['en', 'en', 'en'] | True |
NTLMConnectionPool.__init__ | (self, user, pw, authurl, *args, **kwargs) |
authurl is a random URL on the server that is protected by NTLM.
user is the Windows user, probably in the DOMAIN\\username format.
pw is the password for the user.
|
authurl is a random URL on the server that is protected by NTLM.
user is the Windows user, probably in the DOMAIN\\username format.
pw is the password for the user.
| def __init__(self, user, pw, authurl, *args, **kwargs):
"""
authurl is a random URL on the server that is protected by NTLM.
user is the Windows user, probably in the DOMAIN\\username format.
pw is the password for the user.
"""
super(NTLMConnectionPool, self).__init__(*a... | [
"def",
"__init__",
"(",
"self",
",",
"user",
",",
"pw",
",",
"authurl",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
"NTLMConnectionPool",
",",
"self",
")",
".",
"__init__",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"s... | [
24,
4
] | [
36,
20
] | python | en | ['en', 'error', 'th'] | False |
partial_async_gen | (f, *args) |
Returns an async generator function which is equalivalent to the passed in function,
but only takes in one parameter (the first one).
|
Returns an async generator function which is equalivalent to the passed in function,
but only takes in one parameter (the first one).
| def partial_async_gen(f, *args):
"""
Returns an async generator function which is equalivalent to the passed in function,
but only takes in one parameter (the first one).
"""
async def inner(first_param):
async for x in f(first_param, *args):
yield x
return inner | [
"def",
"partial_async_gen",
"(",
"f",
",",
"*",
"args",
")",
":",
"async",
"def",
"inner",
"(",
"first_param",
")",
":",
"async",
"for",
"x",
"in",
"f",
"(",
"first_param",
",",
"*",
"args",
")",
":",
"yield",
"x",
"return",
"inner"
] | [
0,
0
] | [
10,
16
] | python | en | ['en', 'error', 'th'] | False |
partial_async | (f, *args) |
Returns an async function which is equalivalent to the passed in function,
but only takes in one parameter (the first one).
|
Returns an async function which is equalivalent to the passed in function,
but only takes in one parameter (the first one).
| def partial_async(f, *args):
"""
Returns an async function which is equalivalent to the passed in function,
but only takes in one parameter (the first one).
"""
async def inner(first_param):
return await f(first_param, *args)
return inner | [
"def",
"partial_async",
"(",
"f",
",",
"*",
"args",
")",
":",
"async",
"def",
"inner",
"(",
"first_param",
")",
":",
"return",
"await",
"f",
"(",
"first_param",
",",
"*",
"args",
")",
"return",
"inner"
] | [
13,
0
] | [
22,
16
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.changes | (self, graph, trim_to_apps=None, convert_apps=None, migration_name=None) |
Main entry point to produce a list of applicable changes.
Takes a graph to base names on and an optional set of apps
to try and restrict to (restriction is not guaranteed)
|
Main entry point to produce a list of applicable changes.
Takes a graph to base names on and an optional set of apps
to try and restrict to (restriction is not guaranteed)
| def changes(self, graph, trim_to_apps=None, convert_apps=None, migration_name=None):
"""
Main entry point to produce a list of applicable changes.
Takes a graph to base names on and an optional set of apps
to try and restrict to (restriction is not guaranteed)
"""
changes... | [
"def",
"changes",
"(",
"self",
",",
"graph",
",",
"trim_to_apps",
"=",
"None",
",",
"convert_apps",
"=",
"None",
",",
"migration_name",
"=",
"None",
")",
":",
"changes",
"=",
"self",
".",
"_detect_changes",
"(",
"convert_apps",
",",
"graph",
")",
"changes"... | [
40,
4
] | [
50,
22
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.deep_deconstruct | (self, obj) |
Recursive deconstruction for a field and its arguments.
Used for full comparison for rename/alter; sometimes a single-level
deconstruction will not compare correctly.
|
Recursive deconstruction for a field and its arguments.
Used for full comparison for rename/alter; sometimes a single-level
deconstruction will not compare correctly.
| def deep_deconstruct(self, obj):
"""
Recursive deconstruction for a field and its arguments.
Used for full comparison for rename/alter; sometimes a single-level
deconstruction will not compare correctly.
"""
if isinstance(obj, list):
return [self.deep_deconstr... | [
"def",
"deep_deconstruct",
"(",
"self",
",",
"obj",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"list",
")",
":",
"return",
"[",
"self",
".",
"deep_deconstruct",
"(",
"value",
")",
"for",
"value",
"in",
"obj",
"]",
"elif",
"isinstance",
"(",
"obj",
... | [
52,
4
] | [
90,
22
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.only_relation_agnostic_fields | (self, fields) |
Return a definition of the fields that ignores field names and
what related fields actually relate to.
Used for detecting renames (as, of course, the related fields
change during renames)
|
Return a definition of the fields that ignores field names and
what related fields actually relate to.
Used for detecting renames (as, of course, the related fields
change during renames)
| def only_relation_agnostic_fields(self, fields):
"""
Return a definition of the fields that ignores field names and
what related fields actually relate to.
Used for detecting renames (as, of course, the related fields
change during renames)
"""
fields_def = []
... | [
"def",
"only_relation_agnostic_fields",
"(",
"self",
",",
"fields",
")",
":",
"fields_def",
"=",
"[",
"]",
"for",
"name",
",",
"field",
"in",
"sorted",
"(",
"fields",
")",
":",
"deconstruction",
"=",
"self",
".",
"deep_deconstruct",
"(",
"field",
")",
"if"... | [
92,
4
] | [
105,
25
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector._detect_changes | (self, convert_apps=None, graph=None) |
Returns a dict of migration plans which will achieve the
change from from_state to to_state. The dict has app labels
as keys and a list of migrations as values.
The resulting migrations aren't specially named, but the names
do matter for dependencies inside the set.
co... |
Returns a dict of migration plans which will achieve the
change from from_state to to_state. The dict has app labels
as keys and a list of migrations as values. | def _detect_changes(self, convert_apps=None, graph=None):
"""
Returns a dict of migration plans which will achieve the
change from from_state to to_state. The dict has app labels
as keys and a list of migrations as values.
The resulting migrations aren't specially named, but the... | [
"def",
"_detect_changes",
"(",
"self",
",",
"convert_apps",
"=",
"None",
",",
"graph",
"=",
"None",
")",
":",
"# The first phase is generating all the operations for each app",
"# and gathering them into a big per-app list.",
"# We'll then go through that list later and order it and ... | [
107,
4
] | [
199,
30
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector._prepare_field_lists | (self) |
Prepare field lists, and prepare a list of the fields that used
through models in the old state so we can make dependencies
from the through model deletion to the field that uses it.
|
Prepare field lists, and prepare a list of the fields that used
through models in the old state so we can make dependencies
from the through model deletion to the field that uses it.
| def _prepare_field_lists(self):
"""
Prepare field lists, and prepare a list of the fields that used
through models in the old state so we can make dependencies
from the through model deletion to the field that uses it.
"""
self.kept_model_keys = set(self.old_model_keys).i... | [
"def",
"_prepare_field_lists",
"(",
"self",
")",
":",
"self",
".",
"kept_model_keys",
"=",
"set",
"(",
"self",
".",
"old_model_keys",
")",
".",
"intersection",
"(",
"self",
".",
"new_model_keys",
")",
"self",
".",
"kept_proxy_keys",
"=",
"set",
"(",
"self",
... | [
201,
4
] | [
218,
101
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector._generate_through_model_map | (self) |
Through model map generation
|
Through model map generation
| def _generate_through_model_map(self):
"""
Through model map generation
"""
for app_label, model_name in sorted(self.old_model_keys):
old_model_name = self.renamed_models.get((app_label, model_name), model_name)
old_model_state = self.from_state.models[app_label, ... | [
"def",
"_generate_through_model_map",
"(",
"self",
")",
":",
"for",
"app_label",
",",
"model_name",
"in",
"sorted",
"(",
"self",
".",
"old_model_keys",
")",
":",
"old_model_name",
"=",
"self",
".",
"renamed_models",
".",
"get",
"(",
"(",
"app_label",
",",
"m... | [
220,
4
] | [
235,
93
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector._build_migration_list | (self, graph=None) |
We need to chop the lists of operations up into migrations with
dependencies on each other. We do this by stepping up an app's list of
operations until we find one that has an outgoing dependency that isn't
in another app's migration yet (hasn't been chopped off its list). We
th... |
We need to chop the lists of operations up into migrations with
dependencies on each other. We do this by stepping up an app's list of
operations until we find one that has an outgoing dependency that isn't
in another app's migration yet (hasn't been chopped off its list). We
th... | def _build_migration_list(self, graph=None):
"""
We need to chop the lists of operations up into migrations with
dependencies on each other. We do this by stepping up an app's list of
operations until we find one that has an outgoing dependency that isn't
in another app's migrati... | [
"def",
"_build_migration_list",
"(",
"self",
",",
"graph",
"=",
"None",
")",
":",
"self",
".",
"migrations",
"=",
"{",
"}",
"num_ops",
"=",
"sum",
"(",
"len",
"(",
"x",
")",
"for",
"x",
"in",
"self",
".",
"generated_operations",
".",
"values",
"(",
"... | [
237,
4
] | [
326,
33
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector._sort_migrations | (self) |
Reorder to make things possible. The order we have already isn't bad,
but we need to pull a few things around so FKs work nicely inside the
same app
|
Reorder to make things possible. The order we have already isn't bad,
but we need to pull a few things around so FKs work nicely inside the
same app
| def _sort_migrations(self):
"""
Reorder to make things possible. The order we have already isn't bad,
but we need to pull a few things around so FKs work nicely inside the
same app
"""
for app_label, ops in sorted(self.generated_operations.items()):
# construc... | [
"def",
"_sort_migrations",
"(",
"self",
")",
":",
"for",
"app_label",
",",
"ops",
"in",
"sorted",
"(",
"self",
".",
"generated_operations",
".",
"items",
"(",
")",
")",
":",
"# construct a dependency graph for intra-app dependencies",
"dependency_graph",
"=",
"{",
... | [
328,
4
] | [
345,
97
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.check_dependency | (self, operation, dependency) |
Returns ``True`` if the given operation depends on the given dependency,
``False`` otherwise.
|
Returns ``True`` if the given operation depends on the given dependency,
``False`` otherwise.
| def check_dependency(self, operation, dependency):
"""
Returns ``True`` if the given operation depends on the given dependency,
``False`` otherwise.
"""
# Created model
if dependency[2] is None and dependency[3] is True:
return (
isinstance(ope... | [
"def",
"check_dependency",
"(",
"self",
",",
"operation",
",",
"dependency",
")",
":",
"# Created model",
"if",
"dependency",
"[",
"2",
"]",
"is",
"None",
"and",
"dependency",
"[",
"3",
"]",
"is",
"True",
":",
"return",
"(",
"isinstance",
"(",
"operation",... | [
363,
4
] | [
424,
75
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.swappable_first_key | (self, item) |
Sorting key function that places potential swappable models first in
lists of created models (only real way to solve #22783)
|
Sorting key function that places potential swappable models first in
lists of created models (only real way to solve #22783)
| def swappable_first_key(self, item):
"""
Sorting key function that places potential swappable models first in
lists of created models (only real way to solve #22783)
"""
try:
model = self.new_apps.get_model(item[0], item[1])
base_names = [base.__name__ for... | [
"def",
"swappable_first_key",
"(",
"self",
",",
"item",
")",
":",
"try",
":",
"model",
"=",
"self",
".",
"new_apps",
".",
"get_model",
"(",
"item",
"[",
"0",
"]",
",",
"item",
"[",
"1",
"]",
")",
"base_names",
"=",
"[",
"base",
".",
"__name__",
"fo... | [
434,
4
] | [
452,
19
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_renamed_models | (self) |
Finds any renamed models, and generates the operations for them,
and removes the old entry from the model lists.
Must be run before other model-level generation.
|
Finds any renamed models, and generates the operations for them,
and removes the old entry from the model lists.
Must be run before other model-level generation.
| def generate_renamed_models(self):
"""
Finds any renamed models, and generates the operations for them,
and removes the old entry from the model lists.
Must be run before other model-level generation.
"""
self.renamed_models = {}
self.renamed_models_rel = {}
... | [
"def",
"generate_renamed_models",
"(",
"self",
")",
":",
"self",
".",
"renamed_models",
"=",
"{",
"}",
"self",
".",
"renamed_models_rel",
"=",
"{",
"}",
"added_models",
"=",
"set",
"(",
"self",
".",
"new_model_keys",
")",
"-",
"set",
"(",
"self",
".",
"o... | [
454,
4
] | [
489,
33
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_created_models | (self) |
Find all new models (both managed and unmanaged) and make create
operations for them as well as separate operations to create any
foreign key or M2M relationships (we'll optimize these back in later
if we can).
We also defer any model options that refer to collections of fields... |
Find all new models (both managed and unmanaged) and make create
operations for them as well as separate operations to create any
foreign key or M2M relationships (we'll optimize these back in later
if we can). | def generate_created_models(self):
"""
Find all new models (both managed and unmanaged) and make create
operations for them as well as separate operations to create any
foreign key or M2M relationships (we'll optimize these back in later
if we can).
We also defer any mod... | [
"def",
"generate_created_models",
"(",
"self",
")",
":",
"old_keys",
"=",
"set",
"(",
"self",
".",
"old_model_keys",
")",
".",
"union",
"(",
"self",
".",
"old_unmanaged_keys",
")",
"added_models",
"=",
"set",
"(",
"self",
".",
"new_model_keys",
")",
"-",
"... | [
491,
4
] | [
644,
21
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_created_proxies | (self) |
Makes CreateModel statements for proxy models.
We use the same statements as that way there's less code duplication,
but of course for proxy models we can skip all that pointless field
stuff and just chuck out an operation.
|
Makes CreateModel statements for proxy models.
We use the same statements as that way there's less code duplication,
but of course for proxy models we can skip all that pointless field
stuff and just chuck out an operation.
| def generate_created_proxies(self):
"""
Makes CreateModel statements for proxy models.
We use the same statements as that way there's less code duplication,
but of course for proxy models we can skip all that pointless field
stuff and just chuck out an operation.
"""
... | [
"def",
"generate_created_proxies",
"(",
"self",
")",
":",
"added",
"=",
"set",
"(",
"self",
".",
"new_proxy_keys",
")",
"-",
"set",
"(",
"self",
".",
"old_proxy_keys",
")",
"for",
"app_label",
",",
"model_name",
"in",
"sorted",
"(",
"added",
")",
":",
"m... | [
646,
4
] | [
678,
13
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_deleted_models | (self) |
Find all deleted models (managed and unmanaged) and make delete
operations for them as well as separate operations to delete any
foreign key or M2M relationships (we'll optimize these back in later
if we can).
We also bring forward removal of any model options that refer to
... |
Find all deleted models (managed and unmanaged) and make delete
operations for them as well as separate operations to delete any
foreign key or M2M relationships (we'll optimize these back in later
if we can). | def generate_deleted_models(self):
"""
Find all deleted models (managed and unmanaged) and make delete
operations for them as well as separate operations to delete any
foreign key or M2M relationships (we'll optimize these back in later
if we can).
We also bring forward ... | [
"def",
"generate_deleted_models",
"(",
"self",
")",
":",
"new_keys",
"=",
"set",
"(",
"self",
".",
"new_model_keys",
")",
".",
"union",
"(",
"self",
".",
"new_unmanaged_keys",
")",
"deleted_models",
"=",
"set",
"(",
"self",
".",
"old_model_keys",
")",
"-",
... | [
680,
4
] | [
771,
13
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_deleted_proxies | (self) |
Makes DeleteModel statements for proxy models.
|
Makes DeleteModel statements for proxy models.
| def generate_deleted_proxies(self):
"""
Makes DeleteModel statements for proxy models.
"""
deleted = set(self.old_proxy_keys) - set(self.new_proxy_keys)
for app_label, model_name in sorted(deleted):
model_state = self.from_state.models[app_label, model_name]
... | [
"def",
"generate_deleted_proxies",
"(",
"self",
")",
":",
"deleted",
"=",
"set",
"(",
"self",
".",
"old_proxy_keys",
")",
"-",
"set",
"(",
"self",
".",
"new_proxy_keys",
")",
"for",
"app_label",
",",
"model_name",
"in",
"sorted",
"(",
"deleted",
")",
":",
... | [
773,
4
] | [
786,
13
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_renamed_fields | (self) |
Works out renamed fields
|
Works out renamed fields
| def generate_renamed_fields(self):
"""
Works out renamed fields
"""
self.renamed_fields = {}
for app_label, model_name, field_name in sorted(self.new_field_keys - self.old_field_keys):
old_model_name = self.renamed_models.get((app_label, model_name), model_name)
... | [
"def",
"generate_renamed_fields",
"(",
"self",
")",
":",
"self",
".",
"renamed_fields",
"=",
"{",
"}",
"for",
"app_label",
",",
"model_name",
",",
"field_name",
"in",
"sorted",
"(",
"self",
".",
"new_field_keys",
"-",
"self",
".",
"old_field_keys",
")",
":",... | [
788,
4
] | [
819,
33
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_added_fields | (self) |
Fields that have been added
|
Fields that have been added
| def generate_added_fields(self):
"""
Fields that have been added
"""
for app_label, model_name, field_name in sorted(self.new_field_keys - self.old_field_keys):
self._generate_added_field(app_label, model_name, field_name) | [
"def",
"generate_added_fields",
"(",
"self",
")",
":",
"for",
"app_label",
",",
"model_name",
",",
"field_name",
"in",
"sorted",
"(",
"self",
".",
"new_field_keys",
"-",
"self",
".",
"old_field_keys",
")",
":",
"self",
".",
"_generate_added_field",
"(",
"app_l... | [
821,
4
] | [
826,
73
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_removed_fields | (self) |
Fields that have been removed.
|
Fields that have been removed.
| def generate_removed_fields(self):
"""
Fields that have been removed.
"""
for app_label, model_name, field_name in sorted(self.old_field_keys - self.new_field_keys):
self._generate_removed_field(app_label, model_name, field_name) | [
"def",
"generate_removed_fields",
"(",
"self",
")",
":",
"for",
"app_label",
",",
"model_name",
",",
"field_name",
"in",
"sorted",
"(",
"self",
".",
"old_field_keys",
"-",
"self",
".",
"new_field_keys",
")",
":",
"self",
".",
"_generate_removed_field",
"(",
"a... | [
859,
4
] | [
864,
75
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_altered_fields | (self) |
Fields that have been altered.
|
Fields that have been altered.
| def generate_altered_fields(self):
"""
Fields that have been altered.
"""
for app_label, model_name, field_name in sorted(self.old_field_keys.intersection(self.new_field_keys)):
# Did the field change?
old_model_name = self.renamed_models.get((app_label, model_nam... | [
"def",
"generate_altered_fields",
"(",
"self",
")",
":",
"for",
"app_label",
",",
"model_name",
",",
"field_name",
"in",
"sorted",
"(",
"self",
".",
"old_field_keys",
".",
"intersection",
"(",
"self",
".",
"new_field_keys",
")",
")",
":",
"# Did the field change... | [
882,
4
] | [
937,
81
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.generate_altered_options | (self) |
Works out if any non-schema-affecting options have changed and
makes an operation to represent them in state changes (in case Python
code in migrations needs them)
|
Works out if any non-schema-affecting options have changed and
makes an operation to represent them in state changes (in case Python
code in migrations needs them)
| def generate_altered_options(self):
"""
Works out if any non-schema-affecting options have changed and
makes an operation to represent them in state changes (in case Python
code in migrations needs them)
"""
models_to_check = self.kept_model_keys.union(
self.k... | [
"def",
"generate_altered_options",
"(",
"self",
")",
":",
"models_to_check",
"=",
"self",
".",
"kept_model_keys",
".",
"union",
"(",
"self",
".",
"kept_proxy_keys",
")",
".",
"union",
"(",
"self",
".",
"kept_unmanaged_keys",
")",
".",
"union",
"(",
"# unmanage... | [
1060,
4
] | [
1097,
17
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.arrange_for_graph | (self, changes, graph, migration_name=None) |
Takes in a result from changes() and a MigrationGraph,
and fixes the names and dependencies of the changes so they
extend the graph from the leaf nodes for each app.
|
Takes in a result from changes() and a MigrationGraph,
and fixes the names and dependencies of the changes so they
extend the graph from the leaf nodes for each app.
| def arrange_for_graph(self, changes, graph, migration_name=None):
"""
Takes in a result from changes() and a MigrationGraph,
and fixes the names and dependencies of the changes so they
extend the graph from the leaf nodes for each app.
"""
leaves = graph.leaf_nodes()
... | [
"def",
"arrange_for_graph",
"(",
"self",
",",
"changes",
",",
"graph",
",",
"migration_name",
"=",
"None",
")",
":",
"leaves",
"=",
"graph",
".",
"leaf_nodes",
"(",
")",
"name_map",
"=",
"{",
"}",
"for",
"app_label",
",",
"migrations",
"in",
"list",
"(",... | [
1140,
4
] | [
1187,
22
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector._trim_to_apps | (self, changes, app_labels) |
Takes changes from arrange_for_graph and set of app labels and
returns a modified set of changes which trims out as many migrations
that are not in app_labels as possible.
Note that some other migrations may still be present, as they may be
required dependencies.
|
Takes changes from arrange_for_graph and set of app labels and
returns a modified set of changes which trims out as many migrations
that are not in app_labels as possible.
Note that some other migrations may still be present, as they may be
required dependencies.
| def _trim_to_apps(self, changes, app_labels):
"""
Takes changes from arrange_for_graph and set of app labels and
returns a modified set of changes which trims out as many migrations
that are not in app_labels as possible.
Note that some other migrations may still be present, as t... | [
"def",
"_trim_to_apps",
"(",
"self",
",",
"changes",
",",
"app_labels",
")",
":",
"# Gather other app dependencies in a first pass",
"app_dependencies",
"=",
"{",
"}",
"for",
"app_label",
",",
"migrations",
"in",
"changes",
".",
"items",
"(",
")",
":",
"for",
"m... | [
1189,
4
] | [
1214,
22
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.suggest_name | (cls, ops) |
Given a set of operations, suggests a name for the migration
they might represent. Names are not guaranteed to be unique,
but we put some effort in to the fallback name to avoid VCS conflicts
if we can.
|
Given a set of operations, suggests a name for the migration
they might represent. Names are not guaranteed to be unique,
but we put some effort in to the fallback name to avoid VCS conflicts
if we can.
| def suggest_name(cls, ops):
"""
Given a set of operations, suggests a name for the migration
they might represent. Names are not guaranteed to be unique,
but we put some effort in to the fallback name to avoid VCS conflicts
if we can.
"""
if len(ops) == 1:
... | [
"def",
"suggest_name",
"(",
"cls",
",",
"ops",
")",
":",
"if",
"len",
"(",
"ops",
")",
"==",
"1",
":",
"if",
"isinstance",
"(",
"ops",
"[",
"0",
"]",
",",
"operations",
".",
"CreateModel",
")",
":",
"return",
"ops",
"[",
"0",
"]",
".",
"name_lowe... | [
1217,
4
] | [
1236,
57
] | python | en | ['en', 'error', 'th'] | False |
MigrationAutodetector.parse_number | (cls, name) |
Given a migration name, tries to extract a number from the
beginning of it. If no number found, returns None.
|
Given a migration name, tries to extract a number from the
beginning of it. If no number found, returns None.
| def parse_number(cls, name):
"""
Given a migration name, tries to extract a number from the
beginning of it. If no number found, returns None.
"""
match = re.match(r'^\d+', name)
if match:
return int(match.group())
return None | [
"def",
"parse_number",
"(",
"cls",
",",
"name",
")",
":",
"match",
"=",
"re",
".",
"match",
"(",
"r'^\\d+'",
",",
"name",
")",
"if",
"match",
":",
"return",
"int",
"(",
"match",
".",
"group",
"(",
")",
")",
"return",
"None"
] | [
1239,
4
] | [
1247,
19
] | python | en | ['en', 'error', 'th'] | False |
Model.__init__ | (self, args) |
TODO: Write Comment
|
TODO: Write Comment
| def __init__(self, args):
"""
TODO: Write Comment
"""
import os
from tensorflow.keras import losses, callbacks, optimizers, utils
import plot_utils
self.args = args
self.VERBOSE = self.args.verbose
self.FAMILY_DATASET = s... | [
"def",
"__init__",
"(",
"self",
",",
"args",
")",
":",
"import",
"os",
"from",
"tensorflow",
".",
"keras",
"import",
"losses",
",",
"callbacks",
",",
"optimizers",
",",
"utils",
"import",
"plot_utils",
"self",
".",
"args",
"=",
"args",
"self",
".",
"VERB... | [
10,
4
] | [
63,
70
] | python | en | ['en', 'error', 'th'] | False |
Model.color_preprocess | (self, imgs, istrain=False) |
TODO: Write Comment
|
TODO: Write Comment
| def color_preprocess(self, imgs, istrain=False):
"""
TODO: Write Comment
"""
if imgs.ndim < 4: imgs = np.array([imgs])
imgs = imgs.astype('float32')
if self.raw_defence:
if not self.istrain_defence:
imgs = self.defence(imgs)[0]
... | [
"def",
"color_preprocess",
"(",
"self",
",",
"imgs",
",",
"istrain",
"=",
"False",
")",
":",
"if",
"imgs",
".",
"ndim",
"<",
"4",
":",
"imgs",
"=",
"np",
".",
"array",
"(",
"[",
"imgs",
"]",
")",
"imgs",
"=",
"imgs",
".",
"astype",
"(",
"'float32... | [
67,
4
] | [
85,
19
] | python | en | ['en', 'error', 'th'] | False |
Model.color_postprocess | (self, imgs) |
TODO: Write Comment
|
TODO: Write Comment
| def color_postprocess(self, imgs):
"""
TODO: Write Comment
"""
if imgs.ndim < 4: imgs = np.array([imgs])
imgs = imgs.astype('float32')
for i in range(imgs.shape[-1]): imgs[:,:,:,i] = (imgs[:,:,:,i] * self.std[i]) + self.mean[i]
return imgs | [
"def",
"color_postprocess",
"(",
"self",
",",
"imgs",
")",
":",
"if",
"imgs",
".",
"ndim",
"<",
"4",
":",
"imgs",
"=",
"np",
".",
"array",
"(",
"[",
"imgs",
"]",
")",
"imgs",
"=",
"imgs",
".",
"astype",
"(",
"'float32'",
")",
"for",
"i",
"in",
... | [
87,
4
] | [
97,
19
] | python | en | ['en', 'error', 'th'] | False |
Model.load | (self) |
TODO: Write Comment
|
TODO: Write Comment
| def load(self):
"""
TODO: Write Comment
"""
if self.VERBOSE: print(f"Loading Model...")
self._model = self.build_model()
self._model.compile(loss='categorical_crossentropy', optimizer=self.optimizer, metrics=['accuracy'])
try:
self._... | [
"def",
"load",
"(",
"self",
")",
":",
"if",
"self",
".",
"VERBOSE",
":",
"print",
"(",
"f\"Loading Model...\"",
")",
"self",
".",
"_model",
"=",
"self",
".",
"build_model",
"(",
")",
"self",
".",
"_model",
".",
"compile",
"(",
"loss",
"=",
"'categorica... | [
99,
4
] | [
152,
98
] | python | en | ['en', 'error', 'th'] | False |
Model.save | (self, history) |
TODO: Write Comment
|
TODO: Write Comment
| def save(self, history):
"""
TODO: Write Comment
"""
import pickle
if self.VERBOSE: print(f"Save Model History and Weights...")
with open(f"{self.log_filepath}history.pkl", 'wb') as file: pickle.dump(history, file)
self._model.save(f"{self.log_... | [
"def",
"save",
"(",
"self",
",",
"history",
")",
":",
"import",
"pickle",
"if",
"self",
".",
"VERBOSE",
":",
"print",
"(",
"f\"Save Model History and Weights...\"",
")",
"with",
"open",
"(",
"f\"{self.log_filepath}history.pkl\"",
",",
"'wb'",
")",
"as",
"file",
... | [
157,
4
] | [
169,
72
] | python | en | ['en', 'error', 'th'] | False |
Model.build_model | (self) |
TODO: Write Comment
|
TODO: Write Comment
| def build_model(self):
"""
TODO: Write Comment
"""
from tensorflow.keras import layers, models
img_input = layers.Input(shape=self.input_shape)
return models.Model(img_input, self.network(img_input)) | [
"def",
"build_model",
"(",
"self",
")",
":",
"from",
"tensorflow",
".",
"keras",
"import",
"layers",
",",
"models",
"img_input",
"=",
"layers",
".",
"Input",
"(",
"shape",
"=",
"self",
".",
"input_shape",
")",
"return",
"models",
".",
"Model",
"(",
"img_... | [
173,
4
] | [
182,
63
] | python | en | ['en', 'error', 'th'] | False |
Model.train | (self) |
TODO: Write Comment
|
TODO: Write Comment
| def train(self):
"""
TODO: Write Comment
"""
history = self.fit_normal()
self.save(history) | [
"def",
"train",
"(",
"self",
")",
":",
"history",
"=",
"self",
".",
"fit_normal",
"(",
")",
"self",
".",
"save",
"(",
"history",
")"
] | [
184,
4
] | [
191,
26
] | python | en | ['en', 'error', 'th'] | False |
Model.fit_model | (self, x_train, y_train, x_test, y_test, batch_size, epochs, iterations, cbks, verbose) |
TODO: Write Comment
|
TODO: Write Comment
| def fit_model(self, x_train, y_train, x_test, y_test, batch_size, epochs, iterations, cbks, verbose):
"""
TODO: Write Comment
"""
from tensorflow.keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(horizontal_flip=True, width_shift_range=0.125, heigh... | [
"def",
"fit_model",
"(",
"self",
",",
"x_train",
",",
"y_train",
",",
"x_test",
",",
"y_test",
",",
"batch_size",
",",
"epochs",
",",
"iterations",
",",
"cbks",
",",
"verbose",
")",
":",
"from",
"tensorflow",
".",
"keras",
".",
"preprocessing",
".",
"ima... | [
193,
4
] | [
222,
183
] | python | en | ['en', 'error', 'th'] | False |
Model.fit_normal | (self) |
TODO: Write Comment
|
TODO: Write Comment
| def fit_normal(self):
"""
TODO: Write Comment
"""
x_train = self.processed_x_train if self.NUM_DEFENCE != 1 else self.raw_x_train
history = self.fit_model(x_train, self.processed_y_train, self.processed_x_test, self.processed_y_test, self.batch_size, self.epochs, se... | [
"def",
"fit_normal",
"(",
"self",
")",
":",
"x_train",
"=",
"self",
".",
"processed_x_train",
"if",
"self",
".",
"NUM_DEFENCE",
"!=",
"1",
"else",
"self",
".",
"raw_x_train",
"history",
"=",
"self",
".",
"fit_model",
"(",
"x_train",
",",
"self",
".",
"pr... | [
308,
4
] | [
317,
160
] | python | en | ['en', 'error', 'th'] | False |
Model.predict | (self, img) |
TODO: Write Comment
|
TODO: Write Comment
| def predict(self, img):
"""
TODO: Write Comment
"""
return self._model.predict(self.color_preprocess(img, False), batch_size=self.batch_size) | [
"def",
"predict",
"(",
"self",
",",
"img",
")",
":",
"return",
"self",
".",
"_model",
".",
"predict",
"(",
"self",
".",
"color_preprocess",
"(",
"img",
",",
"False",
")",
",",
"batch_size",
"=",
"self",
".",
"batch_size",
")"
] | [
319,
4
] | [
324,
97
] | python | en | ['en', 'error', 'th'] | False |
Model.get | (self, samples) |
TODO: Write Comment
|
TODO: Write Comment
| def get(self, samples):
"""
TODO: Write Comment
"""
indices = list(range(10000)) # np.random.randint(self.num_images['test'], size=samples)
return indices, self.raw_x_test[indices].astype('float32'), self.raw_y_test[indices] | [
"def",
"get",
"(",
"self",
",",
"samples",
")",
":",
"indices",
"=",
"list",
"(",
"range",
"(",
"10000",
")",
")",
"# np.random.randint(self.num_images['test'], size=samples)",
"return",
"indices",
",",
"self",
".",
"raw_x_test",
"[",
"indices",
"]",
".",
"ast... | [
327,
4
] | [
334,
92
] | python | en | ['en', 'error', 'th'] | False |
_unique_everseen | (iterable, key=None) | List unique elements, preserving order. Remember all elements ever seen. | List unique elements, preserving order. Remember all elements ever seen. | def _unique_everseen(iterable, key=None):
"List unique elements, preserving order. Remember all elements ever seen."
# unique_everseen('AAAABBBCCDAABBB') --> A B C D
# unique_everseen('ABBCcAD', str.lower) --> A B C D
seen = set()
seen_add = seen.add
if key is None:
for element in iterto... | [
"def",
"_unique_everseen",
"(",
"iterable",
",",
"key",
"=",
"None",
")",
":",
"# unique_everseen('AAAABBBCCDAABBB') --> A B C D",
"# unique_everseen('ABBCcAD', str.lower) --> A B C D",
"seen",
"=",
"set",
"(",
")",
"seen_add",
"=",
"seen",
".",
"add",
"if",
"key",
"i... | [
238,
0
] | [
253,
29
] | python | ca | ['ca', 'ca', 'en'] | True |
build_py.run | (self) | Build modules, packages, and copy data files to build directory | Build modules, packages, and copy data files to build directory | def run(self):
"""Build modules, packages, and copy data files to build directory"""
if not self.py_modules and not self.packages:
return
if self.py_modules:
self.build_modules()
if self.packages:
self.build_packages()
self.build_package_... | [
"def",
"run",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"py_modules",
"and",
"not",
"self",
".",
"packages",
":",
"return",
"if",
"self",
".",
"py_modules",
":",
"self",
".",
"build_modules",
"(",
")",
"if",
"self",
".",
"packages",
":",
"self... | [
44,
4
] | [
62,
78
] | python | en | ['en', 'en', 'en'] | True |
build_py.__getattr__ | (self, attr) | lazily compute data files | lazily compute data files | def __getattr__(self, attr):
"lazily compute data files"
if attr == 'data_files':
self.data_files = self._get_data_files()
return self.data_files
return orig.build_py.__getattr__(self, attr) | [
"def",
"__getattr__",
"(",
"self",
",",
"attr",
")",
":",
"if",
"attr",
"==",
"'data_files'",
":",
"self",
".",
"data_files",
"=",
"self",
".",
"_get_data_files",
"(",
")",
"return",
"self",
".",
"data_files",
"return",
"orig",
".",
"build_py",
".",
"__g... | [
64,
4
] | [
69,
52
] | python | it | ['it', 'it', 'it'] | True |
build_py._get_data_files | (self) | Generate list of '(package,src_dir,build_dir,filenames)' tuples | Generate list of '(package,src_dir,build_dir,filenames)' tuples | def _get_data_files(self):
"""Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
self.analyze_manifest()
return list(map(self._get_pkg_data_files, self.packages or ())) | [
"def",
"_get_data_files",
"(",
"self",
")",
":",
"self",
".",
"analyze_manifest",
"(",
")",
"return",
"list",
"(",
"map",
"(",
"self",
".",
"_get_pkg_data_files",
",",
"self",
".",
"packages",
"or",
"(",
")",
")",
")"
] | [
78,
4
] | [
81,
71
] | python | en | ['en', 'af', 'en'] | True |
build_py.find_data_files | (self, package, src_dir) | Return filenames for package's data files in 'src_dir | Return filenames for package's data files in 'src_dir | def find_data_files(self, package, src_dir):
"""Return filenames for package's data files in 'src_dir'"""
patterns = self._get_platform_patterns(
self.package_data,
package,
src_dir,
)
globs_expanded = map(glob, patterns)
# flatten the expanded... | [
"def",
"find_data_files",
"(",
"self",
",",
"package",
",",
"src_dir",
")",
":",
"patterns",
"=",
"self",
".",
"_get_platform_patterns",
"(",
"self",
".",
"package_data",
",",
"package",
",",
"src_dir",
",",
")",
"globs_expanded",
"=",
"map",
"(",
"glob",
... | [
97,
4
] | [
112,
63
] | python | en | ['en', 'no', 'en'] | True |
build_py.build_package_data | (self) | Copy data files into build directory | Copy data files into build directory | def build_package_data(self):
"""Copy data files into build directory"""
for package, src_dir, build_dir, filenames in self.data_files:
for filename in filenames:
target = os.path.join(build_dir, filename)
self.mkpath(os.path.dirname(target))
s... | [
"def",
"build_package_data",
"(",
"self",
")",
":",
"for",
"package",
",",
"src_dir",
",",
"build_dir",
",",
"filenames",
"in",
"self",
".",
"data_files",
":",
"for",
"filename",
"in",
"filenames",
":",
"target",
"=",
"os",
".",
"path",
".",
"join",
"(",... | [
114,
4
] | [
126,
53
] | python | en | ['en', 'en', 'en'] | True |
build_py.check_package | (self, package, package_dir) | Check namespace packages' __init__ for declare_namespace | Check namespace packages' __init__ for declare_namespace | def check_package(self, package, package_dir):
"""Check namespace packages' __init__ for declare_namespace"""
try:
return self.packages_checked[package]
except KeyError:
pass
init_py = orig.build_py.check_package(self, package, package_dir)
self.packages_... | [
"def",
"check_package",
"(",
"self",
",",
"package",
",",
"package_dir",
")",
":",
"try",
":",
"return",
"self",
".",
"packages_checked",
"[",
"package",
"]",
"except",
"KeyError",
":",
"pass",
"init_py",
"=",
"orig",
".",
"build_py",
".",
"check_package",
... | [
155,
4
] | [
183,
22
] | python | en | ['es', 'en', 'en'] | True |
build_py.exclude_data_files | (self, package, src_dir, files) | Filter filenames for package's data files in 'src_dir | Filter filenames for package's data files in 'src_dir | def exclude_data_files(self, package, src_dir, files):
"""Filter filenames for package's data files in 'src_dir'"""
files = list(files)
patterns = self._get_platform_patterns(
self.exclude_package_data,
package,
src_dir,
)
match_groups = (
... | [
"def",
"exclude_data_files",
"(",
"self",
",",
"package",
",",
"src_dir",
",",
"files",
")",
":",
"files",
"=",
"list",
"(",
"files",
")",
"patterns",
"=",
"self",
".",
"_get_platform_patterns",
"(",
"self",
".",
"exclude_package_data",
",",
"package",
",",
... | [
195,
4
] | [
216,
46
] | python | en | ['en', 'en', 'en'] | True |
build_py._get_platform_patterns | (spec, package, src_dir) |
yield platform-specific path patterns (suitable for glob
or fn_match) from a glob-based spec (such as
self.package_data or self.exclude_package_data)
matching package in src_dir.
|
yield platform-specific path patterns (suitable for glob
or fn_match) from a glob-based spec (such as
self.package_data or self.exclude_package_data)
matching package in src_dir.
| def _get_platform_patterns(spec, package, src_dir):
"""
yield platform-specific path patterns (suitable for glob
or fn_match) from a glob-based spec (such as
self.package_data or self.exclude_package_data)
matching package in src_dir.
"""
raw_patterns = itertools.... | [
"def",
"_get_platform_patterns",
"(",
"spec",
",",
"package",
",",
"src_dir",
")",
":",
"raw_patterns",
"=",
"itertools",
".",
"chain",
"(",
"spec",
".",
"get",
"(",
"''",
",",
"[",
"]",
")",
",",
"spec",
".",
"get",
"(",
"package",
",",
"[",
"]",
... | [
219,
4
] | [
234,
9
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.check | (self, app_configs) |
Run the system checks on all ModelAdmins, except if they aren't
customized at all.
|
Run the system checks on all ModelAdmins, except if they aren't
customized at all.
| def check(self, app_configs):
"""
Run the system checks on all ModelAdmins, except if they aren't
customized at all.
"""
if app_configs is None:
app_configs = apps.get_app_configs()
app_configs = set(app_configs) # Speed up lookups below
errors = []
... | [
"def",
"check",
"(",
"self",
",",
"app_configs",
")",
":",
"if",
"app_configs",
"is",
"None",
":",
"app_configs",
"=",
"apps",
".",
"get_app_configs",
"(",
")",
"app_configs",
"=",
"set",
"(",
"app_configs",
")",
"# Speed up lookups below",
"errors",
"=",
"[... | [
67,
4
] | [
81,
21
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.register | (self, model_or_iterable, admin_class=None, **options) |
Registers the given model(s) with the given admin class.
The model(s) should be Model classes, not instances.
If an admin class isn't given, it will use ModelAdmin (the default
admin options). If keyword arguments are given -- e.g., list_display --
they'll be applied as option... |
Registers the given model(s) with the given admin class. | def register(self, model_or_iterable, admin_class=None, **options):
"""
Registers the given model(s) with the given admin class.
The model(s) should be Model classes, not instances.
If an admin class isn't given, it will use ModelAdmin (the default
admin options). If keyword ar... | [
"def",
"register",
"(",
"self",
",",
"model_or_iterable",
",",
"admin_class",
"=",
"None",
",",
"*",
"*",
"options",
")",
":",
"if",
"not",
"admin_class",
":",
"admin_class",
"=",
"ModelAdmin",
"if",
"isinstance",
"(",
"model_or_iterable",
",",
"ModelBase",
... | [
83,
4
] | [
124,
64
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.unregister | (self, model_or_iterable) |
Unregisters the given model(s).
If a model isn't already registered, this will raise NotRegistered.
|
Unregisters the given model(s). | def unregister(self, model_or_iterable):
"""
Unregisters the given model(s).
If a model isn't already registered, this will raise NotRegistered.
"""
if isinstance(model_or_iterable, ModelBase):
model_or_iterable = [model_or_iterable]
for model in model_or_ite... | [
"def",
"unregister",
"(",
"self",
",",
"model_or_iterable",
")",
":",
"if",
"isinstance",
"(",
"model_or_iterable",
",",
"ModelBase",
")",
":",
"model_or_iterable",
"=",
"[",
"model_or_iterable",
"]",
"for",
"model",
"in",
"model_or_iterable",
":",
"if",
"model"... | [
126,
4
] | [
137,
37
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.is_registered | (self, model) |
Check if a model class is registered with this `AdminSite`.
|
Check if a model class is registered with this `AdminSite`.
| def is_registered(self, model):
"""
Check if a model class is registered with this `AdminSite`.
"""
return model in self._registry | [
"def",
"is_registered",
"(",
"self",
",",
"model",
")",
":",
"return",
"model",
"in",
"self",
".",
"_registry"
] | [
139,
4
] | [
143,
38
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.add_action | (self, action, name=None) |
Register an action to be available globally.
|
Register an action to be available globally.
| def add_action(self, action, name=None):
"""
Register an action to be available globally.
"""
name = name or action.__name__
self._actions[name] = action
self._global_actions[name] = action | [
"def",
"add_action",
"(",
"self",
",",
"action",
",",
"name",
"=",
"None",
")",
":",
"name",
"=",
"name",
"or",
"action",
".",
"__name__",
"self",
".",
"_actions",
"[",
"name",
"]",
"=",
"action",
"self",
".",
"_global_actions",
"[",
"name",
"]",
"="... | [
145,
4
] | [
151,
43
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.disable_action | (self, name) |
Disable a globally-registered action. Raises KeyError for invalid names.
|
Disable a globally-registered action. Raises KeyError for invalid names.
| def disable_action(self, name):
"""
Disable a globally-registered action. Raises KeyError for invalid names.
"""
del self._actions[name] | [
"def",
"disable_action",
"(",
"self",
",",
"name",
")",
":",
"del",
"self",
".",
"_actions",
"[",
"name",
"]"
] | [
153,
4
] | [
157,
31
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.get_action | (self, name) |
Explicitly get a registered global action whether it's enabled or
not. Raises KeyError for invalid names.
|
Explicitly get a registered global action whether it's enabled or
not. Raises KeyError for invalid names.
| def get_action(self, name):
"""
Explicitly get a registered global action whether it's enabled or
not. Raises KeyError for invalid names.
"""
return self._global_actions[name] | [
"def",
"get_action",
"(",
"self",
",",
"name",
")",
":",
"return",
"self",
".",
"_global_actions",
"[",
"name",
"]"
] | [
159,
4
] | [
164,
41
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.actions | (self) |
Get all the enabled actions as an iterable of (name, func).
|
Get all the enabled actions as an iterable of (name, func).
| def actions(self):
"""
Get all the enabled actions as an iterable of (name, func).
"""
return six.iteritems(self._actions) | [
"def",
"actions",
"(",
"self",
")",
":",
"return",
"six",
".",
"iteritems",
"(",
"self",
".",
"_actions",
")"
] | [
167,
4
] | [
171,
43
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.has_permission | (self, request) |
Returns True if the given HttpRequest has permission to view
*at least one* page in the admin site.
|
Returns True if the given HttpRequest has permission to view
*at least one* page in the admin site.
| def has_permission(self, request):
"""
Returns True if the given HttpRequest has permission to view
*at least one* page in the admin site.
"""
return request.user.is_active and request.user.is_staff | [
"def",
"has_permission",
"(",
"self",
",",
"request",
")",
":",
"return",
"request",
".",
"user",
".",
"is_active",
"and",
"request",
".",
"user",
".",
"is_staff"
] | [
181,
4
] | [
186,
63
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.admin_view | (self, view, cacheable=False) |
Decorator to create an admin view attached to this ``AdminSite``. This
wraps the view and provides permission checking by calling
``self.has_permission``.
You'll want to use this from within ``AdminSite.get_urls()``:
class MyAdminSite(AdminSite):
def get_u... |
Decorator to create an admin view attached to this ``AdminSite``. This
wraps the view and provides permission checking by calling
``self.has_permission``. | def admin_view(self, view, cacheable=False):
"""
Decorator to create an admin view attached to this ``AdminSite``. This
wraps the view and provides permission checking by calling
``self.has_permission``.
You'll want to use this from within ``AdminSite.get_urls()``:
... | [
"def",
"admin_view",
"(",
"self",
",",
"view",
",",
"cacheable",
"=",
"False",
")",
":",
"def",
"inner",
"(",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"has_permission",
"(",
"request",
")",
":",
"if"... | [
188,
4
] | [
230,
42
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.each_context | (self, request) |
Returns a dictionary of variables to put in the template context for
*every* page in the admin site.
For sites running on a subpath, use the SCRIPT_NAME value if site_url
hasn't been customized.
|
Returns a dictionary of variables to put in the template context for
*every* page in the admin site. | def each_context(self, request):
"""
Returns a dictionary of variables to put in the template context for
*every* page in the admin site.
For sites running on a subpath, use the SCRIPT_NAME value if site_url
hasn't been customized.
"""
script_name = request.META[... | [
"def",
"each_context",
"(",
"self",
",",
"request",
")",
":",
"script_name",
"=",
"request",
".",
"META",
"[",
"'SCRIPT_NAME'",
"]",
"site_url",
"=",
"script_name",
"if",
"self",
".",
"site_url",
"==",
"'/'",
"and",
"script_name",
"else",
"self",
".",
"sit... | [
281,
4
] | [
297,
9
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.password_change | (self, request, extra_context=None) |
Handles the "change password" task -- both form display and validation.
|
Handles the "change password" task -- both form display and validation.
| def password_change(self, request, extra_context=None):
"""
Handles the "change password" task -- both form display and validation.
"""
from django.contrib.admin.forms import AdminPasswordChangeForm
from django.contrib.auth.views import PasswordChangeView
url = reverse('a... | [
"def",
"password_change",
"(",
"self",
",",
"request",
",",
"extra_context",
"=",
"None",
")",
":",
"from",
"django",
".",
"contrib",
".",
"admin",
".",
"forms",
"import",
"AdminPasswordChangeForm",
"from",
"django",
".",
"contrib",
".",
"auth",
".",
"views"... | [
299,
4
] | [
314,
62
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.password_change_done | (self, request, extra_context=None) |
Displays the "success" page after a password change.
|
Displays the "success" page after a password change.
| def password_change_done(self, request, extra_context=None):
"""
Displays the "success" page after a password change.
"""
from django.contrib.auth.views import PasswordChangeDoneView
defaults = {
'extra_context': dict(self.each_context(request), **(extra_context or {}... | [
"def",
"password_change_done",
"(",
"self",
",",
"request",
",",
"extra_context",
"=",
"None",
")",
":",
"from",
"django",
".",
"contrib",
".",
"auth",
".",
"views",
"import",
"PasswordChangeDoneView",
"defaults",
"=",
"{",
"'extra_context'",
":",
"dict",
"(",... | [
316,
4
] | [
327,
66
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.i18n_javascript | (self, request, extra_context=None) |
Displays the i18n JavaScript that the Django admin requires.
`extra_context` is unused but present for consistency with the other
admin views.
|
Displays the i18n JavaScript that the Django admin requires. | def i18n_javascript(self, request, extra_context=None):
"""
Displays the i18n JavaScript that the Django admin requires.
`extra_context` is unused but present for consistency with the other
admin views.
"""
return JavaScriptCatalog.as_view(packages=['django.contrib.admin... | [
"def",
"i18n_javascript",
"(",
"self",
",",
"request",
",",
"extra_context",
"=",
"None",
")",
":",
"return",
"JavaScriptCatalog",
".",
"as_view",
"(",
"packages",
"=",
"[",
"'django.contrib.admin'",
"]",
")",
"(",
"request",
")"
] | [
329,
4
] | [
336,
84
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.logout | (self, request, extra_context=None) |
Logs out the user for the given HttpRequest.
This should *not* assume the user is already logged in.
|
Logs out the user for the given HttpRequest. | def logout(self, request, extra_context=None):
"""
Logs out the user for the given HttpRequest.
This should *not* assume the user is already logged in.
"""
from django.contrib.auth.views import LogoutView
defaults = {
'extra_context': dict(
se... | [
"def",
"logout",
"(",
"self",
",",
"request",
",",
"extra_context",
"=",
"None",
")",
":",
"from",
"django",
".",
"contrib",
".",
"auth",
".",
"views",
"import",
"LogoutView",
"defaults",
"=",
"{",
"'extra_context'",
":",
"dict",
"(",
"self",
".",
"each_... | [
339,
4
] | [
358,
54
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.login | (self, request, extra_context=None) |
Displays the login form for the given HttpRequest.
|
Displays the login form for the given HttpRequest.
| def login(self, request, extra_context=None):
"""
Displays the login form for the given HttpRequest.
"""
if request.method == 'GET' and self.has_permission(request):
# Already logged-in, redirect to admin index
index_path = reverse('admin:index', current_app=self.... | [
"def",
"login",
"(",
"self",
",",
"request",
",",
"extra_context",
"=",
"None",
")",
":",
"if",
"request",
".",
"method",
"==",
"'GET'",
"and",
"self",
".",
"has_permission",
"(",
"request",
")",
":",
"# Already logged-in, redirect to admin index",
"index_path",... | [
361,
4
] | [
392,
53
] | python | en | ['en', 'error', 'th'] | False |
AdminSite._build_app_dict | (self, request, label=None) |
Builds the app dictionary. Takes an optional label parameters to filter
models of a specific app.
|
Builds the app dictionary. Takes an optional label parameters to filter
models of a specific app.
| def _build_app_dict(self, request, label=None):
"""
Builds the app dictionary. Takes an optional label parameters to filter
models of a specific app.
"""
app_dict = {}
if label:
models = {
m: m_a for m, m_a in self._registry.items()
... | [
"def",
"_build_app_dict",
"(",
"self",
",",
"request",
",",
"label",
"=",
"None",
")",
":",
"app_dict",
"=",
"{",
"}",
"if",
"label",
":",
"models",
"=",
"{",
"m",
":",
"m_a",
"for",
"m",
",",
"m_a",
"in",
"self",
".",
"_registry",
".",
"items",
... | [
394,
4
] | [
457,
23
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.get_app_list | (self, request) |
Returns a sorted list of all the installed apps that have been
registered in this site.
|
Returns a sorted list of all the installed apps that have been
registered in this site.
| def get_app_list(self, request):
"""
Returns a sorted list of all the installed apps that have been
registered in this site.
"""
app_dict = self._build_app_dict(request)
# Sort the apps alphabetically.
app_list = sorted(app_dict.values(), key=lambda x: x['name'].... | [
"def",
"get_app_list",
"(",
"self",
",",
"request",
")",
":",
"app_dict",
"=",
"self",
".",
"_build_app_dict",
"(",
"request",
")",
"# Sort the apps alphabetically.",
"app_list",
"=",
"sorted",
"(",
"app_dict",
".",
"values",
"(",
")",
",",
"key",
"=",
"lamb... | [
459,
4
] | [
473,
23
] | python | en | ['en', 'error', 'th'] | False |
AdminSite.index | (self, request, extra_context=None) |
Displays the main admin index page, which lists all of the installed
apps that have been registered in this site.
|
Displays the main admin index page, which lists all of the installed
apps that have been registered in this site.
| def index(self, request, extra_context=None):
"""
Displays the main admin index page, which lists all of the installed
apps that have been registered in this site.
"""
app_list = self.get_app_list(request)
context = dict(
self.each_context(request),
... | [
"def",
"index",
"(",
"self",
",",
"request",
",",
"extra_context",
"=",
"None",
")",
":",
"app_list",
"=",
"self",
".",
"get_app_list",
"(",
"request",
")",
"context",
"=",
"dict",
"(",
"self",
".",
"each_context",
"(",
"request",
")",
",",
"title",
"=... | [
476,
4
] | [
492,
92
] | python | en | ['en', 'error', 'th'] | False |
clear_preregistrationuser_invited_as_admin | (
apps: StateApps, schema_editor: DatabaseSchemaEditor
) | This migration fixes any PreregistrationUser objects that might
have been already corrupted to have the administrator role by the
buggy original version of migration
0198_preregistrationuser_invited_as.
Since invitations that create new users as administrators are
rare, it is cleaner to just remove... | This migration fixes any PreregistrationUser objects that might
have been already corrupted to have the administrator role by the
buggy original version of migration
0198_preregistrationuser_invited_as. | def clear_preregistrationuser_invited_as_admin(
apps: StateApps, schema_editor: DatabaseSchemaEditor
) -> None:
"""This migration fixes any PreregistrationUser objects that might
have been already corrupted to have the administrator role by the
buggy original version of migration
0198_preregistratio... | [
"def",
"clear_preregistrationuser_invited_as_admin",
"(",
"apps",
":",
"StateApps",
",",
"schema_editor",
":",
"DatabaseSchemaEditor",
")",
"->",
"None",
":",
"INVITED_AS_MEMBER",
"=",
"1",
"INVITED_AS_REALM_ADMIN",
"=",
"2",
"PreregistrationUser",
"=",
"apps",
".",
"... | [
9,
0
] | [
30,
5
] | python | en | ['en', 'en', 'en'] | True |
reset_cache | (**kwargs) |
Reset global state when LANGUAGES setting has been changed, as some
languages should no longer be accepted.
|
Reset global state when LANGUAGES setting has been changed, as some
languages should no longer be accepted.
| def reset_cache(**kwargs):
"""
Reset global state when LANGUAGES setting has been changed, as some
languages should no longer be accepted.
"""
if kwargs['setting'] in ('LANGUAGES', 'LANGUAGE_CODE'):
check_for_language.cache_clear()
get_languages.cache_clear()
get_supported_la... | [
"def",
"reset_cache",
"(",
"*",
"*",
"kwargs",
")",
":",
"if",
"kwargs",
"[",
"'setting'",
"]",
"in",
"(",
"'LANGUAGES'",
",",
"'LANGUAGE_CODE'",
")",
":",
"check_for_language",
".",
"cache_clear",
"(",
")",
"get_languages",
".",
"cache_clear",
"(",
")",
"... | [
51,
0
] | [
59,
52
] | python | en | ['en', 'error', 'th'] | False |
to_locale | (language, to_lower=False) |
Turns a language name (en-us) into a locale name (en_US). If 'to_lower' is
True, the last component is lower-cased (en_us).
|
Turns a language name (en-us) into a locale name (en_US). If 'to_lower' is
True, the last component is lower-cased (en_us).
| def to_locale(language, to_lower=False):
"""
Turns a language name (en-us) into a locale name (en_US). If 'to_lower' is
True, the last component is lower-cased (en_us).
"""
p = language.find('-')
if p >= 0:
if to_lower:
return language[:p].lower() + '_' + language[p + 1:].low... | [
"def",
"to_locale",
"(",
"language",
",",
"to_lower",
"=",
"False",
")",
":",
"p",
"=",
"language",
".",
"find",
"(",
"'-'",
")",
"if",
"p",
">=",
"0",
":",
"if",
"to_lower",
":",
"return",
"language",
"[",
":",
"p",
"]",
".",
"lower",
"(",
")",
... | [
62,
0
] | [
77,
31
] | python | en | ['en', 'error', 'th'] | False |
to_language | (locale) | Turns a locale name (en_US) into a language name (en-us). | Turns a locale name (en_US) into a language name (en-us). | def to_language(locale):
"""Turns a locale name (en_US) into a language name (en-us)."""
p = locale.find('_')
if p >= 0:
return locale[:p].lower() + '-' + locale[p + 1:].lower()
else:
return locale.lower() | [
"def",
"to_language",
"(",
"locale",
")",
":",
"p",
"=",
"locale",
".",
"find",
"(",
"'_'",
")",
"if",
"p",
">=",
"0",
":",
"return",
"locale",
"[",
":",
"p",
"]",
".",
"lower",
"(",
")",
"+",
"'-'",
"+",
"locale",
"[",
"p",
"+",
"1",
":",
... | [
80,
0
] | [
86,
29
] | python | en | ['es', 'en', 'en'] | True |
translation | (language) |
Returns a translation object in the default 'django' domain.
|
Returns a translation object in the default 'django' domain.
| def translation(language):
"""
Returns a translation object in the default 'django' domain.
"""
global _translations
if language not in _translations:
_translations[language] = DjangoTranslation(language)
return _translations[language] | [
"def",
"translation",
"(",
"language",
")",
":",
"global",
"_translations",
"if",
"language",
"not",
"in",
"_translations",
":",
"_translations",
"[",
"language",
"]",
"=",
"DjangoTranslation",
"(",
"language",
")",
"return",
"_translations",
"[",
"language",
"]... | [
221,
0
] | [
228,
34
] | python | en | ['en', 'error', 'th'] | False |
activate | (language) |
Fetches the translation object for a given language and installs it as the
current translation object for the current thread.
|
Fetches the translation object for a given language and installs it as the
current translation object for the current thread.
| def activate(language):
"""
Fetches the translation object for a given language and installs it as the
current translation object for the current thread.
"""
if not language:
return
_active.value = translation(language) | [
"def",
"activate",
"(",
"language",
")",
":",
"if",
"not",
"language",
":",
"return",
"_active",
".",
"value",
"=",
"translation",
"(",
"language",
")"
] | [
231,
0
] | [
238,
41
] | python | en | ['en', 'error', 'th'] | False |
deactivate | () |
Deinstalls the currently active translation object so that further _ calls
will resolve against the default translation object, again.
|
Deinstalls the currently active translation object so that further _ calls
will resolve against the default translation object, again.
| def deactivate():
"""
Deinstalls the currently active translation object so that further _ calls
will resolve against the default translation object, again.
"""
if hasattr(_active, "value"):
del _active.value | [
"def",
"deactivate",
"(",
")",
":",
"if",
"hasattr",
"(",
"_active",
",",
"\"value\"",
")",
":",
"del",
"_active",
".",
"value"
] | [
241,
0
] | [
247,
25
] | python | en | ['en', 'error', 'th'] | False |
deactivate_all | () |
Makes the active translation object a NullTranslations() instance. This is
useful when we want delayed translations to appear as the original string
for some reason.
|
Makes the active translation object a NullTranslations() instance. This is
useful when we want delayed translations to appear as the original string
for some reason.
| def deactivate_all():
"""
Makes the active translation object a NullTranslations() instance. This is
useful when we want delayed translations to appear as the original string
for some reason.
"""
_active.value = gettext_module.NullTranslations()
_active.value.to_language = lambda *args: None | [
"def",
"deactivate_all",
"(",
")",
":",
"_active",
".",
"value",
"=",
"gettext_module",
".",
"NullTranslations",
"(",
")",
"_active",
".",
"value",
".",
"to_language",
"=",
"lambda",
"*",
"args",
":",
"None"
] | [
250,
0
] | [
257,
50
] | python | en | ['en', 'error', 'th'] | False |
get_language | () | Returns the currently selected language. | Returns the currently selected language. | def get_language():
"""Returns the currently selected language."""
t = getattr(_active, "value", None)
if t is not None:
try:
return t.to_language()
except AttributeError:
pass
# If we don't have a real translation object, assume it's the default language.
ret... | [
"def",
"get_language",
"(",
")",
":",
"t",
"=",
"getattr",
"(",
"_active",
",",
"\"value\"",
",",
"None",
")",
"if",
"t",
"is",
"not",
"None",
":",
"try",
":",
"return",
"t",
".",
"to_language",
"(",
")",
"except",
"AttributeError",
":",
"pass",
"# I... | [
260,
0
] | [
269,
33
] | python | en | ['en', 'en', 'en'] | True |
get_language_bidi | () |
Returns selected language's BiDi layout.
* False = left-to-right layout
* True = right-to-left layout
|
Returns selected language's BiDi layout. | def get_language_bidi():
"""
Returns selected language's BiDi layout.
* False = left-to-right layout
* True = right-to-left layout
"""
lang = get_language()
if lang is None:
return False
else:
base_lang = get_language().split('-')[0]
return base_lang in settings.... | [
"def",
"get_language_bidi",
"(",
")",
":",
"lang",
"=",
"get_language",
"(",
")",
"if",
"lang",
"is",
"None",
":",
"return",
"False",
"else",
":",
"base_lang",
"=",
"get_language",
"(",
")",
".",
"split",
"(",
"'-'",
")",
"[",
"0",
"]",
"return",
"ba... | [
272,
0
] | [
284,
51
] | python | en | ['en', 'error', 'th'] | False |
catalog | () |
Returns the current active catalog for further processing.
This can be used if you need to modify the catalog or want to access the
whole message catalog instead of just translating one string.
|
Returns the current active catalog for further processing.
This can be used if you need to modify the catalog or want to access the
whole message catalog instead of just translating one string.
| def catalog():
"""
Returns the current active catalog for further processing.
This can be used if you need to modify the catalog or want to access the
whole message catalog instead of just translating one string.
"""
global _default
t = getattr(_active, "value", None)
if t is not None:
... | [
"def",
"catalog",
"(",
")",
":",
"global",
"_default",
"t",
"=",
"getattr",
"(",
"_active",
",",
"\"value\"",
",",
"None",
")",
"if",
"t",
"is",
"not",
"None",
":",
"return",
"t",
"if",
"_default",
"is",
"None",
":",
"_default",
"=",
"translation",
"... | [
287,
0
] | [
300,
19
] | python | en | ['en', 'error', 'th'] | False |
do_translate | (message, translation_function) |
Translates 'message' using the given 'translation_function' name -- which
will be either gettext or ugettext. It uses the current thread to find the
translation object to use. If no current translation is activated, the
message will be run through the default translation object.
|
Translates 'message' using the given 'translation_function' name -- which
will be either gettext or ugettext. It uses the current thread to find the
translation object to use. If no current translation is activated, the
message will be run through the default translation object.
| def do_translate(message, translation_function):
"""
Translates 'message' using the given 'translation_function' name -- which
will be either gettext or ugettext. It uses the current thread to find the
translation object to use. If no current translation is activated, the
message will be run through... | [
"def",
"do_translate",
"(",
"message",
",",
"translation_function",
")",
":",
"global",
"_default",
"# str() is allowing a bytestring message to remain bytestring on Python 2",
"eol_message",
"=",
"message",
".",
"replace",
"(",
"str",
"(",
"'\\r\\n'",
")",
",",
"str",
... | [
303,
0
] | [
328,
17
] | python | en | ['en', 'error', 'th'] | False |
gettext | (message) |
Returns a string of the translation of the message.
Returns a string on Python 3 and an UTF-8-encoded bytestring on Python 2.
|
Returns a string of the translation of the message. | def gettext(message):
"""
Returns a string of the translation of the message.
Returns a string on Python 3 and an UTF-8-encoded bytestring on Python 2.
"""
return do_translate(message, 'gettext') | [
"def",
"gettext",
"(",
"message",
")",
":",
"return",
"do_translate",
"(",
"message",
",",
"'gettext'",
")"
] | [
331,
0
] | [
337,
43
] | python | en | ['en', 'error', 'th'] | False |
gettext_noop | (message) |
Marks strings for translation but doesn't translate them now. This can be
used to store strings in global variables that should stay in the base
language (because they might be used externally) and will be translated
later.
|
Marks strings for translation but doesn't translate them now. This can be
used to store strings in global variables that should stay in the base
language (because they might be used externally) and will be translated
later.
| def gettext_noop(message):
"""
Marks strings for translation but doesn't translate them now. This can be
used to store strings in global variables that should stay in the base
language (because they might be used externally) and will be translated
later.
"""
return message | [
"def",
"gettext_noop",
"(",
"message",
")",
":",
"return",
"message"
] | [
357,
0
] | [
364,
18
] | python | en | ['en', 'error', 'th'] | False |
ngettext | (singular, plural, number) |
Returns a string of the translation of either the singular or plural,
based on the number.
Returns a string on Python 3 and an UTF-8-encoded bytestring on Python 2.
|
Returns a string of the translation of either the singular or plural,
based on the number. | def ngettext(singular, plural, number):
"""
Returns a string of the translation of either the singular or plural,
based on the number.
Returns a string on Python 3 and an UTF-8-encoded bytestring on Python 2.
"""
return do_ntranslate(singular, plural, number, 'ngettext') | [
"def",
"ngettext",
"(",
"singular",
",",
"plural",
",",
"number",
")",
":",
"return",
"do_ntranslate",
"(",
"singular",
",",
"plural",
",",
"number",
",",
"'ngettext'",
")"
] | [
378,
0
] | [
385,
62
] | python | en | ['en', 'error', 'th'] | False |
all_locale_paths | () |
Returns a list of paths to user-provides languages files.
|
Returns a list of paths to user-provides languages files.
| def all_locale_paths():
"""
Returns a list of paths to user-provides languages files.
"""
globalpath = os.path.join(
os.path.dirname(upath(sys.modules[settings.__module__].__file__)), 'locale')
return [globalpath] + list(settings.LOCALE_PATHS) | [
"def",
"all_locale_paths",
"(",
")",
":",
"globalpath",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"upath",
"(",
"sys",
".",
"modules",
"[",
"settings",
".",
"__module__",
"]",
".",
"__file__",
")",
")",
",",
... | [
410,
0
] | [
416,
53
] | python | en | ['en', 'error', 'th'] | False |
check_for_language | (lang_code) |
Checks whether there is a global language file for the given language
code. This is used to decide whether a user-provided language is
available.
lru_cache should have a maxsize to prevent from memory exhaustion attacks,
as the provided language codes are taken from the HTTP request. See also
... |
Checks whether there is a global language file for the given language
code. This is used to decide whether a user-provided language is
available. | def check_for_language(lang_code):
"""
Checks whether there is a global language file for the given language
code. This is used to decide whether a user-provided language is
available.
lru_cache should have a maxsize to prevent from memory exhaustion attacks,
as the provided language codes are ... | [
"def",
"check_for_language",
"(",
"lang_code",
")",
":",
"# First, a quick check to make sure lang_code is well-formed (#21458)",
"if",
"lang_code",
"is",
"None",
"or",
"not",
"language_code_re",
".",
"search",
"(",
"lang_code",
")",
":",
"return",
"False",
"for",
"path... | [
420,
0
] | [
436,
16
] | python | en | ['en', 'error', 'th'] | False |
get_languages | () |
Cache of settings.LANGUAGES in an OrderedDict for easy lookups by key.
|
Cache of settings.LANGUAGES in an OrderedDict for easy lookups by key.
| def get_languages():
"""
Cache of settings.LANGUAGES in an OrderedDict for easy lookups by key.
"""
return OrderedDict(settings.LANGUAGES) | [
"def",
"get_languages",
"(",
")",
":",
"return",
"OrderedDict",
"(",
"settings",
".",
"LANGUAGES",
")"
] | [
440,
0
] | [
444,
42
] | 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.