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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
Url.request_uri | (self) | Absolute path including the query string. | Absolute path including the query string. | def request_uri(self):
"""Absolute path including the query string."""
uri = self.path or "/"
if self.query is not None:
uri += "?" + self.query
return uri | [
"def",
"request_uri",
"(",
"self",
")",
":",
"uri",
"=",
"self",
".",
"path",
"or",
"\"/\"",
"if",
"self",
".",
"query",
"is",
"not",
"None",
":",
"uri",
"+=",
"\"?\"",
"+",
"self",
".",
"query",
"return",
"uri"
] | [
114,
4
] | [
121,
18
] | python | en | ['en', 'en', 'en'] | True |
Url.netloc | (self) | Network location including host and port | Network location including host and port | def netloc(self):
"""Network location including host and port"""
if self.port:
return "%s:%d" % (self.host, self.port)
return self.host | [
"def",
"netloc",
"(",
"self",
")",
":",
"if",
"self",
".",
"port",
":",
"return",
"\"%s:%d\"",
"%",
"(",
"self",
".",
"host",
",",
"self",
".",
"port",
")",
"return",
"self",
".",
"host"
] | [
124,
4
] | [
128,
24
] | python | en | ['en', 'en', 'en'] | True |
Url.url | (self) |
Convert self into a url
This function should more or less round-trip with :func:`.parse_url`. The
returned url may not be exactly the same as the url inputted to
:func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls
with a blank port will have : removed).
... |
Convert self into a url | def url(self):
"""
Convert self into a url
This function should more or less round-trip with :func:`.parse_url`. The
returned url may not be exactly the same as the url inputted to
:func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls
with a blank port w... | [
"def",
"url",
"(",
"self",
")",
":",
"scheme",
",",
"auth",
",",
"host",
",",
"port",
",",
"path",
",",
"query",
",",
"fragment",
"=",
"self",
"url",
"=",
"u\"\"",
"# We use \"is not None\" we want things to happen with empty strings (or 0 port)",
"if",
"scheme",
... | [
131,
4
] | [
168,
18
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.create_test_db | (self, verbosity=1, autoclobber=False, serialize=True, keepdb=False) |
Create a test database, prompting the user for confirmation if the
database already exists. Return the name of the test database created.
|
Create a test database, prompting the user for confirmation if the
database already exists. Return the name of the test database created.
| def create_test_db(self, verbosity=1, autoclobber=False, serialize=True, keepdb=False):
"""
Create a test database, prompting the user for confirmation if the
database already exists. Return the name of the test database created.
"""
# Don't import django.core.management if it is... | [
"def",
"create_test_db",
"(",
"self",
",",
"verbosity",
"=",
"1",
",",
"autoclobber",
"=",
"False",
",",
"serialize",
"=",
"True",
",",
"keepdb",
"=",
"False",
")",
":",
"# Don't import django.core.management if it isn't needed.",
"from",
"django",
".",
"core",
... | [
31,
4
] | [
99,
33
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.set_as_test_mirror | (self, primary_settings_dict) |
Set this database up to be used in testing as a mirror of a primary
database whose settings are given.
|
Set this database up to be used in testing as a mirror of a primary
database whose settings are given.
| def set_as_test_mirror(self, primary_settings_dict):
"""
Set this database up to be used in testing as a mirror of a primary
database whose settings are given.
"""
self.connection.settings_dict['NAME'] = primary_settings_dict['NAME'] | [
"def",
"set_as_test_mirror",
"(",
"self",
",",
"primary_settings_dict",
")",
":",
"self",
".",
"connection",
".",
"settings_dict",
"[",
"'NAME'",
"]",
"=",
"primary_settings_dict",
"[",
"'NAME'",
"]"
] | [
101,
4
] | [
106,
77
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.serialize_db_to_string | (self) |
Serialize all data in the database into a JSON string.
Designed only for test runner usage; will not handle large
amounts of data.
|
Serialize all data in the database into a JSON string.
Designed only for test runner usage; will not handle large
amounts of data.
| def serialize_db_to_string(self):
"""
Serialize all data in the database into a JSON string.
Designed only for test runner usage; will not handle large
amounts of data.
"""
# Iteratively return every object for all models to serialize.
def get_objects():
... | [
"def",
"serialize_db_to_string",
"(",
"self",
")",
":",
"# Iteratively return every object for all models to serialize.",
"def",
"get_objects",
"(",
")",
":",
"from",
"django",
".",
"db",
".",
"migrations",
".",
"loader",
"import",
"MigrationLoader",
"loader",
"=",
"M... | [
108,
4
] | [
136,
29
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.deserialize_db_from_string | (self, data) |
Reload the database with data from a string generated by
the serialize_db_to_string() method.
|
Reload the database with data from a string generated by
the serialize_db_to_string() method.
| def deserialize_db_from_string(self, data):
"""
Reload the database with data from a string generated by
the serialize_db_to_string() method.
"""
data = StringIO(data)
table_names = set()
# Load data in a transaction to handle forward references and cycles.
... | [
"def",
"deserialize_db_from_string",
"(",
"self",
",",
"data",
")",
":",
"data",
"=",
"StringIO",
"(",
"data",
")",
"table_names",
"=",
"set",
"(",
")",
"# Load data in a transaction to handle forward references and cycles.",
"with",
"atomic",
"(",
"using",
"=",
"se... | [
138,
4
] | [
155,
70
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._get_database_display_str | (self, verbosity, database_name) |
Return display string for a database for use in various actions.
|
Return display string for a database for use in various actions.
| def _get_database_display_str(self, verbosity, database_name):
"""
Return display string for a database for use in various actions.
"""
return "'%s'%s" % (
self.connection.alias,
(" ('%s')" % database_name) if verbosity >= 2 else '',
) | [
"def",
"_get_database_display_str",
"(",
"self",
",",
"verbosity",
",",
"database_name",
")",
":",
"return",
"\"'%s'%s\"",
"%",
"(",
"self",
".",
"connection",
".",
"alias",
",",
"(",
"\" ('%s')\"",
"%",
"database_name",
")",
"if",
"verbosity",
">=",
"2",
"e... | [
157,
4
] | [
164,
9
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._get_test_db_name | (self) |
Internal implementation - return the name of the test DB that will be
created. Only useful when called from create_test_db() and
_create_test_db() and when no external munging is done with the 'NAME'
settings.
|
Internal implementation - return the name of the test DB that will be
created. Only useful when called from create_test_db() and
_create_test_db() and when no external munging is done with the 'NAME'
settings.
| def _get_test_db_name(self):
"""
Internal implementation - return the name of the test DB that will be
created. Only useful when called from create_test_db() and
_create_test_db() and when no external munging is done with the 'NAME'
settings.
"""
if self.connectio... | [
"def",
"_get_test_db_name",
"(",
"self",
")",
":",
"if",
"self",
".",
"connection",
".",
"settings_dict",
"[",
"'TEST'",
"]",
"[",
"'NAME'",
"]",
":",
"return",
"self",
".",
"connection",
".",
"settings_dict",
"[",
"'TEST'",
"]",
"[",
"'NAME'",
"]",
"ret... | [
166,
4
] | [
175,
75
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._create_test_db | (self, verbosity, autoclobber, keepdb=False) |
Internal implementation - create the test db tables.
|
Internal implementation - create the test db tables.
| def _create_test_db(self, verbosity, autoclobber, keepdb=False):
"""
Internal implementation - create the test db tables.
"""
test_database_name = self._get_test_db_name()
test_db_params = {
'dbname': self.connection.ops.quote_name(test_database_name),
'su... | [
"def",
"_create_test_db",
"(",
"self",
",",
"verbosity",
",",
"autoclobber",
",",
"keepdb",
"=",
"False",
")",
":",
"test_database_name",
"=",
"self",
".",
"_get_test_db_name",
"(",
")",
"test_db_params",
"=",
"{",
"'dbname'",
":",
"self",
".",
"connection",
... | [
180,
4
] | [
219,
33
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.clone_test_db | (self, suffix, verbosity=1, autoclobber=False, keepdb=False) |
Clone a test database.
|
Clone a test database.
| def clone_test_db(self, suffix, verbosity=1, autoclobber=False, keepdb=False):
"""
Clone a test database.
"""
source_database_name = self.connection.settings_dict['NAME']
if verbosity >= 1:
action = 'Cloning test database'
if keepdb:
actio... | [
"def",
"clone_test_db",
"(",
"self",
",",
"suffix",
",",
"verbosity",
"=",
"1",
",",
"autoclobber",
"=",
"False",
",",
"keepdb",
"=",
"False",
")",
":",
"source_database_name",
"=",
"self",
".",
"connection",
".",
"settings_dict",
"[",
"'NAME'",
"]",
"if",... | [
221,
4
] | [
238,
54
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.get_test_db_clone_settings | (self, suffix) |
Return a modified connection settings dict for the n-th clone of a DB.
|
Return a modified connection settings dict for the n-th clone of a DB.
| def get_test_db_clone_settings(self, suffix):
"""
Return a modified connection settings dict for the n-th clone of a DB.
"""
# When this function is called, the test database has been created
# already and its name has been copied to settings_dict['NAME'] so
# we don't ne... | [
"def",
"get_test_db_clone_settings",
"(",
"self",
",",
"suffix",
")",
":",
"# When this function is called, the test database has been created",
"# already and its name has been copied to settings_dict['NAME'] so",
"# we don't need to call _get_test_db_name.",
"orig_settings_dict",
"=",
"s... | [
240,
4
] | [
248,
97
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._clone_test_db | (self, suffix, verbosity, keepdb=False) |
Internal implementation - duplicate the test db tables.
|
Internal implementation - duplicate the test db tables.
| def _clone_test_db(self, suffix, verbosity, keepdb=False):
"""
Internal implementation - duplicate the test db tables.
"""
raise NotImplementedError(
"The database backend doesn't support cloning databases. "
"Disable the option to run tests in parallel processes.... | [
"def",
"_clone_test_db",
"(",
"self",
",",
"suffix",
",",
"verbosity",
",",
"keepdb",
"=",
"False",
")",
":",
"raise",
"NotImplementedError",
"(",
"\"The database backend doesn't support cloning databases. \"",
"\"Disable the option to run tests in parallel processes.\"",
")"
] | [
250,
4
] | [
256,
69
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.destroy_test_db | (self, old_database_name=None, verbosity=1, keepdb=False, suffix=None) |
Destroy a test database, prompting the user for confirmation if the
database already exists.
|
Destroy a test database, prompting the user for confirmation if the
database already exists.
| def destroy_test_db(self, old_database_name=None, verbosity=1, keepdb=False, suffix=None):
"""
Destroy a test database, prompting the user for confirmation if the
database already exists.
"""
self.connection.close()
if suffix is None:
test_database_name = self... | [
"def",
"destroy_test_db",
"(",
"self",
",",
"old_database_name",
"=",
"None",
",",
"verbosity",
"=",
"1",
",",
"keepdb",
"=",
"False",
",",
"suffix",
"=",
"None",
")",
":",
"self",
".",
"connection",
".",
"close",
"(",
")",
"if",
"suffix",
"is",
"None"... | [
258,
4
] | [
286,
69
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation._destroy_test_db | (self, test_database_name, verbosity) |
Internal implementation - remove the test db tables.
|
Internal implementation - remove the test db tables.
| def _destroy_test_db(self, test_database_name, verbosity):
"""
Internal implementation - remove the test db tables.
"""
# Remove the test database to clean up after
# ourselves. Connect to the previous database (not the test database)
# to do so, because it's not allowed ... | [
"def",
"_destroy_test_db",
"(",
"self",
",",
"test_database_name",
",",
"verbosity",
")",
":",
"# Remove the test database to clean up after",
"# ourselves. Connect to the previous database (not the test database)",
"# to do so, because it's not allowed to delete a database while being",
"... | [
288,
4
] | [
298,
80
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.mark_expected_failures_and_skips | (self) |
Mark tests in Django's test suite which are expected failures on this
database and test which should be skipped on this database.
|
Mark tests in Django's test suite which are expected failures on this
database and test which should be skipped on this database.
| def mark_expected_failures_and_skips(self):
"""
Mark tests in Django's test suite which are expected failures on this
database and test which should be skipped on this database.
"""
for test_name in self.connection.features.django_test_expected_failures:
test_case_nam... | [
"def",
"mark_expected_failures_and_skips",
"(",
"self",
")",
":",
"for",
"test_name",
"in",
"self",
".",
"connection",
".",
"features",
".",
"django_test_expected_failures",
":",
"test_case_name",
",",
"_",
",",
"test_method_name",
"=",
"test_name",
".",
"rpartition... | [
300,
4
] | [
321,
83
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.sql_table_creation_suffix | (self) |
SQL to append to the end of the test table creation statements.
|
SQL to append to the end of the test table creation statements.
| def sql_table_creation_suffix(self):
"""
SQL to append to the end of the test table creation statements.
"""
return '' | [
"def",
"sql_table_creation_suffix",
"(",
"self",
")",
":",
"return",
"''"
] | [
323,
4
] | [
327,
17
] | python | en | ['en', 'error', 'th'] | False |
BaseDatabaseCreation.test_db_signature | (self) |
Return a tuple with elements of self.connection.settings_dict (a
DATABASES setting value) that uniquely identify a database
accordingly to the RDBMS particularities.
|
Return a tuple with elements of self.connection.settings_dict (a
DATABASES setting value) that uniquely identify a database
accordingly to the RDBMS particularities.
| def test_db_signature(self):
"""
Return a tuple with elements of self.connection.settings_dict (a
DATABASES setting value) that uniquely identify a database
accordingly to the RDBMS particularities.
"""
settings_dict = self.connection.settings_dict
return (
... | [
"def",
"test_db_signature",
"(",
"self",
")",
":",
"settings_dict",
"=",
"self",
".",
"connection",
".",
"settings_dict",
"return",
"(",
"settings_dict",
"[",
"'HOST'",
"]",
",",
"settings_dict",
"[",
"'PORT'",
"]",
",",
"settings_dict",
"[",
"'ENGINE'",
"]",
... | [
329,
4
] | [
341,
9
] | python | en | ['en', 'error', 'th'] | False |
run | (argv=None) | The main function which creates the pipeline and runs it. | The main function which creates the pipeline and runs it. | def run(argv=None):
"""The main function which creates the pipeline and runs it."""
parser = argparse.ArgumentParser()
# Add the arguments needed for this specific Dataflow job.
parser.add_argument(
'--input', dest='input', required=True,
help='Input file to read. This can be a local f... | [
"def",
"run",
"(",
"argv",
"=",
"None",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"# Add the arguments needed for this specific Dataflow job.",
"parser",
".",
"add_argument",
"(",
"'--input'",
",",
"dest",
"=",
"'input'",
",",
"required... | [
61,
0
] | [
114,
93
] | python | en | ['en', 'en', 'en'] | True |
RowTransformer.parse | (self, row) | This method translates a single delimited record into a dictionary
which can be loaded into BigQuery. It also adds filename and load_dt
fields to the dictionary. | This method translates a single delimited record into a dictionary
which can be loaded into BigQuery. It also adds filename and load_dt
fields to the dictionary. | def parse(self, row):
"""This method translates a single delimited record into a dictionary
which can be loaded into BigQuery. It also adds filename and load_dt
fields to the dictionary."""
# Strip out the return characters and quote characters.
values = re.split(self.delimiter,... | [
"def",
"parse",
"(",
"self",
",",
"row",
")",
":",
"# Strip out the return characters and quote characters.",
"values",
"=",
"re",
".",
"split",
"(",
"self",
".",
"delimiter",
",",
"re",
".",
"sub",
"(",
"r'[\\r\\n\"]'",
",",
"''",
",",
"row",
")",
")",
"r... | [
42,
4
] | [
58,
18
] | python | en | ['en', 'en', 'en'] | True |
BmpImageFile._bitmap | (self, header=0, offset=0) | Read relevant info about the BMP | Read relevant info about the BMP | def _bitmap(self, header=0, offset=0):
""" Read relevant info about the BMP """
read, seek = self.fp.read, self.fp.seek
if header:
seek(header)
file_info = {}
# read bmp header size @offset 14 (this is part of the header size)
file_info["header_size"] = i32(re... | [
"def",
"_bitmap",
"(",
"self",
",",
"header",
"=",
"0",
",",
"offset",
"=",
"0",
")",
":",
"read",
",",
"seek",
"=",
"self",
".",
"fp",
".",
"read",
",",
"self",
".",
"fp",
".",
"seek",
"if",
"header",
":",
"seek",
"(",
"header",
")",
"file_inf... | [
71,
4
] | [
256,
9
] | python | en | ['en', 'en', 'en'] | True |
BmpImageFile._open | (self) | Open file, check magic number and read header | Open file, check magic number and read header | def _open(self):
""" Open file, check magic number and read header """
# read 14 bytes: magic number, filesize, reserved, header final offset
head_data = self.fp.read(14)
# choke if the file does not have the required magic bytes
if not _accept(head_data):
raise Synta... | [
"def",
"_open",
"(",
"self",
")",
":",
"# read 14 bytes: magic number, filesize, reserved, header final offset",
"head_data",
"=",
"self",
".",
"fp",
".",
"read",
"(",
"14",
")",
"# choke if the file does not have the required magic bytes",
"if",
"not",
"_accept",
"(",
"h... | [
258,
4
] | [
268,
35
] | python | en | ['en', 'en', 'en'] | True |
format_for_columns | (
pkgs: "_ProcessedDists", options: Values
) |
Convert the package data into something usable
by output_package_listing_columns.
|
Convert the package data into something usable
by output_package_listing_columns.
| def format_for_columns(
pkgs: "_ProcessedDists", options: Values
) -> Tuple[List[List[str]], List[str]]:
"""
Convert the package data into something usable
by output_package_listing_columns.
"""
running_outdated = options.outdated
# Adjust the header for the `pip list --outdated` case.
i... | [
"def",
"format_for_columns",
"(",
"pkgs",
":",
"\"_ProcessedDists\"",
",",
"options",
":",
"Values",
")",
"->",
"Tuple",
"[",
"List",
"[",
"List",
"[",
"str",
"]",
"]",
",",
"List",
"[",
"str",
"]",
"]",
":",
"running_outdated",
"=",
"options",
".",
"o... | [
283,
0
] | [
319,
23
] | python | en | ['en', 'error', 'th'] | False |
ListCommand._build_package_finder | (
self, options: Values, session: PipSession
) |
Create a package finder appropriate to this list command.
|
Create a package finder appropriate to this list command.
| def _build_package_finder(
self, options: Values, session: PipSession
) -> PackageFinder:
"""
Create a package finder appropriate to this list command.
"""
link_collector = LinkCollector.create(session, options=options)
# Pass allow_yanked=False to ignore yanked vers... | [
"def",
"_build_package_finder",
"(",
"self",
",",
"options",
":",
"Values",
",",
"session",
":",
"PipSession",
")",
"->",
"PackageFinder",
":",
"link_collector",
"=",
"LinkCollector",
".",
"create",
"(",
"session",
",",
"options",
"=",
"options",
")",
"# Pass ... | [
125,
4
] | [
142,
9
] | python | en | ['en', 'error', 'th'] | False |
parse_tag | (tag: str) |
Parses the provided tag (e.g. `py3-none-any`) into a frozenset of Tag instances.
Returning a set is required due to the possibility that the tag is a
compressed tag set.
|
Parses the provided tag (e.g. `py3-none-any`) into a frozenset of Tag instances. | def parse_tag(tag: str) -> FrozenSet[Tag]:
"""
Parses the provided tag (e.g. `py3-none-any`) into a frozenset of Tag instances.
Returning a set is required due to the possibility that the tag is a
compressed tag set.
"""
tags = set()
interpreters, abis, platforms = tag.split("-")
for in... | [
"def",
"parse_tag",
"(",
"tag",
":",
"str",
")",
"->",
"FrozenSet",
"[",
"Tag",
"]",
":",
"tags",
"=",
"set",
"(",
")",
"interpreters",
",",
"abis",
",",
"platforms",
"=",
"tag",
".",
"split",
"(",
"\"-\"",
")",
"for",
"interpreter",
"in",
"interpret... | [
95,
0
] | [
108,
26
] | python | en | ['en', 'error', 'th'] | False |
_abi3_applies | (python_version: PythonVersion) |
Determine if the Python version supports abi3.
PEP 384 was first implemented in Python 3.2.
|
Determine if the Python version supports abi3. | def _abi3_applies(python_version: PythonVersion) -> bool:
"""
Determine if the Python version supports abi3.
PEP 384 was first implemented in Python 3.2.
"""
return len(python_version) > 1 and tuple(python_version) >= (3, 2) | [
"def",
"_abi3_applies",
"(",
"python_version",
":",
"PythonVersion",
")",
"->",
"bool",
":",
"return",
"len",
"(",
"python_version",
")",
">",
"1",
"and",
"tuple",
"(",
"python_version",
")",
">=",
"(",
"3",
",",
"2",
")"
] | [
124,
0
] | [
130,
70
] | python | en | ['en', 'error', 'th'] | False |
cpython_tags | (
python_version: Optional[PythonVersion] = None,
abis: Optional[Iterable[str]] = None,
platforms: Optional[Iterable[str]] = None,
*,
warn: bool = False,
) |
Yields the tags for a CPython interpreter.
The tags consist of:
- cp<python_version>-<abi>-<platform>
- cp<python_version>-abi3-<platform>
- cp<python_version>-none-<platform>
- cp<less than python_version>-abi3-<platform> # Older Python versions down to 3.2.
If python_version only speci... |
Yields the tags for a CPython interpreter. | def cpython_tags(
python_version: Optional[PythonVersion] = None,
abis: Optional[Iterable[str]] = None,
platforms: Optional[Iterable[str]] = None,
*,
warn: bool = False,
) -> Iterator[Tag]:
"""
Yields the tags for a CPython interpreter.
The tags consist of:
- cp<python_version>-<abi... | [
"def",
"cpython_tags",
"(",
"python_version",
":",
"Optional",
"[",
"PythonVersion",
"]",
"=",
"None",
",",
"abis",
":",
"Optional",
"[",
"Iterable",
"[",
"str",
"]",
"]",
"=",
"None",
",",
"platforms",
":",
"Optional",
"[",
"Iterable",
"[",
"str",
"]",
... | [
169,
0
] | [
223,
57
] | python | en | ['en', 'error', 'th'] | False |
generic_tags | (
interpreter: Optional[str] = None,
abis: Optional[Iterable[str]] = None,
platforms: Optional[Iterable[str]] = None,
*,
warn: bool = False,
) |
Yields the tags for a generic interpreter.
The tags consist of:
- <interpreter>-<abi>-<platform>
The "none" ABI will be added if it was not explicitly provided.
|
Yields the tags for a generic interpreter. | def generic_tags(
interpreter: Optional[str] = None,
abis: Optional[Iterable[str]] = None,
platforms: Optional[Iterable[str]] = None,
*,
warn: bool = False,
) -> Iterator[Tag]:
"""
Yields the tags for a generic interpreter.
The tags consist of:
- <interpreter>-<abi>-<platform>
... | [
"def",
"generic_tags",
"(",
"interpreter",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"abis",
":",
"Optional",
"[",
"Iterable",
"[",
"str",
"]",
"]",
"=",
"None",
",",
"platforms",
":",
"Optional",
"[",
"Iterable",
"[",
"str",
"]",
"]",
"=",... | [
232,
0
] | [
259,
50
] | python | en | ['en', 'error', 'th'] | False |
_py_interpreter_range | (py_version: PythonVersion) |
Yields Python versions in descending order.
After the latest version, the major-only version will be yielded, and then
all previous versions of that major version.
|
Yields Python versions in descending order. | def _py_interpreter_range(py_version: PythonVersion) -> Iterator[str]:
"""
Yields Python versions in descending order.
After the latest version, the major-only version will be yielded, and then
all previous versions of that major version.
"""
if len(py_version) > 1:
yield "py{version}".... | [
"def",
"_py_interpreter_range",
"(",
"py_version",
":",
"PythonVersion",
")",
"->",
"Iterator",
"[",
"str",
"]",
":",
"if",
"len",
"(",
"py_version",
")",
">",
"1",
":",
"yield",
"\"py{version}\"",
".",
"format",
"(",
"version",
"=",
"_version_nodot",
"(",
... | [
262,
0
] | [
274,
86
] | python | en | ['en', 'error', 'th'] | False |
compatible_tags | (
python_version: Optional[PythonVersion] = None,
interpreter: Optional[str] = None,
platforms: Optional[Iterable[str]] = None,
) |
Yields the sequence of tags that are compatible with a specific version of Python.
The tags consist of:
- py*-none-<platform>
- <interpreter>-none-any # ... if `interpreter` is provided.
- py*-none-any
|
Yields the sequence of tags that are compatible with a specific version of Python. | def compatible_tags(
python_version: Optional[PythonVersion] = None,
interpreter: Optional[str] = None,
platforms: Optional[Iterable[str]] = None,
) -> Iterator[Tag]:
"""
Yields the sequence of tags that are compatible with a specific version of Python.
The tags consist of:
- py*-none-<plat... | [
"def",
"compatible_tags",
"(",
"python_version",
":",
"Optional",
"[",
"PythonVersion",
"]",
"=",
"None",
",",
"interpreter",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"platforms",
":",
"Optional",
"[",
"Iterable",
"[",
"str",
"]",
"]",
"=",
"N... | [
277,
0
] | [
299,
41
] | python | en | ['en', 'error', 'th'] | False |
mac_platforms | (
version: Optional[MacVersion] = None, arch: Optional[str] = None
) |
Yields the platform tags for a macOS system.
The `version` parameter is a two-item tuple specifying the macOS version to
generate platform tags for. The `arch` parameter is the CPU architecture to
generate platform tags for. Both parameters default to the appropriate value
for the current system.
... |
Yields the platform tags for a macOS system. | def mac_platforms(
version: Optional[MacVersion] = None, arch: Optional[str] = None
) -> Iterator[str]:
"""
Yields the platform tags for a macOS system.
The `version` parameter is a two-item tuple specifying the macOS version to
generate platform tags for. The `arch` parameter is the CPU architectu... | [
"def",
"mac_platforms",
"(",
"version",
":",
"Optional",
"[",
"MacVersion",
"]",
"=",
"None",
",",
"arch",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
")",
"->",
"Iterator",
"[",
"str",
"]",
":",
"version_str",
",",
"_",
",",
"cpu_arch",
"=",
"pla... | [
344,
0
] | [
413,
17
] | python | en | ['en', 'error', 'th'] | False |
_platform_tags | () |
Provides the platform tags for this installation.
|
Provides the platform tags for this installation.
| def _platform_tags() -> Iterator[str]:
"""
Provides the platform tags for this installation.
"""
if platform.system() == "Darwin":
return mac_platforms()
elif platform.system() == "Linux":
return _linux_platforms()
else:
return _generic_platforms() | [
"def",
"_platform_tags",
"(",
")",
"->",
"Iterator",
"[",
"str",
"]",
":",
"if",
"platform",
".",
"system",
"(",
")",
"==",
"\"Darwin\"",
":",
"return",
"mac_platforms",
"(",
")",
"elif",
"platform",
".",
"system",
"(",
")",
"==",
"\"Linux\"",
":",
"re... | [
433,
0
] | [
442,
35
] | python | en | ['en', 'error', 'th'] | False |
interpreter_name | () |
Returns the name of the running interpreter.
|
Returns the name of the running interpreter.
| def interpreter_name() -> str:
"""
Returns the name of the running interpreter.
"""
name = sys.implementation.name
return INTERPRETER_SHORT_NAMES.get(name) or name | [
"def",
"interpreter_name",
"(",
")",
"->",
"str",
":",
"name",
"=",
"sys",
".",
"implementation",
".",
"name",
"return",
"INTERPRETER_SHORT_NAMES",
".",
"get",
"(",
"name",
")",
"or",
"name"
] | [
445,
0
] | [
450,
52
] | python | en | ['en', 'error', 'th'] | False |
interpreter_version | (*, warn: bool = False) |
Returns the version of the running interpreter.
|
Returns the version of the running interpreter.
| def interpreter_version(*, warn: bool = False) -> str:
"""
Returns the version of the running interpreter.
"""
version = _get_config_var("py_version_nodot", warn=warn)
if version:
version = str(version)
else:
version = _version_nodot(sys.version_info[:2])
return version | [
"def",
"interpreter_version",
"(",
"*",
",",
"warn",
":",
"bool",
"=",
"False",
")",
"->",
"str",
":",
"version",
"=",
"_get_config_var",
"(",
"\"py_version_nodot\"",
",",
"warn",
"=",
"warn",
")",
"if",
"version",
":",
"version",
"=",
"str",
"(",
"versi... | [
453,
0
] | [
462,
18
] | python | en | ['en', 'error', 'th'] | False |
sys_tags | (*, warn: bool = False) |
Returns the sequence of tag triples for the running interpreter.
The order of the sequence corresponds to priority order for the
interpreter, from most to least important.
|
Returns the sequence of tag triples for the running interpreter. | def sys_tags(*, warn: bool = False) -> Iterator[Tag]:
"""
Returns the sequence of tag triples for the running interpreter.
The order of the sequence corresponds to priority order for the
interpreter, from most to least important.
"""
interp_name = interpreter_name()
if interp_name == "cp":... | [
"def",
"sys_tags",
"(",
"*",
",",
"warn",
":",
"bool",
"=",
"False",
")",
"->",
"Iterator",
"[",
"Tag",
"]",
":",
"interp_name",
"=",
"interpreter_name",
"(",
")",
"if",
"interp_name",
"==",
"\"cp\"",
":",
"yield",
"from",
"cpython_tags",
"(",
"warn",
... | [
469,
0
] | [
483,
32
] | python | en | ['en', 'error', 'th'] | False |
Feature.__init__ | (self, feat, layer) |
Initialize Feature from a pointer and its Layer object.
|
Initialize Feature from a pointer and its Layer object.
| def __init__(self, feat, layer):
"""
Initialize Feature from a pointer and its Layer object.
"""
if not feat:
raise GDALException('Cannot create OGR Feature, invalid pointer given.')
self.ptr = feat
self._layer = layer | [
"def",
"__init__",
"(",
"self",
",",
"feat",
",",
"layer",
")",
":",
"if",
"not",
"feat",
":",
"raise",
"GDALException",
"(",
"'Cannot create OGR Feature, invalid pointer given.'",
")",
"self",
".",
"ptr",
"=",
"feat",
"self",
".",
"_layer",
"=",
"layer"
] | [
19,
4
] | [
26,
27
] | python | en | ['en', 'error', 'th'] | False |
Feature.__getitem__ | (self, index) |
Get the Field object at the specified index, which may be either
an integer or the Field's string label. Note that the Field object
is not the field's _value_ -- use the `get` method instead to
retrieve the value (e.g. an integer) instead of a Field instance.
|
Get the Field object at the specified index, which may be either
an integer or the Field's string label. Note that the Field object
is not the field's _value_ -- use the `get` method instead to
retrieve the value (e.g. an integer) instead of a Field instance.
| def __getitem__(self, index):
"""
Get the Field object at the specified index, which may be either
an integer or the Field's string label. Note that the Field object
is not the field's _value_ -- use the `get` method instead to
retrieve the value (e.g. an integer) instead of a F... | [
"def",
"__getitem__",
"(",
"self",
",",
"index",
")",
":",
"if",
"isinstance",
"(",
"index",
",",
"str",
")",
":",
"i",
"=",
"self",
".",
"index",
"(",
"index",
")",
"elif",
"0",
"<=",
"index",
"<",
"self",
".",
"num_fields",
":",
"i",
"=",
"inde... | [
28,
4
] | [
41,
29
] | python | en | ['en', 'error', 'th'] | False |
Feature.__len__ | (self) | Return the count of fields in this feature. | Return the count of fields in this feature. | def __len__(self):
"Return the count of fields in this feature."
return self.num_fields | [
"def",
"__len__",
"(",
"self",
")",
":",
"return",
"self",
".",
"num_fields"
] | [
43,
4
] | [
45,
30
] | python | en | ['en', 'en', 'en'] | True |
Feature.__str__ | (self) | The string name of the feature. | The string name of the feature. | def __str__(self):
"The string name of the feature."
return 'Feature FID %d in Layer<%s>' % (self.fid, self.layer_name) | [
"def",
"__str__",
"(",
"self",
")",
":",
"return",
"'Feature FID %d in Layer<%s>'",
"%",
"(",
"self",
".",
"fid",
",",
"self",
".",
"layer_name",
")"
] | [
47,
4
] | [
49,
74
] | python | en | ['en', 'en', 'en'] | True |
Feature.__eq__ | (self, other) | Do equivalence testing on the features. | Do equivalence testing on the features. | def __eq__(self, other):
"Do equivalence testing on the features."
return bool(capi.feature_equal(self.ptr, other._ptr)) | [
"def",
"__eq__",
"(",
"self",
",",
"other",
")",
":",
"return",
"bool",
"(",
"capi",
".",
"feature_equal",
"(",
"self",
".",
"ptr",
",",
"other",
".",
"_ptr",
")",
")"
] | [
51,
4
] | [
53,
61
] | python | en | ['en', 'en', 'en'] | True |
Feature.fid | (self) | Return the feature identifier. | Return the feature identifier. | def fid(self):
"Return the feature identifier."
return capi.get_fid(self.ptr) | [
"def",
"fid",
"(",
"self",
")",
":",
"return",
"capi",
".",
"get_fid",
"(",
"self",
".",
"ptr",
")"
] | [
61,
4
] | [
63,
37
] | python | en | ['en', 'fy', 'en'] | True |
Feature.layer_name | (self) | Return the name of the layer for the feature. | Return the name of the layer for the feature. | def layer_name(self):
"Return the name of the layer for the feature."
name = capi.get_feat_name(self._layer._ldefn)
return force_str(name, self.encoding, strings_only=True) | [
"def",
"layer_name",
"(",
"self",
")",
":",
"name",
"=",
"capi",
".",
"get_feat_name",
"(",
"self",
".",
"_layer",
".",
"_ldefn",
")",
"return",
"force_str",
"(",
"name",
",",
"self",
".",
"encoding",
",",
"strings_only",
"=",
"True",
")"
] | [
66,
4
] | [
69,
64
] | python | en | ['en', 'en', 'en'] | True |
Feature.num_fields | (self) | Return the number of fields in the Feature. | Return the number of fields in the Feature. | def num_fields(self):
"Return the number of fields in the Feature."
return capi.get_feat_field_count(self.ptr) | [
"def",
"num_fields",
"(",
"self",
")",
":",
"return",
"capi",
".",
"get_feat_field_count",
"(",
"self",
".",
"ptr",
")"
] | [
72,
4
] | [
74,
50
] | python | en | ['en', 'en', 'en'] | True |
Feature.fields | (self) | Return a list of fields in the Feature. | Return a list of fields in the Feature. | def fields(self):
"Return a list of fields in the Feature."
return [
force_str(
capi.get_field_name(capi.get_field_defn(self._layer._ldefn, i)),
self.encoding,
strings_only=True
) for i in range(self.num_fields)
] | [
"def",
"fields",
"(",
"self",
")",
":",
"return",
"[",
"force_str",
"(",
"capi",
".",
"get_field_name",
"(",
"capi",
".",
"get_field_defn",
"(",
"self",
".",
"_layer",
".",
"_ldefn",
",",
"i",
")",
")",
",",
"self",
".",
"encoding",
",",
"strings_only"... | [
77,
4
] | [
85,
9
] | python | en | ['en', 'en', 'en'] | True |
Feature.geom | (self) | Return the OGR Geometry for this Feature. | Return the OGR Geometry for this Feature. | def geom(self):
"Return the OGR Geometry for this Feature."
# Retrieving the geometry pointer for the feature.
geom_ptr = capi.get_feat_geom_ref(self.ptr)
return OGRGeometry(geom_api.clone_geom(geom_ptr)) | [
"def",
"geom",
"(",
"self",
")",
":",
"# Retrieving the geometry pointer for the feature.",
"geom_ptr",
"=",
"capi",
".",
"get_feat_geom_ref",
"(",
"self",
".",
"ptr",
")",
"return",
"OGRGeometry",
"(",
"geom_api",
".",
"clone_geom",
"(",
"geom_ptr",
")",
")"
] | [
88,
4
] | [
92,
57
] | python | en | ['en', 'en', 'en'] | True |
Feature.geom_type | (self) | Return the OGR Geometry Type for this Feature. | Return the OGR Geometry Type for this Feature. | def geom_type(self):
"Return the OGR Geometry Type for this Feature."
return OGRGeomType(capi.get_fd_geom_type(self._layer._ldefn)) | [
"def",
"geom_type",
"(",
"self",
")",
":",
"return",
"OGRGeomType",
"(",
"capi",
".",
"get_fd_geom_type",
"(",
"self",
".",
"_layer",
".",
"_ldefn",
")",
")"
] | [
95,
4
] | [
97,
69
] | python | en | ['en', 'en', 'en'] | True |
Feature.get | (self, field) |
Return the value of the field, instead of an instance of the Field
object. May take a string of the field name or a Field object as
parameters.
|
Return the value of the field, instead of an instance of the Field
object. May take a string of the field name or a Field object as
parameters.
| def get(self, field):
"""
Return the value of the field, instead of an instance of the Field
object. May take a string of the field name or a Field object as
parameters.
"""
field_name = getattr(field, 'name', field)
return self[field_name].value | [
"def",
"get",
"(",
"self",
",",
"field",
")",
":",
"field_name",
"=",
"getattr",
"(",
"field",
",",
"'name'",
",",
"field",
")",
"return",
"self",
"[",
"field_name",
"]",
".",
"value"
] | [
100,
4
] | [
107,
37
] | python | en | ['en', 'error', 'th'] | False |
Feature.index | (self, field_name) | Return the index of the given field name. | Return the index of the given field name. | def index(self, field_name):
"Return the index of the given field name."
i = capi.get_field_index(self.ptr, force_bytes(field_name))
if i < 0:
raise IndexError('Invalid OFT field name given: %s.' % field_name)
return i | [
"def",
"index",
"(",
"self",
",",
"field_name",
")",
":",
"i",
"=",
"capi",
".",
"get_field_index",
"(",
"self",
".",
"ptr",
",",
"force_bytes",
"(",
"field_name",
")",
")",
"if",
"i",
"<",
"0",
":",
"raise",
"IndexError",
"(",
"'Invalid OFT field name g... | [
109,
4
] | [
114,
16
] | python | en | ['en', 'en', 'en'] | True |
View.dispatch_request | (self) | Subclasses have to override this method to implement the
actual view function code. This method is called with all
the arguments from the URL rule.
| Subclasses have to override this method to implement the
actual view function code. This method is called with all
the arguments from the URL rule.
| def dispatch_request(self):
"""Subclasses have to override this method to implement the
actual view function code. This method is called with all
the arguments from the URL rule.
"""
raise NotImplementedError() | [
"def",
"dispatch_request",
"(",
"self",
")",
":",
"raise",
"NotImplementedError",
"(",
")"
] | [
64,
4
] | [
69,
35
] | python | en | ['en', 'en', 'en'] | True |
View.as_view | (cls, name, *class_args, **class_kwargs) | Converts the class into an actual view function that can be used
with the routing system. Internally this generates a function on the
fly which will instantiate the :class:`View` on each request and call
the :meth:`dispatch_request` method on it.
The arguments passed to :meth:`as_view`... | Converts the class into an actual view function that can be used
with the routing system. Internally this generates a function on the
fly which will instantiate the :class:`View` on each request and call
the :meth:`dispatch_request` method on it. | def as_view(cls, name, *class_args, **class_kwargs):
"""Converts the class into an actual view function that can be used
with the routing system. Internally this generates a function on the
fly which will instantiate the :class:`View` on each request and call
the :meth:`dispatch_request... | [
"def",
"as_view",
"(",
"cls",
",",
"name",
",",
"*",
"class_args",
",",
"*",
"*",
"class_kwargs",
")",
":",
"def",
"view",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
"=",
"view",
".",
"view_class",
"(",
"*",
"class_args",
",",
"... | [
72,
4
] | [
101,
19
] | python | en | ['en', 'en', 'en'] | True |
jsonp_loader | (url, prefix_regex=r'^(.*\()', suffix_regex=r'(\);)$', sub_d=None, sub_by='') | Request (JSON) data from a server in a different domain (JSONP)
and covert to python readable data.
1. url is the url (https) where data is located
2. "prefix_regex" and "suffix_regex" are regex patterns used to
remove JSONP specific prefix and suffix, such as callback header: "callback(" and end... | Request (JSON) data from a server in a different domain (JSONP)
and covert to python readable data.
1. url is the url (https) where data is located
2. "prefix_regex" and "suffix_regex" are regex patterns used to
remove JSONP specific prefix and suffix, such as callback header: "callback(" and end... | def jsonp_loader(url, prefix_regex=r'^(.*\()', suffix_regex=r'(\);)$', sub_d=None, sub_by=''):
"""Request (JSON) data from a server in a different domain (JSONP)
and covert to python readable data.
1. url is the url (https) where data is located
2. "prefix_regex" and "suffix_regex" are regex patterns ... | [
"def",
"jsonp_loader",
"(",
"url",
",",
"prefix_regex",
"=",
"r'^(.*\\()'",
",",
"suffix_regex",
"=",
"r'(\\);)$'",
",",
"sub_d",
"=",
"None",
",",
"sub_by",
"=",
"''",
")",
":",
"hdr",
"=",
"{",
"'User-Agent'",
":",
"'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/53... | [
12,
0
] | [
35,
64
] | python | en | ['en', 'en', 'en'] | True |
js_map_loader | (url) | Load map data from a .js source. It is designed for using highcharts' map collection:
https://code.highcharts.com/mapdata/. Map data from other sources are not guaranteed
| Load map data from a .js source. It is designed for using highcharts' map collection:
https://code.highcharts.com/mapdata/. Map data from other sources are not guaranteed
| def js_map_loader(url):
"""Load map data from a .js source. It is designed for using highcharts' map collection:
https://code.highcharts.com/mapdata/. Map data from other sources are not guaranteed
"""
hdr = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.... | [
"def",
"js_map_loader",
"(",
"url",
")",
":",
"hdr",
"=",
"{",
"'User-Agent'",
":",
"'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7'",
"}",
"req",
"=",
"urllib",
".",
"request",
".",
"Request",
"(",
"url",
",",
"heade... | [
37,
0
] | [
48,
29
] | python | en | ['en', 'en', 'en'] | True |
geojson_handler | (geojson, hType='map') | Restructure a GeoJSON object in preparation to be added directly by add_map_data or add_data_set methods.
The geojson will be broken down to fit a specific Highcharts (highmaps) type, either map, mapline or mappoint.
Meta data in GeoJSON's properties object will be copied directly over to object['properties']... | Restructure a GeoJSON object in preparation to be added directly by add_map_data or add_data_set methods.
The geojson will be broken down to fit a specific Highcharts (highmaps) type, either map, mapline or mappoint.
Meta data in GeoJSON's properties object will be copied directly over to object['properties']... | def geojson_handler(geojson, hType='map'):
"""Restructure a GeoJSON object in preparation to be added directly by add_map_data or add_data_set methods.
The geojson will be broken down to fit a specific Highcharts (highmaps) type, either map, mapline or mappoint.
Meta data in GeoJSON's properties object wi... | [
"def",
"geojson_handler",
"(",
"geojson",
",",
"hType",
"=",
"'map'",
")",
":",
"hType_dict",
"=",
"{",
"'map'",
":",
"[",
"'polygon'",
",",
"'multipolygon'",
"]",
",",
"'mapline'",
":",
"[",
"'linestring'",
",",
"'multilinestring'",
"]",
",",
"'mappoint'",
... | [
50,
0
] | [
96,
18
] | python | en | ['en', 'en', 'en'] | True |
JSONPDecoder.decode | (self, json_string) |
json_string is basicly string that you give to json.loads method
|
json_string is basicly string that you give to json.loads method
| def decode(self, json_string):
"""
json_string is basicly string that you give to json.loads method
"""
default_obj = super(JSONPDecoder, self).decode(json_string)
return list(self._iterdecode(default_obj))[0] | [
"def",
"decode",
"(",
"self",
",",
"json_string",
")",
":",
"default_obj",
"=",
"super",
"(",
"JSONPDecoder",
",",
"self",
")",
".",
"decode",
"(",
"json_string",
")",
"return",
"list",
"(",
"self",
".",
"_iterdecode",
"(",
"default_obj",
")",
")",
"[",
... | [
161,
4
] | [
168,
53
] | python | en | ['en', 'error', 'th'] | False |
JSONPDecoder.is_js_date_utc | (json) | Check if the string contains Date.UTC function
and return match group(s) if there is
| Check if the string contains Date.UTC function
and return match group(s) if there is
| def is_js_date_utc(json):
"""Check if the string contains Date.UTC function
and return match group(s) if there is
"""
JS_date_utc_pattern = r'Date\.UTC\(([0-9]+,[0-9]+,[0-9]+)(,[0-9]+,[0-9]+,[0-9]+)?(,[0-9]+)?\)'
re_date = re.compile(JS_date_utc_pattern, re.M)
... | [
"def",
"is_js_date_utc",
"(",
"json",
")",
":",
"JS_date_utc_pattern",
"=",
"r'Date\\.UTC\\(([0-9]+,[0-9]+,[0-9]+)(,[0-9]+,[0-9]+,[0-9]+)?(,[0-9]+)?\\)'",
"re_date",
"=",
"re",
".",
"compile",
"(",
"JS_date_utc_pattern",
",",
"re",
".",
"M",
")",
"if",
"re_date",
".",
... | [
201,
4
] | [
212,
24
] | python | en | ['en', 'en', 'en'] | True |
JSONPDecoder.json2datetime | (json) | Convert JSON representation to date or datetime object depending on
the argument count. Requires UTC datetime representation.
Raises ValueError if the string cannot be parsed.
| Convert JSON representation to date or datetime object depending on
the argument count. Requires UTC datetime representation.
Raises ValueError if the string cannot be parsed.
| def json2datetime(json):
"""Convert JSON representation to date or datetime object depending on
the argument count. Requires UTC datetime representation.
Raises ValueError if the string cannot be parsed.
"""
json_m = re.search(r'([0-9]+,[0-9]+,[0-9]+)(,[0-9]+,[0-9]+,[0-9... | [
"def",
"json2datetime",
"(",
"json",
")",
":",
"json_m",
"=",
"re",
".",
"search",
"(",
"r'([0-9]+,[0-9]+,[0-9]+)(,[0-9]+,[0-9]+,[0-9]+)?(,[0-9]+)?'",
",",
"json",
")",
"args",
"=",
"json_m",
".",
"group",
"(",
"0",
")",
".",
"split",
"(",
"','",
")",
"try",... | [
215,
4
] | [
238,
64
] | python | en | ['en', 'en', 'en'] | True |
generate_hours | (startdate: str, enddate: str, starthour: int, endhour: int, is_train: bool) | generates hours within the specified ranges for training or eval.
Call this method twice, once with is_train=True and next with is_train=False
Args:
starthour (int): Start hour, in the range 0-23
endhour (int): End hour (inclusive), in the range 0-23
startdate (str): Year + Start Ju... | generates hours within the specified ranges for training or eval. | def generate_hours(startdate: str, enddate: str, starthour: int, endhour: int, is_train: bool):
"""generates hours within the specified ranges for training or eval.
Call this method twice, once with is_train=True and next with is_train=False
Args:
starthour (int): Start hour, in the range 0-23
... | [
"def",
"generate_hours",
"(",
"startdate",
":",
"str",
",",
"enddate",
":",
"str",
",",
"starthour",
":",
"int",
",",
"endhour",
":",
"int",
",",
"is_train",
":",
"bool",
")",
":",
"startyear",
"=",
"int",
"(",
"startdate",
"[",
":",
"4",
"]",
")",
... | [
41,
0
] | [
66,
84
] | python | en | ['en', 'en', 'en'] | True |
_int64_feature | (value) | Wrapper for inserting int64 features into Example proto. | Wrapper for inserting int64 features into Example proto. | def _int64_feature(value):
"""Wrapper for inserting int64 features into Example proto."""
if not isinstance(value, list):
value = [value]
return tf.train.Feature(int64_list=tf.train.Int64List(value=value)) | [
"def",
"_int64_feature",
"(",
"value",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"list",
")",
":",
"value",
"=",
"[",
"value",
"]",
"return",
"tf",
".",
"train",
".",
"Feature",
"(",
"int64_list",
"=",
"tf",
".",
"train",
".",
"Int64Lis... | [
68,
0
] | [
72,
69
] | python | en | ['en', 'en', 'en'] | True |
_array_feature | (value, min_value, max_value) | Wrapper for inserting ndarray float features into Example proto. | Wrapper for inserting ndarray float features into Example proto. | def _array_feature(value, min_value, max_value):
"""Wrapper for inserting ndarray float features into Example proto."""
value = np.nan_to_num(value.flatten()) # nan, -inf, +inf to numbers
value = np.clip(value, min_value, max_value) # clip to valid
return tf.train.Feature(float_list=tf.train.FloatList(value=val... | [
"def",
"_array_feature",
"(",
"value",
",",
"min_value",
",",
"max_value",
")",
":",
"value",
"=",
"np",
".",
"nan_to_num",
"(",
"value",
".",
"flatten",
"(",
")",
")",
"# nan, -inf, +inf to numbers",
"value",
"=",
"np",
".",
"clip",
"(",
"value",
",",
"... | [
75,
0
] | [
79,
69
] | python | en | ['en', 'en', 'en'] | True |
_bytes_feature | (value) | Wrapper for inserting bytes features into Example proto. | Wrapper for inserting bytes features into Example proto. | def _bytes_feature(value):
"""Wrapper for inserting bytes features into Example proto."""
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[value])) | [
"def",
"_bytes_feature",
"(",
"value",
")",
":",
"return",
"tf",
".",
"train",
".",
"Feature",
"(",
"bytes_list",
"=",
"tf",
".",
"train",
".",
"BytesList",
"(",
"value",
"=",
"[",
"value",
"]",
")",
")"
] | [
82,
0
] | [
84,
71
] | python | en | ['en', 'en', 'en'] | True |
create_training_examples | (ref, ltg, ltgfcst, griddef, boxdef, samplingfrac) | Input function that yields dicts of CSV, tfrecord for each box in grid. | Input function that yields dicts of CSV, tfrecord for each box in grid. | def create_training_examples(ref, ltg, ltgfcst, griddef, boxdef, samplingfrac):
"""Input function that yields dicts of CSV, tfrecord for each box in grid."""
for example in boxdef.rawdata_input_fn(ref, ltg, griddef, ltgfcst):
# write out all lightning patches, but only some of the non-lightning ones
should_... | [
"def",
"create_training_examples",
"(",
"ref",
",",
"ltg",
",",
"ltgfcst",
",",
"griddef",
",",
"boxdef",
",",
"samplingfrac",
")",
":",
"for",
"example",
"in",
"boxdef",
".",
"rawdata_input_fn",
"(",
"ref",
",",
"ltg",
",",
"griddef",
",",
"ltgfcst",
")",... | [
87,
0
] | [
129,
7
] | python | en | ['en', 'en', 'en'] | True |
get_ir_blob_paths | (hours_dict, max_per_hour=None) | Get IR records in this hour. | Get IR records in this hour. | def get_ir_blob_paths(hours_dict, max_per_hour=None):
"""Get IR records in this hour."""
blob_paths = goesio.get_ir_blob_paths(hours_dict['year'], hours_dict['day'],
hours_dict['hour'])
if max_per_hour and len(blob_paths) > max_per_hour:
blob_paths = blob_paths[:max_per... | [
"def",
"get_ir_blob_paths",
"(",
"hours_dict",
",",
"max_per_hour",
"=",
"None",
")",
":",
"blob_paths",
"=",
"goesio",
".",
"get_ir_blob_paths",
"(",
"hours_dict",
"[",
"'year'",
"]",
",",
"hours_dict",
"[",
"'day'",
"]",
",",
"hours_dict",
"[",
"'hour'",
"... | [
132,
0
] | [
139,
19
] | python | en | ['en', 'en', 'en'] | True |
run_job | (options) | Run the job. | Run the job. | def run_job(options): # pylint: disable=redefined-outer-name
"""Run the job."""
# for repeatability
random.seed(13)
# prediction box
boxdef = bd.BoxDef(options['train_patch_radius'],
options['label_patch_radius'],
options['stride'])
griddef = goesio.create_conus_... | [
"def",
"run_job",
"(",
"options",
")",
":",
"# pylint: disable=redefined-outer-name",
"# for repeatability",
"random",
".",
"seed",
"(",
"13",
")",
"# prediction box",
"boxdef",
"=",
"bd",
".",
"BoxDef",
"(",
"options",
"[",
"'train_patch_radius'",
"]",
",",
"opti... | [
211,
0
] | [
275,
65
] | python | en | ['en', 'fi', 'en'] | True |
parse | (version) |
Parse the given version string and return either a :class:`Version` object
or a :class:`LegacyVersion` object depending on if the given version is
a valid PEP 440 version or a legacy version.
|
Parse the given version string and return either a :class:`Version` object
or a :class:`LegacyVersion` object depending on if the given version is
a valid PEP 440 version or a legacy version.
| def parse(version):
"""
Parse the given version string and return either a :class:`Version` object
or a :class:`LegacyVersion` object depending on if the given version is
a valid PEP 440 version or a legacy version.
"""
try:
return Version(version)
except InvalidVersion:
retu... | [
"def",
"parse",
"(",
"version",
")",
":",
"try",
":",
"return",
"Version",
"(",
"version",
")",
"except",
"InvalidVersion",
":",
"return",
"LegacyVersion",
"(",
"version",
")"
] | [
23,
0
] | [
32,
37
] | python | en | ['en', 'error', 'th'] | False |
_parse_local_version | (local) |
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
|
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
| def _parse_local_version(local):
"""
Takes a string like abc.1.twelve and turns it into ("abc", 1, "twelve").
"""
if local is not None:
return tuple(
part.lower() if not part.isdigit() else int(part)
for part in _local_version_seperators.split(local)
) | [
"def",
"_parse_local_version",
"(",
"local",
")",
":",
"if",
"local",
"is",
"not",
"None",
":",
"return",
"tuple",
"(",
"part",
".",
"lower",
"(",
")",
"if",
"not",
"part",
".",
"isdigit",
"(",
")",
"else",
"int",
"(",
"part",
")",
"for",
"part",
"... | [
331,
0
] | [
339,
9
] | python | en | ['en', 'error', 'th'] | False |
get_current_context | (silent=False) | Returns the current click context. This can be used as a way to
access the current context object from anywhere. This is a more implicit
alternative to the :func:`pass_context` decorator. This function is
primarily useful for helpers such as :func:`echo` which might be
interested in changing its beha... | Returns the current click context. This can be used as a way to
access the current context object from anywhere. This is a more implicit
alternative to the :func:`pass_context` decorator. This function is
primarily useful for helpers such as :func:`echo` which might be
interested in changing its beha... | def get_current_context(silent=False):
"""Returns the current click context. This can be used as a way to
access the current context object from anywhere. This is a more implicit
alternative to the :func:`pass_context` decorator. This function is
primarily useful for helpers such as :func:`echo` whic... | [
"def",
"get_current_context",
"(",
"silent",
"=",
"False",
")",
":",
"try",
":",
"return",
"getattr",
"(",
"_local",
",",
"'stack'",
")",
"[",
"-",
"1",
"]",
"except",
"(",
"AttributeError",
",",
"IndexError",
")",
":",
"if",
"not",
"silent",
":",
"rai... | [
6,
0
] | [
25,
67
] | python | en | ['en', 'en', 'en'] | True |
push_context | (ctx) | Pushes a new context to the current stack. | Pushes a new context to the current stack. | def push_context(ctx):
"""Pushes a new context to the current stack."""
_local.__dict__.setdefault('stack', []).append(ctx) | [
"def",
"push_context",
"(",
"ctx",
")",
":",
"_local",
".",
"__dict__",
".",
"setdefault",
"(",
"'stack'",
",",
"[",
"]",
")",
".",
"append",
"(",
"ctx",
")"
] | [
28,
0
] | [
30,
55
] | python | en | ['en', 'en', 'en'] | True |
pop_context | () | Removes the top level from the stack. | Removes the top level from the stack. | def pop_context():
"""Removes the top level from the stack."""
_local.stack.pop() | [
"def",
"pop_context",
"(",
")",
":",
"_local",
".",
"stack",
".",
"pop",
"(",
")"
] | [
33,
0
] | [
35,
22
] | python | en | ['en', 'en', 'en'] | True |
resolve_color_default | (color=None) | Internal helper to get the default value of the color flag. If a
value is passed it's returned unchanged, otherwise it's looked up from
the current context.
| Internal helper to get the default value of the color flag. If a
value is passed it's returned unchanged, otherwise it's looked up from
the current context.
| def resolve_color_default(color=None):
""""Internal helper to get the default value of the color flag. If a
value is passed it's returned unchanged, otherwise it's looked up from
the current context.
"""
if color is not None:
return color
ctx = get_current_context(silent=True)
if ct... | [
"def",
"resolve_color_default",
"(",
"color",
"=",
"None",
")",
":",
"if",
"color",
"is",
"not",
"None",
":",
"return",
"color",
"ctx",
"=",
"get_current_context",
"(",
"silent",
"=",
"True",
")",
"if",
"ctx",
"is",
"not",
"None",
":",
"return",
"ctx",
... | [
38,
0
] | [
47,
24
] | python | en | ['en', 'en', 'en'] | True |
check_setting_language_code | (app_configs, **kwargs) | Error if LANGUAGE_CODE setting is invalid. | Error if LANGUAGE_CODE setting is invalid. | def check_setting_language_code(app_configs, **kwargs):
"""Error if LANGUAGE_CODE setting is invalid."""
tag = settings.LANGUAGE_CODE
if not isinstance(tag, str) or not language_code_re.match(tag):
return [Error(E001.msg.format(tag), id=E001.id)]
return [] | [
"def",
"check_setting_language_code",
"(",
"app_configs",
",",
"*",
"*",
"kwargs",
")",
":",
"tag",
"=",
"settings",
".",
"LANGUAGE_CODE",
"if",
"not",
"isinstance",
"(",
"tag",
",",
"str",
")",
"or",
"not",
"language_code_re",
".",
"match",
"(",
"tag",
")... | [
29,
0
] | [
34,
13
] | python | en | ['en', 'ja', 'en'] | True |
check_setting_languages | (app_configs, **kwargs) | Error if LANGUAGES setting is invalid. | Error if LANGUAGES setting is invalid. | def check_setting_languages(app_configs, **kwargs):
"""Error if LANGUAGES setting is invalid."""
return [
Error(E002.msg.format(tag), id=E002.id)
for tag, _ in settings.LANGUAGES if not isinstance(tag, str) or not language_code_re.match(tag)
] | [
"def",
"check_setting_languages",
"(",
"app_configs",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"[",
"Error",
"(",
"E002",
".",
"msg",
".",
"format",
"(",
"tag",
")",
",",
"id",
"=",
"E002",
".",
"id",
")",
"for",
"tag",
",",
"_",
"in",
"setting... | [
38,
0
] | [
43,
5
] | python | en | ['en', 'en', 'en'] | True |
check_setting_languages_bidi | (app_configs, **kwargs) | Error if LANGUAGES_BIDI setting is invalid. | Error if LANGUAGES_BIDI setting is invalid. | def check_setting_languages_bidi(app_configs, **kwargs):
"""Error if LANGUAGES_BIDI setting is invalid."""
return [
Error(E003.msg.format(tag), id=E003.id)
for tag in settings.LANGUAGES_BIDI if not isinstance(tag, str) or not language_code_re.match(tag)
] | [
"def",
"check_setting_languages_bidi",
"(",
"app_configs",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"[",
"Error",
"(",
"E003",
".",
"msg",
".",
"format",
"(",
"tag",
")",
",",
"id",
"=",
"E003",
".",
"id",
")",
"for",
"tag",
"in",
"settings",
"."... | [
47,
0
] | [
52,
5
] | python | en | ['en', 'et', 'en'] | True |
check_language_settings_consistent | (app_configs, **kwargs) | Error if language settings are not consistent with each other. | Error if language settings are not consistent with each other. | def check_language_settings_consistent(app_configs, **kwargs):
"""Error if language settings are not consistent with each other."""
try:
get_supported_language_variant(settings.LANGUAGE_CODE)
except LookupError:
return [E004]
else:
return [] | [
"def",
"check_language_settings_consistent",
"(",
"app_configs",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"get_supported_language_variant",
"(",
"settings",
".",
"LANGUAGE_CODE",
")",
"except",
"LookupError",
":",
"return",
"[",
"E004",
"]",
"else",
":",
"... | [
56,
0
] | [
63,
17
] | python | en | ['en', 'en', 'en'] | True |
validate_password | (password, user=None, password_validators=None) |
Validate whether the password meets all validator requirements.
If the password is valid, return ``None``.
If the password is invalid, raise ValidationError with all error messages.
|
Validate whether the password meets all validator requirements. | def validate_password(password, user=None, password_validators=None):
"""
Validate whether the password meets all validator requirements.
If the password is valid, return ``None``.
If the password is invalid, raise ValidationError with all error messages.
"""
errors = []
if password_validat... | [
"def",
"validate_password",
"(",
"password",
",",
"user",
"=",
"None",
",",
"password_validators",
"=",
"None",
")",
":",
"errors",
"=",
"[",
"]",
"if",
"password_validators",
"is",
"None",
":",
"password_validators",
"=",
"get_default_password_validators",
"(",
... | [
34,
0
] | [
50,
37
] | python | en | ['en', 'error', 'th'] | False |
password_changed | (password, user=None, password_validators=None) |
Inform all validators that have implemented a password_changed() method
that the password has been changed.
|
Inform all validators that have implemented a password_changed() method
that the password has been changed.
| def password_changed(password, user=None, password_validators=None):
"""
Inform all validators that have implemented a password_changed() method
that the password has been changed.
"""
if password_validators is None:
password_validators = get_default_password_validators()
for validator i... | [
"def",
"password_changed",
"(",
"password",
",",
"user",
"=",
"None",
",",
"password_validators",
"=",
"None",
")",
":",
"if",
"password_validators",
"is",
"None",
":",
"password_validators",
"=",
"get_default_password_validators",
"(",
")",
"for",
"validator",
"i... | [
53,
0
] | [
62,
40
] | python | en | ['en', 'error', 'th'] | False |
password_validators_help_texts | (password_validators=None) |
Return a list of all help texts of all configured validators.
|
Return a list of all help texts of all configured validators.
| def password_validators_help_texts(password_validators=None):
"""
Return a list of all help texts of all configured validators.
"""
help_texts = []
if password_validators is None:
password_validators = get_default_password_validators()
for validator in password_validators:
help_t... | [
"def",
"password_validators_help_texts",
"(",
"password_validators",
"=",
"None",
")",
":",
"help_texts",
"=",
"[",
"]",
"if",
"password_validators",
"is",
"None",
":",
"password_validators",
"=",
"get_default_password_validators",
"(",
")",
"for",
"validator",
"in",
... | [
65,
0
] | [
74,
21
] | python | en | ['en', 'error', 'th'] | False |
_password_validators_help_text_html | (password_validators=None) |
Return an HTML string with all help texts of all configured validators
in an <ul>.
|
Return an HTML string with all help texts of all configured validators
in an <ul>.
| def _password_validators_help_text_html(password_validators=None):
"""
Return an HTML string with all help texts of all configured validators
in an <ul>.
"""
help_texts = password_validators_help_texts(password_validators)
help_items = format_html_join('', '<li>{}</li>', ((help_text,) for help_t... | [
"def",
"_password_validators_help_text_html",
"(",
"password_validators",
"=",
"None",
")",
":",
"help_texts",
"=",
"password_validators_help_texts",
"(",
"password_validators",
")",
"help_items",
"=",
"format_html_join",
"(",
"''",
",",
"'<li>{}</li>'",
",",
"(",
"(",
... | [
77,
0
] | [
84,
71
] | python | en | ['en', 'error', 'th'] | False |
EmailBackend.send_messages | (self, messages) | Redirect messages to the dummy outbox | Redirect messages to the dummy outbox | def send_messages(self, messages):
"""Redirect messages to the dummy outbox"""
msg_count = 0
for message in messages: # .message() triggers header validation
message.message()
mail.outbox.append(message)
msg_count += 1
return msg_count | [
"def",
"send_messages",
"(",
"self",
",",
"messages",
")",
":",
"msg_count",
"=",
"0",
"for",
"message",
"in",
"messages",
":",
"# .message() triggers header validation",
"message",
".",
"message",
"(",
")",
"mail",
".",
"outbox",
".",
"append",
"(",
"message"... | [
22,
4
] | [
29,
24
] | python | en | ['en', 'en', 'en'] | True |
BaseSpatialOperations.geo_db_type | (self, f) |
Return the database column type for the geometry field on
the spatial backend.
|
Return the database column type for the geometry field on
the spatial backend.
| def geo_db_type(self, f):
"""
Return the database column type for the geometry field on
the spatial backend.
"""
raise NotImplementedError('subclasses of BaseSpatialOperations must provide a geo_db_type() method') | [
"def",
"geo_db_type",
"(",
"self",
",",
"f",
")",
":",
"raise",
"NotImplementedError",
"(",
"'subclasses of BaseSpatialOperations must provide a geo_db_type() method'",
")"
] | [
61,
4
] | [
66,
108
] | python | en | ['en', 'error', 'th'] | False |
BaseSpatialOperations.get_distance | (self, f, value, lookup_type) |
Return the distance parameters for the given geometry field,
lookup value, and lookup type.
|
Return the distance parameters for the given geometry field,
lookup value, and lookup type.
| def get_distance(self, f, value, lookup_type):
"""
Return the distance parameters for the given geometry field,
lookup value, and lookup type.
"""
raise NotImplementedError('Distance operations not available on this spatial backend.') | [
"def",
"get_distance",
"(",
"self",
",",
"f",
",",
"value",
",",
"lookup_type",
")",
":",
"raise",
"NotImplementedError",
"(",
"'Distance operations not available on this spatial backend.'",
")"
] | [
68,
4
] | [
73,
95
] | python | en | ['en', 'error', 'th'] | False |
BaseSpatialOperations.get_geom_placeholder | (self, f, value, compiler) |
Return the placeholder for the given geometry field with the given
value. Depending on the spatial backend, the placeholder may contain a
stored procedure call to the transformation function of the spatial
backend.
|
Return the placeholder for the given geometry field with the given
value. Depending on the spatial backend, the placeholder may contain a
stored procedure call to the transformation function of the spatial
backend.
| def get_geom_placeholder(self, f, value, compiler):
"""
Return the placeholder for the given geometry field with the given
value. Depending on the spatial backend, the placeholder may contain a
stored procedure call to the transformation function of the spatial
backend.
... | [
"def",
"get_geom_placeholder",
"(",
"self",
",",
"f",
",",
"value",
",",
"compiler",
")",
":",
"def",
"transform_value",
"(",
"value",
",",
"field",
")",
":",
"return",
"value",
"is",
"not",
"None",
"and",
"value",
".",
"srid",
"!=",
"field",
".",
"sri... | [
75,
4
] | [
101,
45
] | python | en | ['en', 'error', 'th'] | False |
L_star_fun | (L_star) |
This calcualtes the zero of the optimal well spacing, L_star.
|
This calcualtes the zero of the optimal well spacing, L_star.
| def L_star_fun(L_star):
"""
This calcualtes the zero of the optimal well spacing, L_star.
"""
import numpy as np
# import pudb; pudb.set_trace()
return L_star**2.0*np.log(L_star/D) - \
2.0*np.pi*rho_w*T/viscosity * \
((alphaII*rho_r-rho_w)*gravity*reservoir_depth) * \
... | [
"def",
"L_star_fun",
"(",
"L_star",
")",
":",
"import",
"numpy",
"as",
"np",
"# import pudb; pudb.set_trace()",
"return",
"L_star",
"**",
"2.0",
"*",
"np",
".",
"log",
"(",
"L_star",
"/",
"D",
")",
"-",
"2.0",
"*",
"np",
".",
"pi",
"*",
"rho_w",
"*",
... | [
30,
0
] | [
39,
71
] | python | en | ['en', 'error', 'th'] | False |
L_star_fun2 | (L_star) |
This calcualtes the optimal well spacing, L_star, if the reservoir
constraints imply a flow rate that is higher than the flow rate that
would minimize the LCOH.
define capital_costs and CRF externally
|
This calcualtes the optimal well spacing, L_star, if the reservoir
constraints imply a flow rate that is higher than the flow rate that
would minimize the LCOH. | def L_star_fun2(L_star):
"""
This calcualtes the optimal well spacing, L_star, if the reservoir
constraints imply a flow rate that is higher than the flow rate that
would minimize the LCOH.
define capital_costs and CRF externally
"""
import numpy as np
return (capital_cost_internal*CRF... | [
"def",
"L_star_fun2",
"(",
"L_star",
")",
":",
"import",
"numpy",
"as",
"np",
"return",
"(",
"capital_cost_internal",
"*",
"CRF",
"*",
"rho_w",
"*",
"rho_w",
"*",
"np",
".",
"pi",
"*",
"permeability_",
"*",
"b_",
"/",
"(",
"2.0",
"*",
"dollars_per_kWhth"... | [
41,
0
] | [
55,
40
] | python | en | ['en', 'error', 'th'] | False |
_pad_for_encryption | (message, target_length) | r"""Pads the message for encryption, returning the padded message.
:return: 00 02 RANDOM_DATA 00 MESSAGE
>>> block = _pad_for_encryption(b'hello', 16)
>>> len(block)
16
>>> block[0:2]
b'\x00\x02'
>>> block[-6:]
b'\x00hello'
| r"""Pads the message for encryption, returning the padded message. | def _pad_for_encryption(message, target_length):
r"""Pads the message for encryption, returning the padded message.
:return: 00 02 RANDOM_DATA 00 MESSAGE
>>> block = _pad_for_encryption(b'hello', 16)
>>> len(block)
16
>>> block[0:2]
b'\x00\x02'
>>> block[-6:]
b'\x00hello'
"""
... | [
"def",
"_pad_for_encryption",
"(",
"message",
",",
"target_length",
")",
":",
"max_msglength",
"=",
"target_length",
"-",
"11",
"msglength",
"=",
"len",
"(",
"message",
")",
"if",
"msglength",
">",
"max_msglength",
":",
"raise",
"OverflowError",
"(",
"'%i bytes ... | [
68,
0
] | [
111,
30
] | python | en | ['en', 'en', 'en'] | True |
_pad_for_signing | (message, target_length) | r"""Pads the message for signing, returning the padded message.
The padding is always a repetition of FF bytes.
:return: 00 01 PADDING 00 MESSAGE
>>> block = _pad_for_signing(b'hello', 16)
>>> len(block)
16
>>> block[0:2]
b'\x00\x01'
>>> block[-6:]
b'\x00hello'
>>> block[2:-6]... | r"""Pads the message for signing, returning the padded message. | def _pad_for_signing(message, target_length):
r"""Pads the message for signing, returning the padded message.
The padding is always a repetition of FF bytes.
:return: 00 01 PADDING 00 MESSAGE
>>> block = _pad_for_signing(b'hello', 16)
>>> len(block)
16
>>> block[0:2]
b'\x00\x01'
>... | [
"def",
"_pad_for_signing",
"(",
"message",
",",
"target_length",
")",
":",
"max_msglength",
"=",
"target_length",
"-",
"11",
"msglength",
"=",
"len",
"(",
"message",
")",
"if",
"msglength",
">",
"max_msglength",
":",
"raise",
"OverflowError",
"(",
"'%i bytes nee... | [
114,
0
] | [
145,
30
] | python | en | ['en', 'en', 'en'] | True |
encrypt | (message, pub_key) | Encrypts the given message using PKCS#1 v1.5
:param message: the message to encrypt. Must be a byte string no longer than
``k-11`` bytes, where ``k`` is the number of bytes needed to encode
the ``n`` component of the public key.
:param pub_key: the :py:class:`rsa.PublicKey` to encrypt with.
... | Encrypts the given message using PKCS#1 v1.5 | def encrypt(message, pub_key):
"""Encrypts the given message using PKCS#1 v1.5
:param message: the message to encrypt. Must be a byte string no longer than
``k-11`` bytes, where ``k`` is the number of bytes needed to encode
the ``n`` component of the public key.
:param pub_key: the :py:clas... | [
"def",
"encrypt",
"(",
"message",
",",
"pub_key",
")",
":",
"keylength",
"=",
"common",
".",
"byte_size",
"(",
"pub_key",
".",
"n",
")",
"padded",
"=",
"_pad_for_encryption",
"(",
"message",
",",
"keylength",
")",
"payload",
"=",
"transform",
".",
"bytes2i... | [
148,
0
] | [
177,
16
] | python | en | ['en', 'en', 'en'] | True |
decrypt | (crypto, priv_key) | r"""Decrypts the given message using PKCS#1 v1.5
The decryption is considered 'failed' when the resulting cleartext doesn't
start with the bytes 00 02, or when the 00 byte between the padding and
the message cannot be found.
:param crypto: the crypto text as returned by :py:func:`rsa.encrypt`
:par... | r"""Decrypts the given message using PKCS#1 v1.5 | def decrypt(crypto, priv_key):
r"""Decrypts the given message using PKCS#1 v1.5
The decryption is considered 'failed' when the resulting cleartext doesn't
start with the bytes 00 02, or when the 00 byte between the padding and
the message cannot be found.
:param crypto: the crypto text as returned... | [
"def",
"decrypt",
"(",
"crypto",
",",
"priv_key",
")",
":",
"blocksize",
"=",
"common",
".",
"byte_size",
"(",
"priv_key",
".",
"n",
")",
"encrypted",
"=",
"transform",
".",
"bytes2int",
"(",
"crypto",
")",
"decrypted",
"=",
"priv_key",
".",
"blinded_decry... | [
180,
0
] | [
246,
34
] | python | en | ['en', 'en', 'en'] | True |
sign_hash | (hash_value, priv_key, hash_method) | Signs a precomputed hash with the private key.
Hashes the message, then signs the hash with the given key. This is known
as a "detached signature", because the message itself isn't altered.
:param hash_value: A precomputed hash to sign (ignores message). Should be set to
None if needing to hash an... | Signs a precomputed hash with the private key. | def sign_hash(hash_value, priv_key, hash_method):
"""Signs a precomputed hash with the private key.
Hashes the message, then signs the hash with the given key. This is known
as a "detached signature", because the message itself isn't altered.
:param hash_value: A precomputed hash to sign (ignores mess... | [
"def",
"sign_hash",
"(",
"hash_value",
",",
"priv_key",
",",
"hash_method",
")",
":",
"# Get the ASN1 code for this hash method",
"if",
"hash_method",
"not",
"in",
"HASH_ASN1",
":",
"raise",
"ValueError",
"(",
"'Invalid hash method: %s'",
"%",
"hash_method",
")",
"asn... | [
249,
0
] | [
280,
16
] | python | en | ['en', 'en', 'en'] | True |
sign | (message, priv_key, hash_method) | Signs the message with the private key.
Hashes the message, then signs the hash with the given key. This is known
as a "detached signature", because the message itself isn't altered.
:param message: the message to sign. Can be an 8-bit string or a file-like
object. If ``message`` has a ``read()`` ... | Signs the message with the private key. | def sign(message, priv_key, hash_method):
"""Signs the message with the private key.
Hashes the message, then signs the hash with the given key. This is known
as a "detached signature", because the message itself isn't altered.
:param message: the message to sign. Can be an 8-bit string or a file-like... | [
"def",
"sign",
"(",
"message",
",",
"priv_key",
",",
"hash_method",
")",
":",
"msg_hash",
"=",
"compute_hash",
"(",
"message",
",",
"hash_method",
")",
"return",
"sign_hash",
"(",
"msg_hash",
",",
"priv_key",
",",
"hash_method",
")"
] | [
283,
0
] | [
302,
53
] | python | en | ['en', 'en', 'en'] | True |
verify | (message, signature, pub_key) | Verifies that the signature matches the message.
The hash method is detected automatically from the signature.
:param message: the signed message. Can be an 8-bit string or a file-like
object. If ``message`` has a ``read()`` method, it is assumed to be a
file-like object.
:param signature:... | Verifies that the signature matches the message. | def verify(message, signature, pub_key):
"""Verifies that the signature matches the message.
The hash method is detected automatically from the signature.
:param message: the signed message. Can be an 8-bit string or a file-like
object. If ``message`` has a ``read()`` method, it is assumed to be a... | [
"def",
"verify",
"(",
"message",
",",
"signature",
",",
"pub_key",
")",
":",
"keylength",
"=",
"common",
".",
"byte_size",
"(",
"pub_key",
".",
"n",
")",
"encrypted",
"=",
"transform",
".",
"bytes2int",
"(",
"signature",
")",
"decrypted",
"=",
"core",
".... | [
305,
0
] | [
337,
22
] | python | en | ['en', 'en', 'en'] | True |
find_signature_hash | (signature, pub_key) | Returns the hash name detected from the signature.
If you also want to verify the message, use :py:func:`rsa.verify()` instead.
It also returns the name of the used hash.
:param signature: the signature block, as created with :py:func:`rsa.sign`.
:param pub_key: the :py:class:`rsa.PublicKey` of the pe... | Returns the hash name detected from the signature. | def find_signature_hash(signature, pub_key):
"""Returns the hash name detected from the signature.
If you also want to verify the message, use :py:func:`rsa.verify()` instead.
It also returns the name of the used hash.
:param signature: the signature block, as created with :py:func:`rsa.sign`.
:pa... | [
"def",
"find_signature_hash",
"(",
"signature",
",",
"pub_key",
")",
":",
"keylength",
"=",
"common",
".",
"byte_size",
"(",
"pub_key",
".",
"n",
")",
"encrypted",
"=",
"transform",
".",
"bytes2int",
"(",
"signature",
")",
"decrypted",
"=",
"core",
".",
"d... | [
340,
0
] | [
356,
38
] | python | en | ['en', 'en', 'en'] | True |
yield_fixedblocks | (infile, blocksize) | Generator, yields each block of ``blocksize`` bytes in the input file.
:param infile: file to read and separate in blocks.
:param blocksize: block size in bytes.
:returns: a generator that yields the contents of each block
| Generator, yields each block of ``blocksize`` bytes in the input file. | def yield_fixedblocks(infile, blocksize):
"""Generator, yields each block of ``blocksize`` bytes in the input file.
:param infile: file to read and separate in blocks.
:param blocksize: block size in bytes.
:returns: a generator that yields the contents of each block
"""
while True:
bl... | [
"def",
"yield_fixedblocks",
"(",
"infile",
",",
"blocksize",
")",
":",
"while",
"True",
":",
"block",
"=",
"infile",
".",
"read",
"(",
"blocksize",
")",
"read_bytes",
"=",
"len",
"(",
"block",
")",
"if",
"read_bytes",
"==",
"0",
":",
"break",
"yield",
... | [
359,
0
] | [
377,
17
] | python | en | ['en', 'en', 'en'] | True |
compute_hash | (message, method_name) | Returns the message digest.
:param message: the signed message. Can be an 8-bit string or a file-like
object. If ``message`` has a ``read()`` method, it is assumed to be a
file-like object.
:param method_name: the hash method, must be a key of
:py:const:`HASH_METHODS`.
| Returns the message digest. | def compute_hash(message, method_name):
"""Returns the message digest.
:param message: the signed message. Can be an 8-bit string or a file-like
object. If ``message`` has a ``read()`` method, it is assumed to be a
file-like object.
:param method_name: the hash method, must be a key of
... | [
"def",
"compute_hash",
"(",
"message",
",",
"method_name",
")",
":",
"if",
"method_name",
"not",
"in",
"HASH_METHODS",
":",
"raise",
"ValueError",
"(",
"'Invalid hash method: %s'",
"%",
"method_name",
")",
"method",
"=",
"HASH_METHODS",
"[",
"method_name",
"]",
... | [
380,
0
] | [
405,
26
] | python | en | ['en', 'en', 'en'] | True |
_find_method_hash | (clearsig) | Finds the hash method.
:param clearsig: full padded ASN1 and hash.
:return: the used hash method.
:raise VerificationFailed: when the hash method cannot be found
| Finds the hash method. | def _find_method_hash(clearsig):
"""Finds the hash method.
:param clearsig: full padded ASN1 and hash.
:return: the used hash method.
:raise VerificationFailed: when the hash method cannot be found
"""
for (hashname, asn1code) in HASH_ASN1.items():
if asn1code in clearsig:
... | [
"def",
"_find_method_hash",
"(",
"clearsig",
")",
":",
"for",
"(",
"hashname",
",",
"asn1code",
")",
"in",
"HASH_ASN1",
".",
"items",
"(",
")",
":",
"if",
"asn1code",
"in",
"clearsig",
":",
"return",
"hashname",
"raise",
"VerificationError",
"(",
"'Verificat... | [
408,
0
] | [
420,
50
] | python | en | ['en', 'en', 'en'] | True |
ContactList.search | (self, name) | Return all contacts that contain the search value | Return all contacts that contain the search value | def search(self, name):
"Return all contacts that contain the search value"
matching_contacts = []
for contact in self:
if name in contact.name:
matching_contacts.append(contact)
return matching_contacts | [
"def",
"search",
"(",
"self",
",",
"name",
")",
":",
"matching_contacts",
"=",
"[",
"]",
"for",
"contact",
"in",
"self",
":",
"if",
"name",
"in",
"contact",
".",
"name",
":",
"matching_contacts",
".",
"append",
"(",
"contact",
")",
"return",
"matching_co... | [
19,
4
] | [
25,
32
] | python | en | ['en', 'en', 'en'] | True |
_parse_ld_musl_from_elf | (f: IO[bytes]) | Detect musl libc location by parsing the Python executable.
Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
| Detect musl libc location by parsing the Python executable. | def _parse_ld_musl_from_elf(f: IO[bytes]) -> Optional[str]:
"""Detect musl libc location by parsing the Python executable.
Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
"""
f.seek(0)
try:
... | [
"def",
"_parse_ld_musl_from_elf",
"(",
"f",
":",
"IO",
"[",
"bytes",
"]",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"f",
".",
"seek",
"(",
"0",
")",
"try",
":",
"ident",
"=",
"_read_unpacked",
"(",
"f",
",",
"\"16B\"",
")",
"except",
"struct",
"... | [
21,
0
] | [
67,
15
] | python | en | ['en', 'en', 'en'] | True |
_get_musl_version | (executable: str) | Detect currently-running musl runtime version.
This is done by checking the specified executable's dynamic linking
information, and invoking the loader to parse its output for a version
string. If the loader is musl, the output would be something like::
musl libc (x86_64)
Version 1.2.2
... | Detect currently-running musl runtime version. | def _get_musl_version(executable: str) -> Optional[_MuslVersion]:
"""Detect currently-running musl runtime version.
This is done by checking the specified executable's dynamic linking
information, and invoking the loader to parse its output for a version
string. If the loader is musl, the output would ... | [
"def",
"_get_musl_version",
"(",
"executable",
":",
"str",
")",
"->",
"Optional",
"[",
"_MuslVersion",
"]",
":",
"with",
"contextlib",
".",
"ExitStack",
"(",
")",
"as",
"stack",
":",
"try",
":",
"f",
"=",
"stack",
".",
"enter_context",
"(",
"open",
"(",
... | [
86,
0
] | [
106,
43
] | python | en | ['en', 'en', 'en'] | True |
platform_tags | (arch: str) | Generate musllinux tags compatible to the current platform.
:param arch: Should be the part of platform tag after the ``linux_``
prefix, e.g. ``x86_64``. The ``linux_`` prefix is assumed as a
prerequisite for the current platform to be musllinux-compatible.
:returns: An iterator of compatible ... | Generate musllinux tags compatible to the current platform. | def platform_tags(arch: str) -> Iterator[str]:
"""Generate musllinux tags compatible to the current platform.
:param arch: Should be the part of platform tag after the ``linux_``
prefix, e.g. ``x86_64``. The ``linux_`` prefix is assumed as a
prerequisite for the current platform to be musllinux... | [
"def",
"platform_tags",
"(",
"arch",
":",
"str",
")",
"->",
"Iterator",
"[",
"str",
"]",
":",
"sys_musl",
"=",
"_get_musl_version",
"(",
"sys",
".",
"executable",
")",
"if",
"sys_musl",
"is",
"None",
":",
"# Python not dynamically linked against musl.",
"return"... | [
109,
0
] | [
122,
58
] | python | en | ['en', 'en', 'en'] | True |
format_num | (num, decplaces=10) | Converts a number into a more a readable string-version. | Converts a number into a more a readable string-version. | def format_num(num, decplaces=10):
"Converts a number into a more a readable string-version."
try:
dec = Decimal(num)
# Cut the decimal off at "precision" decimal places.
if decplaces < 1:
dec = dec.quantize(Decimal("0"))
else:
# Set our precision to at le... | [
"def",
"format_num",
"(",
"num",
",",
"decplaces",
"=",
"10",
")",
":",
"try",
":",
"dec",
"=",
"Decimal",
"(",
"num",
")",
"# Cut the decimal off at \"precision\" decimal places.",
"if",
"decplaces",
"<",
"1",
":",
"dec",
"=",
"dec",
".",
"quantize",
"(",
... | [
6,
0
] | [
37,
14
] | python | en | ['en', 'en', 'en'] | True |
rot | (message, shift=3) | Employs the Ceasar Cipher to encode/decode messages. | Employs the Ceasar Cipher to encode/decode messages. | def rot(message, shift=3):
"Employs the Ceasar Cipher to encode/decode messages."
alphabet = ascii_lowercase
shifted_alphabet = alphabet[shift:] + alphabet[:shift]
table = maketrans(alphabet, shifted_alphabet)
return message.lower().translate(table) | [
"def",
"rot",
"(",
"message",
",",
"shift",
"=",
"3",
")",
":",
"alphabet",
"=",
"ascii_lowercase",
"shifted_alphabet",
"=",
"alphabet",
"[",
"shift",
":",
"]",
"+",
"alphabet",
"[",
":",
"shift",
"]",
"table",
"=",
"maketrans",
"(",
"alphabet",
",",
"... | [
40,
0
] | [
45,
43
] | 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.