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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ValidatorMixin.validate | (self) |
Публичный метод для запуска валидатора сущности
|
Публичный метод для запуска валидатора сущности
| def validate(self):
"""
Публичный метод для запуска валидатора сущности
"""
if self._validator:
self._validator.validate(self) | [
"def",
"validate",
"(",
"self",
")",
":",
"if",
"self",
".",
"_validator",
":",
"self",
".",
"_validator",
".",
"validate",
"(",
"self",
")"
] | [
88,
4
] | [
93,
42
] | python | en | ['en', 'error', 'th'] | False |
ValidatorMixin.after_validate | (self) |
Возможность расширения запускаемого объекта после валидации
|
Возможность расширения запускаемого объекта после валидации
| def after_validate(self):
"""
Возможность расширения запускаемого объекта после валидации
""" | [
"def",
"after_validate",
"(",
"self",
")",
":"
] | [
95,
4
] | [
98,
11
] | python | en | ['en', 'error', 'th'] | False |
GlobalHelperMixin.global_helper | (self) |
Возвращает глобального помощника
|
Возвращает глобального помощника
| def global_helper(self):
"""
Возвращает глобального помощника
"""
return self._global_helper | [
"def",
"global_helper",
"(",
"self",
")",
":",
"return",
"self",
".",
"_global_helper"
] | [
113,
4
] | [
117,
34
] | python | en | ['en', 'error', 'th'] | False |
GlobalHelperMixin._prepare_global_helper_class | (self) |
Возвращает класс помощника
|
Возвращает класс помощника
| def _prepare_global_helper_class(self) -> Type[BaseRunnerHelper]:
"""
Возвращает класс помощника
"""
return BaseRunnerHelper | [
"def",
"_prepare_global_helper_class",
"(",
"self",
")",
"->",
"Type",
"[",
"BaseRunnerHelper",
"]",
":",
"return",
"BaseRunnerHelper"
] | [
119,
4
] | [
123,
31
] | python | en | ['en', 'error', 'th'] | False |
GlobalHelperMixin._prepare_global_helper | (self, *args, **kwargs) |
Предназначен для определения глобального помощника
|
Предназначен для определения глобального помощника
| def _prepare_global_helper(self, *args, **kwargs):
"""
Предназначен для определения глобального помощника
"""
global_helper_class = self._prepare_global_helper_class()
if issubclass(global_helper_class, BaseRunnerHelper):
global_helper = global_helper_class(*args, **... | [
"def",
"_prepare_global_helper",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"global_helper_class",
"=",
"self",
".",
"_prepare_global_helper_class",
"(",
")",
"if",
"issubclass",
"(",
"global_helper_class",
",",
"BaseRunnerHelper",
")",
":... | [
125,
4
] | [
136,
28
] | python | en | ['en', 'error', 'th'] | False |
GlobalHelperMixin.set_global_helper | (
self,
global_helper: BaseRunnerHelper,
) |
Публичный метод для установки глобального помощника
|
Публичный метод для установки глобального помощника
| def set_global_helper(
self,
global_helper: BaseRunnerHelper,
):
"""
Публичный метод для установки глобального помощника
"""
self._global_helper = global_helper | [
"def",
"set_global_helper",
"(",
"self",
",",
"global_helper",
":",
"BaseRunnerHelper",
",",
")",
":",
"self",
".",
"_global_helper",
"=",
"global_helper"
] | [
138,
4
] | [
145,
43
] | python | en | ['en', 'error', 'th'] | False |
_pytest | (request) | Return a helper which offers a gethookrecorder(hook) method which
returns a HookRecorder instance which helps to make assertions about called
hooks.
| Return a helper which offers a gethookrecorder(hook) method which
returns a HookRecorder instance which helps to make assertions about called
hooks. | def _pytest(request):
"""Return a helper which offers a gethookrecorder(hook) method which
returns a HookRecorder instance which helps to make assertions about called
hooks.
"""
return PytestArg(request) | [
"def",
"_pytest",
"(",
"request",
")",
":",
"return",
"PytestArg",
"(",
"request",
")"
] | [
164,
0
] | [
170,
29
] | python | en | ['en', 'en', 'en'] | True |
get_public_names | (values) | Only return names from iterator values without a leading underscore. | Only return names from iterator values without a leading underscore. | def get_public_names(values):
"""Only return names from iterator values without a leading underscore."""
return [x for x in values if x[0] != "_"] | [
"def",
"get_public_names",
"(",
"values",
")",
":",
"return",
"[",
"x",
"for",
"x",
"in",
"values",
"if",
"x",
"[",
"0",
"]",
"!=",
"\"_\"",
"]"
] | [
183,
0
] | [
185,
45
] | python | en | ['en', 'en', 'en'] | True |
HookRecorder.matchreport | (self, inamepart="",
names="pytest_runtest_logreport pytest_collectreport", when=None) | return a testreport whose dotted import path matches | return a testreport whose dotted import path matches | def matchreport(self, inamepart="",
names="pytest_runtest_logreport pytest_collectreport", when=None):
"""return a testreport whose dotted import path matches"""
values = []
for rep in self.getreports(names=names):
try:
if not when and rep.when != ... | [
"def",
"matchreport",
"(",
"self",
",",
"inamepart",
"=",
"\"\"",
",",
"names",
"=",
"\"pytest_runtest_logreport pytest_collectreport\"",
",",
"when",
"=",
"None",
")",
":",
"values",
"=",
"[",
"]",
"for",
"rep",
"in",
"self",
".",
"getreports",
"(",
"names"... | [
269,
4
] | [
290,
24
] | python | en | ['en', 'en', 'en'] | True |
RunResult.parseoutcomes | (self) | Return a dictionary of outcomestring->num from parsing the terminal
output that the test process produced.
| Return a dictionary of outcomestring->num from parsing the terminal
output that the test process produced. | def parseoutcomes(self):
"""Return a dictionary of outcomestring->num from parsing the terminal
output that the test process produced.
"""
for line in reversed(self.outlines):
if 'seconds' in line:
outcomes = rex_outcome.findall(line)
if outco... | [
"def",
"parseoutcomes",
"(",
"self",
")",
":",
"for",
"line",
"in",
"reversed",
"(",
"self",
".",
"outlines",
")",
":",
"if",
"'seconds'",
"in",
"line",
":",
"outcomes",
"=",
"rex_outcome",
".",
"findall",
"(",
"line",
")",
"if",
"outcomes",
":",
"d",
... | [
369,
4
] | [
382,
60
] | python | en | ['en', 'en', 'en'] | True |
RunResult.assert_outcomes | (self, passed=0, skipped=0, failed=0, error=0) | Assert that the specified outcomes appear with the respective
numbers (0 means it didn't occur) in the text output from a test run.
| Assert that the specified outcomes appear with the respective
numbers (0 means it didn't occur) in the text output from a test run. | def assert_outcomes(self, passed=0, skipped=0, failed=0, error=0):
"""Assert that the specified outcomes appear with the respective
numbers (0 means it didn't occur) in the text output from a test run.
"""
d = self.parseoutcomes()
obtained = {
'passed': d.get('passed... | [
"def",
"assert_outcomes",
"(",
"self",
",",
"passed",
"=",
"0",
",",
"skipped",
"=",
"0",
",",
"failed",
"=",
"0",
",",
"error",
"=",
"0",
")",
":",
"d",
"=",
"self",
".",
"parseoutcomes",
"(",
")",
"obtained",
"=",
"{",
"'passed'",
":",
"d",
"."... | [
384,
4
] | [
396,
91
] | python | en | ['en', 'en', 'en'] | True |
Testdir.finalize | (self) | Clean up global state artifacts.
Some methods modify the global interpreter state and this tries to
clean this up. It does not remove the temporary directory however so
it can be looked at after the test run has finished.
| Clean up global state artifacts. | def finalize(self):
"""Clean up global state artifacts.
Some methods modify the global interpreter state and this tries to
clean this up. It does not remove the temporary directory however so
it can be looked at after the test run has finished.
"""
self._sys_modules_sn... | [
"def",
"finalize",
"(",
"self",
")",
":",
"self",
".",
"_sys_modules_snapshot",
".",
"restore",
"(",
")",
"self",
".",
"_sys_path_snapshot",
".",
"restore",
"(",
")",
"self",
".",
"_cwd_snapshot",
".",
"restore",
"(",
")"
] | [
466,
4
] | [
476,
36
] | python | en | ['en', 'en', 'en'] | True |
Testdir.make_hook_recorder | (self, pluginmanager) | Create a new :py:class:`HookRecorder` for a PluginManager. | Create a new :py:class:`HookRecorder` for a PluginManager. | def make_hook_recorder(self, pluginmanager):
"""Create a new :py:class:`HookRecorder` for a PluginManager."""
assert not hasattr(pluginmanager, "reprec")
pluginmanager.reprec = reprec = HookRecorder(pluginmanager)
self.request.addfinalizer(reprec.finish_recording)
return reprec | [
"def",
"make_hook_recorder",
"(",
"self",
",",
"pluginmanager",
")",
":",
"assert",
"not",
"hasattr",
"(",
"pluginmanager",
",",
"\"reprec\"",
")",
"pluginmanager",
".",
"reprec",
"=",
"reprec",
"=",
"HookRecorder",
"(",
"pluginmanager",
")",
"self",
".",
"req... | [
486,
4
] | [
491,
21
] | python | en | ['en', 'en', 'en'] | True |
Testdir.chdir | (self) | Cd into the temporary directory.
This is done automatically upon instantiation.
| Cd into the temporary directory. | def chdir(self):
"""Cd into the temporary directory.
This is done automatically upon instantiation.
"""
self.tmpdir.chdir() | [
"def",
"chdir",
"(",
"self",
")",
":",
"self",
".",
"tmpdir",
".",
"chdir",
"(",
")"
] | [
493,
4
] | [
499,
27
] | python | en | ['en', 'en', 'en'] | True |
Testdir.makefile | (self, ext, *args, **kwargs) | Create a new file in the testdir.
ext: The extension the file should use, including the dot, e.g. `.py`.
args: All args will be treated as strings and joined using newlines.
The result will be written as contents to the file. The name of the
file will be based on the test functi... | Create a new file in the testdir. | def makefile(self, ext, *args, **kwargs):
"""Create a new file in the testdir.
ext: The extension the file should use, including the dot, e.g. `.py`.
args: All args will be treated as strings and joined using newlines.
The result will be written as contents to the file. The name of... | [
"def",
"makefile",
"(",
"self",
",",
"ext",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_makefile",
"(",
"ext",
",",
"args",
",",
"kwargs",
")"
] | [
523,
4
] | [
538,
48
] | python | en | ['en', 'en', 'en'] | True |
Testdir.makeconftest | (self, source) | Write a contest.py file with 'source' as contents. | Write a contest.py file with 'source' as contents. | def makeconftest(self, source):
"""Write a contest.py file with 'source' as contents."""
return self.makepyfile(conftest=source) | [
"def",
"makeconftest",
"(",
"self",
",",
"source",
")",
":",
"return",
"self",
".",
"makepyfile",
"(",
"conftest",
"=",
"source",
")"
] | [
540,
4
] | [
542,
47
] | python | en | ['en', 'en', 'en'] | True |
Testdir.makeini | (self, source) | Write a tox.ini file with 'source' as contents. | Write a tox.ini file with 'source' as contents. | def makeini(self, source):
"""Write a tox.ini file with 'source' as contents."""
return self.makefile('.ini', tox=source) | [
"def",
"makeini",
"(",
"self",
",",
"source",
")",
":",
"return",
"self",
".",
"makefile",
"(",
"'.ini'",
",",
"tox",
"=",
"source",
")"
] | [
544,
4
] | [
546,
48
] | python | en | ['en', 'en', 'en'] | True |
Testdir.getinicfg | (self, source) | Return the pytest section from the tox.ini config file. | Return the pytest section from the tox.ini config file. | def getinicfg(self, source):
"""Return the pytest section from the tox.ini config file."""
p = self.makeini(source)
return py.iniconfig.IniConfig(p)['pytest'] | [
"def",
"getinicfg",
"(",
"self",
",",
"source",
")",
":",
"p",
"=",
"self",
".",
"makeini",
"(",
"source",
")",
"return",
"py",
".",
"iniconfig",
".",
"IniConfig",
"(",
"p",
")",
"[",
"'pytest'",
"]"
] | [
548,
4
] | [
551,
50
] | python | en | ['en', 'en', 'en'] | True |
Testdir.makepyfile | (self, *args, **kwargs) | Shortcut for .makefile() with a .py extension. | Shortcut for .makefile() with a .py extension. | def makepyfile(self, *args, **kwargs):
"""Shortcut for .makefile() with a .py extension."""
return self._makefile('.py', args, kwargs) | [
"def",
"makepyfile",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_makefile",
"(",
"'.py'",
",",
"args",
",",
"kwargs",
")"
] | [
553,
4
] | [
555,
50
] | python | en | ['en', 'en', 'en'] | True |
Testdir.maketxtfile | (self, *args, **kwargs) | Shortcut for .makefile() with a .txt extension. | Shortcut for .makefile() with a .txt extension. | def maketxtfile(self, *args, **kwargs):
"""Shortcut for .makefile() with a .txt extension."""
return self._makefile('.txt', args, kwargs) | [
"def",
"maketxtfile",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"_makefile",
"(",
"'.txt'",
",",
"args",
",",
"kwargs",
")"
] | [
557,
4
] | [
559,
51
] | python | en | ['en', 'en', 'en'] | True |
Testdir.syspathinsert | (self, path=None) | Prepend a directory to sys.path, defaults to :py:attr:`tmpdir`.
This is undone automatically when this object dies at the end of each
test.
| Prepend a directory to sys.path, defaults to :py:attr:`tmpdir`. | def syspathinsert(self, path=None):
"""Prepend a directory to sys.path, defaults to :py:attr:`tmpdir`.
This is undone automatically when this object dies at the end of each
test.
"""
if path is None:
path = self.tmpdir
sys.path.insert(0, str(path))
#... | [
"def",
"syspathinsert",
"(",
"self",
",",
"path",
"=",
"None",
")",
":",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"self",
".",
"tmpdir",
"sys",
".",
"path",
".",
"insert",
"(",
"0",
",",
"str",
"(",
"path",
")",
")",
"# a call to syspathinsert()... | [
561,
4
] | [
574,
49
] | python | en | ['en', 'en', 'en'] | True |
Testdir.mkdir | (self, name) | Create a new (sub)directory. | Create a new (sub)directory. | def mkdir(self, name):
"""Create a new (sub)directory."""
return self.tmpdir.mkdir(name) | [
"def",
"mkdir",
"(",
"self",
",",
"name",
")",
":",
"return",
"self",
".",
"tmpdir",
".",
"mkdir",
"(",
"name",
")"
] | [
586,
4
] | [
588,
38
] | python | en | ['en', 'en', 'en'] | True |
Testdir.mkpydir | (self, name) | Create a new python package.
This creates a (sub)directory with an empty ``__init__.py`` file so it
gets recognised as a python package.
| Create a new python package. | def mkpydir(self, name):
"""Create a new python package.
This creates a (sub)directory with an empty ``__init__.py`` file so it
gets recognised as a python package.
"""
p = self.mkdir(name)
p.ensure("__init__.py")
return p | [
"def",
"mkpydir",
"(",
"self",
",",
"name",
")",
":",
"p",
"=",
"self",
".",
"mkdir",
"(",
"name",
")",
"p",
".",
"ensure",
"(",
"\"__init__.py\"",
")",
"return",
"p"
] | [
590,
4
] | [
599,
16
] | python | en | ['en', 'en', 'en'] | True |
Testdir.getnode | (self, config, arg) | Return the collection node of a file.
:param config: :py:class:`_pytest.config.Config` instance, see
:py:meth:`parseconfig` and :py:meth:`parseconfigure` to create the
configuration
:param arg: a :py:class:`py.path.local` instance of the file
| Return the collection node of a file. | def getnode(self, config, arg):
"""Return the collection node of a file.
:param config: :py:class:`_pytest.config.Config` instance, see
:py:meth:`parseconfig` and :py:meth:`parseconfigure` to create the
configuration
:param arg: a :py:class:`py.path.local` instance of the... | [
"def",
"getnode",
"(",
"self",
",",
"config",
",",
"arg",
")",
":",
"session",
"=",
"Session",
"(",
"config",
")",
"assert",
"'::'",
"not",
"in",
"str",
"(",
"arg",
")",
"p",
"=",
"py",
".",
"path",
".",
"local",
"(",
"arg",
")",
"config",
".",
... | [
603,
4
] | [
619,
18
] | python | en | ['en', 'en', 'en'] | True |
Testdir.getpathnode | (self, path) | Return the collection node of a file.
This is like :py:meth:`getnode` but uses :py:meth:`parseconfigure` to
create the (configured) pytest Config instance.
:param path: a :py:class:`py.path.local` instance of the file
| Return the collection node of a file. | def getpathnode(self, path):
"""Return the collection node of a file.
This is like :py:meth:`getnode` but uses :py:meth:`parseconfigure` to
create the (configured) pytest Config instance.
:param path: a :py:class:`py.path.local` instance of the file
"""
config = self.p... | [
"def",
"getpathnode",
"(",
"self",
",",
"path",
")",
":",
"config",
"=",
"self",
".",
"parseconfigure",
"(",
"path",
")",
"session",
"=",
"Session",
"(",
"config",
")",
"x",
"=",
"session",
".",
"fspath",
".",
"bestrelpath",
"(",
"path",
")",
"config",... | [
621,
4
] | [
636,
18
] | python | en | ['en', 'en', 'en'] | True |
Testdir.genitems | (self, colitems) | Generate all test items from a collection node.
This recurses into the collection node and returns a list of all the
test items contained within.
| Generate all test items from a collection node. | def genitems(self, colitems):
"""Generate all test items from a collection node.
This recurses into the collection node and returns a list of all the
test items contained within.
"""
session = colitems[0].session
result = []
for colitem in colitems:
... | [
"def",
"genitems",
"(",
"self",
",",
"colitems",
")",
":",
"session",
"=",
"colitems",
"[",
"0",
"]",
".",
"session",
"result",
"=",
"[",
"]",
"for",
"colitem",
"in",
"colitems",
":",
"result",
".",
"extend",
"(",
"session",
".",
"genitems",
"(",
"co... | [
638,
4
] | [
649,
21
] | python | en | ['en', 'en', 'en'] | True |
Testdir.runitem | (self, source) | Run the "test_func" Item.
The calling test instance (class containing the test method) must
provide a ``.getrunner()`` method which should return a runner which
can run the test protocol for a single item, e.g.
:py:func:`_pytest.runner.runtestprotocol`.
| Run the "test_func" Item. | def runitem(self, source):
"""Run the "test_func" Item.
The calling test instance (class containing the test method) must
provide a ``.getrunner()`` method which should return a runner which
can run the test protocol for a single item, e.g.
:py:func:`_pytest.runner.runtestprotoc... | [
"def",
"runitem",
"(",
"self",
",",
"source",
")",
":",
"# used from runner functional tests",
"item",
"=",
"self",
".",
"getitem",
"(",
"source",
")",
"# the test class where we are called from wants to provide the runner",
"testclassinstance",
"=",
"self",
".",
"request... | [
651,
4
] | [
665,
27
] | python | en | ['en', 'zh', 'en'] | True |
Testdir.inline_runsource | (self, source, *cmdlineargs) | Run a test module in process using ``pytest.main()``.
This run writes "source" into a temporary file and runs
``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance
for the result.
:param source: the source code of the test module
:param cmdlineargs: any extra ... | Run a test module in process using ``pytest.main()``. | def inline_runsource(self, source, *cmdlineargs):
"""Run a test module in process using ``pytest.main()``.
This run writes "source" into a temporary file and runs
``pytest.main()`` on it, returning a :py:class:`HookRecorder` instance
for the result.
:param source: the source co... | [
"def",
"inline_runsource",
"(",
"self",
",",
"source",
",",
"*",
"cmdlineargs",
")",
":",
"p",
"=",
"self",
".",
"makepyfile",
"(",
"source",
")",
"values",
"=",
"list",
"(",
"cmdlineargs",
")",
"+",
"[",
"p",
"]",
"return",
"self",
".",
"inline_run",
... | [
667,
4
] | [
683,
39
] | python | en | ['en', 'ha', 'en'] | True |
Testdir.inline_genitems | (self, *args) | Run ``pytest.main(['--collectonly'])`` in-process.
Runs the :py:func:`pytest.main` function to run all of pytest inside
the test process itself like :py:meth:`inline_run`, but returns a
tuple of the collected items and a :py:class:`HookRecorder` instance.
| Run ``pytest.main(['--collectonly'])`` in-process. | def inline_genitems(self, *args):
"""Run ``pytest.main(['--collectonly'])`` in-process.
Runs the :py:func:`pytest.main` function to run all of pytest inside
the test process itself like :py:meth:`inline_run`, but returns a
tuple of the collected items and a :py:class:`HookRecorder` inst... | [
"def",
"inline_genitems",
"(",
"self",
",",
"*",
"args",
")",
":",
"rec",
"=",
"self",
".",
"inline_run",
"(",
"\"--collect-only\"",
",",
"*",
"args",
")",
"items",
"=",
"[",
"x",
".",
"item",
"for",
"x",
"in",
"rec",
".",
"getcalls",
"(",
"\"pytest_... | [
685,
4
] | [
695,
25
] | python | en | ['en', 'en', 'en'] | True |
Testdir.inline_run | (self, *args, **kwargs) | Run ``pytest.main()`` in-process, returning a HookRecorder.
Runs the :py:func:`pytest.main` function to run all of pytest inside
the test process itself. This means it can return a
:py:class:`HookRecorder` instance which gives more detailed results
from that run than can be done by mat... | Run ``pytest.main()`` in-process, returning a HookRecorder. | def inline_run(self, *args, **kwargs):
"""Run ``pytest.main()`` in-process, returning a HookRecorder.
Runs the :py:func:`pytest.main` function to run all of pytest inside
the test process itself. This means it can return a
:py:class:`HookRecorder` instance which gives more detailed res... | [
"def",
"inline_run",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"finalizers",
"=",
"[",
"]",
"try",
":",
"# When running py.test inline any plugins active in the main test",
"# process are already imported. So this disables the warning which",
"# wil... | [
697,
4
] | [
765,
27
] | python | en | ['en', 'sv', 'en'] | True |
Testdir.runpytest_inprocess | (self, *args, **kwargs) | Return result of running pytest in-process, providing a similar
interface to what self.runpytest() provides.
| Return result of running pytest in-process, providing a similar
interface to what self.runpytest() provides. | def runpytest_inprocess(self, *args, **kwargs):
"""Return result of running pytest in-process, providing a similar
interface to what self.runpytest() provides.
"""
if kwargs.get("syspathinsert"):
self.syspathinsert()
now = time.time()
capture = MultiCapture(C... | [
"def",
"runpytest_inprocess",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"kwargs",
".",
"get",
"(",
"\"syspathinsert\"",
")",
":",
"self",
".",
"syspathinsert",
"(",
")",
"now",
"=",
"time",
".",
"time",
"(",
")",
"captur... | [
767,
4
] | [
800,
18
] | python | en | ['en', 'sv', 'en'] | True |
Testdir.runpytest | (self, *args, **kwargs) | Run pytest inline or in a subprocess, depending on the command line
option "--runpytest" and return a :py:class:`RunResult`.
| Run pytest inline or in a subprocess, depending on the command line
option "--runpytest" and return a :py:class:`RunResult`. | def runpytest(self, *args, **kwargs):
"""Run pytest inline or in a subprocess, depending on the command line
option "--runpytest" and return a :py:class:`RunResult`.
"""
args = self._ensure_basetemp(args)
return self._runpytest_method(*args, **kwargs) | [
"def",
"runpytest",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"args",
"=",
"self",
".",
"_ensure_basetemp",
"(",
"args",
")",
"return",
"self",
".",
"_runpytest_method",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")"
] | [
802,
4
] | [
808,
54
] | python | en | ['en', 'en', 'en'] | True |
Testdir.parseconfig | (self, *args) | Return a new pytest Config instance from given commandline args.
This invokes the pytest bootstrapping code in _pytest.config to create
a new :py:class:`_pytest.core.PluginManager` and call the
pytest_cmdline_parse hook to create a new
:py:class:`_pytest.config.Config` instance.
... | Return a new pytest Config instance from given commandline args. | def parseconfig(self, *args):
"""Return a new pytest Config instance from given commandline args.
This invokes the pytest bootstrapping code in _pytest.config to create
a new :py:class:`_pytest.core.PluginManager` and call the
pytest_cmdline_parse hook to create a new
:py:class:... | [
"def",
"parseconfig",
"(",
"self",
",",
"*",
"args",
")",
":",
"args",
"=",
"self",
".",
"_ensure_basetemp",
"(",
"args",
")",
"import",
"_pytest",
".",
"config",
"config",
"=",
"_pytest",
".",
"config",
".",
"_prepareconfig",
"(",
"args",
",",
"self",
... | [
821,
4
] | [
841,
21
] | python | en | ['en', 'en', 'en'] | True |
Testdir.parseconfigure | (self, *args) | Return a new pytest configured Config instance.
This returns a new :py:class:`_pytest.config.Config` instance like
:py:meth:`parseconfig`, but also calls the pytest_configure hook.
| Return a new pytest configured Config instance. | def parseconfigure(self, *args):
"""Return a new pytest configured Config instance.
This returns a new :py:class:`_pytest.config.Config` instance like
:py:meth:`parseconfig`, but also calls the pytest_configure hook.
"""
config = self.parseconfig(*args)
config._do_confi... | [
"def",
"parseconfigure",
"(",
"self",
",",
"*",
"args",
")",
":",
"config",
"=",
"self",
".",
"parseconfig",
"(",
"*",
"args",
")",
"config",
".",
"_do_configure",
"(",
")",
"self",
".",
"request",
".",
"addfinalizer",
"(",
"config",
".",
"_ensure_unconf... | [
843,
4
] | [
853,
21
] | python | en | ['en', 'en', 'en'] | True |
Testdir.getitem | (self, source, funcname="test_func") | Return the test item for a test function.
This writes the source to a python file and runs pytest's collection on
the resulting module, returning the test item for the requested
function name.
:param source: the module source
:param funcname: the name of the test function for ... | Return the test item for a test function. | def getitem(self, source, funcname="test_func"):
"""Return the test item for a test function.
This writes the source to a python file and runs pytest's collection on
the resulting module, returning the test item for the requested
function name.
:param source: the module source
... | [
"def",
"getitem",
"(",
"self",
",",
"source",
",",
"funcname",
"=",
"\"test_func\"",
")",
":",
"items",
"=",
"self",
".",
"getitems",
"(",
"source",
")",
"for",
"item",
"in",
"items",
":",
"if",
"item",
".",
"name",
"==",
"funcname",
":",
"return",
"... | [
855,
4
] | [
873,
42
] | python | en | ['en', 'en', 'en'] | True |
Testdir.getitems | (self, source) | Return all test items collected from the module.
This writes the source to a python file and runs pytest's collection on
the resulting module, returning all test items contained within.
| Return all test items collected from the module. | def getitems(self, source):
"""Return all test items collected from the module.
This writes the source to a python file and runs pytest's collection on
the resulting module, returning all test items contained within.
"""
modcol = self.getmodulecol(source)
return self.ge... | [
"def",
"getitems",
"(",
"self",
",",
"source",
")",
":",
"modcol",
"=",
"self",
".",
"getmodulecol",
"(",
"source",
")",
"return",
"self",
".",
"genitems",
"(",
"[",
"modcol",
"]",
")"
] | [
875,
4
] | [
883,
38
] | python | en | ['en', 'en', 'en'] | True |
Testdir.getmodulecol | (self, source, configargs=(), withinit=False) | Return the module collection node for ``source``.
This writes ``source`` to a file using :py:meth:`makepyfile` and then
runs the pytest collection on it, returning the collection node for the
test module.
:param source: the source code of the module to collect
:param configarg... | Return the module collection node for ``source``. | def getmodulecol(self, source, configargs=(), withinit=False):
"""Return the module collection node for ``source``.
This writes ``source`` to a file using :py:meth:`makepyfile` and then
runs the pytest collection on it, returning the collection node for the
test module.
:param ... | [
"def",
"getmodulecol",
"(",
"self",
",",
"source",
",",
"configargs",
"=",
"(",
")",
",",
"withinit",
"=",
"False",
")",
":",
"kw",
"=",
"{",
"self",
".",
"request",
".",
"function",
".",
"__name__",
":",
"Source",
"(",
"source",
")",
".",
"strip",
... | [
885,
4
] | [
908,
19
] | python | en | ['en', 'en', 'en'] | True |
Testdir.collect_by_name | (self, modcol, name) | Return the collection node for name from the module collection.
This will search a module collection node for a collection node
matching the given name.
:param modcol: a module collection node; see :py:meth:`getmodulecol`
:param name: the name of the node to return
| Return the collection node for name from the module collection. | def collect_by_name(self, modcol, name):
"""Return the collection node for name from the module collection.
This will search a module collection node for a collection node
matching the given name.
:param modcol: a module collection node; see :py:meth:`getmodulecol`
:param name... | [
"def",
"collect_by_name",
"(",
"self",
",",
"modcol",
",",
"name",
")",
":",
"if",
"modcol",
"not",
"in",
"self",
".",
"_mod_collections",
":",
"self",
".",
"_mod_collections",
"[",
"modcol",
"]",
"=",
"list",
"(",
"modcol",
".",
"collect",
"(",
")",
"... | [
910,
4
] | [
925,
30
] | python | en | ['en', 'en', 'en'] | True |
Testdir.popen | (self, cmdargs, stdout, stderr, **kw) | Invoke subprocess.Popen.
This calls subprocess.Popen making sure the current working directory
is in the PYTHONPATH.
You probably want to use :py:meth:`run` instead.
| Invoke subprocess.Popen. | def popen(self, cmdargs, stdout, stderr, **kw):
"""Invoke subprocess.Popen.
This calls subprocess.Popen making sure the current working directory
is in the PYTHONPATH.
You probably want to use :py:meth:`run` instead.
"""
env = os.environ.copy()
env['PYTHONPATH'... | [
"def",
"popen",
"(",
"self",
",",
"cmdargs",
",",
"stdout",
",",
"stderr",
",",
"*",
"*",
"kw",
")",
":",
"env",
"=",
"os",
".",
"environ",
".",
"copy",
"(",
")",
"env",
"[",
"'PYTHONPATH'",
"]",
"=",
"os",
".",
"pathsep",
".",
"join",
"(",
"fi... | [
927,
4
] | [
944,
20
] | python | it | ['nl', 'it', 'it'] | False |
Testdir.run | (self, *cmdargs) | Run a command with arguments.
Run a process using subprocess.Popen saving the stdout and stderr.
Returns a :py:class:`RunResult`.
| Run a command with arguments. | def run(self, *cmdargs):
"""Run a command with arguments.
Run a process using subprocess.Popen saving the stdout and stderr.
Returns a :py:class:`RunResult`.
"""
return self._run(*cmdargs) | [
"def",
"run",
"(",
"self",
",",
"*",
"cmdargs",
")",
":",
"return",
"self",
".",
"_run",
"(",
"*",
"cmdargs",
")"
] | [
946,
4
] | [
954,
34
] | python | en | ['en', 'en', 'en'] | True |
Testdir.runpython | (self, script) | Run a python script using sys.executable as interpreter.
Returns a :py:class:`RunResult`.
| Run a python script using sys.executable as interpreter. | def runpython(self, script):
"""Run a python script using sys.executable as interpreter.
Returns a :py:class:`RunResult`.
"""
return self.run(sys.executable, script) | [
"def",
"runpython",
"(",
"self",
",",
"script",
")",
":",
"return",
"self",
".",
"run",
"(",
"sys",
".",
"executable",
",",
"script",
")"
] | [
996,
4
] | [
1002,
47
] | python | en | ['en', 'gl', 'en'] | True |
Testdir.runpython_c | (self, command) | Run python -c "command", return a :py:class:`RunResult`. | Run python -c "command", return a :py:class:`RunResult`. | def runpython_c(self, command):
"""Run python -c "command", return a :py:class:`RunResult`."""
return self.run(sys.executable, "-c", command) | [
"def",
"runpython_c",
"(",
"self",
",",
"command",
")",
":",
"return",
"self",
".",
"run",
"(",
"sys",
".",
"executable",
",",
"\"-c\"",
",",
"command",
")"
] | [
1004,
4
] | [
1006,
54
] | python | en | ['es', 'vi', 'en'] | False |
Testdir.runpytest_subprocess | (self, *args, **kwargs) | Run pytest as a subprocess with given arguments.
Any plugins added to the :py:attr:`plugins` list will added using the
``-p`` command line option. Additionally ``--basetemp`` is used put
any temporary files and directories in a numbered directory prefixed
with "runpytest-" so they do n... | Run pytest as a subprocess with given arguments. | def runpytest_subprocess(self, *args, **kwargs):
"""Run pytest as a subprocess with given arguments.
Any plugins added to the :py:attr:`plugins` list will added using the
``-p`` command line option. Additionally ``--basetemp`` is used put
any temporary files and directories in a number... | [
"def",
"runpytest_subprocess",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"p",
"=",
"py",
".",
"path",
".",
"local",
".",
"make_numbered_dir",
"(",
"prefix",
"=",
"\"runpytest-\"",
",",
"keep",
"=",
"None",
",",
"rootdir",
"=",
... | [
1008,
4
] | [
1027,
30
] | python | en | ['en', 'en', 'en'] | True |
Testdir.spawn_pytest | (self, string, expect_timeout=10.0) | Run pytest using pexpect.
This makes sure to use the right pytest and sets up the temporary
directory locations.
The pexpect child is returned.
| Run pytest using pexpect. | def spawn_pytest(self, string, expect_timeout=10.0):
"""Run pytest using pexpect.
This makes sure to use the right pytest and sets up the temporary
directory locations.
The pexpect child is returned.
"""
basetemp = self.tmpdir.mkdir("temp-pexpect")
invoke = " "... | [
"def",
"spawn_pytest",
"(",
"self",
",",
"string",
",",
"expect_timeout",
"=",
"10.0",
")",
":",
"basetemp",
"=",
"self",
".",
"tmpdir",
".",
"mkdir",
"(",
"\"temp-pexpect\"",
")",
"invoke",
"=",
"\" \"",
".",
"join",
"(",
"map",
"(",
"str",
",",
"self... | [
1029,
4
] | [
1041,
61
] | python | en | ['fr', 'sn', 'en'] | False |
Testdir.spawn | (self, cmd, expect_timeout=10.0) | Run a command using pexpect.
The pexpect child is returned.
| Run a command using pexpect. | def spawn(self, cmd, expect_timeout=10.0):
"""Run a command using pexpect.
The pexpect child is returned.
"""
pexpect = pytest.importorskip("pexpect", "3.0")
if hasattr(sys, 'pypy_version_info') and '64' in platform.machine():
pytest.skip("pypy-64 bit not supported"... | [
"def",
"spawn",
"(",
"self",
",",
"cmd",
",",
"expect_timeout",
"=",
"10.0",
")",
":",
"pexpect",
"=",
"pytest",
".",
"importorskip",
"(",
"\"pexpect\"",
",",
"\"3.0\"",
")",
"if",
"hasattr",
"(",
"sys",
",",
"'pypy_version_info'",
")",
"and",
"'64'",
"i... | [
1043,
4
] | [
1058,
20
] | python | en | ['en', 'gd', 'en'] | True |
LineComp.assert_contains_lines | (self, lines2) | Assert that lines2 are contained (linearly) in lines1.
Return a list of extralines found.
| Assert that lines2 are contained (linearly) in lines1. | def assert_contains_lines(self, lines2):
"""Assert that lines2 are contained (linearly) in lines1.
Return a list of extralines found.
"""
__tracebackhide__ = True
val = self.stringio.getvalue()
self.stringio.truncate(0)
self.stringio.seek(0)
lines1 = val... | [
"def",
"assert_contains_lines",
"(",
"self",
",",
"lines2",
")",
":",
"__tracebackhide__",
"=",
"True",
"val",
"=",
"self",
".",
"stringio",
".",
"getvalue",
"(",
")",
"self",
".",
"stringio",
".",
"truncate",
"(",
"0",
")",
"self",
".",
"stringio",
".",... | [
1073,
4
] | [
1084,
56
] | python | en | ['en', 'en', 'en'] | True |
LineMatcher.str | (self) | Return the entire original text. | Return the entire original text. | def str(self):
"""Return the entire original text."""
return "\n".join(self.lines) | [
"def",
"str",
"(",
"self",
")",
":",
"return",
"\"\\n\"",
".",
"join",
"(",
"self",
".",
"lines",
")"
] | [
1102,
4
] | [
1104,
36
] | python | en | ['en', 'la', 'en'] | True |
LineMatcher.fnmatch_lines_random | (self, lines2) | Check lines exist in the output using in any order.
Lines are checked using ``fnmatch.fnmatch``. The argument is a list of
lines which have to occur in the output, in any order.
| Check lines exist in the output using in any order. | def fnmatch_lines_random(self, lines2):
"""Check lines exist in the output using in any order.
Lines are checked using ``fnmatch.fnmatch``. The argument is a list of
lines which have to occur in the output, in any order.
"""
self._match_lines_random(lines2, fnmatch) | [
"def",
"fnmatch_lines_random",
"(",
"self",
",",
"lines2",
")",
":",
"self",
".",
"_match_lines_random",
"(",
"lines2",
",",
"fnmatch",
")"
] | [
1113,
4
] | [
1120,
49
] | python | en | ['en', 'en', 'en'] | True |
LineMatcher.re_match_lines_random | (self, lines2) | Check lines exist in the output using ``re.match``, in any order.
The argument is a list of lines which have to occur in the output, in
any order.
| Check lines exist in the output using ``re.match``, in any order. | def re_match_lines_random(self, lines2):
"""Check lines exist in the output using ``re.match``, in any order.
The argument is a list of lines which have to occur in the output, in
any order.
"""
self._match_lines_random(lines2, lambda name, pat: re.match(pat, name)) | [
"def",
"re_match_lines_random",
"(",
"self",
",",
"lines2",
")",
":",
"self",
".",
"_match_lines_random",
"(",
"lines2",
",",
"lambda",
"name",
",",
"pat",
":",
"re",
".",
"match",
"(",
"pat",
",",
"name",
")",
")"
] | [
1122,
4
] | [
1129,
79
] | python | en | ['en', 'en', 'en'] | True |
LineMatcher._match_lines_random | (self, lines2, match_func) | Check lines exist in the output.
The argument is a list of lines which have to occur in the output, in
any order. Each line can contain glob whildcards.
| Check lines exist in the output. | def _match_lines_random(self, lines2, match_func):
"""Check lines exist in the output.
The argument is a list of lines which have to occur in the output, in
any order. Each line can contain glob whildcards.
"""
lines2 = self._getlines(lines2)
for line in lines2:
... | [
"def",
"_match_lines_random",
"(",
"self",
",",
"lines2",
",",
"match_func",
")",
":",
"lines2",
"=",
"self",
".",
"_getlines",
"(",
"lines2",
")",
"for",
"line",
"in",
"lines2",
":",
"for",
"x",
"in",
"self",
".",
"lines",
":",
"if",
"line",
"==",
"... | [
1131,
4
] | [
1146,
48
] | python | en | ['en', 'en', 'en'] | True |
LineMatcher.get_lines_after | (self, fnline) | Return all lines following the given line in the text.
The given line can contain glob wildcards.
| Return all lines following the given line in the text. | def get_lines_after(self, fnline):
"""Return all lines following the given line in the text.
The given line can contain glob wildcards.
"""
for i, line in enumerate(self.lines):
if fnline == line or fnmatch(line, fnline):
return self.lines[i + 1:]
ra... | [
"def",
"get_lines_after",
"(",
"self",
",",
"fnline",
")",
":",
"for",
"i",
",",
"line",
"in",
"enumerate",
"(",
"self",
".",
"lines",
")",
":",
"if",
"fnline",
"==",
"line",
"or",
"fnmatch",
"(",
"line",
",",
"fnline",
")",
":",
"return",
"self",
... | [
1148,
4
] | [
1157,
64
] | python | en | ['en', 'en', 'en'] | True |
LineMatcher.fnmatch_lines | (self, lines2) | Search captured text for matching lines using ``fnmatch.fnmatch``.
The argument is a list of lines which have to match and can use glob
wildcards. If they do not match a pytest.fail() is called. The
matches and non-matches are also printed on stdout.
| Search captured text for matching lines using ``fnmatch.fnmatch``. | def fnmatch_lines(self, lines2):
"""Search captured text for matching lines using ``fnmatch.fnmatch``.
The argument is a list of lines which have to match and can use glob
wildcards. If they do not match a pytest.fail() is called. The
matches and non-matches are also printed on stdout... | [
"def",
"fnmatch_lines",
"(",
"self",
",",
"lines2",
")",
":",
"self",
".",
"_match_lines",
"(",
"lines2",
",",
"fnmatch",
",",
"'fnmatch'",
")"
] | [
1166,
4
] | [
1174,
53
] | python | en | ['en', 'en', 'en'] | True |
LineMatcher.re_match_lines | (self, lines2) | Search captured text for matching lines using ``re.match``.
The argument is a list of lines which have to match using ``re.match``.
If they do not match a pytest.fail() is called.
The matches and non-matches are also printed on stdout.
| Search captured text for matching lines using ``re.match``. | def re_match_lines(self, lines2):
"""Search captured text for matching lines using ``re.match``.
The argument is a list of lines which have to match using ``re.match``.
If they do not match a pytest.fail() is called.
The matches and non-matches are also printed on stdout.
"""
... | [
"def",
"re_match_lines",
"(",
"self",
",",
"lines2",
")",
":",
"self",
".",
"_match_lines",
"(",
"lines2",
",",
"lambda",
"name",
",",
"pat",
":",
"re",
".",
"match",
"(",
"pat",
",",
"name",
")",
",",
"'re.match'",
")"
] | [
1176,
4
] | [
1185,
84
] | python | en | ['en', 'en', 'en'] | True |
LineMatcher._match_lines | (self, lines2, match_func, match_nickname) | Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``.
:param list[str] lines2: list of string patterns to match. The actual
format depends on ``match_func``
:param match_func: a callable ``match_func(line, pattern)`` where line
is the captured line from stdout/s... | Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``. | def _match_lines(self, lines2, match_func, match_nickname):
"""Underlying implementation of ``fnmatch_lines`` and ``re_match_lines``.
:param list[str] lines2: list of string patterns to match. The actual
format depends on ``match_func``
:param match_func: a callable ``match_func(lin... | [
"def",
"_match_lines",
"(",
"self",
",",
"lines2",
",",
"match_func",
",",
"match_nickname",
")",
":",
"lines2",
"=",
"self",
".",
"_getlines",
"(",
"lines2",
")",
"lines1",
"=",
"self",
".",
"lines",
"[",
":",
"]",
"nextline",
"=",
"None",
"extralines",... | [
1187,
4
] | [
1223,
43
] | python | en | ['en', 'en', 'en'] | True |
dict_to_sequence | (d) | Returns an internal sequence dictionary update. | Returns an internal sequence dictionary update. | def dict_to_sequence(d):
"""Returns an internal sequence dictionary update."""
if hasattr(d, 'items'):
d = d.items()
return d | [
"def",
"dict_to_sequence",
"(",
"d",
")",
":",
"if",
"hasattr",
"(",
"d",
",",
"'items'",
")",
":",
"d",
"=",
"d",
".",
"items",
"(",
")",
"return",
"d"
] | [
98,
0
] | [
104,
12
] | python | en | ['en', 'lb', 'en'] | True |
get_netrc_auth | (url, raise_errors=False) | Returns the Requests tuple auth for a given url from netrc. | Returns the Requests tuple auth for a given url from netrc. | def get_netrc_auth(url, raise_errors=False):
"""Returns the Requests tuple auth for a given url from netrc."""
try:
from netrc import netrc, NetrcParseError
netrc_path = None
for f in NETRC_FILES:
try:
loc = os.path.expanduser('~/{}'.format(f))
... | [
"def",
"get_netrc_auth",
"(",
"url",
",",
"raise_errors",
"=",
"False",
")",
":",
"try",
":",
"from",
"netrc",
"import",
"netrc",
",",
"NetrcParseError",
"netrc_path",
"=",
"None",
"for",
"f",
"in",
"NETRC_FILES",
":",
"try",
":",
"loc",
"=",
"os",
".",
... | [
168,
0
] | [
216,
12
] | python | en | ['en', 'en', 'en'] | True |
guess_filename | (obj) | Tries to guess the filename of the given object. | Tries to guess the filename of the given object. | def guess_filename(obj):
"""Tries to guess the filename of the given object."""
name = getattr(obj, 'name', None)
if (name and isinstance(name, basestring) and name[0] != '<' and
name[-1] != '>'):
return os.path.basename(name) | [
"def",
"guess_filename",
"(",
"obj",
")",
":",
"name",
"=",
"getattr",
"(",
"obj",
",",
"'name'",
",",
"None",
")",
"if",
"(",
"name",
"and",
"isinstance",
"(",
"name",
",",
"basestring",
")",
"and",
"name",
"[",
"0",
"]",
"!=",
"'<'",
"and",
"name... | [
219,
0
] | [
224,
37
] | python | en | ['en', 'en', 'en'] | True |
extract_zipped_paths | (path) | Replace nonexistent paths that look like they refer to a member of a zip
archive with the location of an extracted copy of the target, or else
just return the provided path unchanged.
| Replace nonexistent paths that look like they refer to a member of a zip
archive with the location of an extracted copy of the target, or else
just return the provided path unchanged.
| def extract_zipped_paths(path):
"""Replace nonexistent paths that look like they refer to a member of a zip
archive with the location of an extracted copy of the target, or else
just return the provided path unchanged.
"""
if os.path.exists(path):
# this is already a valid path, no need to d... | [
"def",
"extract_zipped_paths",
"(",
"path",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"path",
")",
":",
"# this is already a valid path, no need to do anything further",
"return",
"path",
"# find the first valid part of the provided path and treat that as a zip arc... | [
227,
0
] | [
256,
25
] | python | en | ['en', 'en', 'en'] | True |
from_key_val_list | (value) | Take an object and test to see if it can be represented as a
dictionary. Unless it can not be represented as such, return an
OrderedDict, e.g.,
::
>>> from_key_val_list([('key', 'val')])
OrderedDict([('key', 'val')])
>>> from_key_val_list('string')
Traceback (most recent ca... | Take an object and test to see if it can be represented as a
dictionary. Unless it can not be represented as such, return an
OrderedDict, e.g., | def from_key_val_list(value):
"""Take an object and test to see if it can be represented as a
dictionary. Unless it can not be represented as such, return an
OrderedDict, e.g.,
::
>>> from_key_val_list([('key', 'val')])
OrderedDict([('key', 'val')])
>>> from_key_val_list('strin... | [
"def",
"from_key_val_list",
"(",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"value",
",",
"(",
"str",
",",
"bytes",
",",
"bool",
",",
"int",
")",
")",
":",
"raise",
"ValueError",
"(",
"'cannot encode... | [
259,
0
] | [
283,
29
] | python | en | ['en', 'en', 'en'] | True |
to_key_val_list | (value) | Take an object and test to see if it can be represented as a
dictionary. If it can be, return a list of tuples, e.g.,
::
>>> to_key_val_list([('key', 'val')])
[('key', 'val')]
>>> to_key_val_list({'key': 'val'})
[('key', 'val')]
>>> to_key_val_list('string')
Tra... | Take an object and test to see if it can be represented as a
dictionary. If it can be, return a list of tuples, e.g., | def to_key_val_list(value):
"""Take an object and test to see if it can be represented as a
dictionary. If it can be, return a list of tuples, e.g.,
::
>>> to_key_val_list([('key', 'val')])
[('key', 'val')]
>>> to_key_val_list({'key': 'val'})
[('key', 'val')]
>>> to... | [
"def",
"to_key_val_list",
"(",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"isinstance",
"(",
"value",
",",
"(",
"str",
",",
"bytes",
",",
"bool",
",",
"int",
")",
")",
":",
"raise",
"ValueError",
"(",
"'cannot encode o... | [
286,
0
] | [
312,
22
] | python | en | ['en', 'en', 'en'] | True |
parse_list_header | (value) | Parse lists as described by RFC 2068 Section 2.
In particular, parse comma-separated lists where the elements of
the list may include quoted-strings. A quoted-string could
contain a comma. A non-quoted string could have quotes in the
middle. Quotes are removed automatically after parsing.
It ba... | Parse lists as described by RFC 2068 Section 2. | def parse_list_header(value):
"""Parse lists as described by RFC 2068 Section 2.
In particular, parse comma-separated lists where the elements of
the list may include quoted-strings. A quoted-string could
contain a comma. A non-quoted string could have quotes in the
middle. Quotes are removed au... | [
"def",
"parse_list_header",
"(",
"value",
")",
":",
"result",
"=",
"[",
"]",
"for",
"item",
"in",
"_parse_list_header",
"(",
"value",
")",
":",
"if",
"item",
"[",
":",
"1",
"]",
"==",
"item",
"[",
"-",
"1",
":",
"]",
"==",
"'\"'",
":",
"item",
"=... | [
316,
0
] | [
344,
17
] | python | en | ['en', 'en', 'en'] | True |
parse_dict_header | (value) | Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict:
>>> d = parse_dict_header('foo="is a fish", bar="as well"')
>>> type(d) is dict
True
>>> sorted(d.items())
[('bar', 'as well'), ('foo', 'is a fish')]
If there is no value for a key it wi... | Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict: | def parse_dict_header(value):
"""Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict:
>>> d = parse_dict_header('foo="is a fish", bar="as well"')
>>> type(d) is dict
True
>>> sorted(d.items())
[('bar', 'as well'), ('foo', 'is a fish')]
... | [
"def",
"parse_dict_header",
"(",
"value",
")",
":",
"result",
"=",
"{",
"}",
"for",
"item",
"in",
"_parse_list_header",
"(",
"value",
")",
":",
"if",
"'='",
"not",
"in",
"item",
":",
"result",
"[",
"item",
"]",
"=",
"None",
"continue",
"name",
",",
"... | [
348,
0
] | [
379,
17
] | python | en | ['en', 'en', 'en'] | True |
unquote_header_value | (value, is_filename=False) | r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting.
:param value: the header value to unquote.
:rtype: str
| r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting. | def unquote_header_value(value, is_filename=False):
r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting.
:param value: the header value to unquote.
:rtype: str
"""
if value and value[0]... | [
"def",
"unquote_header_value",
"(",
"value",
",",
"is_filename",
"=",
"False",
")",
":",
"if",
"value",
"and",
"value",
"[",
"0",
"]",
"==",
"value",
"[",
"-",
"1",
"]",
"==",
"'\"'",
":",
"# this is not the real unquoting, but fixing this so that the",
"# RFC i... | [
383,
0
] | [
405,
16
] | python | en | ['en', 'en', 'en'] | True |
dict_from_cookiejar | (cj) | Returns a key/value dictionary from a CookieJar.
:param cj: CookieJar object to extract cookies from.
:rtype: dict
| Returns a key/value dictionary from a CookieJar. | def dict_from_cookiejar(cj):
"""Returns a key/value dictionary from a CookieJar.
:param cj: CookieJar object to extract cookies from.
:rtype: dict
"""
cookie_dict = {}
for cookie in cj:
cookie_dict[cookie.name] = cookie.value
return cookie_dict | [
"def",
"dict_from_cookiejar",
"(",
"cj",
")",
":",
"cookie_dict",
"=",
"{",
"}",
"for",
"cookie",
"in",
"cj",
":",
"cookie_dict",
"[",
"cookie",
".",
"name",
"]",
"=",
"cookie",
".",
"value",
"return",
"cookie_dict"
] | [
408,
0
] | [
420,
22
] | python | en | ['en', 'en', 'en'] | True |
add_dict_to_cookiejar | (cj, cookie_dict) | Returns a CookieJar from a key/value dictionary.
:param cj: CookieJar to insert cookies into.
:param cookie_dict: Dict of key/values to insert into CookieJar.
:rtype: CookieJar
| Returns a CookieJar from a key/value dictionary. | def add_dict_to_cookiejar(cj, cookie_dict):
"""Returns a CookieJar from a key/value dictionary.
:param cj: CookieJar to insert cookies into.
:param cookie_dict: Dict of key/values to insert into CookieJar.
:rtype: CookieJar
"""
return cookiejar_from_dict(cookie_dict, cj) | [
"def",
"add_dict_to_cookiejar",
"(",
"cj",
",",
"cookie_dict",
")",
":",
"return",
"cookiejar_from_dict",
"(",
"cookie_dict",
",",
"cj",
")"
] | [
423,
0
] | [
431,
47
] | python | en | ['en', 'en', 'en'] | True |
get_encodings_from_content | (content) | Returns encodings from given content string.
:param content: bytestring to extract encodings from.
| Returns encodings from given content string. | def get_encodings_from_content(content):
"""Returns encodings from given content string.
:param content: bytestring to extract encodings from.
"""
warnings.warn((
'In requests 3.0, get_encodings_from_content will be removed. For '
'more information, please see the discussion on issue #2... | [
"def",
"get_encodings_from_content",
"(",
"content",
")",
":",
"warnings",
".",
"warn",
"(",
"(",
"'In requests 3.0, get_encodings_from_content will be removed. For '",
"'more information, please see the discussion on issue #2266. (This'",
"' warning should only appear once.)'",
")",
"... | [
434,
0
] | [
451,
36
] | python | en | ['en', 'en', 'en'] | True |
_parse_content_type_header | (header) | Returns content type and parameters from given header
:param header: string
:return: tuple containing content type and dictionary of
parameters
| Returns content type and parameters from given header | def _parse_content_type_header(header):
"""Returns content type and parameters from given header
:param header: string
:return: tuple containing content type and dictionary of
parameters
"""
tokens = header.split(';')
content_type, params = tokens[0].strip(), tokens[1:]
params_dic... | [
"def",
"_parse_content_type_header",
"(",
"header",
")",
":",
"tokens",
"=",
"header",
".",
"split",
"(",
"';'",
")",
"content_type",
",",
"params",
"=",
"tokens",
"[",
"0",
"]",
".",
"strip",
"(",
")",
",",
"tokens",
"[",
"1",
":",
"]",
"params_dict",... | [
454,
0
] | [
476,
36
] | python | en | ['en', 'en', 'en'] | True |
get_encoding_from_headers | (headers) | Returns encodings from given HTTP Header Dict.
:param headers: dictionary to extract encoding from.
:rtype: str
| Returns encodings from given HTTP Header Dict. | def get_encoding_from_headers(headers):
"""Returns encodings from given HTTP Header Dict.
:param headers: dictionary to extract encoding from.
:rtype: str
"""
content_type = headers.get('content-type')
if not content_type:
return None
content_type, params = _parse_content_type_he... | [
"def",
"get_encoding_from_headers",
"(",
"headers",
")",
":",
"content_type",
"=",
"headers",
".",
"get",
"(",
"'content-type'",
")",
"if",
"not",
"content_type",
":",
"return",
"None",
"content_type",
",",
"params",
"=",
"_parse_content_type_header",
"(",
"conten... | [
479,
0
] | [
497,
27
] | python | en | ['en', 'en', 'en'] | True |
stream_decode_response_unicode | (iterator, r) | Stream decodes a iterator. | Stream decodes a iterator. | def stream_decode_response_unicode(iterator, r):
"""Stream decodes a iterator."""
if r.encoding is None:
for item in iterator:
yield item
return
decoder = codecs.getincrementaldecoder(r.encoding)(errors='replace')
for chunk in iterator:
rv = decoder.decode(chunk)
... | [
"def",
"stream_decode_response_unicode",
"(",
"iterator",
",",
"r",
")",
":",
"if",
"r",
".",
"encoding",
"is",
"None",
":",
"for",
"item",
"in",
"iterator",
":",
"yield",
"item",
"return",
"decoder",
"=",
"codecs",
".",
"getincrementaldecoder",
"(",
"r",
... | [
500,
0
] | [
515,
16
] | python | en | ['en', 'zh', 'pt'] | False |
iter_slices | (string, slice_length) | Iterate over slices of a string. | Iterate over slices of a string. | def iter_slices(string, slice_length):
"""Iterate over slices of a string."""
pos = 0
if slice_length is None or slice_length <= 0:
slice_length = len(string)
while pos < len(string):
yield string[pos:pos + slice_length]
pos += slice_length | [
"def",
"iter_slices",
"(",
"string",
",",
"slice_length",
")",
":",
"pos",
"=",
"0",
"if",
"slice_length",
"is",
"None",
"or",
"slice_length",
"<=",
"0",
":",
"slice_length",
"=",
"len",
"(",
"string",
")",
"while",
"pos",
"<",
"len",
"(",
"string",
")... | [
518,
0
] | [
525,
27
] | python | en | ['en', 'en', 'en'] | True |
get_unicode_from_response | (r) | Returns the requested content back in unicode.
:param r: Response object to get unicode content from.
Tried:
1. charset from content-type
2. fall back and replace all unicode characters
:rtype: str
| Returns the requested content back in unicode. | def get_unicode_from_response(r):
"""Returns the requested content back in unicode.
:param r: Response object to get unicode content from.
Tried:
1. charset from content-type
2. fall back and replace all unicode characters
:rtype: str
"""
warnings.warn((
'In requests 3.0, get... | [
"def",
"get_unicode_from_response",
"(",
"r",
")",
":",
"warnings",
".",
"warn",
"(",
"(",
"'In requests 3.0, get_unicode_from_response will be removed. For '",
"'more information, please see the discussion on issue #2266. (This'",
"' warning should only appear once.)'",
")",
",",
"D... | [
528,
0
] | [
561,
24
] | python | en | ['en', 'en', 'en'] | True |
unquote_unreserved | (uri) | Un-escape any percent-escape sequences in a URI that are unreserved
characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
:rtype: str
| Un-escape any percent-escape sequences in a URI that are unreserved
characters. This leaves all reserved, illegal and non-ASCII bytes encoded. | def unquote_unreserved(uri):
"""Un-escape any percent-escape sequences in a URI that are unreserved
characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
:rtype: str
"""
parts = uri.split('%')
for i in range(1, len(parts)):
h = parts[i][0:2]
if len(h) == 2 a... | [
"def",
"unquote_unreserved",
"(",
"uri",
")",
":",
"parts",
"=",
"uri",
".",
"split",
"(",
"'%'",
")",
"for",
"i",
"in",
"range",
"(",
"1",
",",
"len",
"(",
"parts",
")",
")",
":",
"h",
"=",
"parts",
"[",
"i",
"]",
"[",
"0",
":",
"2",
"]",
... | [
569,
0
] | [
590,
25
] | python | en | ['en', 'it', 'en'] | True |
requote_uri | (uri) | Re-quote the given URI.
This function passes the given URI through an unquote/quote cycle to
ensure that it is fully and consistently quoted.
:rtype: str
| Re-quote the given URI. | def requote_uri(uri):
"""Re-quote the given URI.
This function passes the given URI through an unquote/quote cycle to
ensure that it is fully and consistently quoted.
:rtype: str
"""
safe_with_percent = "!#$%&'()*+,/:;=?@[]~"
safe_without_percent = "!#$&'()*+,/:;=?@[]~"
try:
# ... | [
"def",
"requote_uri",
"(",
"uri",
")",
":",
"safe_with_percent",
"=",
"\"!#$%&'()*+,/:;=?@[]~\"",
"safe_without_percent",
"=",
"\"!#$&'()*+,/:;=?@[]~\"",
"try",
":",
"# Unquote only the unreserved characters",
"# Then quote only illegal characters (do not quote reserved,",
"# unreser... | [
593,
0
] | [
612,
52
] | python | en | ['en', 'en', 'en'] | True |
address_in_network | (ip, net) | This function allows you to check if an IP belongs to a network subnet
Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
returns False if ip = 192.168.1.1 and net = 192.168.100.0/24
:rtype: bool
| This function allows you to check if an IP belongs to a network subnet | def address_in_network(ip, net):
"""This function allows you to check if an IP belongs to a network subnet
Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
returns False if ip = 192.168.1.1 and net = 192.168.100.0/24
:rtype: bool
"""
ipaddr = struct.unpack('=L', sock... | [
"def",
"address_in_network",
"(",
"ip",
",",
"net",
")",
":",
"ipaddr",
"=",
"struct",
".",
"unpack",
"(",
"'=L'",
",",
"socket",
".",
"inet_aton",
"(",
"ip",
")",
")",
"[",
"0",
"]",
"netaddr",
",",
"bits",
"=",
"net",
".",
"split",
"(",
"'/'",
... | [
615,
0
] | [
627,
52
] | python | en | ['en', 'en', 'en'] | True |
dotted_netmask | (mask) | Converts mask from /xx format to xxx.xxx.xxx.xxx
Example: if mask is 24 function returns 255.255.255.0
:rtype: str
| Converts mask from /xx format to xxx.xxx.xxx.xxx | def dotted_netmask(mask):
"""Converts mask from /xx format to xxx.xxx.xxx.xxx
Example: if mask is 24 function returns 255.255.255.0
:rtype: str
"""
bits = 0xffffffff ^ (1 << 32 - mask) - 1
return socket.inet_ntoa(struct.pack('>I', bits)) | [
"def",
"dotted_netmask",
"(",
"mask",
")",
":",
"bits",
"=",
"0xffffffff",
"^",
"(",
"1",
"<<",
"32",
"-",
"mask",
")",
"-",
"1",
"return",
"socket",
".",
"inet_ntoa",
"(",
"struct",
".",
"pack",
"(",
"'>I'",
",",
"bits",
")",
")"
] | [
630,
0
] | [
638,
52
] | python | en | ['en', 'pl', 'en'] | True |
is_ipv4_address | (string_ip) |
:rtype: bool
|
:rtype: bool
| def is_ipv4_address(string_ip):
"""
:rtype: bool
"""
try:
socket.inet_aton(string_ip)
except socket.error:
return False
return True | [
"def",
"is_ipv4_address",
"(",
"string_ip",
")",
":",
"try",
":",
"socket",
".",
"inet_aton",
"(",
"string_ip",
")",
"except",
"socket",
".",
"error",
":",
"return",
"False",
"return",
"True"
] | [
641,
0
] | [
649,
15
] | python | en | ['en', 'error', 'th'] | False |
is_valid_cidr | (string_network) |
Very simple check of the cidr format in no_proxy variable.
:rtype: bool
|
Very simple check of the cidr format in no_proxy variable. | def is_valid_cidr(string_network):
"""
Very simple check of the cidr format in no_proxy variable.
:rtype: bool
"""
if string_network.count('/') == 1:
try:
mask = int(string_network.split('/')[1])
except ValueError:
return False
if mask < 1 or mask > ... | [
"def",
"is_valid_cidr",
"(",
"string_network",
")",
":",
"if",
"string_network",
".",
"count",
"(",
"'/'",
")",
"==",
"1",
":",
"try",
":",
"mask",
"=",
"int",
"(",
"string_network",
".",
"split",
"(",
"'/'",
")",
"[",
"1",
"]",
")",
"except",
"Value... | [
652,
0
] | [
673,
15
] | python | en | ['en', 'error', 'th'] | False |
set_environ | (env_name, value) | Set the environment variable 'env_name' to 'value'
Save previous value, yield, and then restore the previous value stored in
the environment variable 'env_name'.
If 'value' is None, do nothing | Set the environment variable 'env_name' to 'value' | def set_environ(env_name, value):
"""Set the environment variable 'env_name' to 'value'
Save previous value, yield, and then restore the previous value stored in
the environment variable 'env_name'.
If 'value' is None, do nothing"""
value_changed = value is not None
if value_changed:
o... | [
"def",
"set_environ",
"(",
"env_name",
",",
"value",
")",
":",
"value_changed",
"=",
"value",
"is",
"not",
"None",
"if",
"value_changed",
":",
"old_value",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"env_name",
")",
"os",
".",
"environ",
"[",
"env_name"... | [
677,
0
] | [
695,
48
] | python | en | ['en', 'en', 'en'] | True |
should_bypass_proxies | (url, no_proxy) |
Returns whether we should bypass proxies or not.
:rtype: bool
|
Returns whether we should bypass proxies or not. | def should_bypass_proxies(url, no_proxy):
"""
Returns whether we should bypass proxies or not.
:rtype: bool
"""
# Prioritize lowercase environment variables over uppercase
# to keep a consistent behaviour with other http projects (curl, wget).
get_proxy = lambda k: os.environ.get(k) or os.e... | [
"def",
"should_bypass_proxies",
"(",
"url",
",",
"no_proxy",
")",
":",
"# Prioritize lowercase environment variables over uppercase",
"# to keep a consistent behaviour with other http projects (curl, wget).",
"get_proxy",
"=",
"lambda",
"k",
":",
"os",
".",
"environ",
".",
"get... | [
698,
0
] | [
756,
16
] | python | en | ['en', 'error', 'th'] | False |
get_environ_proxies | (url, no_proxy=None) |
Return a dict of environment proxies.
:rtype: dict
|
Return a dict of environment proxies. | def get_environ_proxies(url, no_proxy=None):
"""
Return a dict of environment proxies.
:rtype: dict
"""
if should_bypass_proxies(url, no_proxy=no_proxy):
return {}
else:
return getproxies() | [
"def",
"get_environ_proxies",
"(",
"url",
",",
"no_proxy",
"=",
"None",
")",
":",
"if",
"should_bypass_proxies",
"(",
"url",
",",
"no_proxy",
"=",
"no_proxy",
")",
":",
"return",
"{",
"}",
"else",
":",
"return",
"getproxies",
"(",
")"
] | [
759,
0
] | [
768,
27
] | python | en | ['en', 'error', 'th'] | False |
select_proxy | (url, proxies) | Select a proxy for the url, if applicable.
:param url: The url being for the request
:param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
| Select a proxy for the url, if applicable. | def select_proxy(url, proxies):
"""Select a proxy for the url, if applicable.
:param url: The url being for the request
:param proxies: A dictionary of schemes or schemes and hosts to proxy URLs
"""
proxies = proxies or {}
urlparts = urlparse(url)
if urlparts.hostname is None:
retur... | [
"def",
"select_proxy",
"(",
"url",
",",
"proxies",
")",
":",
"proxies",
"=",
"proxies",
"or",
"{",
"}",
"urlparts",
"=",
"urlparse",
"(",
"url",
")",
"if",
"urlparts",
".",
"hostname",
"is",
"None",
":",
"return",
"proxies",
".",
"get",
"(",
"urlparts"... | [
771,
0
] | [
794,
16
] | python | en | ['en', 'en', 'en'] | True |
default_user_agent | (name="python-requests") |
Return a string representing the default user agent.
:rtype: str
|
Return a string representing the default user agent. | def default_user_agent(name="python-requests"):
"""
Return a string representing the default user agent.
:rtype: str
"""
return '%s/%s' % (name, __version__) | [
"def",
"default_user_agent",
"(",
"name",
"=",
"\"python-requests\"",
")",
":",
"return",
"'%s/%s'",
"%",
"(",
"name",
",",
"__version__",
")"
] | [
797,
0
] | [
803,
40
] | python | en | ['en', 'error', 'th'] | False |
default_headers | () |
:rtype: requests.structures.CaseInsensitiveDict
|
:rtype: requests.structures.CaseInsensitiveDict
| def default_headers():
"""
:rtype: requests.structures.CaseInsensitiveDict
"""
return CaseInsensitiveDict({
'User-Agent': default_user_agent(),
'Accept-Encoding': ', '.join(('gzip', 'deflate')),
'Accept': '*/*',
'Connection': 'keep-alive',
}) | [
"def",
"default_headers",
"(",
")",
":",
"return",
"CaseInsensitiveDict",
"(",
"{",
"'User-Agent'",
":",
"default_user_agent",
"(",
")",
",",
"'Accept-Encoding'",
":",
"', '",
".",
"join",
"(",
"(",
"'gzip'",
",",
"'deflate'",
")",
")",
",",
"'Accept'",
":",... | [
806,
0
] | [
815,
6
] | python | en | ['en', 'error', 'th'] | False |
parse_header_links | (value) | Return a list of parsed link headers proxies.
i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"
:rtype: list
| Return a list of parsed link headers proxies. | def parse_header_links(value):
"""Return a list of parsed link headers proxies.
i.e. Link: <http:/.../front.jpeg>; rel=front; type="image/jpeg",<http://.../back.jpeg>; rel=back;type="image/jpeg"
:rtype: list
"""
links = []
replace_chars = ' \'"'
value = value.strip(replace_chars)
if... | [
"def",
"parse_header_links",
"(",
"value",
")",
":",
"links",
"=",
"[",
"]",
"replace_chars",
"=",
"' \\'\"'",
"value",
"=",
"value",
".",
"strip",
"(",
"replace_chars",
")",
"if",
"not",
"value",
":",
"return",
"links",
"for",
"val",
"in",
"re",
".",
... | [
818,
0
] | [
852,
16
] | python | en | ['en', 'af', 'en'] | True |
guess_json_utf | (data) |
:rtype: str
|
:rtype: str
| def guess_json_utf(data):
"""
:rtype: str
"""
# JSON always starts with two ASCII characters, so detection is as
# easy as counting the nulls and from their location and count
# determine the encoding. Also detect a BOM, if present.
sample = data[:4]
if sample in (codecs.BOM_UTF32_LE, co... | [
"def",
"guess_json_utf",
"(",
"data",
")",
":",
"# JSON always starts with two ASCII characters, so detection is as",
"# easy as counting the nulls and from their location and count",
"# determine the encoding. Also detect a BOM, if present.",
"sample",
"=",
"data",
"[",
":",
"4",
"]",... | [
861,
0
] | [
890,
15
] | python | en | ['en', 'error', 'th'] | False |
prepend_scheme_if_needed | (url, new_scheme) | Given a URL that may or may not have a scheme, prepend the given scheme.
Does not replace a present scheme with the one provided as an argument.
:rtype: str
| Given a URL that may or may not have a scheme, prepend the given scheme.
Does not replace a present scheme with the one provided as an argument. | def prepend_scheme_if_needed(url, new_scheme):
"""Given a URL that may or may not have a scheme, prepend the given scheme.
Does not replace a present scheme with the one provided as an argument.
:rtype: str
"""
scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme)
# urlpars... | [
"def",
"prepend_scheme_if_needed",
"(",
"url",
",",
"new_scheme",
")",
":",
"scheme",
",",
"netloc",
",",
"path",
",",
"params",
",",
"query",
",",
"fragment",
"=",
"urlparse",
"(",
"url",
",",
"new_scheme",
")",
"# urlparse is a finicky beast, and sometimes decid... | [
893,
0
] | [
907,
70
] | python | en | ['en', 'en', 'en'] | True |
get_auth_from_url | (url) | Given a url with authentication components, extract them into a tuple of
username,password.
:rtype: (str,str)
| Given a url with authentication components, extract them into a tuple of
username,password. | def get_auth_from_url(url):
"""Given a url with authentication components, extract them into a tuple of
username,password.
:rtype: (str,str)
"""
parsed = urlparse(url)
try:
auth = (unquote(parsed.username), unquote(parsed.password))
except (AttributeError, TypeError):
auth ... | [
"def",
"get_auth_from_url",
"(",
"url",
")",
":",
"parsed",
"=",
"urlparse",
"(",
"url",
")",
"try",
":",
"auth",
"=",
"(",
"unquote",
"(",
"parsed",
".",
"username",
")",
",",
"unquote",
"(",
"parsed",
".",
"password",
")",
")",
"except",
"(",
"Attr... | [
910,
0
] | [
923,
15
] | python | en | ['en', 'en', 'en'] | True |
check_header_validity | (header) | Verifies that header value is a string which doesn't contain
leading whitespace or return characters. This prevents unintended
header injection.
:param header: tuple, in the format (name, value).
| Verifies that header value is a string which doesn't contain
leading whitespace or return characters. This prevents unintended
header injection. | def check_header_validity(header):
"""Verifies that header value is a string which doesn't contain
leading whitespace or return characters. This prevents unintended
header injection.
:param header: tuple, in the format (name, value).
"""
name, value = header
if isinstance(value, bytes):
... | [
"def",
"check_header_validity",
"(",
"header",
")",
":",
"name",
",",
"value",
"=",
"header",
"if",
"isinstance",
"(",
"value",
",",
"bytes",
")",
":",
"pat",
"=",
"_CLEAN_HEADER_REGEX_BYTE",
"else",
":",
"pat",
"=",
"_CLEAN_HEADER_REGEX_STR",
"try",
":",
"i... | [
931,
0
] | [
949,
73
] | python | en | ['en', 'en', 'en'] | True |
urldefragauth | (url) |
Given a url remove the fragment and the authentication part.
:rtype: str
|
Given a url remove the fragment and the authentication part. | def urldefragauth(url):
"""
Given a url remove the fragment and the authentication part.
:rtype: str
"""
scheme, netloc, path, params, query, fragment = urlparse(url)
# see func:`prepend_scheme_if_needed`
if not netloc:
netloc, path = path, netloc
netloc = netloc.rsplit('@', 1... | [
"def",
"urldefragauth",
"(",
"url",
")",
":",
"scheme",
",",
"netloc",
",",
"path",
",",
"params",
",",
"query",
",",
"fragment",
"=",
"urlparse",
"(",
"url",
")",
"# see func:`prepend_scheme_if_needed`",
"if",
"not",
"netloc",
":",
"netloc",
",",
"path",
... | [
952,
0
] | [
966,
64
] | python | en | ['en', 'error', 'th'] | False |
rewind_body | (prepared_request) | Move file pointer back to its recorded starting position
so it can be read again on redirect.
| Move file pointer back to its recorded starting position
so it can be read again on redirect.
| def rewind_body(prepared_request):
"""Move file pointer back to its recorded starting position
so it can be read again on redirect.
"""
body_seek = getattr(prepared_request.body, 'seek', None)
if body_seek is not None and isinstance(prepared_request._body_position, integer_types):
try:
... | [
"def",
"rewind_body",
"(",
"prepared_request",
")",
":",
"body_seek",
"=",
"getattr",
"(",
"prepared_request",
".",
"body",
",",
"'seek'",
",",
"None",
")",
"if",
"body_seek",
"is",
"not",
"None",
"and",
"isinstance",
"(",
"prepared_request",
".",
"_body_posit... | [
969,
0
] | [
981,
82
] | python | en | ['en', 'en', 'en'] | True |
TestVolumeSnapshotsBasic.setUp | (self) | Setup: create volume | Setup: create volume | def setUp(self):
"""Setup: create volume"""
super(TestVolumeSnapshotsBasic, self).setUp()
volumes_page = self.home_pg.go_to_project_volumes_volumespage()
volumes_page.create_volume(self.VOLUME_NAME)
volumes_page.find_message_and_dismiss(messages.INFO)
self.assertTrue(volu... | [
"def",
"setUp",
"(",
"self",
")",
":",
"super",
"(",
"TestVolumeSnapshotsBasic",
",",
"self",
")",
".",
"setUp",
"(",
")",
"volumes_page",
"=",
"self",
".",
"home_pg",
".",
"go_to_project_volumes_volumespage",
"(",
")",
"volumes_page",
".",
"create_volume",
"(... | [
26,
4
] | [
41,
32
] | python | en | ['nl', 'et', 'en'] | False |
TestVolumeSnapshotsBasic.test_create_edit_delete_volume_snapshot | (self) | Test checks create/delete volume snapshot action
Steps:
1. Login to Horizon Dashboard
2. Navigate to Project -> Volumes -> Volumes page
3. Create snapshot for existed volume
4. Check that no ERROR appears
5. Check that snapshot is in the list
6. Check that snapsh... | Test checks create/delete volume snapshot action | def test_create_edit_delete_volume_snapshot(self):
"""Test checks create/delete volume snapshot action
Steps:
1. Login to Horizon Dashboard
2. Navigate to Project -> Volumes -> Volumes page
3. Create snapshot for existed volume
4. Check that no ERROR appears
5. C... | [
"def",
"test_create_edit_delete_volume_snapshot",
"(",
"self",
")",
":",
"volumes_page",
"=",
"self",
".",
"home_pg",
".",
"go_to_project_volumes_volumespage",
"(",
")",
"volumes_snapshot_page",
"=",
"volumes_page",
".",
"create_volume_snapshot",
"(",
"self",
".",
"VOLU... | [
44,
4
] | [
87,
22
] | python | el-Latn | ['it', 'el-Latn', 'en'] | False |
TestVolumeSnapshotsBasic.test_volume_snapshots_pagination | (self) | This test checks volumes snapshots pagination
Steps:
1) Login to Horizon Dashboard
2) Go to Project -> Volumes -> Volumes tab, create
volumes and 3 snapshots
3) Navigate to user settings page
4) Change 'Items Per Page' value to 1
5) Go to Project -> Volumes ->... | This test checks volumes snapshots pagination | def test_volume_snapshots_pagination(self):
"""This test checks volumes snapshots pagination
Steps:
1) Login to Horizon Dashboard
2) Go to Project -> Volumes -> Volumes tab, create
volumes and 3 snapshots
3) Navigate to user settings page
4) Change 'Items Per ... | [
"def",
"test_volume_snapshots_pagination",
"(",
"self",
")",
":",
"volumes_page",
"=",
"self",
".",
"home_pg",
".",
"go_to_project_volumes_volumespage",
"(",
")",
"count",
"=",
"3",
"items_per_page",
"=",
"1",
"snapshot_names",
"=",
"[",
"\"{0}_{1}\"",
".",
"forma... | [
90,
4
] | [
169,
66
] | python | en | ['en', 'en', 'en'] | True |
TestVolumeSnapshotsAdvanced.setUp | (self) | Setup: create volume | Setup: create volume | def setUp(self):
"""Setup: create volume"""
super(TestVolumeSnapshotsAdvanced, self).setUp()
volumes_page = self.home_pg.go_to_project_volumes_volumespage()
volumes_page.create_volume(self.VOLUME_NAME)
volumes_page.find_message_and_dismiss(messages.INFO)
self.assertTrue(v... | [
"def",
"setUp",
"(",
"self",
")",
":",
"super",
"(",
"TestVolumeSnapshotsAdvanced",
",",
"self",
")",
".",
"setUp",
"(",
")",
"volumes_page",
"=",
"self",
".",
"home_pg",
".",
"go_to_project_volumes_volumespage",
"(",
")",
"volumes_page",
".",
"create_volume",
... | [
202,
4
] | [
220,
32
] | python | en | ['nl', 'et', 'en'] | False |
TestVolumeSnapshotsAdvanced.test_create_volume_from_snapshot | (self) | Test checks possibility to create volume from snapshot
Steps:
1. Login to Horizon Dashboard as regular user
2. Navigate to Project -> Volumes -> Volumes page
3. Create snapshot for existed volume
4. Create new volume from snapshot
5. Check the volume is created and has '... | Test checks possibility to create volume from snapshot | def test_create_volume_from_snapshot(self):
"""Test checks possibility to create volume from snapshot
Steps:
1. Login to Horizon Dashboard as regular user
2. Navigate to Project -> Volumes -> Volumes page
3. Create snapshot for existed volume
4. Create new volume from sn... | [
"def",
"test_create_volume_from_snapshot",
"(",
"self",
")",
":",
"volumes_page",
"=",
"self",
".",
"home_pg",
".",
"go_to_project_volumes_volumespage",
"(",
")",
"volumes_snapshot_page",
"=",
"volumes_page",
".",
"create_volume_snapshot",
"(",
"self",
".",
"VOLUME_NAME... | [
223,
4
] | [
263,
67
] | python | en | ['en', 'en', 'en'] | True |
tf_normalize | (obs, obs_space, low=None, high=None) | Result will be float32 tensor with values in [-1, 1]. | Result will be float32 tensor with values in [-1, 1]. | def tf_normalize(obs, obs_space, low=None, high=None):
"""Result will be float32 tensor with values in [-1, 1]."""
if low is None:
low = obs_space.low.flat[0]
if high is None:
high = obs_space.high.flat[0]
mean = (low + high) * 0.5
if obs_space.dtype != np.float32:
obs = tf.... | [
"def",
"tf_normalize",
"(",
"obs",
",",
"obs_space",
",",
"low",
"=",
"None",
",",
"high",
"=",
"None",
")",
":",
"if",
"low",
"is",
"None",
":",
"low",
"=",
"obs_space",
".",
"low",
".",
"flat",
"[",
"0",
"]",
"if",
"high",
"is",
"None",
":",
... | [
10,
0
] | [
23,
14
] | python | en | ['en', 'en', 'en'] | True |
timesince_or_never | (dt, default=None) | Call the Django ``timesince`` filter or a given default string.
It returns the string *default* if *dt* is not a valid ``date``
or ``datetime`` object.
When *default* is None, "Never" is returned.
| Call the Django ``timesince`` filter or a given default string. | def timesince_or_never(dt, default=None):
"""Call the Django ``timesince`` filter or a given default string.
It returns the string *default* if *dt* is not a valid ``date``
or ``datetime`` object.
When *default* is None, "Never" is returned.
"""
if default is None:
default = _("Never")
... | [
"def",
"timesince_or_never",
"(",
"dt",
",",
"default",
"=",
"None",
")",
":",
"if",
"default",
"is",
"None",
":",
"default",
"=",
"_",
"(",
"\"Never\"",
")",
"if",
"isinstance",
"(",
"dt",
",",
"datetime",
".",
"date",
")",
":",
"return",
"timesince",... | [
41,
0
] | [
54,
22
] | python | en | ['en', 'en', 'en'] | True |
Builder.__init__ | (self, resolver) |
@param resolver: A schema object name resolver.
@type resolver: L{resolver.Resolver}
| def __init__(self, resolver):
"""
@param resolver: A schema object name resolver.
@type resolver: L{resolver.Resolver}
"""
self.resolver = resolver | [
"def",
"__init__",
"(",
"self",
",",
"resolver",
")",
":",
"self",
".",
"resolver",
"=",
"resolver"
] | [
30,
4
] | [
35,
32
] | python | en | ['en', 'error', 'th'] | False | |
Builder.build | (self, name) | build a an object for the specified typename as defined in the schema | build a an object for the specified typename as defined in the schema | def build(self, name):
""" build a an object for the specified typename as defined in the schema """
if isinstance(name, basestring):
type = self.resolver.find(name)
if type is None:
raise TypeNotFound(name)
else:
type = name
cls = type... | [
"def",
"build",
"(",
"self",
",",
"name",
")",
":",
"if",
"isinstance",
"(",
"name",
",",
"basestring",
")",
":",
"type",
"=",
"self",
".",
"resolver",
".",
"find",
"(",
"name",
")",
"if",
"type",
"is",
"None",
":",
"raise",
"TypeNotFound",
"(",
"n... | [
37,
4
] | [
60,
19
] | python | en | ['en', 'en', 'en'] | True |
Builder.process | (self, data, type, history) | process the specified type then process its children | process the specified type then process its children | def process(self, data, type, history):
""" process the specified type then process its children """
if type in history:
return
if type.enum():
return
history.append(type)
resolved = type.resolve()
value = None
if type.unbounded():
... | [
"def",
"process",
"(",
"self",
",",
"data",
",",
"type",
",",
"history",
")",
":",
"if",
"type",
"in",
"history",
":",
"return",
"if",
"type",
".",
"enum",
"(",
")",
":",
"return",
"history",
".",
"append",
"(",
"type",
")",
"resolved",
"=",
"type"... | [
62,
4
] | [
92,
53
] | 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.