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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
EnvironmentInfo.FxTools | (self) |
Microsoft .NET Framework Tools
|
Microsoft .NET Framework Tools
| def FxTools(self):
"""
Microsoft .NET Framework Tools
"""
pi = self.pi
si = self.si
if self.vc_ver <= 10.0:
include32 = True
include64 = not pi.target_is_x86() and not pi.current_is_x86()
else:
include32 = pi.target_is_x86() or... | [
"def",
"FxTools",
"(",
"self",
")",
":",
"pi",
"=",
"self",
".",
"pi",
"si",
"=",
"self",
".",
"si",
"if",
"self",
".",
"vc_ver",
"<=",
"10.0",
":",
"include32",
"=",
"True",
"include64",
"=",
"not",
"pi",
".",
"target_is_x86",
"(",
")",
"and",
"... | [
1071,
4
] | [
1092,
20
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.NetFxSDKLibraries | (self) |
Microsoft .Net Framework SDK Libraries
|
Microsoft .Net Framework SDK Libraries
| def NetFxSDKLibraries(self):
"""
Microsoft .Net Framework SDK Libraries
"""
if self.vc_ver < 14.0 or not self.si.NetFxSdkDir:
return []
arch_subdir = self.pi.target_dir(x64=True)
return [os.path.join(self.si.NetFxSdkDir, r'lib\um%s' % arch_subdir)] | [
"def",
"NetFxSDKLibraries",
"(",
"self",
")",
":",
"if",
"self",
".",
"vc_ver",
"<",
"14.0",
"or",
"not",
"self",
".",
"si",
".",
"NetFxSdkDir",
":",
"return",
"[",
"]",
"arch_subdir",
"=",
"self",
".",
"pi",
".",
"target_dir",
"(",
"x64",
"=",
"True... | [
1095,
4
] | [
1103,
77
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.NetFxSDKIncludes | (self) |
Microsoft .Net Framework SDK Includes
|
Microsoft .Net Framework SDK Includes
| def NetFxSDKIncludes(self):
"""
Microsoft .Net Framework SDK Includes
"""
if self.vc_ver < 14.0 or not self.si.NetFxSdkDir:
return []
return [os.path.join(self.si.NetFxSdkDir, r'include\um')] | [
"def",
"NetFxSDKIncludes",
"(",
"self",
")",
":",
"if",
"self",
".",
"vc_ver",
"<",
"14.0",
"or",
"not",
"self",
".",
"si",
".",
"NetFxSdkDir",
":",
"return",
"[",
"]",
"return",
"[",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"si",
".",
"... | [
1106,
4
] | [
1113,
65
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.VsTDb | (self) |
Microsoft Visual Studio Team System Database
|
Microsoft Visual Studio Team System Database
| def VsTDb(self):
"""
Microsoft Visual Studio Team System Database
"""
return [os.path.join(self.si.VSInstallDir, r'VSTSDB\Deploy')] | [
"def",
"VsTDb",
"(",
"self",
")",
":",
"return",
"[",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"si",
".",
"VSInstallDir",
",",
"r'VSTSDB\\Deploy'",
")",
"]"
] | [
1116,
4
] | [
1120,
69
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.MSBuild | (self) |
Microsoft Build Engine
|
Microsoft Build Engine
| def MSBuild(self):
"""
Microsoft Build Engine
"""
if self.vc_ver < 12.0:
return []
elif self.vc_ver < 15.0:
base_path = self.si.ProgramFilesx86
arch_subdir = self.pi.current_dir(hidex86=True)
else:
base_path = self.si.VSInst... | [
"def",
"MSBuild",
"(",
"self",
")",
":",
"if",
"self",
".",
"vc_ver",
"<",
"12.0",
":",
"return",
"[",
"]",
"elif",
"self",
".",
"vc_ver",
"<",
"15.0",
":",
"base_path",
"=",
"self",
".",
"si",
".",
"ProgramFilesx86",
"arch_subdir",
"=",
"self",
".",... | [
1123,
4
] | [
1143,
20
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.HTMLHelpWorkshop | (self) |
Microsoft HTML Help Workshop
|
Microsoft HTML Help Workshop
| def HTMLHelpWorkshop(self):
"""
Microsoft HTML Help Workshop
"""
if self.vc_ver < 11.0:
return []
return [os.path.join(self.si.ProgramFilesx86, 'HTML Help Workshop')] | [
"def",
"HTMLHelpWorkshop",
"(",
"self",
")",
":",
"if",
"self",
".",
"vc_ver",
"<",
"11.0",
":",
"return",
"[",
"]",
"return",
"[",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"si",
".",
"ProgramFilesx86",
",",
"'HTML Help Workshop'",
")",
"]"
] | [
1146,
4
] | [
1153,
76
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.UCRTLibraries | (self) |
Microsoft Universal C Runtime SDK Libraries
|
Microsoft Universal C Runtime SDK Libraries
| def UCRTLibraries(self):
"""
Microsoft Universal C Runtime SDK Libraries
"""
if self.vc_ver < 14.0:
return []
arch_subdir = self.pi.target_dir(x64=True)
lib = os.path.join(self.si.UniversalCRTSdkDir, 'lib')
ucrtver = self._ucrt_subdir
return [... | [
"def",
"UCRTLibraries",
"(",
"self",
")",
":",
"if",
"self",
".",
"vc_ver",
"<",
"14.0",
":",
"return",
"[",
"]",
"arch_subdir",
"=",
"self",
".",
"pi",
".",
"target_dir",
"(",
"x64",
"=",
"True",
")",
"lib",
"=",
"os",
".",
"path",
".",
"join",
... | [
1156,
4
] | [
1166,
71
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.UCRTIncludes | (self) |
Microsoft Universal C Runtime SDK Include
|
Microsoft Universal C Runtime SDK Include
| def UCRTIncludes(self):
"""
Microsoft Universal C Runtime SDK Include
"""
if self.vc_ver < 14.0:
return []
include = os.path.join(self.si.UniversalCRTSdkDir, 'include')
return [os.path.join(include, '%sucrt' % self._ucrt_subdir)] | [
"def",
"UCRTIncludes",
"(",
"self",
")",
":",
"if",
"self",
".",
"vc_ver",
"<",
"14.0",
":",
"return",
"[",
"]",
"include",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"si",
".",
"UniversalCRTSdkDir",
",",
"'include'",
")",
"return",
"[",
... | [
1169,
4
] | [
1177,
68
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo._ucrt_subdir | (self) |
Microsoft Universal C Runtime SDK version subdir
|
Microsoft Universal C Runtime SDK version subdir
| def _ucrt_subdir(self):
"""
Microsoft Universal C Runtime SDK version subdir
"""
ucrtver = self.si.UniversalCRTSdkLastVersion
return ('%s\\' % ucrtver) if ucrtver else '' | [
"def",
"_ucrt_subdir",
"(",
"self",
")",
":",
"ucrtver",
"=",
"self",
".",
"si",
".",
"UniversalCRTSdkLastVersion",
"return",
"(",
"'%s\\\\'",
"%",
"ucrtver",
")",
"if",
"ucrtver",
"else",
"''"
] | [
1180,
4
] | [
1185,
52
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.FSharp | (self) |
Microsoft Visual F#
|
Microsoft Visual F#
| def FSharp(self):
"""
Microsoft Visual F#
"""
if self.vc_ver < 11.0 and self.vc_ver > 12.0:
return []
return self.si.FSharpInstallDir | [
"def",
"FSharp",
"(",
"self",
")",
":",
"if",
"self",
".",
"vc_ver",
"<",
"11.0",
"and",
"self",
".",
"vc_ver",
">",
"12.0",
":",
"return",
"[",
"]",
"return",
"self",
".",
"si",
".",
"FSharpInstallDir"
] | [
1188,
4
] | [
1195,
39
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.VCRuntimeRedist | (self) |
Microsoft Visual C++ runtime redistribuable dll
|
Microsoft Visual C++ runtime redistribuable dll
| def VCRuntimeRedist(self):
"""
Microsoft Visual C++ runtime redistribuable dll
"""
arch_subdir = self.pi.target_dir(x64=True)
if self.vc_ver < 15:
redist_path = self.si.VCInstallDir
vcruntime = 'redist%s\\Microsoft.VC%d0.CRT\\vcruntime%d0.dll'
else... | [
"def",
"VCRuntimeRedist",
"(",
"self",
")",
":",
"arch_subdir",
"=",
"self",
".",
"pi",
".",
"target_dir",
"(",
"x64",
"=",
"True",
")",
"if",
"self",
".",
"vc_ver",
"<",
"15",
":",
"redist_path",
"=",
"self",
".",
"si",
".",
"VCInstallDir",
"vcruntime... | [
1198,
4
] | [
1214,
51
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo.return_env | (self, exists=True) |
Return environment dict.
Parameters
----------
exists: bool
It True, only return existing paths.
|
Return environment dict. | def return_env(self, exists=True):
"""
Return environment dict.
Parameters
----------
exists: bool
It True, only return existing paths.
"""
env = dict(
include=self._build_paths('include',
[self.VCIncl... | [
"def",
"return_env",
"(",
"self",
",",
"exists",
"=",
"True",
")",
":",
"env",
"=",
"dict",
"(",
"include",
"=",
"self",
".",
"_build_paths",
"(",
"'include'",
",",
"[",
"self",
".",
"VCIncludes",
",",
"self",
".",
"OSIncludes",
",",
"self",
".",
"UC... | [
1216,
4
] | [
1259,
18
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo._build_paths | (self, name, spec_path_lists, exists) |
Given an environment variable name and specified paths,
return a pathsep-separated string of paths containing
unique, extant, directories from those paths and from
the environment variable. Raise an error if no paths
are resolved.
|
Given an environment variable name and specified paths,
return a pathsep-separated string of paths containing
unique, extant, directories from those paths and from
the environment variable. Raise an error if no paths
are resolved.
| def _build_paths(self, name, spec_path_lists, exists):
"""
Given an environment variable name and specified paths,
return a pathsep-separated string of paths containing
unique, extant, directories from those paths and from
the environment variable. Raise an error if no paths
... | [
"def",
"_build_paths",
"(",
"self",
",",
"name",
",",
"spec_path_lists",
",",
"exists",
")",
":",
"# flatten spec_path_lists",
"spec_paths",
"=",
"itertools",
".",
"chain",
".",
"from_iterable",
"(",
"spec_path_lists",
")",
"env_paths",
"=",
"safe_env",
".",
"ge... | [
1261,
4
] | [
1278,
44
] | python | en | ['en', 'error', 'th'] | False |
EnvironmentInfo._unique_everseen | (self, iterable, key=None) |
List unique elements, preserving order.
Remember all elements ever seen.
_unique_everseen('AAAABBBCCDAABBB') --> A B C D
_unique_everseen('ABBCcAD', str.lower) --> A B C D
|
List unique elements, preserving order.
Remember all elements ever seen. | def _unique_everseen(self, iterable, key=None):
"""
List unique elements, preserving order.
Remember all elements ever seen.
_unique_everseen('AAAABBBCCDAABBB') --> A B C D
_unique_everseen('ABBCcAD', str.lower) --> A B C D
"""
seen = set()
seen_add = se... | [
"def",
"_unique_everseen",
"(",
"self",
",",
"iterable",
",",
"key",
"=",
"None",
")",
":",
"seen",
"=",
"set",
"(",
")",
"seen_add",
"=",
"seen",
".",
"add",
"if",
"key",
"is",
"None",
":",
"for",
"element",
"in",
"filterfalse",
"(",
"seen",
".",
... | [
1281,
4
] | [
1301,
33
] | python | en | ['en', 'error', 'th'] | False |
markup_join | (seq) | Concatenation that escapes if necessary and converts to unicode. | Concatenation that escapes if necessary and converts to unicode. | def markup_join(seq):
"""Concatenation that escapes if necessary and converts to unicode."""
buf = []
iterator = imap(soft_unicode, seq)
for arg in iterator:
buf.append(arg)
if hasattr(arg, '__html__'):
return Markup(u'').join(chain(buf, iterator))
return concat(buf) | [
"def",
"markup_join",
"(",
"seq",
")",
":",
"buf",
"=",
"[",
"]",
"iterator",
"=",
"imap",
"(",
"soft_unicode",
",",
"seq",
")",
"for",
"arg",
"in",
"iterator",
":",
"buf",
".",
"append",
"(",
"arg",
")",
"if",
"hasattr",
"(",
"arg",
",",
"'__html_... | [
42,
0
] | [
50,
22
] | python | en | ['en', 'en', 'en'] | True |
unicode_join | (seq) | Simple args to unicode conversion and concatenation. | Simple args to unicode conversion and concatenation. | def unicode_join(seq):
"""Simple args to unicode conversion and concatenation."""
return concat(imap(text_type, seq)) | [
"def",
"unicode_join",
"(",
"seq",
")",
":",
"return",
"concat",
"(",
"imap",
"(",
"text_type",
",",
"seq",
")",
")"
] | [
53,
0
] | [
55,
39
] | python | en | ['en', 'en', 'en'] | True |
new_context | (environment, template_name, blocks, vars=None,
shared=None, globals=None, locals=None) | Internal helper to for context creation. | Internal helper to for context creation. | def new_context(environment, template_name, blocks, vars=None,
shared=None, globals=None, locals=None):
"""Internal helper to for context creation."""
if vars is None:
vars = {}
if shared:
parent = vars
else:
parent = dict(globals or (), **vars)
if locals:
... | [
"def",
"new_context",
"(",
"environment",
",",
"template_name",
",",
"blocks",
",",
"vars",
"=",
"None",
",",
"shared",
"=",
"None",
",",
"globals",
"=",
"None",
",",
"locals",
"=",
"None",
")",
":",
"if",
"vars",
"is",
"None",
":",
"vars",
"=",
"{",... | [
58,
0
] | [
76,
44
] | python | en | ['en', 'en', 'en'] | True |
make_logging_undefined | (logger=None, base=None) | Given a logger object this returns a new undefined class that will
log certain failures. It will log iterations and printing. If no
logger is given a default logger is created.
Example::
logger = logging.getLogger(__name__)
LoggingUndefined = make_logging_undefined(
logger=lo... | Given a logger object this returns a new undefined class that will
log certain failures. It will log iterations and printing. If no
logger is given a default logger is created. | def make_logging_undefined(logger=None, base=None):
"""Given a logger object this returns a new undefined class that will
log certain failures. It will log iterations and printing. If no
logger is given a default logger is created.
Example::
logger = logging.getLogger(__name__)
Loggi... | [
"def",
"make_logging_undefined",
"(",
"logger",
"=",
"None",
",",
"base",
"=",
"None",
")",
":",
"if",
"logger",
"is",
"None",
":",
"import",
"logging",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"__name__",
")",
"logger",
".",
"addHandler",
"(",
"... | [
671,
0
] | [
749,
27
] | python | en | ['en', 'en', 'en'] | True |
Context.super | (self, name, current) | Render a parent block. | Render a parent block. | def super(self, name, current):
"""Render a parent block."""
try:
blocks = self.blocks[name]
index = blocks.index(current) + 1
blocks[index]
except LookupError:
return self.environment.undefined('there is no parent block '
... | [
"def",
"super",
"(",
"self",
",",
"name",
",",
"current",
")",
":",
"try",
":",
"blocks",
"=",
"self",
".",
"blocks",
"[",
"name",
"]",
"index",
"=",
"blocks",
".",
"index",
"(",
"current",
")",
"+",
"1",
"blocks",
"[",
"index",
"]",
"except",
"L... | [
174,
4
] | [
184,
56
] | python | en | ['en', 'ca', 'en'] | True |
Context.get | (self, key, default=None) | Returns an item from the template context, if it doesn't exist
`default` is returned.
| Returns an item from the template context, if it doesn't exist
`default` is returned.
| def get(self, key, default=None):
"""Returns an item from the template context, if it doesn't exist
`default` is returned.
"""
try:
return self[key]
except KeyError:
return default | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
"[",
"key",
"]",
"except",
"KeyError",
":",
"return",
"default"
] | [
186,
4
] | [
193,
26
] | python | en | ['en', 'en', 'en'] | True |
Context.resolve | (self, key) | Looks up a variable like `__getitem__` or `get` but returns an
:class:`Undefined` object with the name of the name looked up.
| Looks up a variable like `__getitem__` or `get` but returns an
:class:`Undefined` object with the name of the name looked up.
| def resolve(self, key):
"""Looks up a variable like `__getitem__` or `get` but returns an
:class:`Undefined` object with the name of the name looked up.
"""
if self._legacy_resolve_mode:
rv = resolve_or_missing(self, key)
else:
rv = self.resolve_or_missing... | [
"def",
"resolve",
"(",
"self",
",",
"key",
")",
":",
"if",
"self",
".",
"_legacy_resolve_mode",
":",
"rv",
"=",
"resolve_or_missing",
"(",
"self",
",",
"key",
")",
"else",
":",
"rv",
"=",
"self",
".",
"resolve_or_missing",
"(",
"key",
")",
"if",
"rv",
... | [
195,
4
] | [
205,
17
] | python | en | ['en', 'en', 'en'] | True |
Context.resolve_or_missing | (self, key) | Resolves a variable like :meth:`resolve` but returns the
special `missing` value if it cannot be found.
| Resolves a variable like :meth:`resolve` but returns the
special `missing` value if it cannot be found.
| def resolve_or_missing(self, key):
"""Resolves a variable like :meth:`resolve` but returns the
special `missing` value if it cannot be found.
"""
if self._legacy_resolve_mode:
rv = self.resolve(key)
if isinstance(rv, Undefined):
rv = missing
... | [
"def",
"resolve_or_missing",
"(",
"self",
",",
"key",
")",
":",
"if",
"self",
".",
"_legacy_resolve_mode",
":",
"rv",
"=",
"self",
".",
"resolve",
"(",
"key",
")",
"if",
"isinstance",
"(",
"rv",
",",
"Undefined",
")",
":",
"rv",
"=",
"missing",
"return... | [
207,
4
] | [
216,
44
] | python | en | ['en', 'en', 'en'] | True |
Context.get_exported | (self) | Get a new dict with the exported variables. | Get a new dict with the exported variables. | def get_exported(self):
"""Get a new dict with the exported variables."""
return dict((k, self.vars[k]) for k in self.exported_vars) | [
"def",
"get_exported",
"(",
"self",
")",
":",
"return",
"dict",
"(",
"(",
"k",
",",
"self",
".",
"vars",
"[",
"k",
"]",
")",
"for",
"k",
"in",
"self",
".",
"exported_vars",
")"
] | [
218,
4
] | [
220,
66
] | python | en | ['en', 'en', 'en'] | True |
Context.get_all | (self) | Return the complete context as dict including the exported
variables. For optimizations reasons this might not return an
actual copy so be careful with using it.
| Return the complete context as dict including the exported
variables. For optimizations reasons this might not return an
actual copy so be careful with using it.
| def get_all(self):
"""Return the complete context as dict including the exported
variables. For optimizations reasons this might not return an
actual copy so be careful with using it.
"""
if not self.vars:
return self.parent
if not self.parent:
re... | [
"def",
"get_all",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"vars",
":",
"return",
"self",
".",
"parent",
"if",
"not",
"self",
".",
"parent",
":",
"return",
"self",
".",
"vars",
"return",
"dict",
"(",
"self",
".",
"parent",
",",
"*",
"*",
... | [
222,
4
] | [
231,
45
] | python | en | ['en', 'en', 'en'] | True |
Context.call | (__self, __obj, *args, **kwargs) | Call the callable with the arguments and keyword arguments
provided but inject the active context or environment as first
argument if the callable is a :func:`contextfunction` or
:func:`environmentfunction`.
| Call the callable with the arguments and keyword arguments
provided but inject the active context or environment as first
argument if the callable is a :func:`contextfunction` or
:func:`environmentfunction`.
| def call(__self, __obj, *args, **kwargs):
"""Call the callable with the arguments and keyword arguments
provided but inject the active context or environment as first
argument if the callable is a :func:`contextfunction` or
:func:`environmentfunction`.
"""
if __debug__:
... | [
"def",
"call",
"(",
"__self",
",",
"__obj",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"__debug__",
":",
"__traceback_hide__",
"=",
"True",
"# noqa",
"# Allow callable classes to take a context",
"if",
"hasattr",
"(",
"__obj",
",",
"'__call__'"... | [
234,
4
] | [
265,
74
] | python | en | ['en', 'en', 'en'] | True |
Context.derived | (self, locals=None) | Internal helper function to create a derived context. This is
used in situations where the system needs a new context in the same
template that is independent.
| Internal helper function to create a derived context. This is
used in situations where the system needs a new context in the same
template that is independent.
| def derived(self, locals=None):
"""Internal helper function to create a derived context. This is
used in situations where the system needs a new context in the same
template that is independent.
"""
context = new_context(self.environment, self.name, {},
... | [
"def",
"derived",
"(",
"self",
",",
"locals",
"=",
"None",
")",
":",
"context",
"=",
"new_context",
"(",
"self",
".",
"environment",
",",
"self",
".",
"name",
",",
"{",
"}",
",",
"self",
".",
"get_all",
"(",
")",
",",
"True",
",",
"None",
",",
"l... | [
267,
4
] | [
276,
22
] | python | en | ['en', 'en', 'en'] | True |
Context.__getitem__ | (self, key) | Lookup a variable or raise `KeyError` if the variable is
undefined.
| Lookup a variable or raise `KeyError` if the variable is
undefined.
| def __getitem__(self, key):
"""Lookup a variable or raise `KeyError` if the variable is
undefined.
"""
item = self.resolve_or_missing(key)
if item is missing:
raise KeyError(key)
return item | [
"def",
"__getitem__",
"(",
"self",
",",
"key",
")",
":",
"item",
"=",
"self",
".",
"resolve_or_missing",
"(",
"key",
")",
"if",
"item",
"is",
"missing",
":",
"raise",
"KeyError",
"(",
"key",
")",
"return",
"item"
] | [
298,
4
] | [
305,
19
] | python | en | ['en', 'en', 'en'] | True |
BlockReference.super | (self) | Super the block. | Super the block. | def super(self):
"""Super the block."""
if self._depth + 1 >= len(self._stack):
return self._context.environment. \
undefined('there is no parent block called %r.' %
self.name, name='super')
return BlockReference(self.name, self._context, sel... | [
"def",
"super",
"(",
"self",
")",
":",
"if",
"self",
".",
"_depth",
"+",
"1",
">=",
"len",
"(",
"self",
".",
"_stack",
")",
":",
"return",
"self",
".",
"_context",
".",
"environment",
".",
"undefined",
"(",
"'there is no parent block called %r.'",
"%",
"... | [
328,
4
] | [
335,
46
] | python | en | ['en', 'la', 'en'] | True |
LoopContextBase.cycle | (self, *args) | Cycles among the arguments with the current loop index. | Cycles among the arguments with the current loop index. | def cycle(self, *args):
"""Cycles among the arguments with the current loop index."""
if not args:
raise TypeError('no items for cycling given')
return args[self.index0 % len(args)] | [
"def",
"cycle",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"not",
"args",
":",
"raise",
"TypeError",
"(",
"'no items for cycling given'",
")",
"return",
"args",
"[",
"self",
".",
"index0",
"%",
"len",
"(",
"args",
")",
"]"
] | [
360,
4
] | [
364,
44
] | python | en | ['en', 'en', 'en'] | True |
LoopContextBase.changed | (self, *value) | Checks whether the value has changed since the last call. | Checks whether the value has changed since the last call. | def changed(self, *value):
"""Checks whether the value has changed since the last call."""
if self._last_checked_value != value:
self._last_checked_value = value
return True
return False | [
"def",
"changed",
"(",
"self",
",",
"*",
"value",
")",
":",
"if",
"self",
".",
"_last_checked_value",
"!=",
"value",
":",
"self",
".",
"_last_checked_value",
"=",
"value",
"return",
"True",
"return",
"False"
] | [
366,
4
] | [
371,
20
] | python | en | ['en', 'en', 'en'] | True |
Macro._invoke | (self, arguments, autoescape) | This method is being swapped out by the async implementation. | This method is being swapped out by the async implementation. | def _invoke(self, arguments, autoescape):
"""This method is being swapped out by the async implementation."""
rv = self._func(*arguments)
if autoescape:
rv = Markup(rv)
return rv | [
"def",
"_invoke",
"(",
"self",
",",
"arguments",
",",
"autoescape",
")",
":",
"rv",
"=",
"self",
".",
"_func",
"(",
"*",
"arguments",
")",
"if",
"autoescape",
":",
"rv",
"=",
"Markup",
"(",
"rv",
")",
"return",
"rv"
] | [
571,
4
] | [
576,
17
] | python | en | ['en', 'en', 'en'] | True |
is_fp_closed | (obj) |
Checks whether a given file-like object is closed.
:param obj:
The file-like object to check.
|
Checks whether a given file-like object is closed. | def is_fp_closed(obj):
"""
Checks whether a given file-like object is closed.
:param obj:
The file-like object to check.
"""
try:
# Check `isclosed()` first, in case Python3 doesn't set `closed`.
# GH Issue #928
return obj.isclosed()
except AttributeError:
... | [
"def",
"is_fp_closed",
"(",
"obj",
")",
":",
"try",
":",
"# Check `isclosed()` first, in case Python3 doesn't set `closed`.",
"# GH Issue #928",
"return",
"obj",
".",
"isclosed",
"(",
")",
"except",
"AttributeError",
":",
"pass",
"try",
":",
"# Check via the official file... | [
8,
0
] | [
36,
65
] | python | en | ['en', 'error', 'th'] | False |
assert_header_parsing | (headers) |
Asserts whether all headers have been successfully parsed.
Extracts encountered errors from the result of parsing headers.
Only works on Python 3.
:param http.client.HTTPMessage headers: Headers to verify.
:raises urllib3.exceptions.HeaderParsingError:
If parsing errors are found.
|
Asserts whether all headers have been successfully parsed.
Extracts encountered errors from the result of parsing headers. | def assert_header_parsing(headers):
"""
Asserts whether all headers have been successfully parsed.
Extracts encountered errors from the result of parsing headers.
Only works on Python 3.
:param http.client.HTTPMessage headers: Headers to verify.
:raises urllib3.exceptions.HeaderParsingError:
... | [
"def",
"assert_header_parsing",
"(",
"headers",
")",
":",
"# This will fail silently if we pass in the wrong kind of parameter.",
"# To make debugging easier add an explicit check.",
"if",
"not",
"isinstance",
"(",
"headers",
",",
"httplib",
".",
"HTTPMessage",
")",
":",
"raise... | [
39,
0
] | [
90,
78
] | python | en | ['en', 'error', 'th'] | False |
is_response_to_head | (response) |
Checks whether the request of a response has been a HEAD-request.
Handles the quirks of AppEngine.
:param http.client.HTTPResponse response:
Response to check if the originating request
used 'HEAD' as a method.
|
Checks whether the request of a response has been a HEAD-request.
Handles the quirks of AppEngine. | def is_response_to_head(response):
"""
Checks whether the request of a response has been a HEAD-request.
Handles the quirks of AppEngine.
:param http.client.HTTPResponse response:
Response to check if the originating request
used 'HEAD' as a method.
"""
# FIXME: Can we do this s... | [
"def",
"is_response_to_head",
"(",
"response",
")",
":",
"# FIXME: Can we do this somehow without accessing private httplib _method?",
"method",
"=",
"response",
".",
"_method",
"if",
"isinstance",
"(",
"method",
",",
"int",
")",
":",
"# Platform-specific: Appengine",
"retu... | [
93,
0
] | [
106,
35
] | python | en | ['en', 'error', 'th'] | False |
test_app | (environ, start_response) | Simple test application that dumps the environment. You can use
it to check if Werkzeug is working properly:
.. sourcecode:: pycon
>>> from werkzeug.serving import run_simple
>>> from werkzeug.testapp import test_app
>>> run_simple('localhost', 3000, test_app)
* Running on ht... | Simple test application that dumps the environment. You can use
it to check if Werkzeug is working properly: | def test_app(environ, start_response):
"""Simple test application that dumps the environment. You can use
it to check if Werkzeug is working properly:
.. sourcecode:: pycon
>>> from werkzeug.serving import run_simple
>>> from werkzeug.testapp import test_app
>>> run_simple('localh... | [
"def",
"test_app",
"(",
"environ",
",",
"start_response",
")",
":",
"req",
"=",
"Request",
"(",
"environ",
",",
"populate_request",
"=",
"False",
")",
"if",
"req",
".",
"args",
".",
"get",
"(",
"\"resource\"",
")",
"==",
"\"logo\"",
":",
"response",
"=",... | [
215,
0
] | [
234,
44
] | python | en | ['en', 'en', 'en'] | True |
init | (argv, name, version, doc, filename, scope=None, parents=[], discovery_filename=None) | A common initialization routine for samples.
Many of the sample applications do the same initialization, which has now
been consolidated into this function. This function uses common idioms found
in almost all the samples, i.e. for an API with name 'apiname', the
credentials are stored in a file named apiname.... | A common initialization routine for samples. | def init(argv, name, version, doc, filename, scope=None, parents=[], discovery_filename=None):
"""A common initialization routine for samples.
Many of the sample applications do the same initialization, which has now
been consolidated into this function. This function uses common idioms found
in almost all the... | [
"def",
"init",
"(",
"argv",
",",
"name",
",",
"version",
",",
"doc",
",",
"filename",
",",
"scope",
"=",
"None",
",",
"parents",
"=",
"[",
"]",
",",
"discovery_filename",
"=",
"None",
")",
":",
"if",
"scope",
"is",
"None",
":",
"scope",
"=",
"'http... | [
34,
0
] | [
102,
25
] | python | en | ['en', 'en', 'en'] | True |
setup | (set_prefix=True) |
Configure the settings (this happens as a side effect of accessing the
first setting), configure logging and populate the app registry.
Set the thread-local urlresolvers script prefix if `set_prefix` is True.
|
Configure the settings (this happens as a side effect of accessing the
first setting), configure logging and populate the app registry.
Set the thread-local urlresolvers script prefix if `set_prefix` is True.
| def setup(set_prefix=True):
"""
Configure the settings (this happens as a side effect of accessing the
first setting), configure logging and populate the app registry.
Set the thread-local urlresolvers script prefix if `set_prefix` is True.
"""
from django.apps import apps
from django.conf i... | [
"def",
"setup",
"(",
"set_prefix",
"=",
"True",
")",
":",
"from",
"django",
".",
"apps",
"import",
"apps",
"from",
"django",
".",
"conf",
"import",
"settings",
"from",
"django",
".",
"urls",
"import",
"set_script_prefix",
"from",
"django",
".",
"utils",
".... | [
7,
0
] | [
23,
42
] | python | en | ['en', 'error', 'th'] | False |
HTMLTokenizer.__iter__ | (self) | This is where the magic happens.
We do our usually processing through the states and when we have a token
to return we yield the token which pauses processing until the next token
is requested.
| This is where the magic happens. | def __iter__(self):
""" This is where the magic happens.
We do our usually processing through the states and when we have a token
to return we yield the token which pauses processing until the next token
is requested.
"""
self.tokenQueue = deque([])
# Start proce... | [
"def",
"__iter__",
"(",
"self",
")",
":",
"self",
".",
"tokenQueue",
"=",
"deque",
"(",
"[",
"]",
")",
"# Start processing. When EOF is reached self.state will return False",
"# instead of True and the loop will terminate.",
"while",
"self",
".",
"state",
"(",
")",
":",... | [
54,
4
] | [
68,
47
] | python | en | ['en', 'en', 'en'] | True |
HTMLTokenizer.consumeNumberEntity | (self, isHex) | This function returns either U+FFFD or the character based on the
decimal or hexadecimal representation. It also discards ";" if present.
If not present self.tokenQueue.append({"type": tokenTypes["ParseError"]}) is invoked.
| This function returns either U+FFFD or the character based on the
decimal or hexadecimal representation. It also discards ";" if present.
If not present self.tokenQueue.append({"type": tokenTypes["ParseError"]}) is invoked.
| def consumeNumberEntity(self, isHex):
"""This function returns either U+FFFD or the character based on the
decimal or hexadecimal representation. It also discards ";" if present.
If not present self.tokenQueue.append({"type": tokenTypes["ParseError"]}) is invoked.
"""
allowed = ... | [
"def",
"consumeNumberEntity",
"(",
"self",
",",
"isHex",
")",
":",
"allowed",
"=",
"digits",
"radix",
"=",
"10",
"if",
"isHex",
":",
"allowed",
"=",
"hexDigits",
"radix",
"=",
"16",
"charStack",
"=",
"[",
"]",
"# Consume all the characters that are in range whil... | [
70,
4
] | [
140,
19
] | python | en | ['en', 'en', 'en'] | True |
HTMLTokenizer.processEntityInAttribute | (self, allowedChar) | This method replaces the need for "entityInAttributeValueState".
| This method replaces the need for "entityInAttributeValueState".
| def processEntityInAttribute(self, allowedChar):
"""This method replaces the need for "entityInAttributeValueState".
"""
self.consumeEntity(allowedChar=allowedChar, fromAttribute=True) | [
"def",
"processEntityInAttribute",
"(",
"self",
",",
"allowedChar",
")",
":",
"self",
".",
"consumeEntity",
"(",
"allowedChar",
"=",
"allowedChar",
",",
"fromAttribute",
"=",
"True",
")"
] | [
222,
4
] | [
225,
71
] | python | en | ['en', 'en', 'en'] | True |
HTMLTokenizer.emitCurrentToken | (self) | This method is a generic handler for emitting the tags. It also sets
the state to "data" because that's what's needed after a token has been
emitted.
| This method is a generic handler for emitting the tags. It also sets
the state to "data" because that's what's needed after a token has been
emitted.
| def emitCurrentToken(self):
"""This method is a generic handler for emitting the tags. It also sets
the state to "data" because that's what's needed after a token has been
emitted.
"""
token = self.currentToken
# Add token to the queue to be yielded
if (token["typ... | [
"def",
"emitCurrentToken",
"(",
"self",
")",
":",
"token",
"=",
"self",
".",
"currentToken",
"# Add token to the queue to be yielded",
"if",
"(",
"token",
"[",
"\"type\"",
"]",
"in",
"tagTokenTypes",
")",
":",
"token",
"[",
"\"name\"",
"]",
"=",
"token",
"[",
... | [
227,
4
] | [
252,
35
] | python | en | ['en', 'en', 'en'] | True |
update_last_login | (sender, user, **kwargs) |
A signal receiver which updates the last_login date for
the user logging in.
|
A signal receiver which updates the last_login date for
the user logging in.
| def update_last_login(sender, user, **kwargs):
"""
A signal receiver which updates the last_login date for
the user logging in.
"""
user.last_login = timezone.now()
user.save(update_fields=['last_login']) | [
"def",
"update_last_login",
"(",
"sender",
",",
"user",
",",
"*",
"*",
"kwargs",
")",
":",
"user",
".",
"last_login",
"=",
"timezone",
".",
"now",
"(",
")",
"user",
".",
"save",
"(",
"update_fields",
"=",
"[",
"'last_login'",
"]",
")"
] | [
15,
0
] | [
21,
43
] | python | en | ['en', 'error', 'th'] | False |
_user_has_perm | (user, perm, obj) |
A backend can raise `PermissionDenied` to short-circuit permission checking.
|
A backend can raise `PermissionDenied` to short-circuit permission checking.
| def _user_has_perm(user, perm, obj):
"""
A backend can raise `PermissionDenied` to short-circuit permission checking.
"""
for backend in auth.get_backends():
if not hasattr(backend, 'has_perm'):
continue
try:
if backend.has_perm(user, perm, obj):
r... | [
"def",
"_user_has_perm",
"(",
"user",
",",
"perm",
",",
"obj",
")",
":",
"for",
"backend",
"in",
"auth",
".",
"get_backends",
"(",
")",
":",
"if",
"not",
"hasattr",
"(",
"backend",
",",
"'has_perm'",
")",
":",
"continue",
"try",
":",
"if",
"backend",
... | [
201,
0
] | [
213,
16
] | python | en | ['en', 'error', 'th'] | False |
_user_has_module_perms | (user, app_label) |
A backend can raise `PermissionDenied` to short-circuit permission checking.
|
A backend can raise `PermissionDenied` to short-circuit permission checking.
| def _user_has_module_perms(user, app_label):
"""
A backend can raise `PermissionDenied` to short-circuit permission checking.
"""
for backend in auth.get_backends():
if not hasattr(backend, 'has_module_perms'):
continue
try:
if backend.has_module_perms(user, app_l... | [
"def",
"_user_has_module_perms",
"(",
"user",
",",
"app_label",
")",
":",
"for",
"backend",
"in",
"auth",
".",
"get_backends",
"(",
")",
":",
"if",
"not",
"hasattr",
"(",
"backend",
",",
"'has_module_perms'",
")",
":",
"continue",
"try",
":",
"if",
"backen... | [
216,
0
] | [
228,
16
] | python | en | ['en', 'error', 'th'] | False |
UserManager._create_user | (self, username, email, password, **extra_fields) |
Create and save a user with the given username, email, and password.
|
Create and save a user with the given username, email, and password.
| def _create_user(self, username, email, password, **extra_fields):
"""
Create and save a user with the given username, email, and password.
"""
if not username:
raise ValueError('The given username must be set')
email = self.normalize_email(email)
# Lookup the... | [
"def",
"_create_user",
"(",
"self",
",",
"username",
",",
"email",
",",
"password",
",",
"*",
"*",
"extra_fields",
")",
":",
"if",
"not",
"username",
":",
"raise",
"ValueError",
"(",
"'The given username must be set'",
")",
"email",
"=",
"self",
".",
"normal... | [
131,
4
] | [
146,
19
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.get_user_permissions | (self, obj=None) |
Return a list of permission strings that this user has directly.
Query all available auth backends. If an object is passed in,
return only permissions matching this object.
|
Return a list of permission strings that this user has directly.
Query all available auth backends. If an object is passed in,
return only permissions matching this object.
| def get_user_permissions(self, obj=None):
"""
Return a list of permission strings that this user has directly.
Query all available auth backends. If an object is passed in,
return only permissions matching this object.
"""
return _user_get_permissions(self, obj, 'user') | [
"def",
"get_user_permissions",
"(",
"self",
",",
"obj",
"=",
"None",
")",
":",
"return",
"_user_get_permissions",
"(",
"self",
",",
"obj",
",",
"'user'",
")"
] | [
267,
4
] | [
273,
55
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.get_group_permissions | (self, obj=None) |
Return a list of permission strings that this user has through their
groups. Query all available auth backends. If an object is passed in,
return only permissions matching this object.
|
Return a list of permission strings that this user has through their
groups. Query all available auth backends. If an object is passed in,
return only permissions matching this object.
| def get_group_permissions(self, obj=None):
"""
Return a list of permission strings that this user has through their
groups. Query all available auth backends. If an object is passed in,
return only permissions matching this object.
"""
return _user_get_permissions(self, o... | [
"def",
"get_group_permissions",
"(",
"self",
",",
"obj",
"=",
"None",
")",
":",
"return",
"_user_get_permissions",
"(",
"self",
",",
"obj",
",",
"'group'",
")"
] | [
275,
4
] | [
281,
56
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.has_perm | (self, perm, obj=None) |
Return True if the user has the specified permission. Query all
available auth backends, but return immediately if any backend returns
True. Thus, a user who has permission from a single auth backend is
assumed to have permission in general. If an object is provided, check
permi... |
Return True if the user has the specified permission. Query all
available auth backends, but return immediately if any backend returns
True. Thus, a user who has permission from a single auth backend is
assumed to have permission in general. If an object is provided, check
permi... | def has_perm(self, perm, obj=None):
"""
Return True if the user has the specified permission. Query all
available auth backends, but return immediately if any backend returns
True. Thus, a user who has permission from a single auth backend is
assumed to have permission in general... | [
"def",
"has_perm",
"(",
"self",
",",
"perm",
",",
"obj",
"=",
"None",
")",
":",
"# Active superusers have all permissions.",
"if",
"self",
".",
"is_active",
"and",
"self",
".",
"is_superuser",
":",
"return",
"True",
"# Otherwise we need to check the backends.",
"ret... | [
286,
4
] | [
299,
46
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.has_perms | (self, perm_list, obj=None) |
Return True if the user has each of the specified permissions. If
object is passed, check if the user has all required perms for it.
|
Return True if the user has each of the specified permissions. If
object is passed, check if the user has all required perms for it.
| def has_perms(self, perm_list, obj=None):
"""
Return True if the user has each of the specified permissions. If
object is passed, check if the user has all required perms for it.
"""
return all(self.has_perm(perm, obj) for perm in perm_list) | [
"def",
"has_perms",
"(",
"self",
",",
"perm_list",
",",
"obj",
"=",
"None",
")",
":",
"return",
"all",
"(",
"self",
".",
"has_perm",
"(",
"perm",
",",
"obj",
")",
"for",
"perm",
"in",
"perm_list",
")"
] | [
301,
4
] | [
306,
66
] | python | en | ['en', 'error', 'th'] | False |
PermissionsMixin.has_module_perms | (self, app_label) |
Return True if the user has any permissions in the given app label.
Use similar logic as has_perm(), above.
|
Return True if the user has any permissions in the given app label.
Use similar logic as has_perm(), above.
| def has_module_perms(self, app_label):
"""
Return True if the user has any permissions in the given app label.
Use similar logic as has_perm(), above.
"""
# Active superusers have all permissions.
if self.is_active and self.is_superuser:
return True
r... | [
"def",
"has_module_perms",
"(",
"self",
",",
"app_label",
")",
":",
"# Active superusers have all permissions.",
"if",
"self",
".",
"is_active",
"and",
"self",
".",
"is_superuser",
":",
"return",
"True",
"return",
"_user_has_module_perms",
"(",
"self",
",",
"app_lab... | [
308,
4
] | [
317,
54
] | python | en | ['en', 'error', 'th'] | False |
AbstractUser.get_full_name | (self) |
Return the first_name plus the last_name, with a space in between.
|
Return the first_name plus the last_name, with a space in between.
| def get_full_name(self):
"""
Return the first_name plus the last_name, with a space in between.
"""
full_name = '%s %s' % (self.first_name, self.last_name)
return full_name.strip() | [
"def",
"get_full_name",
"(",
"self",
")",
":",
"full_name",
"=",
"'%s %s'",
"%",
"(",
"self",
".",
"first_name",
",",
"self",
".",
"last_name",
")",
"return",
"full_name",
".",
"strip",
"(",
")"
] | [
372,
4
] | [
377,
32
] | python | en | ['en', 'error', 'th'] | False |
AbstractUser.get_short_name | (self) | Return the short name for the user. | Return the short name for the user. | def get_short_name(self):
"""Return the short name for the user."""
return self.first_name | [
"def",
"get_short_name",
"(",
"self",
")",
":",
"return",
"self",
".",
"first_name"
] | [
379,
4
] | [
381,
30
] | python | en | ['en', 'no', 'en'] | True |
AbstractUser.email_user | (self, subject, message, from_email=None, **kwargs) | Send an email to this user. | Send an email to this user. | def email_user(self, subject, message, from_email=None, **kwargs):
"""Send an email to this user."""
send_mail(subject, message, from_email, [self.email], **kwargs) | [
"def",
"email_user",
"(",
"self",
",",
"subject",
",",
"message",
",",
"from_email",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"send_mail",
"(",
"subject",
",",
"message",
",",
"from_email",
",",
"[",
"self",
".",
"email",
"]",
",",
"*",
"*",
... | [
383,
4
] | [
385,
71
] | python | en | ['en', 'en', 'en'] | True |
mgf1 | (seed, length, hasher='SHA-1') |
MGF1 is a Mask Generation Function based on a hash function.
A mask generation function takes an octet string of variable length and a
desired output length as input, and outputs an octet string of the desired
length. The plaintext-awareness of RSAES-OAEP relies on the random nature of
the output ... |
MGF1 is a Mask Generation Function based on a hash function. | def mgf1(seed, length, hasher='SHA-1'):
"""
MGF1 is a Mask Generation Function based on a hash function.
A mask generation function takes an octet string of variable length and a
desired output length as input, and outputs an octet string of the desired
length. The plaintext-awareness of RSAES-OAEP... | [
"def",
"mgf1",
"(",
"seed",
",",
"length",
",",
"hasher",
"=",
"'SHA-1'",
")",
":",
"try",
":",
"hash_length",
"=",
"pkcs1",
".",
"HASH_METHODS",
"[",
"hasher",
"]",
"(",
")",
".",
"digest_size",
"except",
"KeyError",
":",
"raise",
"ValueError",
"(",
"... | [
30,
0
] | [
83,
26
] | python | en | ['en', 'error', 'th'] | False |
_request_user_info | (credentials) |
Makes an HTTP request to the Google OAuth2 API to retrieve the user's basic
profile information, including full name and photo, and stores it in the
Flask session.
|
Makes an HTTP request to the Google OAuth2 API to retrieve the user's basic
profile information, including full name and photo, and stores it in the
Flask session.
| def _request_user_info(credentials):
"""
Makes an HTTP request to the Google OAuth2 API to retrieve the user's basic
profile information, including full name and photo, and stores it in the
Flask session.
"""
http = httplib2.Http()
credentials.authorize(http)
resp, content = http.request... | [
"def",
"_request_user_info",
"(",
"credentials",
")",
":",
"http",
"=",
"httplib2",
".",
"Http",
"(",
")",
"credentials",
".",
"authorize",
"(",
"http",
")",
"resp",
",",
"content",
"=",
"http",
".",
"request",
"(",
"'https://www.googleapis.com/oauth2/v3/userinf... | [
108,
0
] | [
124,
60
] | python | en | ['en', 'error', 'th'] | False |
isImageType | (t) |
Checks if an object is an image object.
.. warning::
This function is for internal use only.
:param t: object to check if it's an image
:returns: True if the object is an image
|
Checks if an object is an image object. | def isImageType(t):
"""
Checks if an object is an image object.
.. warning::
This function is for internal use only.
:param t: object to check if it's an image
:returns: True if the object is an image
"""
return hasattr(t, "im") | [
"def",
"isImageType",
"(",
"t",
")",
":",
"return",
"hasattr",
"(",
"t",
",",
"\"im\"",
")"
] | [
148,
0
] | [
159,
27
] | python | en | ['en', 'error', 'th'] | False |
getmodebase | (mode) |
Gets the "base" mode for given mode. This function returns "L" for
images that contain grayscale data, and "RGB" for images that
contain color data.
:param mode: Input mode.
:returns: "L" or "RGB".
:exception KeyError: If the input mode was not a standard mode.
|
Gets the "base" mode for given mode. This function returns "L" for
images that contain grayscale data, and "RGB" for images that
contain color data. | def getmodebase(mode):
"""
Gets the "base" mode for given mode. This function returns "L" for
images that contain grayscale data, and "RGB" for images that
contain color data.
:param mode: Input mode.
:returns: "L" or "RGB".
:exception KeyError: If the input mode was not a standard mode.
... | [
"def",
"getmodebase",
"(",
"mode",
")",
":",
"return",
"ImageMode",
".",
"getmode",
"(",
"mode",
")",
".",
"basemode"
] | [
283,
0
] | [
293,
43
] | python | en | ['en', 'error', 'th'] | False |
getmodetype | (mode) |
Gets the storage type mode. Given a mode, this function returns a
single-layer mode suitable for storing individual bands.
:param mode: Input mode.
:returns: "L", "I", or "F".
:exception KeyError: If the input mode was not a standard mode.
|
Gets the storage type mode. Given a mode, this function returns a
single-layer mode suitable for storing individual bands. | def getmodetype(mode):
"""
Gets the storage type mode. Given a mode, this function returns a
single-layer mode suitable for storing individual bands.
:param mode: Input mode.
:returns: "L", "I", or "F".
:exception KeyError: If the input mode was not a standard mode.
"""
return ImageMod... | [
"def",
"getmodetype",
"(",
"mode",
")",
":",
"return",
"ImageMode",
".",
"getmode",
"(",
"mode",
")",
".",
"basetype"
] | [
296,
0
] | [
305,
43
] | python | en | ['en', 'error', 'th'] | False |
getmodebandnames | (mode) |
Gets a list of individual band names. Given a mode, this function returns
a tuple containing the names of individual bands (use
:py:method:`~PIL.Image.getmodetype` to get the mode used to store each
individual band.
:param mode: Input mode.
:returns: A tuple containing band names. The length... |
Gets a list of individual band names. Given a mode, this function returns
a tuple containing the names of individual bands (use
:py:method:`~PIL.Image.getmodetype` to get the mode used to store each
individual band. | def getmodebandnames(mode):
"""
Gets a list of individual band names. Given a mode, this function returns
a tuple containing the names of individual bands (use
:py:method:`~PIL.Image.getmodetype` to get the mode used to store each
individual band.
:param mode: Input mode.
:returns: A tuple... | [
"def",
"getmodebandnames",
"(",
"mode",
")",
":",
"return",
"ImageMode",
".",
"getmode",
"(",
"mode",
")",
".",
"bands"
] | [
308,
0
] | [
320,
40
] | python | en | ['en', 'error', 'th'] | False |
getmodebands | (mode) |
Gets the number of individual bands for this mode.
:param mode: Input mode.
:returns: The number of bands in this mode.
:exception KeyError: If the input mode was not a standard mode.
|
Gets the number of individual bands for this mode. | def getmodebands(mode):
"""
Gets the number of individual bands for this mode.
:param mode: Input mode.
:returns: The number of bands in this mode.
:exception KeyError: If the input mode was not a standard mode.
"""
return len(ImageMode.getmode(mode).bands) | [
"def",
"getmodebands",
"(",
"mode",
")",
":",
"return",
"len",
"(",
"ImageMode",
".",
"getmode",
"(",
"mode",
")",
".",
"bands",
")"
] | [
323,
0
] | [
331,
45
] | python | en | ['en', 'error', 'th'] | False |
preinit | () | Explicitly load standard file format drivers. | Explicitly load standard file format drivers. | def preinit():
"""Explicitly load standard file format drivers."""
global _initialized
if _initialized >= 1:
return
try:
from . import BmpImagePlugin
assert BmpImagePlugin
except ImportError:
pass
try:
from . import GifImagePlugin
assert GifIma... | [
"def",
"preinit",
"(",
")",
":",
"global",
"_initialized",
"if",
"_initialized",
">=",
"1",
":",
"return",
"try",
":",
"from",
".",
"import",
"BmpImagePlugin",
"assert",
"BmpImagePlugin",
"except",
"ImportError",
":",
"pass",
"try",
":",
"from",
".",
"import... | [
340,
0
] | [
383,
20
] | python | en | ['en', 'en', 'en'] | True |
init | () |
Explicitly initializes the Python Imaging Library. This function
loads all available file format drivers.
|
Explicitly initializes the Python Imaging Library. This function
loads all available file format drivers.
| def init():
"""
Explicitly initializes the Python Imaging Library. This function
loads all available file format drivers.
"""
global _initialized
if _initialized >= 2:
return 0
for plugin in _plugins:
try:
logger.debug("Importing %s", plugin)
__impor... | [
"def",
"init",
"(",
")",
":",
"global",
"_initialized",
"if",
"_initialized",
">=",
"2",
":",
"return",
"0",
"for",
"plugin",
"in",
"_plugins",
":",
"try",
":",
"logger",
".",
"debug",
"(",
"\"Importing %s\"",
",",
"plugin",
")",
"__import__",
"(",
"f\"P... | [
386,
0
] | [
405,
16
] | python | en | ['en', 'error', 'th'] | False |
_wedge | () | Create greyscale wedge (for debugging only) | Create greyscale wedge (for debugging only) | def _wedge():
"""Create greyscale wedge (for debugging only)"""
return Image()._new(core.wedge("L")) | [
"def",
"_wedge",
"(",
")",
":",
"return",
"Image",
"(",
")",
".",
"_new",
"(",
"core",
".",
"wedge",
"(",
"\"L\"",
")",
")"
] | [
2637,
0
] | [
2640,
40
] | python | en | ['en', 'en', 'en'] | True |
_check_size | (size) |
Common check to enforce type and sanity check on size tuples
:param size: Should be a 2 tuple of (width, height)
:returns: True, or raises a ValueError
|
Common check to enforce type and sanity check on size tuples | def _check_size(size):
"""
Common check to enforce type and sanity check on size tuples
:param size: Should be a 2 tuple of (width, height)
:returns: True, or raises a ValueError
"""
if not isinstance(size, (list, tuple)):
raise ValueError("Size must be a tuple")
if len(size) != 2:... | [
"def",
"_check_size",
"(",
"size",
")",
":",
"if",
"not",
"isinstance",
"(",
"size",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"raise",
"ValueError",
"(",
"\"Size must be a tuple\"",
")",
"if",
"len",
"(",
"size",
")",
"!=",
"2",
":",
"raise",
"... | [
2643,
0
] | [
2658,
15
] | python | en | ['en', 'error', 'th'] | False |
new | (mode, size, color=0) |
Creates a new image with the given mode and size.
:param mode: The mode to use for the new image. See:
:ref:`concept-modes`.
:param size: A 2-tuple, containing (width, height) in pixels.
:param color: What color to use for the image. Default is black.
If given, this should be a single i... |
Creates a new image with the given mode and size. | def new(mode, size, color=0):
"""
Creates a new image with the given mode and size.
:param mode: The mode to use for the new image. See:
:ref:`concept-modes`.
:param size: A 2-tuple, containing (width, height) in pixels.
:param color: What color to use for the image. Default is black.
... | [
"def",
"new",
"(",
"mode",
",",
"size",
",",
"color",
"=",
"0",
")",
":",
"_check_size",
"(",
"size",
")",
"if",
"color",
"is",
"None",
":",
"# don't initialize",
"return",
"Image",
"(",
")",
".",
"_new",
"(",
"core",
".",
"new",
"(",
"mode",
",",
... | [
2661,
0
] | [
2697,
48
] | python | en | ['en', 'error', 'th'] | False |
frombytes | (mode, size, data, decoder_name="raw", *args) |
Creates a copy of an image memory from pixel data in a buffer.
In its simplest form, this function takes three arguments
(mode, size, and unpacked pixel data).
You can also use any pixel decoder supported by PIL. For more
information on available decoders, see the section
:ref:`Writing Your ... |
Creates a copy of an image memory from pixel data in a buffer. | def frombytes(mode, size, data, decoder_name="raw", *args):
"""
Creates a copy of an image memory from pixel data in a buffer.
In its simplest form, this function takes three arguments
(mode, size, and unpacked pixel data).
You can also use any pixel decoder supported by PIL. For more
informa... | [
"def",
"frombytes",
"(",
"mode",
",",
"size",
",",
"data",
",",
"decoder_name",
"=",
"\"raw\"",
",",
"*",
"args",
")",
":",
"_check_size",
"(",
"size",
")",
"# may pass tuple instead of argument list",
"if",
"len",
"(",
"args",
")",
"==",
"1",
"and",
"isin... | [
2700,
0
] | [
2735,
13
] | python | en | ['en', 'error', 'th'] | False |
frombuffer | (mode, size, data, decoder_name="raw", *args) |
Creates an image memory referencing pixel data in a byte buffer.
This function is similar to :py:func:`~PIL.Image.frombytes`, but uses data
in the byte buffer, where possible. This means that changes to the
original buffer object are reflected in this image). Not all modes can
share memory; supp... |
Creates an image memory referencing pixel data in a byte buffer. | def frombuffer(mode, size, data, decoder_name="raw", *args):
"""
Creates an image memory referencing pixel data in a byte buffer.
This function is similar to :py:func:`~PIL.Image.frombytes`, but uses data
in the byte buffer, where possible. This means that changes to the
original buffer object are... | [
"def",
"frombuffer",
"(",
"mode",
",",
"size",
",",
"data",
",",
"decoder_name",
"=",
"\"raw\"",
",",
"*",
"args",
")",
":",
"_check_size",
"(",
"size",
")",
"# may pass tuple instead of argument list",
"if",
"len",
"(",
"args",
")",
"==",
"1",
"and",
"isi... | [
2738,
0
] | [
2788,
58
] | python | en | ['en', 'error', 'th'] | False |
fromarray | (obj, mode=None) |
Creates an image memory from an object exporting the array interface
(using the buffer protocol).
If ``obj`` is not contiguous, then the ``tobytes`` method is called
and :py:func:`~PIL.Image.frombuffer` is used.
If you have an image in NumPy::
from PIL import Image
import numpy as np... |
Creates an image memory from an object exporting the array interface
(using the buffer protocol). | def fromarray(obj, mode=None):
"""
Creates an image memory from an object exporting the array interface
(using the buffer protocol).
If ``obj`` is not contiguous, then the ``tobytes`` method is called
and :py:func:`~PIL.Image.frombuffer` is used.
If you have an image in NumPy::
from PIL... | [
"def",
"fromarray",
"(",
"obj",
",",
"mode",
"=",
"None",
")",
":",
"arr",
"=",
"obj",
".",
"__array_interface__",
"shape",
"=",
"arr",
"[",
"\"shape\"",
"]",
"ndim",
"=",
"len",
"(",
"shape",
")",
"strides",
"=",
"arr",
".",
"get",
"(",
"\"strides\"... | [
2791,
0
] | [
2848,
60
] | python | en | ['en', 'error', 'th'] | False |
fromqimage | (im) | Creates an image instance from a QImage image | Creates an image instance from a QImage image | def fromqimage(im):
"""Creates an image instance from a QImage image"""
from . import ImageQt
if not ImageQt.qt_is_installed:
raise ImportError("Qt bindings are not installed")
return ImageQt.fromqimage(im) | [
"def",
"fromqimage",
"(",
"im",
")",
":",
"from",
".",
"import",
"ImageQt",
"if",
"not",
"ImageQt",
".",
"qt_is_installed",
":",
"raise",
"ImportError",
"(",
"\"Qt bindings are not installed\"",
")",
"return",
"ImageQt",
".",
"fromqimage",
"(",
"im",
")"
] | [
2851,
0
] | [
2857,
33
] | python | en | ['en', 'en', 'en'] | True |
fromqpixmap | (im) | Creates an image instance from a QPixmap image | Creates an image instance from a QPixmap image | def fromqpixmap(im):
"""Creates an image instance from a QPixmap image"""
from . import ImageQt
if not ImageQt.qt_is_installed:
raise ImportError("Qt bindings are not installed")
return ImageQt.fromqpixmap(im) | [
"def",
"fromqpixmap",
"(",
"im",
")",
":",
"from",
".",
"import",
"ImageQt",
"if",
"not",
"ImageQt",
".",
"qt_is_installed",
":",
"raise",
"ImportError",
"(",
"\"Qt bindings are not installed\"",
")",
"return",
"ImageQt",
".",
"fromqpixmap",
"(",
"im",
")"
] | [
2860,
0
] | [
2866,
34
] | python | en | ['en', 'en', 'en'] | True |
Image.close | (self) |
Closes the file pointer, if possible.
This operation will destroy the image core and release its memory.
The image data will be unusable afterward.
This function is required to close images that have multiple frames or
have not had their file read and closed by the
:py... |
Closes the file pointer, if possible. | def close(self):
"""
Closes the file pointer, if possible.
This operation will destroy the image core and release its memory.
The image data will be unusable afterward.
This function is required to close images that have multiple frames or
have not had their file read a... | [
"def",
"close",
"(",
"self",
")",
":",
"try",
":",
"if",
"hasattr",
"(",
"self",
",",
"\"_close__fp\"",
")",
":",
"self",
".",
"_close__fp",
"(",
")",
"if",
"self",
".",
"fp",
":",
"self",
".",
"fp",
".",
"close",
"(",
")",
"self",
".",
"fp",
"... | [
586,
4
] | [
613,
73
] | python | en | ['en', 'error', 'th'] | False |
Image._repr_png_ | (self) | iPython display hook support
:returns: png version of the image as bytes
| iPython display hook support | def _repr_png_(self):
"""iPython display hook support
:returns: png version of the image as bytes
"""
b = io.BytesIO()
try:
self.save(b, "PNG")
except Exception as e:
raise ValueError("Could not save to PNG for display") from e
return b.ge... | [
"def",
"_repr_png_",
"(",
"self",
")",
":",
"b",
"=",
"io",
".",
"BytesIO",
"(",
")",
"try",
":",
"self",
".",
"save",
"(",
"b",
",",
"\"PNG\"",
")",
"except",
"Exception",
"as",
"e",
":",
"raise",
"ValueError",
"(",
"\"Could not save to PNG for display\... | [
671,
4
] | [
681,
27
] | python | de | ['de', 'ky', 'en'] | False |
Image.tobytes | (self, encoder_name="raw", *args) |
Return image as a bytes object.
.. warning::
This method returns the raw image data from the internal
storage. For compressed image data (e.g. PNG, JPEG) use
:meth:`~.save`, with a BytesIO parameter for in-memory
data.
:param encoder_name: Wha... |
Return image as a bytes object. | def tobytes(self, encoder_name="raw", *args):
"""
Return image as a bytes object.
.. warning::
This method returns the raw image data from the internal
storage. For compressed image data (e.g. PNG, JPEG) use
:meth:`~.save`, with a BytesIO parameter for in-m... | [
"def",
"tobytes",
"(",
"self",
",",
"encoder_name",
"=",
"\"raw\"",
",",
"*",
"args",
")",
":",
"# may pass tuple instead of argument list",
"if",
"len",
"(",
"args",
")",
"==",
"1",
"and",
"isinstance",
"(",
"args",
"[",
"0",
"]",
",",
"tuple",
")",
":"... | [
719,
4
] | [
760,
29
] | python | en | ['en', 'error', 'th'] | False |
Image.tobitmap | (self, name="image") |
Returns the image converted to an X11 bitmap.
.. note:: This method only works for mode "1" images.
:param name: The name prefix to use for the bitmap variables.
:returns: A string containing an X11 bitmap.
:raises ValueError: If the mode is not "1"
|
Returns the image converted to an X11 bitmap. | def tobitmap(self, name="image"):
"""
Returns the image converted to an X11 bitmap.
.. note:: This method only works for mode "1" images.
:param name: The name prefix to use for the bitmap variables.
:returns: A string containing an X11 bitmap.
:raises ValueError: If th... | [
"def",
"tobitmap",
"(",
"self",
",",
"name",
"=",
"\"image\"",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"self",
".",
"mode",
"!=",
"\"1\"",
":",
"raise",
"ValueError",
"(",
"\"not a bitmap\"",
")",
"data",
"=",
"self",
".",
"tobytes",
"(",
"\"x... | [
762,
4
] | [
785,
9
] | python | en | ['en', 'error', 'th'] | False |
Image.frombytes | (self, data, decoder_name="raw", *args) |
Loads this image with pixel data from a bytes object.
This method is similar to the :py:func:`~PIL.Image.frombytes` function,
but loads data into this image instead of creating a new image object.
|
Loads this image with pixel data from a bytes object. | def frombytes(self, data, decoder_name="raw", *args):
"""
Loads this image with pixel data from a bytes object.
This method is similar to the :py:func:`~PIL.Image.frombytes` function,
but loads data into this image instead of creating a new image object.
"""
# may pass ... | [
"def",
"frombytes",
"(",
"self",
",",
"data",
",",
"decoder_name",
"=",
"\"raw\"",
",",
"*",
"args",
")",
":",
"# may pass tuple instead of argument list",
"if",
"len",
"(",
"args",
")",
"==",
"1",
"and",
"isinstance",
"(",
"args",
"[",
"0",
"]",
",",
"t... | [
787,
4
] | [
811,
56
] | python | en | ['en', 'error', 'th'] | False |
Image.load | (self) |
Allocates storage for the image and loads the pixel data. In
normal cases, you don't need to call this method, since the
Image class automatically loads an opened image when it is
accessed for the first time.
If the file associated with the image was opened by Pillow, then thi... |
Allocates storage for the image and loads the pixel data. In
normal cases, you don't need to call this method, since the
Image class automatically loads an opened image when it is
accessed for the first time. | def load(self):
"""
Allocates storage for the image and loads the pixel data. In
normal cases, you don't need to call this method, since the
Image class automatically loads an opened image when it is
accessed for the first time.
If the file associated with the image was... | [
"def",
"load",
"(",
"self",
")",
":",
"if",
"self",
".",
"im",
"and",
"self",
".",
"palette",
"and",
"self",
".",
"palette",
".",
"dirty",
":",
"# realize palette",
"mode",
",",
"arr",
"=",
"self",
".",
"palette",
".",
"getdata",
"(",
")",
"if",
"m... | [
813,
4
] | [
859,
54
] | python | en | ['en', 'error', 'th'] | False |
Image.verify | (self) |
Verifies the contents of a file. For data read from a file, this
method attempts to determine if the file is broken, without
actually decoding the image data. If this method finds any
problems, it raises suitable exceptions. If you need to load
the image after using this metho... |
Verifies the contents of a file. For data read from a file, this
method attempts to determine if the file is broken, without
actually decoding the image data. If this method finds any
problems, it raises suitable exceptions. If you need to load
the image after using this metho... | def verify(self):
"""
Verifies the contents of a file. For data read from a file, this
method attempts to determine if the file is broken, without
actually decoding the image data. If this method finds any
problems, it raises suitable exceptions. If you need to load
the... | [
"def",
"verify",
"(",
"self",
")",
":",
"pass"
] | [
861,
4
] | [
870,
12
] | python | en | ['en', 'error', 'th'] | False |
Image.convert | (self, mode=None, matrix=None, dither=None, palette=WEB, colors=256) |
Returns a converted copy of this image. For the "P" mode, this
method translates pixels through the palette. If mode is
omitted, a mode is chosen so that all information in the image
and the palette can be represented without a palette.
The current version supports all possibl... |
Returns a converted copy of this image. For the "P" mode, this
method translates pixels through the palette. If mode is
omitted, a mode is chosen so that all information in the image
and the palette can be represented without a palette. | def convert(self, mode=None, matrix=None, dither=None, palette=WEB, colors=256):
"""
Returns a converted copy of this image. For the "P" mode, this
method translates pixels through the palette. If mode is
omitted, a mode is chosen so that all information in the image
and the pal... | [
"def",
"convert",
"(",
"self",
",",
"mode",
"=",
"None",
",",
"matrix",
"=",
"None",
",",
"dither",
"=",
"None",
",",
"palette",
"=",
"WEB",
",",
"colors",
"=",
"256",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"not",
"mode",
"and",
"self",
... | [
872,
4
] | [
1074,
21
] | python | en | ['en', 'error', 'th'] | False |
Image.quantize | (self, colors=256, method=None, kmeans=0, palette=None, dither=1) |
Convert the image to 'P' mode with the specified number
of colors.
:param colors: The desired number of colors, <= 256
:param method: :data:`MEDIANCUT` (median cut),
:data:`MAXCOVERAGE` (maximum coverage),
:data:`FASTOCTREE` (fast octree),
... |
Convert the image to 'P' mode with the specified number
of colors. | def quantize(self, colors=256, method=None, kmeans=0, palette=None, dither=1):
"""
Convert the image to 'P' mode with the specified number
of colors.
:param colors: The desired number of colors, <= 256
:param method: :data:`MEDIANCUT` (median cut),
:data:`... | [
"def",
"quantize",
"(",
"self",
",",
"colors",
"=",
"256",
",",
"method",
"=",
"None",
",",
"kmeans",
"=",
"0",
",",
"palette",
"=",
"None",
",",
"dither",
"=",
"1",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"method",
"is",
"None",
":",
"#... | [
1076,
4
] | [
1139,
17
] | python | en | ['en', 'error', 'th'] | False |
Image.copy | (self) |
Copies this image. Use this method if you wish to paste things
into an image, but still retain the original.
:rtype: :py:class:`~PIL.Image.Image`
:returns: An :py:class:`~PIL.Image.Image` object.
|
Copies this image. Use this method if you wish to paste things
into an image, but still retain the original. | def copy(self):
"""
Copies this image. Use this method if you wish to paste things
into an image, but still retain the original.
:rtype: :py:class:`~PIL.Image.Image`
:returns: An :py:class:`~PIL.Image.Image` object.
"""
self.load()
return self._new(self.i... | [
"def",
"copy",
"(",
"self",
")",
":",
"self",
".",
"load",
"(",
")",
"return",
"self",
".",
"_new",
"(",
"self",
".",
"im",
".",
"copy",
"(",
")",
")"
] | [
1141,
4
] | [
1150,
40
] | python | en | ['en', 'error', 'th'] | False |
Image.crop | (self, box=None) |
Returns a rectangular region from this image. The box is a
4-tuple defining the left, upper, right, and lower pixel
coordinate. See :ref:`coordinate-system`.
Note: Prior to Pillow 3.4.0, this was a lazy operation.
:param box: The crop rectangle, as a (left, upper, right, lower... |
Returns a rectangular region from this image. The box is a
4-tuple defining the left, upper, right, and lower pixel
coordinate. See :ref:`coordinate-system`. | def crop(self, box=None):
"""
Returns a rectangular region from this image. The box is a
4-tuple defining the left, upper, right, and lower pixel
coordinate. See :ref:`coordinate-system`.
Note: Prior to Pillow 3.4.0, this was a lazy operation.
:param box: The crop recta... | [
"def",
"crop",
"(",
"self",
",",
"box",
"=",
"None",
")",
":",
"if",
"box",
"is",
"None",
":",
"return",
"self",
".",
"copy",
"(",
")",
"self",
".",
"load",
"(",
")",
"return",
"self",
".",
"_new",
"(",
"self",
".",
"_crop",
"(",
"self",
".",
... | [
1154,
4
] | [
1171,
50
] | python | en | ['en', 'error', 'th'] | False |
Image._crop | (self, im, box) |
Returns a rectangular region from the core image object im.
This is equivalent to calling im.crop((x0, y0, x1, y1)), but
includes additional sanity checks.
:param im: a core image object
:param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
:returns: ... |
Returns a rectangular region from the core image object im. | def _crop(self, im, box):
"""
Returns a rectangular region from the core image object im.
This is equivalent to calling im.crop((x0, y0, x1, y1)), but
includes additional sanity checks.
:param im: a core image object
:param box: The crop rectangle, as a (left, upper, ri... | [
"def",
"_crop",
"(",
"self",
",",
"im",
",",
"box",
")",
":",
"x0",
",",
"y0",
",",
"x1",
",",
"y1",
"=",
"map",
"(",
"int",
",",
"map",
"(",
"round",
",",
"box",
")",
")",
"absolute_values",
"=",
"(",
"abs",
"(",
"x1",
"-",
"x0",
")",
",",... | [
1173,
4
] | [
1191,
40
] | python | en | ['en', 'error', 'th'] | False |
Image.draft | (self, mode, size) |
Configures the image file loader so it returns a version of the
image that as closely as possible matches the given mode and
size. For example, you can use this method to convert a color
JPEG to greyscale while loading it.
If any changes are made, returns a tuple with the chose... |
Configures the image file loader so it returns a version of the
image that as closely as possible matches the given mode and
size. For example, you can use this method to convert a color
JPEG to greyscale while loading it. | def draft(self, mode, size):
"""
Configures the image file loader so it returns a version of the
image that as closely as possible matches the given mode and
size. For example, you can use this method to convert a color
JPEG to greyscale while loading it.
If any changes ... | [
"def",
"draft",
"(",
"self",
",",
"mode",
",",
"size",
")",
":",
"pass"
] | [
1193,
4
] | [
1213,
12
] | python | en | ['en', 'error', 'th'] | False |
Image.filter | (self, filter) |
Filters this image using the given filter. For a list of
available filters, see the :py:mod:`~PIL.ImageFilter` module.
:param filter: Filter kernel.
:returns: An :py:class:`~PIL.Image.Image` object. |
Filters this image using the given filter. For a list of
available filters, see the :py:mod:`~PIL.ImageFilter` module. | def filter(self, filter):
"""
Filters this image using the given filter. For a list of
available filters, see the :py:mod:`~PIL.ImageFilter` module.
:param filter: Filter kernel.
:returns: An :py:class:`~PIL.Image.Image` object."""
from . import ImageFilter
se... | [
"def",
"filter",
"(",
"self",
",",
"filter",
")",
":",
"from",
".",
"import",
"ImageFilter",
"self",
".",
"load",
"(",
")",
"if",
"isinstance",
"(",
"filter",
",",
"Callable",
")",
":",
"filter",
"=",
"filter",
"(",
")",
"if",
"not",
"hasattr",
"(",
... | [
1221,
4
] | [
1247,
36
] | python | en | ['en', 'error', 'th'] | False |
Image.getbands | (self) |
Returns a tuple containing the name of each band in this image.
For example, ``getbands`` on an RGB image returns ("R", "G", "B").
:returns: A tuple containing band names.
:rtype: tuple
|
Returns a tuple containing the name of each band in this image.
For example, ``getbands`` on an RGB image returns ("R", "G", "B"). | def getbands(self):
"""
Returns a tuple containing the name of each band in this image.
For example, ``getbands`` on an RGB image returns ("R", "G", "B").
:returns: A tuple containing band names.
:rtype: tuple
"""
return ImageMode.getmode(self.mode).bands | [
"def",
"getbands",
"(",
"self",
")",
":",
"return",
"ImageMode",
".",
"getmode",
"(",
"self",
".",
"mode",
")",
".",
"bands"
] | [
1249,
4
] | [
1257,
49
] | python | en | ['en', 'error', 'th'] | False |
Image.getbbox | (self) |
Calculates the bounding box of the non-zero regions in the
image.
:returns: The bounding box is returned as a 4-tuple defining the
left, upper, right, and lower pixel coordinate. See
:ref:`coordinate-system`. If the image is completely empty, this
method return... |
Calculates the bounding box of the non-zero regions in the
image. | def getbbox(self):
"""
Calculates the bounding box of the non-zero regions in the
image.
:returns: The bounding box is returned as a 4-tuple defining the
left, upper, right, and lower pixel coordinate. See
:ref:`coordinate-system`. If the image is completely empty,... | [
"def",
"getbbox",
"(",
"self",
")",
":",
"self",
".",
"load",
"(",
")",
"return",
"self",
".",
"im",
".",
"getbbox",
"(",
")"
] | [
1259,
4
] | [
1272,
32
] | python | en | ['en', 'error', 'th'] | False |
Image.getcolors | (self, maxcolors=256) |
Returns a list of colors used in this image.
The colors will be in the image's mode. For example, an RGB image will
return a tuple of (red, green, blue) color values, and a P image will
return the index of the color in the palette.
:param maxcolors: Maximum number of colors. ... |
Returns a list of colors used in this image. | def getcolors(self, maxcolors=256):
"""
Returns a list of colors used in this image.
The colors will be in the image's mode. For example, an RGB image will
return a tuple of (red, green, blue) color values, and a P image will
return the index of the color in the palette.
... | [
"def",
"getcolors",
"(",
"self",
",",
"maxcolors",
"=",
"256",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"self",
".",
"mode",
"in",
"(",
"\"1\"",
",",
"\"L\"",
",",
"\"P\"",
")",
":",
"h",
"=",
"self",
".",
"im",
".",
"histogram",
"(",
")"... | [
1274,
4
] | [
1298,
43
] | python | en | ['en', 'error', 'th'] | False |
Image.getdata | (self, band=None) |
Returns the contents of this image as a sequence object
containing pixel values. The sequence object is flattened, so
that values for line one follow directly after the values of
line zero, and so on.
Note that the sequence object returned by this method is an
internal... |
Returns the contents of this image as a sequence object
containing pixel values. The sequence object is flattened, so
that values for line one follow directly after the values of
line zero, and so on. | def getdata(self, band=None):
"""
Returns the contents of this image as a sequence object
containing pixel values. The sequence object is flattened, so
that values for line one follow directly after the values of
line zero, and so on.
Note that the sequence object retur... | [
"def",
"getdata",
"(",
"self",
",",
"band",
"=",
"None",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"band",
"is",
"not",
"None",
":",
"return",
"self",
".",
"im",
".",
"getband",
"(",
"band",
")",
"return",
"self",
".",
"im"
] | [
1300,
4
] | [
1321,
22
] | python | en | ['en', 'error', 'th'] | False |
Image.getextrema | (self) |
Gets the the minimum and maximum pixel values for each band in
the image.
:returns: For a single-band image, a 2-tuple containing the
minimum and maximum pixel value. For a multi-band image,
a tuple containing one 2-tuple for each band.
|
Gets the the minimum and maximum pixel values for each band in
the image. | def getextrema(self):
"""
Gets the the minimum and maximum pixel values for each band in
the image.
:returns: For a single-band image, a 2-tuple containing the
minimum and maximum pixel value. For a multi-band image,
a tuple containing one 2-tuple for each band.
... | [
"def",
"getextrema",
"(",
"self",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"self",
".",
"im",
".",
"bands",
">",
"1",
":",
"extrema",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"self",
".",
"im",
".",
"bands",
")",
":",
"extrema",
"... | [
1323,
4
] | [
1339,
35
] | python | en | ['en', 'error', 'th'] | False |
Image.getim | (self) |
Returns a capsule that points to the internal image memory.
:returns: A capsule object.
|
Returns a capsule that points to the internal image memory. | def getim(self):
"""
Returns a capsule that points to the internal image memory.
:returns: A capsule object.
"""
self.load()
return self.im.ptr | [
"def",
"getim",
"(",
"self",
")",
":",
"self",
".",
"load",
"(",
")",
"return",
"self",
".",
"im",
".",
"ptr"
] | [
1398,
4
] | [
1406,
26
] | python | en | ['en', 'error', 'th'] | False |
Image.getpalette | (self) |
Returns the image palette as a list.
:returns: A list of color values [r, g, b, ...], or None if the
image has no palette.
|
Returns the image palette as a list. | def getpalette(self):
"""
Returns the image palette as a list.
:returns: A list of color values [r, g, b, ...], or None if the
image has no palette.
"""
self.load()
try:
return list(self.im.getpalette())
except ValueError:
retu... | [
"def",
"getpalette",
"(",
"self",
")",
":",
"self",
".",
"load",
"(",
")",
"try",
":",
"return",
"list",
"(",
"self",
".",
"im",
".",
"getpalette",
"(",
")",
")",
"except",
"ValueError",
":",
"return",
"None"
] | [
1408,
4
] | [
1420,
23
] | python | en | ['en', 'error', 'th'] | False |
Image.getpixel | (self, xy) |
Returns the pixel value at a given position.
:param xy: The coordinate, given as (x, y). See
:ref:`coordinate-system`.
:returns: The pixel value. If the image is a multi-layer image,
this method returns a tuple.
|
Returns the pixel value at a given position. | def getpixel(self, xy):
"""
Returns the pixel value at a given position.
:param xy: The coordinate, given as (x, y). See
:ref:`coordinate-system`.
:returns: The pixel value. If the image is a multi-layer image,
this method returns a tuple.
"""
sel... | [
"def",
"getpixel",
"(",
"self",
",",
"xy",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"self",
".",
"pyaccess",
":",
"return",
"self",
".",
"pyaccess",
".",
"getpixel",
"(",
"xy",
")",
"return",
"self",
".",
"im",
".",
"getpixel",
"(",
"xy",
"... | [
1422,
4
] | [
1435,
35
] | python | en | ['en', 'error', 'th'] | False |
Image.getprojection | (self) |
Get projection to x and y axes
:returns: Two sequences, indicating where there are non-zero
pixels along the X-axis and the Y-axis, respectively.
|
Get projection to x and y axes | def getprojection(self):
"""
Get projection to x and y axes
:returns: Two sequences, indicating where there are non-zero
pixels along the X-axis and the Y-axis, respectively.
"""
self.load()
x, y = self.im.getprojection()
return list(x), list(y) | [
"def",
"getprojection",
"(",
"self",
")",
":",
"self",
".",
"load",
"(",
")",
"x",
",",
"y",
"=",
"self",
".",
"im",
".",
"getprojection",
"(",
")",
"return",
"list",
"(",
"x",
")",
",",
"list",
"(",
"y",
")"
] | [
1437,
4
] | [
1447,
31
] | python | en | ['en', 'error', 'th'] | False |
Image.histogram | (self, mask=None, extrema=None) |
Returns a histogram for the image. The histogram is returned as
a list of pixel counts, one for each pixel value in the source
image. If the image has more than one band, the histograms for
all bands are concatenated (for example, the histogram for an
"RGB" image contains 768 va... |
Returns a histogram for the image. The histogram is returned as
a list of pixel counts, one for each pixel value in the source
image. If the image has more than one band, the histograms for
all bands are concatenated (for example, the histogram for an
"RGB" image contains 768 va... | def histogram(self, mask=None, extrema=None):
"""
Returns a histogram for the image. The histogram is returned as
a list of pixel counts, one for each pixel value in the source
image. If the image has more than one band, the histograms for
all bands are concatenated (for example,... | [
"def",
"histogram",
"(",
"self",
",",
"mask",
"=",
"None",
",",
"extrema",
"=",
"None",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"mask",
":",
"mask",
".",
"load",
"(",
")",
"return",
"self",
".",
"im",
".",
"histogram",
"(",
"(",
"0",
","... | [
1449,
4
] | [
1477,
34
] | python | en | ['en', 'error', 'th'] | False |
Image.entropy | (self, mask=None, extrema=None) |
Calculates and returns the entropy for the image.
A bilevel image (mode "1") is treated as a greyscale ("L")
image by this method.
If a mask is provided, the method employs the histogram for
those parts of the image where the mask image is non-zero.
The mask image must... |
Calculates and returns the entropy for the image. | def entropy(self, mask=None, extrema=None):
"""
Calculates and returns the entropy for the image.
A bilevel image (mode "1") is treated as a greyscale ("L")
image by this method.
If a mask is provided, the method employs the histogram for
those parts of the image where ... | [
"def",
"entropy",
"(",
"self",
",",
"mask",
"=",
"None",
",",
"extrema",
"=",
"None",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"mask",
":",
"mask",
".",
"load",
"(",
")",
"return",
"self",
".",
"im",
".",
"entropy",
"(",
"(",
"0",
",",
... | [
1479,
4
] | [
1503,
32
] | python | en | ['en', 'error', 'th'] | False |
Image.paste | (self, im, box=None, mask=None) |
Pastes another image into this image. The box argument is either
a 2-tuple giving the upper left corner, a 4-tuple defining the
left, upper, right, and lower pixel coordinate, or None (same as
(0, 0)). See :ref:`coordinate-system`. If a 4-tuple is given, the size
of the pasted i... |
Pastes another image into this image. The box argument is either
a 2-tuple giving the upper left corner, a 4-tuple defining the
left, upper, right, and lower pixel coordinate, or None (same as
(0, 0)). See :ref:`coordinate-system`. If a 4-tuple is given, the size
of the pasted i... | def paste(self, im, box=None, mask=None):
"""
Pastes another image into this image. The box argument is either
a 2-tuple giving the upper left corner, a 4-tuple defining the
left, upper, right, and lower pixel coordinate, or None (same as
(0, 0)). See :ref:`coordinate-system`. If... | [
"def",
"paste",
"(",
"self",
",",
"im",
",",
"box",
"=",
"None",
",",
"mask",
"=",
"None",
")",
":",
"if",
"isImageType",
"(",
"box",
")",
"and",
"mask",
"is",
"None",
":",
"# abbreviated paste(im, mask) syntax",
"mask",
"=",
"box",
"box",
"=",
"None",... | [
1505,
4
] | [
1583,
34
] | python | en | ['en', 'error', 'th'] | False |
Image.alpha_composite | (self, im, dest=(0, 0), source=(0, 0)) | In-place' analog of Image.alpha_composite. Composites an image
onto this image.
:param im: image to composite over this one
:param dest: Optional 2 tuple (left, top) specifying the upper
left corner in this (destination) image.
:param source: Optional 2 (left, top) tuple for t... | In-place' analog of Image.alpha_composite. Composites an image
onto this image. | def alpha_composite(self, im, dest=(0, 0), source=(0, 0)):
"""'In-place' analog of Image.alpha_composite. Composites an image
onto this image.
:param im: image to composite over this one
:param dest: Optional 2 tuple (left, top) specifying the upper
left corner in this (destin... | [
"def",
"alpha_composite",
"(",
"self",
",",
"im",
",",
"dest",
"=",
"(",
"0",
",",
"0",
")",
",",
"source",
"=",
"(",
"0",
",",
"0",
")",
")",
":",
"if",
"not",
"isinstance",
"(",
"source",
",",
"(",
"list",
",",
"tuple",
")",
")",
":",
"rais... | [
1585,
4
] | [
1629,
31
] | python | en | ['en', 'en', 'en'] | True |
Image.point | (self, lut, mode=None) |
Maps this image through a lookup table or function.
:param lut: A lookup table, containing 256 (or 65536 if
self.mode=="I" and mode == "L") values per band in the
image. A function can be used instead, it should take a
single argument. The function is called once for ... |
Maps this image through a lookup table or function. | def point(self, lut, mode=None):
"""
Maps this image through a lookup table or function.
:param lut: A lookup table, containing 256 (or 65536 if
self.mode=="I" and mode == "L") values per band in the
image. A function can be used instead, it should take a
singl... | [
"def",
"point",
"(",
"self",
",",
"lut",
",",
"mode",
"=",
"None",
")",
":",
"self",
".",
"load",
"(",
")",
"if",
"isinstance",
"(",
"lut",
",",
"ImagePointHandler",
")",
":",
"return",
"lut",
".",
"point",
"(",
"self",
")",
"if",
"callable",
"(",
... | [
1631,
4
] | [
1675,
50
] | python | en | ['en', 'error', 'th'] | False |
Image.putalpha | (self, alpha) |
Adds or replaces the alpha layer in this image. If the image
does not have an alpha layer, it's converted to "LA" or "RGBA".
The new layer must be either "L" or "1".
:param alpha: The new alpha layer. This can either be an "L" or "1"
image having the same size as this imag... |
Adds or replaces the alpha layer in this image. If the image
does not have an alpha layer, it's converted to "LA" or "RGBA".
The new layer must be either "L" or "1". | def putalpha(self, alpha):
"""
Adds or replaces the alpha layer in this image. If the image
does not have an alpha layer, it's converted to "LA" or "RGBA".
The new layer must be either "L" or "1".
:param alpha: The new alpha layer. This can either be an "L" or "1"
i... | [
"def",
"putalpha",
"(",
"self",
",",
"alpha",
")",
":",
"self",
".",
"_ensure_mutable",
"(",
")",
"if",
"self",
".",
"mode",
"not",
"in",
"(",
"\"LA\"",
",",
"\"PA\"",
",",
"\"RGBA\"",
")",
":",
"# attempt to promote self to a matching alpha mode",
"try",
":... | [
1677,
4
] | [
1729,
39
] | python | en | ['en', 'error', 'th'] | False |
Image.putdata | (self, data, scale=1.0, offset=0.0) |
Copies pixel data to this image. This method copies data from a
sequence object into the image, starting at the upper left
corner (0, 0), and continuing until either the image or the
sequence ends. The scale and offset values are used to adjust
the sequence values: **pixel = v... |
Copies pixel data to this image. This method copies data from a
sequence object into the image, starting at the upper left
corner (0, 0), and continuing until either the image or the
sequence ends. The scale and offset values are used to adjust
the sequence values: **pixel = v... | def putdata(self, data, scale=1.0, offset=0.0):
"""
Copies pixel data to this image. This method copies data from a
sequence object into the image, starting at the upper left
corner (0, 0), and continuing until either the image or the
sequence ends. The scale and offset values ... | [
"def",
"putdata",
"(",
"self",
",",
"data",
",",
"scale",
"=",
"1.0",
",",
"offset",
"=",
"0.0",
")",
":",
"self",
".",
"_ensure_mutable",
"(",
")",
"self",
".",
"im",
".",
"putdata",
"(",
"data",
",",
"scale",
",",
"offset",
")"
] | [
1731,
4
] | [
1746,
44
] | python | en | ['en', 'error', 'th'] | False |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.