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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
HelpfulArgumentParser.error | (self, message) | Prints a usage message incorporating the message to stderr and
exits.
If you override this in a subclass, it should not return -- it
should either exit or raise an exception.
| Prints a usage message incorporating the message to stderr and
exits.
If you override this in a subclass, it should not return -- it
should either exit or raise an exception.
| def error(self, message): # pragma: nocover
"""Prints a usage message incorporating the message to stderr and
exits.
If you override this in a subclass, it should not return -- it
should either exit or raise an exception.
"""
self.print_help(sys.stderr)
self._pri... | [
"def",
"error",
"(",
"self",
",",
"message",
")",
":",
"# pragma: nocover",
"self",
".",
"print_help",
"(",
"sys",
".",
"stderr",
")",
"self",
".",
"_print_message",
"(",
"'\\n'",
")",
"self",
".",
"exit",
"(",
"2",
",",
"'%s: %s\\n'",
"%",
"(",
"self"... | [
32,
4
] | [
40,
55
] | python | en | ['en', 'en', 'en'] | True |
constant | (image, value) | Fill a channel with a given grey level.
:rtype: :py:class:`~PIL.Image.Image`
| Fill a channel with a given grey level. | def constant(image, value):
"""Fill a channel with a given grey level.
:rtype: :py:class:`~PIL.Image.Image`
"""
return Image.new("L", image.size, value) | [
"def",
"constant",
"(",
"image",
",",
"value",
")",
":",
"return",
"Image",
".",
"new",
"(",
"\"L\"",
",",
"image",
".",
"size",
",",
"value",
")"
] | [
20,
0
] | [
26,
44
] | python | en | ['en', 'en', 'en'] | True |
duplicate | (image) | Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`.
:rtype: :py:class:`~PIL.Image.Image`
| Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`. | def duplicate(image):
"""Copy a channel. Alias for :py:meth:`PIL.Image.Image.copy`.
:rtype: :py:class:`~PIL.Image.Image`
"""
return image.copy() | [
"def",
"duplicate",
"(",
"image",
")",
":",
"return",
"image",
".",
"copy",
"(",
")"
] | [
29,
0
] | [
35,
23
] | python | en | ['en', 'fr', 'en'] | True |
invert | (image) |
Invert an image (channel).
.. code-block:: python
out = MAX - image
:rtype: :py:class:`~PIL.Image.Image`
|
Invert an image (channel). | def invert(image):
"""
Invert an image (channel).
.. code-block:: python
out = MAX - image
:rtype: :py:class:`~PIL.Image.Image`
"""
image.load()
return image._new(image.im.chop_invert()) | [
"def",
"invert",
"(",
"image",
")",
":",
"image",
".",
"load",
"(",
")",
"return",
"image",
".",
"_new",
"(",
"image",
".",
"im",
".",
"chop_invert",
"(",
")",
")"
] | [
38,
0
] | [
50,
45
] | python | en | ['en', 'error', 'th'] | False |
lighter | (image1, image2) |
Compares the two images, pixel by pixel, and returns a new image containing
the lighter values.
.. code-block:: python
out = max(image1, image2)
:rtype: :py:class:`~PIL.Image.Image`
|
Compares the two images, pixel by pixel, and returns a new image containing
the lighter values. | def lighter(image1, image2):
"""
Compares the two images, pixel by pixel, and returns a new image containing
the lighter values.
.. code-block:: python
out = max(image1, image2)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1... | [
"def",
"lighter",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_lighter",
"(",
"image2",
".",
"im",
")",
")"
] | [
53,
0
] | [
67,
57
] | python | en | ['en', 'error', 'th'] | False |
darker | (image1, image2) |
Compares the two images, pixel by pixel, and returns a new image containing
the darker values.
.. code-block:: python
out = min(image1, image2)
:rtype: :py:class:`~PIL.Image.Image`
|
Compares the two images, pixel by pixel, and returns a new image containing
the darker values. | def darker(image1, image2):
"""
Compares the two images, pixel by pixel, and returns a new image containing
the darker values.
.. code-block:: python
out = min(image1, image2)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.i... | [
"def",
"darker",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_darker",
"(",
"image2",
".",
"im",
")",
")"
] | [
70,
0
] | [
84,
56
] | python | en | ['en', 'error', 'th'] | False |
difference | (image1, image2) |
Returns the absolute value of the pixel-by-pixel difference between the two
images.
.. code-block:: python
out = abs(image1 - image2)
:rtype: :py:class:`~PIL.Image.Image`
|
Returns the absolute value of the pixel-by-pixel difference between the two
images. | def difference(image1, image2):
"""
Returns the absolute value of the pixel-by-pixel difference between the two
images.
.. code-block:: python
out = abs(image1 - image2)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop... | [
"def",
"difference",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_difference",
"(",
"image2",
".",
"im",
")",
")"
] | [
87,
0
] | [
101,
60
] | python | en | ['en', 'error', 'th'] | False |
multiply | (image1, image2) |
Superimposes two images on top of each other.
If you multiply an image with a solid black image, the result is black. If
you multiply with a solid white image, the image is unaffected.
.. code-block:: python
out = image1 * image2 / MAX
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two images on top of each other. | def multiply(image1, image2):
"""
Superimposes two images on top of each other.
If you multiply an image with a solid black image, the result is black. If
you multiply with a solid white image, the image is unaffected.
.. code-block:: python
out = image1 * image2 / MAX
:rtype: :py:cl... | [
"def",
"multiply",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_multiply",
"(",
"image2",
".",
"im",
")",
")"
] | [
104,
0
] | [
120,
58
] | python | en | ['en', 'error', 'th'] | False |
screen | (image1, image2) |
Superimposes two inverted images on top of each other.
.. code-block:: python
out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two inverted images on top of each other. | def screen(image1, image2):
"""
Superimposes two inverted images on top of each other.
.. code-block:: python
out = MAX - ((MAX - image1) * (MAX - image2) / MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_screen(imag... | [
"def",
"screen",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_screen",
"(",
"image2",
".",
"im",
")",
")"
] | [
123,
0
] | [
136,
56
] | python | en | ['en', 'error', 'th'] | False |
soft_light | (image1, image2) |
Superimposes two images on top of each other using the Soft Light algorithm
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two images on top of each other using the Soft Light algorithm | def soft_light(image1, image2):
"""
Superimposes two images on top of each other using the Soft Light algorithm
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_soft_light(image2.im)) | [
"def",
"soft_light",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_soft_light",
"(",
"image2",
".",
"im",
")",
")"
] | [
139,
0
] | [
148,
60
] | python | en | ['en', 'error', 'th'] | False |
hard_light | (image1, image2) |
Superimposes two images on top of each other using the Hard Light algorithm
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two images on top of each other using the Hard Light algorithm | def hard_light(image1, image2):
"""
Superimposes two images on top of each other using the Hard Light algorithm
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_hard_light(image2.im)) | [
"def",
"hard_light",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_hard_light",
"(",
"image2",
".",
"im",
")",
")"
] | [
151,
0
] | [
160,
60
] | python | en | ['en', 'error', 'th'] | False |
overlay | (image1, image2) |
Superimposes two images on top of each other using the Overlay algorithm
:rtype: :py:class:`~PIL.Image.Image`
|
Superimposes two images on top of each other using the Overlay algorithm | def overlay(image1, image2):
"""
Superimposes two images on top of each other using the Overlay algorithm
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_overlay(image2.im)) | [
"def",
"overlay",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_overlay",
"(",
"image2",
".",
"im",
")",
")"
] | [
163,
0
] | [
172,
57
] | python | en | ['en', 'error', 'th'] | False |
add | (image1, image2, scale=1.0, offset=0) |
Adds two images, dividing the result by scale and adding the
offset. If omitted, scale defaults to 1.0, and offset to 0.0.
.. code-block:: python
out = ((image1 + image2) / scale + offset)
:rtype: :py:class:`~PIL.Image.Image`
|
Adds two images, dividing the result by scale and adding the
offset. If omitted, scale defaults to 1.0, and offset to 0.0. | def add(image1, image2, scale=1.0, offset=0):
"""
Adds two images, dividing the result by scale and adding the
offset. If omitted, scale defaults to 1.0, and offset to 0.0.
.. code-block:: python
out = ((image1 + image2) / scale + offset)
:rtype: :py:class:`~PIL.Image.Image`
"""
... | [
"def",
"add",
"(",
"image1",
",",
"image2",
",",
"scale",
"=",
"1.0",
",",
"offset",
"=",
"0",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_add",... | [
175,
0
] | [
189,
68
] | python | en | ['en', 'error', 'th'] | False |
subtract | (image1, image2, scale=1.0, offset=0) |
Subtracts two images, dividing the result by scale and adding the offset.
If omitted, scale defaults to 1.0, and offset to 0.0.
.. code-block:: python
out = ((image1 - image2) / scale + offset)
:rtype: :py:class:`~PIL.Image.Image`
|
Subtracts two images, dividing the result by scale and adding the offset.
If omitted, scale defaults to 1.0, and offset to 0.0. | def subtract(image1, image2, scale=1.0, offset=0):
"""
Subtracts two images, dividing the result by scale and adding the offset.
If omitted, scale defaults to 1.0, and offset to 0.0.
.. code-block:: python
out = ((image1 - image2) / scale + offset)
:rtype: :py:class:`~PIL.Image.Image`
... | [
"def",
"subtract",
"(",
"image1",
",",
"image2",
",",
"scale",
"=",
"1.0",
",",
"offset",
"=",
"0",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_... | [
192,
0
] | [
206,
73
] | python | en | ['en', 'error', 'th'] | False |
add_modulo | (image1, image2) | Add two images, without clipping the result.
.. code-block:: python
out = ((image1 + image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
| Add two images, without clipping the result. | def add_modulo(image1, image2):
"""Add two images, without clipping the result.
.. code-block:: python
out = ((image1 + image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_add_modulo(image2.im)) | [
"def",
"add_modulo",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_add_modulo",
"(",
"image2",
".",
"im",
")",
")"
] | [
209,
0
] | [
221,
60
] | python | en | ['en', 'en', 'en'] | True |
subtract_modulo | (image1, image2) | Subtract two images, without clipping the result.
.. code-block:: python
out = ((image1 - image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
| Subtract two images, without clipping the result. | def subtract_modulo(image1, image2):
"""Subtract two images, without clipping the result.
.. code-block:: python
out = ((image1 - image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_subtract_modulo(image2.im)) | [
"def",
"subtract_modulo",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_subtract_modulo",
"(",
"image2",
".",
"im",
")",
... | [
224,
0
] | [
236,
65
] | python | en | ['en', 'en', 'en'] | True |
logical_and | (image1, image2) | Logical AND between two images.
Both of the images must have mode "1". If you would like to perform a
logical AND on an image with a mode other than "1", try
:py:meth:`~PIL.ImageChops.multiply` instead, using a black-and-white mask
as the second image.
.. code-block:: python
out = ((image... | Logical AND between two images. | def logical_and(image1, image2):
"""Logical AND between two images.
Both of the images must have mode "1". If you would like to perform a
logical AND on an image with a mode other than "1", try
:py:meth:`~PIL.ImageChops.multiply` instead, using a black-and-white mask
as the second image.
.. co... | [
"def",
"logical_and",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_and",
"(",
"image2",
".",
"im",
")",
")"
] | [
239,
0
] | [
256,
53
] | python | en | ['en', 'en', 'en'] | True |
logical_or | (image1, image2) | Logical OR between two images.
Both of the images must have mode "1".
.. code-block:: python
out = ((image1 or image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
| Logical OR between two images. | def logical_or(image1, image2):
"""Logical OR between two images.
Both of the images must have mode "1".
.. code-block:: python
out = ((image1 or image2) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.chop_or(image2.i... | [
"def",
"logical_or",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_or",
"(",
"image2",
".",
"im",
")",
")"
] | [
259,
0
] | [
273,
52
] | python | en | ['en', 'en', 'en'] | True |
logical_xor | (image1, image2) | Logical XOR between two images.
Both of the images must have mode "1".
.. code-block:: python
out = ((bool(image1) != bool(image2)) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
| Logical XOR between two images. | def logical_xor(image1, image2):
"""Logical XOR between two images.
Both of the images must have mode "1".
.. code-block:: python
out = ((bool(image1) != bool(image2)) % MAX)
:rtype: :py:class:`~PIL.Image.Image`
"""
image1.load()
image2.load()
return image1._new(image1.im.ch... | [
"def",
"logical_xor",
"(",
"image1",
",",
"image2",
")",
":",
"image1",
".",
"load",
"(",
")",
"image2",
".",
"load",
"(",
")",
"return",
"image1",
".",
"_new",
"(",
"image1",
".",
"im",
".",
"chop_xor",
"(",
"image2",
".",
"im",
")",
")"
] | [
276,
0
] | [
290,
53
] | python | en | ['en', 'en', 'en'] | True |
blend | (image1, image2, alpha) | Blend images using constant transparency weight. Alias for
:py:func:`PIL.Image.blend`.
:rtype: :py:class:`~PIL.Image.Image`
| Blend images using constant transparency weight. Alias for
:py:func:`PIL.Image.blend`. | def blend(image1, image2, alpha):
"""Blend images using constant transparency weight. Alias for
:py:func:`PIL.Image.blend`.
:rtype: :py:class:`~PIL.Image.Image`
"""
return Image.blend(image1, image2, alpha) | [
"def",
"blend",
"(",
"image1",
",",
"image2",
",",
"alpha",
")",
":",
"return",
"Image",
".",
"blend",
"(",
"image1",
",",
"image2",
",",
"alpha",
")"
] | [
293,
0
] | [
300,
45
] | python | en | ['en', 'en', 'en'] | True |
composite | (image1, image2, mask) | Create composite using transparency mask. Alias for
:py:func:`PIL.Image.composite`.
:rtype: :py:class:`~PIL.Image.Image`
| Create composite using transparency mask. Alias for
:py:func:`PIL.Image.composite`. | def composite(image1, image2, mask):
"""Create composite using transparency mask. Alias for
:py:func:`PIL.Image.composite`.
:rtype: :py:class:`~PIL.Image.Image`
"""
return Image.composite(image1, image2, mask) | [
"def",
"composite",
"(",
"image1",
",",
"image2",
",",
"mask",
")",
":",
"return",
"Image",
".",
"composite",
"(",
"image1",
",",
"image2",
",",
"mask",
")"
] | [
303,
0
] | [
310,
48
] | python | en | ['en', 'en', 'en'] | True |
offset | (image, xoffset, yoffset=None) | Returns a copy of the image where data has been offset by the given
distances. Data wraps around the edges. If ``yoffset`` is omitted, it
is assumed to be equal to ``xoffset``.
:param xoffset: The horizontal distance.
:param yoffset: The vertical distance. If omitted, both
distances are set to... | Returns a copy of the image where data has been offset by the given
distances. Data wraps around the edges. If ``yoffset`` is omitted, it
is assumed to be equal to ``xoffset``. | def offset(image, xoffset, yoffset=None):
"""Returns a copy of the image where data has been offset by the given
distances. Data wraps around the edges. If ``yoffset`` is omitted, it
is assumed to be equal to ``xoffset``.
:param xoffset: The horizontal distance.
:param yoffset: The vertical distanc... | [
"def",
"offset",
"(",
"image",
",",
"xoffset",
",",
"yoffset",
"=",
"None",
")",
":",
"if",
"yoffset",
"is",
"None",
":",
"yoffset",
"=",
"xoffset",
"image",
".",
"load",
"(",
")",
"return",
"image",
".",
"_new",
"(",
"image",
".",
"im",
".",
"offs... | [
313,
0
] | [
327,
56
] | python | en | ['en', 'en', 'en'] | True |
to_genshi | (walker) | Convert a tree to a genshi tree
:arg walker: the treewalker to use to walk the tree to convert it
:returns: generator of genshi nodes
| Convert a tree to a genshi tree | def to_genshi(walker):
"""Convert a tree to a genshi tree
:arg walker: the treewalker to use to walk the tree to convert it
:returns: generator of genshi nodes
"""
text = []
for token in walker:
type = token["type"]
if type in ("Characters", "SpaceCharacters"):
tex... | [
"def",
"to_genshi",
"(",
"walker",
")",
":",
"text",
"=",
"[",
"]",
"for",
"token",
"in",
"walker",
":",
"type",
"=",
"token",
"[",
"\"type\"",
"]",
"if",
"type",
"in",
"(",
"\"Characters\"",
",",
"\"SpaceCharacters\"",
")",
":",
"text",
".",
"append",... | [
6,
0
] | [
53,
49
] | python | en | ['en', 'mk', 'en'] | True |
current_umask | () | Get the current umask which involves having to set it temporarily. | Get the current umask which involves having to set it temporarily. | def current_umask():
# type: () -> int
"""Get the current umask which involves having to set it temporarily."""
mask = os.umask(0)
os.umask(mask)
return mask | [
"def",
"current_umask",
"(",
")",
":",
"# type: () -> int",
"mask",
"=",
"os",
".",
"umask",
"(",
"0",
")",
"os",
".",
"umask",
"(",
"mask",
")",
"return",
"mask"
] | [
46,
0
] | [
51,
15
] | python | en | ['en', 'en', 'en'] | True |
has_leading_dir | (paths) | Returns true if all the paths have the same leading path name
(i.e., everything is in one subdirectory in an archive) | Returns true if all the paths have the same leading path name
(i.e., everything is in one subdirectory in an archive) | def has_leading_dir(paths):
# type: (Iterable[Union[str, Text]]) -> bool
"""Returns true if all the paths have the same leading path name
(i.e., everything is in one subdirectory in an archive)"""
common_prefix = None
for path in paths:
prefix, rest = split_leading_dir(path)
if not p... | [
"def",
"has_leading_dir",
"(",
"paths",
")",
":",
"# type: (Iterable[Union[str, Text]]) -> bool",
"common_prefix",
"=",
"None",
"for",
"path",
"in",
"paths",
":",
"prefix",
",",
"rest",
"=",
"split_leading_dir",
"(",
"path",
")",
"if",
"not",
"prefix",
":",
"ret... | [
70,
0
] | [
83,
15
] | python | en | ['en', 'en', 'en'] | True |
is_within_directory | (directory, target) |
Return true if the absolute path of target is within the directory
|
Return true if the absolute path of target is within the directory
| def is_within_directory(directory, target):
# type: ((Union[str, Text]), (Union[str, Text])) -> bool
"""
Return true if the absolute path of target is within the directory
"""
abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)
prefix = os.path.commonprefix([abs_... | [
"def",
"is_within_directory",
"(",
"directory",
",",
"target",
")",
":",
"# type: ((Union[str, Text]), (Union[str, Text])) -> bool",
"abs_directory",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"directory",
")",
"abs_target",
"=",
"os",
".",
"path",
".",
"abspath",... | [
86,
0
] | [
95,
34
] | python | en | ['en', 'error', 'th'] | False |
set_extracted_file_to_default_mode_plus_executable | (path) |
Make file present at path have execute for user/group/world
(chmod +x) is no-op on windows per python docs
|
Make file present at path have execute for user/group/world
(chmod +x) is no-op on windows per python docs
| def set_extracted_file_to_default_mode_plus_executable(path):
# type: (Union[str, Text]) -> None
"""
Make file present at path have execute for user/group/world
(chmod +x) is no-op on windows per python docs
"""
os.chmod(path, (0o777 & ~current_umask() | 0o111)) | [
"def",
"set_extracted_file_to_default_mode_plus_executable",
"(",
"path",
")",
":",
"# type: (Union[str, Text]) -> None",
"os",
".",
"chmod",
"(",
"path",
",",
"(",
"0o777",
"&",
"~",
"current_umask",
"(",
")",
"|",
"0o111",
")",
")"
] | [
98,
0
] | [
104,
54
] | python | en | ['en', 'error', 'th'] | False |
unzip_file | (filename, location, flatten=True) |
Unzip the file (with path `filename`) to the destination `location`. All
files are written based on system defaults and umask (i.e. permissions are
not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written. Not... |
Unzip the file (with path `filename`) to the destination `location`. All
files are written based on system defaults and umask (i.e. permissions are
not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written. Not... | def unzip_file(filename, location, flatten=True):
# type: (str, str, bool) -> None
"""
Unzip the file (with path `filename`) to the destination `location`. All
files are written based on system defaults and umask (i.e. permissions are
not preserved), except that regular file members with any execut... | [
"def",
"unzip_file",
"(",
"filename",
",",
"location",
",",
"flatten",
"=",
"True",
")",
":",
"# type: (str, str, bool) -> None",
"ensure_dir",
"(",
"location",
")",
"zipfp",
"=",
"open",
"(",
"filename",
",",
"'rb'",
")",
"try",
":",
"zip",
"=",
"zipfile",
... | [
115,
0
] | [
159,
21
] | python | en | ['en', 'error', 'th'] | False |
untar_file | (filename, location) |
Untar the file (with path `filename`) to the destination `location`.
All files are written based on system defaults and umask (i.e. permissions
are not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written. Not... |
Untar the file (with path `filename`) to the destination `location`.
All files are written based on system defaults and umask (i.e. permissions
are not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written. Not... | def untar_file(filename, location):
# type: (str, str) -> None
"""
Untar the file (with path `filename`) to the destination `location`.
All files are written based on system defaults and umask (i.e. permissions
are not preserved), except that regular file members with any execute
permissions (us... | [
"def",
"untar_file",
"(",
"filename",
",",
"location",
")",
":",
"# type: (str, str) -> None",
"ensure_dir",
"(",
"location",
")",
"if",
"filename",
".",
"lower",
"(",
")",
".",
"endswith",
"(",
"'.gz'",
")",
"or",
"filename",
".",
"lower",
"(",
")",
".",
... | [
162,
0
] | [
242,
19
] | python | en | ['en', 'error', 'th'] | False |
api_github_webhook | (
request: HttpRequest,
user_profile: UserProfile,
payload: Dict[str, Any] = REQ(argument_type="body"),
branches: Optional[str] = REQ(default=None),
user_specified_topic: Optional[str] = REQ("topic", default=None),
) |
GitHub sends the event as an HTTP header. We have our
own Zulip-specific concept of an event that often maps
directly to the X_GITHUB_EVENT header's event, but we sometimes
refine it based on the payload.
|
GitHub sends the event as an HTTP header. We have our
own Zulip-specific concept of an event that often maps
directly to the X_GITHUB_EVENT header's event, but we sometimes
refine it based on the payload.
| def api_github_webhook(
request: HttpRequest,
user_profile: UserProfile,
payload: Dict[str, Any] = REQ(argument_type="body"),
branches: Optional[str] = REQ(default=None),
user_specified_topic: Optional[str] = REQ("topic", default=None),
) -> HttpResponse:
"""
GitHub sends the event as an HTT... | [
"def",
"api_github_webhook",
"(",
"request",
":",
"HttpRequest",
",",
"user_profile",
":",
"UserProfile",
",",
"payload",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
"=",
"REQ",
"(",
"argument_type",
"=",
"\"body\"",
")",
",",
"branches",
":",
"Optional",
"[... | [
677,
0
] | [
712,
25
] | python | en | ['en', 'error', 'th'] | False |
get_zulip_event_name | (
header_event: str,
payload: Dict[str, Any],
branches: Optional[str],
) |
Usually, we return an event name that is a key in EVENT_FUNCTION_MAPPER.
We return None for an event that we know we don't want to handle.
|
Usually, we return an event name that is a key in EVENT_FUNCTION_MAPPER. | def get_zulip_event_name(
header_event: str,
payload: Dict[str, Any],
branches: Optional[str],
) -> Optional[str]:
"""
Usually, we return an event name that is a key in EVENT_FUNCTION_MAPPER.
We return None for an event that we know we don't want to handle.
"""
if header_event == "pull_... | [
"def",
"get_zulip_event_name",
"(",
"header_event",
":",
"str",
",",
"payload",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
",",
"branches",
":",
"Optional",
"[",
"str",
"]",
",",
")",
"->",
"Optional",
"[",
"str",
"]",
":",
"if",
"header_event",
"==",
... | [
715,
0
] | [
773,
53
] | python | en | ['en', 'error', 'th'] | False |
SessionStorage._get | (self, *args, **kwargs) |
Retrieves a list of messages from the request's session. This storage
always stores everything it is given, so return True for the
all_retrieved flag.
|
Retrieves a list of messages from the request's session. This storage
always stores everything it is given, so return True for the
all_retrieved flag.
| def _get(self, *args, **kwargs):
"""
Retrieves a list of messages from the request's session. This storage
always stores everything it is given, so return True for the
all_retrieved flag.
"""
return self.deserialize_messages(self.request.session.get(self.session_key)), T... | [
"def",
"_get",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"deserialize_messages",
"(",
"self",
".",
"request",
".",
"session",
".",
"get",
"(",
"self",
".",
"session_key",
")",
")",
",",
"True"
] | [
23,
4
] | [
29,
90
] | python | en | ['en', 'error', 'th'] | False |
SessionStorage._store | (self, messages, response, *args, **kwargs) |
Stores a list of messages to the request's session.
|
Stores a list of messages to the request's session.
| def _store(self, messages, response, *args, **kwargs):
"""
Stores a list of messages to the request's session.
"""
if messages:
self.request.session[self.session_key] = self.serialize_messages(messages)
else:
self.request.session.pop(self.session_key, None... | [
"def",
"_store",
"(",
"self",
",",
"messages",
",",
"response",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"messages",
":",
"self",
".",
"request",
".",
"session",
"[",
"self",
".",
"session_key",
"]",
"=",
"self",
".",
"serialize_mes... | [
31,
4
] | [
39,
17
] | python | en | ['en', 'error', 'th'] | False |
ResourceOptionsParser.__init__ | (self, v2, page, resource, parser) | Used to submit an OPTIONS request to the appropriate endpoint
and apply the appropriate argparse arguments
:param v2: a awxkit.api.pages.page.TentativePage instance
:param page: a awxkit.api.pages.page.TentativePage instance
:param resource: a string containing the resource (e.g., jobs)... | Used to submit an OPTIONS request to the appropriate endpoint
and apply the appropriate argparse arguments | def __init__(self, v2, page, resource, parser):
"""Used to submit an OPTIONS request to the appropriate endpoint
and apply the appropriate argparse arguments
:param v2: a awxkit.api.pages.page.TentativePage instance
:param page: a awxkit.api.pages.page.TentativePage instance
:pa... | [
"def",
"__init__",
"(",
"self",
",",
"v2",
",",
"page",
",",
"resource",
",",
"parser",
")",
":",
"self",
".",
"v2",
"=",
"v2",
"self",
".",
"page",
"=",
"page",
"self",
".",
"resource",
"=",
"resource",
"self",
".",
"parser",
"=",
"parser",
"self"... | [
68,
4
] | [
89,
36
] | python | en | ['en', 'en', 'en'] | True |
normalize | (mx) | Row-normalize sparse matrix | Row-normalize sparse matrix | def normalize(mx):
"""Row-normalize sparse matrix"""
rowsum = np.array(mx.sum(1))
rowsum = (rowsum==0)*1+rowsum
r_inv = np.power(rowsum, -1).flatten()
r_inv[np.isinf(r_inv)] = 0.
r_mat_inv = sp.diags(r_inv)
mx = r_mat_inv.dot(mx)
return mx | [
"def",
"normalize",
"(",
"mx",
")",
":",
"rowsum",
"=",
"np",
".",
"array",
"(",
"mx",
".",
"sum",
"(",
"1",
")",
")",
"rowsum",
"=",
"(",
"rowsum",
"==",
"0",
")",
"*",
"1",
"+",
"rowsum",
"r_inv",
"=",
"np",
".",
"power",
"(",
"rowsum",
","... | [
18,
0
] | [
26,
13
] | python | en | ['en', 'en', 'tr'] | True |
sparse_mx_to_torch_sparse_tensor | (sparse_mx) | Convert a scipy sparse matrix to a torch sparse tensor. | Convert a scipy sparse matrix to a torch sparse tensor. | def sparse_mx_to_torch_sparse_tensor(sparse_mx):
"""Convert a scipy sparse matrix to a torch sparse tensor."""
sparse_mx = sparse_mx.tocoo().astype(np.float32)
indices = torch.from_numpy(
np.vstack((sparse_mx.row, sparse_mx.col)).astype(np.int64))
values = torch.from_numpy(sparse_mx.data)
sh... | [
"def",
"sparse_mx_to_torch_sparse_tensor",
"(",
"sparse_mx",
")",
":",
"sparse_mx",
"=",
"sparse_mx",
".",
"tocoo",
"(",
")",
".",
"astype",
"(",
"np",
".",
"float32",
")",
"indices",
"=",
"torch",
".",
"from_numpy",
"(",
"np",
".",
"vstack",
"(",
"(",
"... | [
38,
0
] | [
45,
59
] | python | en | ['en', 'en', 'it'] | True |
parse_index_file | (filename) | Parse index file. | Parse index file. | def parse_index_file(filename):
"""Parse index file."""
index = []
for line in open(filename):
index.append(int(line.strip()))
return index | [
"def",
"parse_index_file",
"(",
"filename",
")",
":",
"index",
"=",
"[",
"]",
"for",
"line",
"in",
"open",
"(",
"filename",
")",
":",
"index",
".",
"append",
"(",
"int",
"(",
"line",
".",
"strip",
"(",
")",
")",
")",
"return",
"index"
] | [
47,
0
] | [
52,
16
] | python | en | ['en', 'la', 'en'] | True |
load_citation | (dataset_str="cora") |
Load Citation Networks Datasets.
|
Load Citation Networks Datasets.
| def load_citation(dataset_str="cora"):
"""
Load Citation Networks Datasets.
"""
names = ['x', 'y', 'tx', 'ty', 'allx', 'ally', 'graph']
objects = []
for i in range(len(names)):
with open("data/ind.{}.{}".format(dataset_str.lower(), names[i]), 'rb') as f:
if sys.version_info >... | [
"def",
"load_citation",
"(",
"dataset_str",
"=",
"\"cora\"",
")",
":",
"names",
"=",
"[",
"'x'",
",",
"'y'",
",",
"'tx'",
",",
"'ty'",
",",
"'allx'",
",",
"'ally'",
",",
"'graph'",
"]",
"objects",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"len... | [
55,
0
] | [
105,
62
] | python | en | ['en', 'error', 'th'] | False |
staticfiles_urlpatterns | (prefix=None) |
Helper function to return a URL pattern for serving static files.
|
Helper function to return a URL pattern for serving static files.
| def staticfiles_urlpatterns(prefix=None):
"""
Helper function to return a URL pattern for serving static files.
"""
if prefix is None:
prefix = settings.STATIC_URL
return static(prefix, view=serve) | [
"def",
"staticfiles_urlpatterns",
"(",
"prefix",
"=",
"None",
")",
":",
"if",
"prefix",
"is",
"None",
":",
"prefix",
"=",
"settings",
".",
"STATIC_URL",
"return",
"static",
"(",
"prefix",
",",
"view",
"=",
"serve",
")"
] | [
7,
0
] | [
13,
37
] | python | en | ['en', 'error', 'th'] | False |
torch_complement | (tensor1, tensor2, boolean_out=False) |
Return the complement of tensors 1 and 2.
|
Return the complement of tensors 1 and 2.
| def torch_complement(tensor1, tensor2, boolean_out=False):
"""
Return the complement of tensors 1 and 2.
"""
boolean = []
for i in range(len(tensor1)):
boolean_i = True
if boolean.count(False) < len(tensor2):
for j in range(len(tensor2)):
if tens... | [
"def",
"torch_complement",
"(",
"tensor1",
",",
"tensor2",
",",
"boolean_out",
"=",
"False",
")",
":",
"boolean",
"=",
"[",
"]",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"tensor1",
")",
")",
":",
"boolean_i",
"=",
"True",
"if",
"boolean",
".",
"co... | [
10,
0
] | [
29,
31
] | python | en | ['en', 'error', 'th'] | False |
train_test_split | (X, y, test_size=0.2, random_state=10, gpu=False) |
Training and test splits for torch array.
|
Training and test splits for torch array.
| def train_test_split(X, y, test_size=0.2, random_state=10, gpu=False):
"""
Training and test splits for torch array.
"""
X_train, X_test, y_train, y_test = sklms.train_test_split(X.numpy(),
y.numpy(),
... | [
"def",
"train_test_split",
"(",
"X",
",",
"y",
",",
"test_size",
"=",
"0.2",
",",
"random_state",
"=",
"10",
",",
"gpu",
"=",
"False",
")",
":",
"X_train",
",",
"X_test",
",",
"y_train",
",",
"y_test",
"=",
"sklms",
".",
"train_test_split",
"(",
"X",
... | [
33,
0
] | [
47,
43
] | python | en | ['en', 'error', 'th'] | False |
cv_split | (X, n_splits=5, random_state=10) |
CV indices for K-fold cross-validation.
|
CV indices for K-fold cross-validation.
| def cv_split(X, n_splits=5, random_state=10):
"""
CV indices for K-fold cross-validation.
"""
if type(X) == torch.Tensor:
if X.is_cuda:
copy = X.cpu().numpy()
else:
copy = X.numpy()
else:
copy = X.copy()
kf = sklms.KFold(n_splits=n_splits... | [
"def",
"cv_split",
"(",
"X",
",",
"n_splits",
"=",
"5",
",",
"random_state",
"=",
"10",
")",
":",
"if",
"type",
"(",
"X",
")",
"==",
"torch",
".",
"Tensor",
":",
"if",
"X",
".",
"is_cuda",
":",
"copy",
"=",
"X",
".",
"cpu",
"(",
")",
".",
"nu... | [
51,
0
] | [
67,
17
] | python | en | ['en', 'error', 'th'] | False |
getimage | (photo) | Copies the contents of a PhotoImage to a PIL image memory. | Copies the contents of a PhotoImage to a PIL image memory. | def getimage(photo):
"""Copies the contents of a PhotoImage to a PIL image memory."""
im = Image.new("RGBA", (photo.width(), photo.height()))
block = im.im
photo.tk.call("PyImagingPhotoGet", photo, block.id)
return im | [
"def",
"getimage",
"(",
"photo",
")",
":",
"im",
"=",
"Image",
".",
"new",
"(",
"\"RGBA\"",
",",
"(",
"photo",
".",
"width",
"(",
")",
",",
"photo",
".",
"height",
"(",
")",
")",
")",
"block",
"=",
"im",
".",
"im",
"photo",
".",
"tk",
".",
"c... | [
273,
0
] | [
280,
13
] | python | en | ['en', 'en', 'en'] | True |
_show | (image, title) | Helper for the Image.show method. | Helper for the Image.show method. | def _show(image, title):
"""Helper for the Image.show method."""
class UI(tkinter.Label):
def __init__(self, master, im):
if im.mode == "1":
self.image = BitmapImage(im, foreground="white", master=master)
else:
self.image = PhotoImage(im, master=m... | [
"def",
"_show",
"(",
"image",
",",
"title",
")",
":",
"class",
"UI",
"(",
"tkinter",
".",
"Label",
")",
":",
"def",
"__init__",
"(",
"self",
",",
"master",
",",
"im",
")",
":",
"if",
"im",
".",
"mode",
"==",
"\"1\"",
":",
"self",
".",
"image",
... | [
283,
0
] | [
299,
25
] | python | en | ['en', 'en', 'en'] | True |
PhotoImage.__str__ | (self) |
Get the Tkinter photo image identifier. This method is automatically
called by Tkinter whenever a PhotoImage object is passed to a Tkinter
method.
:return: A Tkinter photo image identifier (a string).
|
Get the Tkinter photo image identifier. This method is automatically
called by Tkinter whenever a PhotoImage object is passed to a Tkinter
method. | def __str__(self):
"""
Get the Tkinter photo image identifier. This method is automatically
called by Tkinter whenever a PhotoImage object is passed to a Tkinter
method.
:return: A Tkinter photo image identifier (a string).
"""
return str(self.__photo) | [
"def",
"__str__",
"(",
"self",
")",
":",
"return",
"str",
"(",
"self",
".",
"__photo",
")"
] | [
124,
4
] | [
132,
32
] | python | en | ['en', 'error', 'th'] | False |
PhotoImage.width | (self) |
Get the width of the image.
:return: The width, in pixels.
|
Get the width of the image. | def width(self):
"""
Get the width of the image.
:return: The width, in pixels.
"""
return self.__size[0] | [
"def",
"width",
"(",
"self",
")",
":",
"return",
"self",
".",
"__size",
"[",
"0",
"]"
] | [
134,
4
] | [
140,
29
] | python | en | ['en', 'error', 'th'] | False |
PhotoImage.height | (self) |
Get the height of the image.
:return: The height, in pixels.
|
Get the height of the image. | def height(self):
"""
Get the height of the image.
:return: The height, in pixels.
"""
return self.__size[1] | [
"def",
"height",
"(",
"self",
")",
":",
"return",
"self",
".",
"__size",
"[",
"1",
"]"
] | [
142,
4
] | [
148,
29
] | python | en | ['en', 'error', 'th'] | False |
PhotoImage.paste | (self, im, box=None) |
Paste a PIL image into the photo image. Note that this can
be very slow if the photo image is displayed.
:param im: A PIL image. The size must match the target region. If the
mode does not match, the image is converted to the mode of
the bitmap image.
... |
Paste a PIL image into the photo image. Note that this can
be very slow if the photo image is displayed. | def paste(self, im, box=None):
"""
Paste a PIL image into the photo image. Note that this can
be very slow if the photo image is displayed.
:param im: A PIL image. The size must match the target region. If the
mode does not match, the image is converted to the mode ... | [
"def",
"paste",
"(",
"self",
",",
"im",
",",
"box",
"=",
"None",
")",
":",
"# convert to blittable",
"im",
".",
"load",
"(",
")",
"image",
"=",
"im",
".",
"im",
"if",
"image",
".",
"isblock",
"(",
")",
"and",
"im",
".",
"mode",
"==",
"self",
".",... | [
150,
4
] | [
198,
21
] | python | en | ['en', 'error', 'th'] | False |
BitmapImage.width | (self) |
Get the width of the image.
:return: The width, in pixels.
|
Get the width of the image. | def width(self):
"""
Get the width of the image.
:return: The width, in pixels.
"""
return self.__size[0] | [
"def",
"width",
"(",
"self",
")",
":",
"return",
"self",
".",
"__size",
"[",
"0",
"]"
] | [
246,
4
] | [
252,
29
] | python | en | ['en', 'error', 'th'] | False |
BitmapImage.height | (self) |
Get the height of the image.
:return: The height, in pixels.
|
Get the height of the image. | def height(self):
"""
Get the height of the image.
:return: The height, in pixels.
"""
return self.__size[1] | [
"def",
"height",
"(",
"self",
")",
":",
"return",
"self",
".",
"__size",
"[",
"1",
"]"
] | [
254,
4
] | [
260,
29
] | python | en | ['en', 'error', 'th'] | False |
BitmapImage.__str__ | (self) |
Get the Tkinter bitmap image identifier. This method is automatically
called by Tkinter whenever a BitmapImage object is passed to a Tkinter
method.
:return: A Tkinter bitmap image identifier (a string).
|
Get the Tkinter bitmap image identifier. This method is automatically
called by Tkinter whenever a BitmapImage object is passed to a Tkinter
method. | def __str__(self):
"""
Get the Tkinter bitmap image identifier. This method is automatically
called by Tkinter whenever a BitmapImage object is passed to a Tkinter
method.
:return: A Tkinter bitmap image identifier (a string).
"""
return str(self.__photo) | [
"def",
"__str__",
"(",
"self",
")",
":",
"return",
"str",
"(",
"self",
".",
"__photo",
")"
] | [
262,
4
] | [
270,
32
] | python | en | ['en', 'error', 'th'] | False |
popen_wrapper | (args, os_err_exc_type=Exception, stdout_encoding='utf-8') |
Friendly wrapper around Popen.
Returns stdout output, stderr output and OS status code.
|
Friendly wrapper around Popen.
Returns stdout output, stderr output and OS status code.
| def popen_wrapper(args, os_err_exc_type=Exception, stdout_encoding='utf-8'):
"""
Friendly wrapper around Popen.
Returns stdout output, stderr output and OS status code.
"""
try:
p = Popen(args, shell=False, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt')
except OSError as e:
... | [
"def",
"popen_wrapper",
"(",
"args",
",",
"os_err_exc_type",
"=",
"Exception",
",",
"stdout_encoding",
"=",
"'utf-8'",
")",
":",
"try",
":",
"p",
"=",
"Popen",
"(",
"args",
",",
"shell",
"=",
"False",
",",
"stdout",
"=",
"PIPE",
",",
"stderr",
"=",
"PI... | [
33,
0
] | [
49,
5
] | python | en | ['en', 'error', 'th'] | False |
get_system_encoding | () |
The encoding of the default system locale but falls back to the given
fallback encoding if the encoding is unsupported by python or could
not be determined. See tickets #10335 and #5846
|
The encoding of the default system locale but falls back to the given
fallback encoding if the encoding is unsupported by python or could
not be determined. See tickets #10335 and #5846
| def get_system_encoding():
"""
The encoding of the default system locale but falls back to the given
fallback encoding if the encoding is unsupported by python or could
not be determined. See tickets #10335 and #5846
"""
try:
encoding = locale.getdefaultlocale()[1] or 'ascii'
co... | [
"def",
"get_system_encoding",
"(",
")",
":",
"try",
":",
"encoding",
"=",
"locale",
".",
"getdefaultlocale",
"(",
")",
"[",
"1",
"]",
"or",
"'ascii'",
"codecs",
".",
"lookup",
"(",
"encoding",
")",
"except",
"Exception",
":",
"encoding",
"=",
"'ascii'",
... | [
52,
0
] | [
63,
19
] | python | en | ['en', 'error', 'th'] | False |
is_protected_type | (obj) | Determine if the object instance is of a protected type.
Objects of protected types are preserved as-is when passed to
force_text(strings_only=True).
| Determine if the object instance is of a protected type.
Objects of protected types are preserved as-is when passed to
force_text(strings_only=True).
| def is_protected_type(obj):
"""Determine if the object instance is of a protected type.
Objects of protected types are preserved as-is when passed to
force_text(strings_only=True).
"""
return isinstance(obj, _PROTECTED_TYPES) | [
"def",
"is_protected_type",
"(",
"obj",
")",
":",
"return",
"isinstance",
"(",
"obj",
",",
"_PROTECTED_TYPES",
")"
] | [
71,
0
] | [
76,
44
] | python | en | ['en', 'en', 'en'] | True |
force_text | (s, encoding='utf-8', strings_only=False, errors='strict') |
Similar to smart_text, except that lazy instances are resolved to
strings, rather than kept as lazy objects.
If strings_only is True, don't convert (some) non-string-like objects.
|
Similar to smart_text, except that lazy instances are resolved to
strings, rather than kept as lazy objects.
If strings_only is True, don't convert (some) non-string-like objects.
| def force_text(s, encoding='utf-8', strings_only=False, errors='strict'):
"""
Similar to smart_text, except that lazy instances are resolved to
strings, rather than kept as lazy objects.
If strings_only is True, don't convert (some) non-string-like objects.
"""
# Handle the common case first for... | [
"def",
"force_text",
"(",
"s",
",",
"encoding",
"=",
"'utf-8'",
",",
"strings_only",
"=",
"False",
",",
"errors",
"=",
"'strict'",
")",
":",
"# Handle the common case first for performance reasons.",
"if",
"issubclass",
"(",
"type",
"(",
"s",
")",
",",
"str",
... | [
82,
0
] | [
115,
12
] | python | en | ['en', 'error', 'th'] | False |
get_page_models | () |
Returns a list of all non-abstract Page model classes defined in this project.
|
Returns a list of all non-abstract Page model classes defined in this project.
| def get_page_models():
"""
Returns a list of all non-abstract Page model classes defined in this project.
"""
return PAGE_MODEL_CLASSES | [
"def",
"get_page_models",
"(",
")",
":",
"return",
"PAGE_MODEL_CLASSES"
] | [
111,
0
] | [
115,
29
] | python | en | ['en', 'error', 'th'] | False |
get_default_page_content_type | () |
Returns the content type to use as a default for pages whose content type
has been deleted.
|
Returns the content type to use as a default for pages whose content type
has been deleted.
| def get_default_page_content_type():
"""
Returns the content type to use as a default for pages whose content type
has been deleted.
"""
return ContentType.objects.get_for_model(Page) | [
"def",
"get_default_page_content_type",
"(",
")",
":",
"return",
"ContentType",
".",
"objects",
".",
"get_for_model",
"(",
"Page",
")"
] | [
118,
0
] | [
123,
50
] | python | en | ['en', 'error', 'th'] | False |
Page.set_url_path | (self, parent) |
Populate the url_path field based on this page's slug and the specified parent page.
(We pass a parent in here, rather than retrieving it via get_parent, so that we can give
new unsaved pages a meaningful URL when previewing them; at that point the page has not
been assigned a position ... |
Populate the url_path field based on this page's slug and the specified parent page.
(We pass a parent in here, rather than retrieving it via get_parent, so that we can give
new unsaved pages a meaningful URL when previewing them; at that point the page has not
been assigned a position ... | def set_url_path(self, parent):
"""
Populate the url_path field based on this page's slug and the specified parent page.
(We pass a parent in here, rather than retrieving it via get_parent, so that we can give
new unsaved pages a meaningful URL when previewing them; at that point the pag... | [
"def",
"set_url_path",
"(",
"self",
",",
"parent",
")",
":",
"if",
"parent",
":",
"self",
".",
"url_path",
"=",
"parent",
".",
"url_path",
"+",
"self",
".",
"slug",
"+",
"'/'",
"else",
":",
"# a page without a parent is the tree root, which always has a url_path o... | [
360,
4
] | [
373,
28
] | python | en | ['en', 'error', 'th'] | False |
Page._slug_is_available | (slug, parent_page, page=None) |
Determine whether the given slug is available for use on a child page of
parent_page. If 'page' is passed, the slug is intended for use on that page
(and so it will be excluded from the duplicate check).
|
Determine whether the given slug is available for use on a child page of
parent_page. If 'page' is passed, the slug is intended for use on that page
(and so it will be excluded from the duplicate check).
| def _slug_is_available(slug, parent_page, page=None):
"""
Determine whether the given slug is available for use on a child page of
parent_page. If 'page' is passed, the slug is intended for use on that page
(and so it will be excluded from the duplicate check).
"""
if par... | [
"def",
"_slug_is_available",
"(",
"slug",
",",
"parent_page",
",",
"page",
"=",
"None",
")",
":",
"if",
"parent_page",
"is",
"None",
":",
"# the root page's slug can be whatever it likes...",
"return",
"True",
"siblings",
"=",
"parent_page",
".",
"get_children",
"("... | [
376,
4
] | [
390,
54
] | python | en | ['en', 'error', 'th'] | False |
Page.get_default_locale | (self) |
Finds the default locale to use for this page.
This will be called just before the initial save.
|
Finds the default locale to use for this page. | def get_default_locale(self):
"""
Finds the default locale to use for this page.
This will be called just before the initial save.
"""
parent = self.get_parent()
if parent is not None:
return (
parent.specific_class.objects.defer().select_rela... | [
"def",
"get_default_locale",
"(",
"self",
")",
":",
"parent",
"=",
"self",
".",
"get_parent",
"(",
")",
"if",
"parent",
"is",
"not",
"None",
":",
"return",
"(",
"parent",
".",
"specific_class",
".",
"objects",
".",
"defer",
"(",
")",
".",
"select_related... | [
404,
4
] | [
418,
43
] | python | en | ['en', 'error', 'th'] | False |
Page.is_site_root | (self) |
Returns True if this page is the root of any site.
This includes translations of site root pages as well.
|
Returns True if this page is the root of any site. | def is_site_root(self):
"""
Returns True if this page is the root of any site.
This includes translations of site root pages as well.
"""
# `_is_site_root` may be populated by `annotate_site_root_state` on `PageQuerySet` as a
# performance optimisation
if hasattr... | [
"def",
"is_site_root",
"(",
"self",
")",
":",
"# `_is_site_root` may be populated by `annotate_site_root_state` on `PageQuerySet` as a",
"# performance optimisation",
"if",
"hasattr",
"(",
"self",
",",
"\"_is_site_root\"",
")",
":",
"return",
"self",
".",
"_is_site_root",
"re... | [
446,
4
] | [
459,
18
] | python | en | ['en', 'error', 'th'] | False |
Page.save | (self, clean=True, user=None, log_action=False, **kwargs) |
Overrides default method behaviour to make additional updates unique to pages,
such as updating the ``url_path`` value of descendant page to reflect changes
to this page's slug.
New pages should generally be saved via the ``add_child()`` or ``add_sibling()``
method of an existi... |
Overrides default method behaviour to make additional updates unique to pages,
such as updating the ``url_path`` value of descendant page to reflect changes
to this page's slug. | def save(self, clean=True, user=None, log_action=False, **kwargs):
"""
Overrides default method behaviour to make additional updates unique to pages,
such as updating the ``url_path`` value of descendant page to reflect changes
to this page's slug.
New pages should generally be ... | [
"def",
"save",
"(",
"self",
",",
"clean",
"=",
"True",
",",
"user",
"=",
"None",
",",
"log_action",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"clean",
":",
"self",
".",
"full_clean",
"(",
")",
"update_descendant_url_paths",
"=",
"False",
... | [
463,
4
] | [
544,
21
] | python | en | ['en', 'error', 'th'] | False |
Page.get_specific | (self, deferred=False, copy_attrs=None, copy_attrs_exclude=None) |
.. versionadded:: 2.12
Return this page in its most specific subclassed form.
.. versionchanged:: 2.13
* When ``copy_attrs`` is not supplied, all known non-field attribute
values are copied to the returned object. Previously, no non-field
values would b... |
.. versionadded:: 2.12 | def get_specific(self, deferred=False, copy_attrs=None, copy_attrs_exclude=None):
"""
.. versionadded:: 2.12
Return this page in its most specific subclassed form.
.. versionchanged:: 2.13
* When ``copy_attrs`` is not supplied, all known non-field attribute
va... | [
"def",
"get_specific",
"(",
"self",
",",
"deferred",
"=",
"False",
",",
"copy_attrs",
"=",
"None",
",",
"copy_attrs_exclude",
"=",
"None",
")",
":",
"model_class",
"=",
"self",
".",
"specific_class",
"if",
"model_class",
"is",
"None",
":",
"# The codebase and ... | [
643,
4
] | [
726,
27
] | python | en | ['en', 'error', 'th'] | False |
Page.specific | (self) |
Returns this page in its most specific subclassed form with all field
values fetched from the database. The result is cached in memory.
|
Returns this page in its most specific subclassed form with all field
values fetched from the database. The result is cached in memory.
| def specific(self):
"""
Returns this page in its most specific subclassed form with all field
values fetched from the database. The result is cached in memory.
"""
return self.get_specific() | [
"def",
"specific",
"(",
"self",
")",
":",
"return",
"self",
".",
"get_specific",
"(",
")"
] | [
729,
4
] | [
734,
34
] | python | en | ['en', 'error', 'th'] | False |
Page.specific_deferred | (self) |
.. versionadded:: 2.12
Returns this page in its most specific subclassed form without any
additional field values being fetched from the database. The result
is cached in memory.
|
.. versionadded:: 2.12 | def specific_deferred(self):
"""
.. versionadded:: 2.12
Returns this page in its most specific subclassed form without any
additional field values being fetched from the database. The result
is cached in memory.
"""
return self.get_specific(deferred=True) | [
"def",
"specific_deferred",
"(",
"self",
")",
":",
"return",
"self",
".",
"get_specific",
"(",
"deferred",
"=",
"True",
")"
] | [
737,
4
] | [
745,
47
] | python | en | ['en', 'error', 'th'] | False |
Page.specific_class | (self) |
Return the class that this page would be if instantiated in its
most specific form.
If the model class can no longer be found in the codebase, and the
relevant ``ContentType`` has been removed by a database migration,
the return value will be ``None``.
If the model cla... |
Return the class that this page would be if instantiated in its
most specific form. | def specific_class(self):
"""
Return the class that this page would be if instantiated in its
most specific form.
If the model class can no longer be found in the codebase, and the
relevant ``ContentType`` has been removed by a database migration,
the return value will b... | [
"def",
"specific_class",
"(",
"self",
")",
":",
"return",
"self",
".",
"cached_content_type",
".",
"model_class",
"(",
")"
] | [
748,
4
] | [
762,
53
] | python | en | ['en', 'error', 'th'] | False |
Page.cached_content_type | (self) |
.. versionadded:: 2.10
Return this page's ``content_type`` value from the ``ContentType``
model's cached manager, which will avoid a database query if the
object is already in memory.
|
.. versionadded:: 2.10 | def cached_content_type(self):
"""
.. versionadded:: 2.10
Return this page's ``content_type`` value from the ``ContentType``
model's cached manager, which will avoid a database query if the
object is already in memory.
"""
return ContentType.objects.get_for_id(se... | [
"def",
"cached_content_type",
"(",
"self",
")",
":",
"return",
"ContentType",
".",
"objects",
".",
"get_for_id",
"(",
"self",
".",
"content_type_id",
")"
] | [
765,
4
] | [
773,
67
] | python | en | ['en', 'error', 'th'] | False |
Page.localized_draft | (self) |
Finds the translation in the current active language.
If there is no translation in the active language, self is returned.
Note: This will return translations that are in draft. If you want to exclude
these, use the ``.localized`` attribute.
|
Finds the translation in the current active language. | def localized_draft(self):
"""
Finds the translation in the current active language.
If there is no translation in the active language, self is returned.
Note: This will return translations that are in draft. If you want to exclude
these, use the ``.localized`` attribute.
... | [
"def",
"localized_draft",
"(",
"self",
")",
":",
"try",
":",
"locale",
"=",
"Locale",
".",
"get_active",
"(",
")",
"except",
"(",
"LookupError",
",",
"Locale",
".",
"DoesNotExist",
")",
":",
"return",
"self",
"if",
"locale",
".",
"id",
"==",
"self",
".... | [
776,
4
] | [
793,
59
] | python | en | ['en', 'error', 'th'] | False |
Page.localized | (self) |
Finds the translation in the current active language.
If there is no translation in the active language, self is returned.
Note: This will not return the translation if it is in draft.
If you want to include drafts, use the ``.localized_draft`` attribute instead.
|
Finds the translation in the current active language. | def localized(self):
"""
Finds the translation in the current active language.
If there is no translation in the active language, self is returned.
Note: This will not return the translation if it is in draft.
If you want to include drafts, use the ``.localized_draft`` attribut... | [
"def",
"localized",
"(",
"self",
")",
":",
"localized",
"=",
"self",
".",
"localized_draft",
"if",
"not",
"localized",
".",
"live",
":",
"return",
"self",
"return",
"localized"
] | [
796,
4
] | [
809,
24
] | python | en | ['en', 'error', 'th'] | False |
Page.get_admin_display_title | (self) |
Return the title for this page as it should appear in the admin backend;
override this if you wish to display extra contextual information about the page,
such as language. By default, returns ``draft_title``.
|
Return the title for this page as it should appear in the admin backend;
override this if you wish to display extra contextual information about the page,
such as language. By default, returns ``draft_title``.
| def get_admin_display_title(self):
"""
Return the title for this page as it should appear in the admin backend;
override this if you wish to display extra contextual information about the page,
such as language. By default, returns ``draft_title``.
"""
# Fall back on titl... | [
"def",
"get_admin_display_title",
"(",
"self",
")",
":",
"# Fall back on title if draft_title is blank (which may happen if the page was created",
"# in a fixture or migration that didn't explicitly handle draft_title)",
"return",
"self",
".",
"draft_title",
"or",
"self",
".",
"title"
... | [
831,
4
] | [
839,
45
] | python | en | ['en', 'error', 'th'] | False |
Page.save_revision | (self, user=None, submitted_for_moderation=False, approved_go_live_at=None, changed=True,
log_action=False, previous_revision=None, clean=True) |
Creates and saves a page revision.
:param user: the user performing the action
:param submitted_for_moderation: indicates whether the page was submitted for moderation
:param approved_go_live_at: the date and time the revision is approved to go live
:param changed: indicates whe... |
Creates and saves a page revision.
:param user: the user performing the action
:param submitted_for_moderation: indicates whether the page was submitted for moderation
:param approved_go_live_at: the date and time the revision is approved to go live
:param changed: indicates whe... | def save_revision(self, user=None, submitted_for_moderation=False, approved_go_live_at=None, changed=True,
log_action=False, previous_revision=None, clean=True):
"""
Creates and saves a page revision.
:param user: the user performing the action
:param submitted_for_... | [
"def",
"save_revision",
"(",
"self",
",",
"user",
"=",
"None",
",",
"submitted_for_moderation",
"=",
"False",
",",
"approved_go_live_at",
"=",
"None",
",",
"changed",
"=",
"True",
",",
"log_action",
"=",
"False",
",",
"previous_revision",
"=",
"None",
",",
"... | [
841,
4
] | [
926,
23
] | python | en | ['en', 'error', 'th'] | False |
Page.update_aliases | (self, *, revision=None, user=None, _content_json=None, _updated_ids=None) |
Publishes all aliases that follow this page with the latest content from this page.
This is called by Wagtail whenever a page with aliases is published.
:param revision: The revision of the original page that we are updating to (used for logging purposes)
:type revision: PageRevision,... |
Publishes all aliases that follow this page with the latest content from this page. | def update_aliases(self, *, revision=None, user=None, _content_json=None, _updated_ids=None):
"""
Publishes all aliases that follow this page with the latest content from this page.
This is called by Wagtail whenever a page with aliases is published.
:param revision: The revision of th... | [
"def",
"update_aliases",
"(",
"self",
",",
"*",
",",
"revision",
"=",
"None",
",",
"user",
"=",
"None",
",",
"_content_json",
"=",
"None",
",",
"_updated_ids",
"=",
"None",
")",
":",
"specific_self",
"=",
"self",
".",
"specific",
"# Only compute this if nece... | [
948,
4
] | [
1050,
107
] | python | en | ['en', 'error', 'th'] | False |
Page.unpublish | (self, set_expired=False, commit=True, user=None, log_action=True) |
Unpublish the page by setting ``live`` to ``False``. Does nothing if ``live`` is already ``False``
:param log_action: flag for logging the action. Pass False to skip logging. Can be passed an action string.
Defaults to 'wagtail.unpublish'
|
Unpublish the page by setting ``live`` to ``False``. Does nothing if ``live`` is already ``False``
:param log_action: flag for logging the action. Pass False to skip logging. Can be passed an action string.
Defaults to 'wagtail.unpublish'
| def unpublish(self, set_expired=False, commit=True, user=None, log_action=True):
"""
Unpublish the page by setting ``live`` to ``False``. Does nothing if ``live`` is already ``False``
:param log_action: flag for logging the action. Pass False to skip logging. Can be passed an action string.
... | [
"def",
"unpublish",
"(",
"self",
",",
"set_expired",
"=",
"False",
",",
"commit",
"=",
"True",
",",
"user",
"=",
"None",
",",
"log_action",
"=",
"True",
")",
":",
"if",
"self",
".",
"live",
":",
"self",
".",
"live",
"=",
"False",
"self",
".",
"has_... | [
1054,
4
] | [
1087,
33
] | python | en | ['en', 'error', 'th'] | False |
Page.is_navigable | (self) |
Return true if it's meaningful to browse subpages of this page -
i.e. it currently has subpages,
or it's at the top level (this rule necessary for empty out-of-the-box sites to have working navigation)
|
Return true if it's meaningful to browse subpages of this page -
i.e. it currently has subpages,
or it's at the top level (this rule necessary for empty out-of-the-box sites to have working navigation)
| def is_navigable(self):
"""
Return true if it's meaningful to browse subpages of this page -
i.e. it currently has subpages,
or it's at the top level (this rule necessary for empty out-of-the-box sites to have working navigation)
"""
return (not self.is_leaf()) or self.de... | [
"def",
"is_navigable",
"(",
"self",
")",
":",
"return",
"(",
"not",
"self",
".",
"is_leaf",
"(",
")",
")",
"or",
"self",
".",
"depth",
"==",
"2"
] | [
1118,
4
] | [
1124,
54
] | python | en | ['en', 'error', 'th'] | False |
Page._get_site_root_paths | (self, request=None) |
Return ``Site.get_site_root_paths()``, using the cached copy on the
request object if available.
|
Return ``Site.get_site_root_paths()``, using the cached copy on the
request object if available.
| def _get_site_root_paths(self, request=None):
"""
Return ``Site.get_site_root_paths()``, using the cached copy on the
request object if available.
"""
# if we have a request, use that to cache site_root_paths; otherwise, use self
cache_object = request if request else sel... | [
"def",
"_get_site_root_paths",
"(",
"self",
",",
"request",
"=",
"None",
")",
":",
"# if we have a request, use that to cache site_root_paths; otherwise, use self",
"cache_object",
"=",
"request",
"if",
"request",
"else",
"self",
"try",
":",
"return",
"cache_object",
".",... | [
1126,
4
] | [
1137,
63
] | python | en | ['en', 'error', 'th'] | False |
Page.get_url_parts | (self, request=None) |
Determine the URL for this page and return it as a tuple of
``(site_id, site_root_url, page_url_relative_to_site_root)``.
Return None if the page is not routable.
This is used internally by the ``full_url``, ``url``, ``relative_url``
and ``get_site`` properties and methods; pag... |
Determine the URL for this page and return it as a tuple of
``(site_id, site_root_url, page_url_relative_to_site_root)``.
Return None if the page is not routable. | def get_url_parts(self, request=None):
"""
Determine the URL for this page and return it as a tuple of
``(site_id, site_root_url, page_url_relative_to_site_root)``.
Return None if the page is not routable.
This is used internally by the ``full_url``, ``url``, ``relative_url``
... | [
"def",
"get_url_parts",
"(",
"self",
",",
"request",
"=",
"None",
")",
":",
"possible_sites",
"=",
"[",
"(",
"pk",
",",
"path",
",",
"url",
",",
"language_code",
")",
"for",
"pk",
",",
"path",
",",
"url",
",",
"language_code",
"in",
"self",
".",
"_ge... | [
1139,
4
] | [
1209,
45
] | python | en | ['en', 'error', 'th'] | False |
Page.get_full_url | (self, request=None) | Return the full URL (including protocol / domain) to this page, or None if it is not routable | Return the full URL (including protocol / domain) to this page, or None if it is not routable | def get_full_url(self, request=None):
"""Return the full URL (including protocol / domain) to this page, or None if it is not routable"""
url_parts = self.get_url_parts(request=request)
if url_parts is None or url_parts[1] is None and url_parts[2] is None:
# page is not routable
... | [
"def",
"get_full_url",
"(",
"self",
",",
"request",
"=",
"None",
")",
":",
"url_parts",
"=",
"self",
".",
"get_url_parts",
"(",
"request",
"=",
"request",
")",
"if",
"url_parts",
"is",
"None",
"or",
"url_parts",
"[",
"1",
"]",
"is",
"None",
"and",
"url... | [
1211,
4
] | [
1221,
35
] | python | en | ['en', 'en', 'en'] | True |
Page.get_url | (self, request=None, current_site=None) |
Return the 'most appropriate' URL for referring to this page from the pages we serve,
within the Wagtail backend and actual website templates;
this is the local URL (starting with '/') if we're only running a single site
(i.e. we know that whatever the current page is being served from,... |
Return the 'most appropriate' URL for referring to this page from the pages we serve,
within the Wagtail backend and actual website templates;
this is the local URL (starting with '/') if we're only running a single site
(i.e. we know that whatever the current page is being served from,... | def get_url(self, request=None, current_site=None):
"""
Return the 'most appropriate' URL for referring to this page from the pages we serve,
within the Wagtail backend and actual website templates;
this is the local URL (starting with '/') if we're only running a single site
(i.... | [
"def",
"get_url",
"(",
"self",
",",
"request",
"=",
"None",
",",
"current_site",
"=",
"None",
")",
":",
"# ``current_site`` is purposefully undocumented, as one can simply pass the request and get",
"# a relative URL based on ``Site.find_for_request()``. Nonetheless, support it here to... | [
1225,
4
] | [
1261,
39
] | python | en | ['en', 'error', 'th'] | False |
Page.relative_url | (self, current_site, request=None) |
Return the 'most appropriate' URL for this page taking into account the site we're currently on;
a local URL if the site matches, or a fully qualified one otherwise.
Return None if the page is not routable.
Accepts an optional but recommended ``request`` keyword argument that, if provi... |
Return the 'most appropriate' URL for this page taking into account the site we're currently on;
a local URL if the site matches, or a fully qualified one otherwise.
Return None if the page is not routable. | def relative_url(self, current_site, request=None):
"""
Return the 'most appropriate' URL for this page taking into account the site we're currently on;
a local URL if the site matches, or a fully qualified one otherwise.
Return None if the page is not routable.
Accepts an optio... | [
"def",
"relative_url",
"(",
"self",
",",
"current_site",
",",
"request",
"=",
"None",
")",
":",
"return",
"self",
".",
"get_url",
"(",
"request",
"=",
"request",
",",
"current_site",
"=",
"current_site",
")"
] | [
1265,
4
] | [
1275,
71
] | python | en | ['en', 'error', 'th'] | False |
Page.get_site | (self) |
Return the Site object that this page belongs to.
|
Return the Site object that this page belongs to.
| def get_site(self):
"""
Return the Site object that this page belongs to.
"""
url_parts = self.get_url_parts()
if url_parts is None:
# page is not routable
return
site_id, root_url, page_path = url_parts
return Site.objects.get(id=site_... | [
"def",
"get_site",
"(",
"self",
")",
":",
"url_parts",
"=",
"self",
".",
"get_url_parts",
"(",
")",
"if",
"url_parts",
"is",
"None",
":",
"# page is not routable",
"return",
"site_id",
",",
"root_url",
",",
"page_path",
"=",
"url_parts",
"return",
"Site",
".... | [
1277,
4
] | [
1290,
43
] | python | en | ['en', 'error', 'th'] | False |
Page.clean_subpage_models | (cls) |
Returns the list of subpage types, normalised as model classes.
Throws ValueError if any entry in subpage_types cannot be recognised as a model name,
or LookupError if a model does not exist (or is not a Page subclass).
|
Returns the list of subpage types, normalised as model classes.
Throws ValueError if any entry in subpage_types cannot be recognised as a model name,
or LookupError if a model does not exist (or is not a Page subclass).
| def clean_subpage_models(cls):
"""
Returns the list of subpage types, normalised as model classes.
Throws ValueError if any entry in subpage_types cannot be recognised as a model name,
or LookupError if a model does not exist (or is not a Page subclass).
"""
if cls._clean... | [
"def",
"clean_subpage_models",
"(",
"cls",
")",
":",
"if",
"cls",
".",
"_clean_subpage_models",
"is",
"None",
":",
"subpage_types",
"=",
"getattr",
"(",
"cls",
",",
"'subpage_types'",
",",
"None",
")",
"if",
"subpage_types",
"is",
"None",
":",
"# if subpage_ty... | [
1308,
4
] | [
1329,
40
] | python | en | ['en', 'error', 'th'] | False |
Page.clean_parent_page_models | (cls) |
Returns the list of parent page types, normalised as model classes.
Throws ValueError if any entry in parent_page_types cannot be recognised as a model name,
or LookupError if a model does not exist (or is not a Page subclass).
|
Returns the list of parent page types, normalised as model classes.
Throws ValueError if any entry in parent_page_types cannot be recognised as a model name,
or LookupError if a model does not exist (or is not a Page subclass).
| def clean_parent_page_models(cls):
"""
Returns the list of parent page types, normalised as model classes.
Throws ValueError if any entry in parent_page_types cannot be recognised as a model name,
or LookupError if a model does not exist (or is not a Page subclass).
"""
... | [
"def",
"clean_parent_page_models",
"(",
"cls",
")",
":",
"if",
"cls",
".",
"_clean_parent_page_models",
"is",
"None",
":",
"parent_page_types",
"=",
"getattr",
"(",
"cls",
",",
"'parent_page_types'",
",",
"None",
")",
"if",
"parent_page_types",
"is",
"None",
":"... | [
1332,
4
] | [
1354,
44
] | python | en | ['en', 'error', 'th'] | False |
Page.allowed_parent_page_models | (cls) |
Returns the list of page types that this page type can be a subpage of,
as a list of model classes
|
Returns the list of page types that this page type can be a subpage of,
as a list of model classes
| def allowed_parent_page_models(cls):
"""
Returns the list of page types that this page type can be a subpage of,
as a list of model classes
"""
return [
parent_model for parent_model in cls.clean_parent_page_models()
if cls in parent_model.clean_subpage_mo... | [
"def",
"allowed_parent_page_models",
"(",
"cls",
")",
":",
"return",
"[",
"parent_model",
"for",
"parent_model",
"in",
"cls",
".",
"clean_parent_page_models",
"(",
")",
"if",
"cls",
"in",
"parent_model",
".",
"clean_subpage_models",
"(",
")",
"]"
] | [
1357,
4
] | [
1365,
9
] | python | en | ['en', 'error', 'th'] | False |
Page.allowed_subpage_models | (cls) |
Returns the list of page types that this page type can have as subpages,
as a list of model classes
|
Returns the list of page types that this page type can have as subpages,
as a list of model classes
| def allowed_subpage_models(cls):
"""
Returns the list of page types that this page type can have as subpages,
as a list of model classes
"""
return [
subpage_model for subpage_model in cls.clean_subpage_models()
if cls in subpage_model.clean_parent_page_mo... | [
"def",
"allowed_subpage_models",
"(",
"cls",
")",
":",
"return",
"[",
"subpage_model",
"for",
"subpage_model",
"in",
"cls",
".",
"clean_subpage_models",
"(",
")",
"if",
"cls",
"in",
"subpage_model",
".",
"clean_parent_page_models",
"(",
")",
"]"
] | [
1368,
4
] | [
1376,
9
] | python | en | ['en', 'error', 'th'] | False |
Page.creatable_subpage_models | (cls) |
Returns the list of page types that may be created under this page type,
as a list of model classes
|
Returns the list of page types that may be created under this page type,
as a list of model classes
| def creatable_subpage_models(cls):
"""
Returns the list of page types that may be created under this page type,
as a list of model classes
"""
return [
page_model for page_model in cls.allowed_subpage_models()
if page_model.is_creatable
] | [
"def",
"creatable_subpage_models",
"(",
"cls",
")",
":",
"return",
"[",
"page_model",
"for",
"page_model",
"in",
"cls",
".",
"allowed_subpage_models",
"(",
")",
"if",
"page_model",
".",
"is_creatable",
"]"
] | [
1379,
4
] | [
1387,
9
] | python | en | ['en', 'error', 'th'] | False |
Page.can_exist_under | (cls, parent) |
Checks if this page type can exist as a subpage under a parent page
instance.
See also: :func:`Page.can_create_at` and :func:`Page.can_move_to`
|
Checks if this page type can exist as a subpage under a parent page
instance. | def can_exist_under(cls, parent):
"""
Checks if this page type can exist as a subpage under a parent page
instance.
See also: :func:`Page.can_create_at` and :func:`Page.can_move_to`
"""
return cls in parent.specific_class.allowed_subpage_models() | [
"def",
"can_exist_under",
"(",
"cls",
",",
"parent",
")",
":",
"return",
"cls",
"in",
"parent",
".",
"specific_class",
".",
"allowed_subpage_models",
"(",
")"
] | [
1390,
4
] | [
1397,
68
] | python | en | ['en', 'error', 'th'] | False |
Page.can_create_at | (cls, parent) |
Checks if this page type can be created as a subpage under a parent
page instance.
|
Checks if this page type can be created as a subpage under a parent
page instance.
| def can_create_at(cls, parent):
"""
Checks if this page type can be created as a subpage under a parent
page instance.
"""
can_create = cls.is_creatable and cls.can_exist_under(parent)
if cls.max_count is not None:
can_create = can_create and cls.objects.coun... | [
"def",
"can_create_at",
"(",
"cls",
",",
"parent",
")",
":",
"can_create",
"=",
"cls",
".",
"is_creatable",
"and",
"cls",
".",
"can_exist_under",
"(",
"parent",
")",
"if",
"cls",
".",
"max_count",
"is",
"not",
"None",
":",
"can_create",
"=",
"can_create",
... | [
1400,
4
] | [
1413,
25
] | python | en | ['en', 'error', 'th'] | False |
Page.can_move_to | (self, parent) |
Checks if this page instance can be moved to be a subpage of a parent
page instance.
|
Checks if this page instance can be moved to be a subpage of a parent
page instance.
| def can_move_to(self, parent):
"""
Checks if this page instance can be moved to be a subpage of a parent
page instance.
"""
# Prevent pages from being moved to different language sections
# The only page that can have multi-lingual children is the root page
parent... | [
"def",
"can_move_to",
"(",
"self",
",",
"parent",
")",
":",
"# Prevent pages from being moved to different language sections",
"# The only page that can have multi-lingual children is the root page",
"parent_is_root",
"=",
"parent",
".",
"depth",
"==",
"1",
"if",
"not",
"parent... | [
1415,
4
] | [
1426,
43
] | python | en | ['en', 'error', 'th'] | False |
Page.get_verbose_name | (cls) |
Returns the human-readable "verbose name" of this page model e.g "Blog page".
|
Returns the human-readable "verbose name" of this page model e.g "Blog page".
| def get_verbose_name(cls):
"""
Returns the human-readable "verbose name" of this page model e.g "Blog page".
"""
# This is similar to doing cls._meta.verbose_name.title()
# except this doesn't convert any characters to lowercase
return capfirst(cls._meta.verbose_name) | [
"def",
"get_verbose_name",
"(",
"cls",
")",
":",
"# This is similar to doing cls._meta.verbose_name.title()",
"# except this doesn't convert any characters to lowercase",
"return",
"capfirst",
"(",
"cls",
".",
"_meta",
".",
"verbose_name",
")"
] | [
1429,
4
] | [
1435,
47
] | python | en | ['en', 'error', 'th'] | False |
Page.has_unpublished_subtree | (self) |
An awkwardly-defined flag used in determining whether unprivileged editors have
permission to delete this article. Returns true if and only if this page is non-live,
and it has no live children.
|
An awkwardly-defined flag used in determining whether unprivileged editors have
permission to delete this article. Returns true if and only if this page is non-live,
and it has no live children.
| def has_unpublished_subtree(self):
"""
An awkwardly-defined flag used in determining whether unprivileged editors have
permission to delete this article. Returns true if and only if this page is non-live,
and it has no live children.
"""
return (not self.live) and (not se... | [
"def",
"has_unpublished_subtree",
"(",
"self",
")",
":",
"return",
"(",
"not",
"self",
".",
"live",
")",
"and",
"(",
"not",
"self",
".",
"get_descendants",
"(",
")",
".",
"filter",
"(",
"live",
"=",
"True",
")",
".",
"exists",
"(",
")",
")"
] | [
1467,
4
] | [
1473,
90
] | python | en | ['en', 'error', 'th'] | False |
Page.move | (self, target, pos=None, user=None) |
Extension to the treebeard 'move' method to ensure that url_path is updated,
and to emit a 'pre_page_move' and 'post_page_move' signals.
|
Extension to the treebeard 'move' method to ensure that url_path is updated,
and to emit a 'pre_page_move' and 'post_page_move' signals.
| def move(self, target, pos=None, user=None):
"""
Extension to the treebeard 'move' method to ensure that url_path is updated,
and to emit a 'pre_page_move' and 'post_page_move' signals.
"""
# Determine old and new parents
parent_before = self.get_parent()
if pos i... | [
"def",
"move",
"(",
"self",
",",
"target",
",",
"pos",
"=",
"None",
",",
"user",
"=",
"None",
")",
":",
"# Determine old and new parents",
"parent_before",
"=",
"self",
".",
"get_parent",
"(",
")",
"if",
"pos",
"in",
"(",
"'first-child'",
",",
"'last-child... | [
1475,
4
] | [
1545,
90
] | python | en | ['en', 'error', 'th'] | False |
Page.copy | (self, recursive=False, to=None, update_attrs=None, copy_revisions=True, keep_live=True, user=None,
process_child_object=None, exclude_fields=None, log_action='wagtail.copy', reset_translation_key=True, _mpnode_attrs=None) |
Copies a given page
:param log_action flag for logging the action. Pass None to skip logging.
Can be passed an action string. Defaults to 'wagtail.copy'
|
Copies a given page
:param log_action flag for logging the action. Pass None to skip logging.
Can be passed an action string. Defaults to 'wagtail.copy'
| def copy(self, recursive=False, to=None, update_attrs=None, copy_revisions=True, keep_live=True, user=None,
process_child_object=None, exclude_fields=None, log_action='wagtail.copy', reset_translation_key=True, _mpnode_attrs=None):
"""
Copies a given page
:param log_action flag for ... | [
"def",
"copy",
"(",
"self",
",",
"recursive",
"=",
"False",
",",
"to",
"=",
"None",
",",
"update_attrs",
"=",
"None",
",",
"copy_revisions",
"=",
"True",
",",
"keep_live",
"=",
"True",
",",
"user",
"=",
"None",
",",
"process_child_object",
"=",
"None",
... | [
1547,
4
] | [
1733,
24
] | python | en | ['en', 'error', 'th'] | False |
Page.create_alias | (self, *, recursive=False, parent=None, update_slug=None, update_locale=None, user=None, log_action='wagtail.create_alias', reset_translation_key=True, _mpnode_attrs=None) |
Creates an alias of the given page.
An alias is like a copy, but an alias remains in sync with the original page. They
are not directly editable and do not have revisions.
You can convert an alias into a regular page by setting the .alias_of attribute to None
and creating an i... |
Creates an alias of the given page. | def create_alias(self, *, recursive=False, parent=None, update_slug=None, update_locale=None, user=None, log_action='wagtail.create_alias', reset_translation_key=True, _mpnode_attrs=None):
"""
Creates an alias of the given page.
An alias is like a copy, but an alias remains in sync with the ori... | [
"def",
"create_alias",
"(",
"self",
",",
"*",
",",
"recursive",
"=",
"False",
",",
"parent",
"=",
"None",
",",
"update_slug",
"=",
"None",
",",
"update_locale",
"=",
"None",
",",
"user",
"=",
"None",
",",
"log_action",
"=",
"'wagtail.create_alias'",
",",
... | [
1737,
4
] | [
1874,
20
] | python | en | ['en', 'error', 'th'] | False |
Page.copy_for_translation | (self, locale, copy_parents=False, alias=False, exclude_fields=None) |
Creates a copy of this page in the specified locale.
The new page will be created in draft as a child of this page's translated
parent.
For example, if you are translating a blog post from English into French,
this method will look for the French version of the blog index and ... |
Creates a copy of this page in the specified locale. | def copy_for_translation(self, locale, copy_parents=False, alias=False, exclude_fields=None):
"""
Creates a copy of this page in the specified locale.
The new page will be created in draft as a child of this page's translated
parent.
For example, if you are translating a blog p... | [
"def",
"copy_for_translation",
"(",
"self",
",",
"locale",
",",
"copy_parents",
"=",
"False",
",",
"alias",
"=",
"False",
",",
"exclude_fields",
"=",
"None",
")",
":",
"# Find the translated version of the parent page to create the new page under",
"parent",
"=",
"self"... | [
1879,
4
] | [
1953,
13
] | python | en | ['en', 'error', 'th'] | False |
Page.permissions_for_user | (self, user) |
Return a PagePermissionsTester object defining what actions the user can perform on this page
|
Return a PagePermissionsTester object defining what actions the user can perform on this page
| def permissions_for_user(self, user):
"""
Return a PagePermissionsTester object defining what actions the user can perform on this page
"""
user_perms = UserPagePermissionsProxy(user)
return user_perms.for_page(self) | [
"def",
"permissions_for_user",
"(",
"self",
",",
"user",
")",
":",
"user_perms",
"=",
"UserPagePermissionsProxy",
"(",
"user",
")",
"return",
"user_perms",
".",
"for_page",
"(",
"self",
")"
] | [
1957,
4
] | [
1962,
40
] | python | en | ['en', 'error', 'th'] | False |
Page.make_preview_request | (self, original_request=None, preview_mode=None, extra_request_attrs=None) |
Simulate a request to this page, by constructing a fake HttpRequest object that is (as far
as possible) representative of a real request to this page's front-end URL, and invoking
serve_preview with that request (and the given preview_mode).
Used for previewing / moderation and any oth... |
Simulate a request to this page, by constructing a fake HttpRequest object that is (as far
as possible) representative of a real request to this page's front-end URL, and invoking
serve_preview with that request (and the given preview_mode). | def make_preview_request(self, original_request=None, preview_mode=None, extra_request_attrs=None):
"""
Simulate a request to this page, by constructing a fake HttpRequest object that is (as far
as possible) representative of a real request to this page's front-end URL, and invoking
serv... | [
"def",
"make_preview_request",
"(",
"self",
",",
"original_request",
"=",
"None",
",",
"preview_mode",
"=",
"None",
",",
"extra_request_attrs",
"=",
"None",
")",
":",
"dummy_meta",
"=",
"self",
".",
"_get_dummy_headers",
"(",
"original_request",
")",
"request",
... | [
1964,
4
] | [
2002,
44
] | python | en | ['en', 'error', 'th'] | False |
Page._get_dummy_headers | (self, original_request=None) |
Return a dict of META information to be included in a faked HttpRequest object to pass to
serve_preview.
|
Return a dict of META information to be included in a faked HttpRequest object to pass to
serve_preview.
| def _get_dummy_headers(self, original_request=None):
"""
Return a dict of META information to be included in a faked HttpRequest object to pass to
serve_preview.
"""
url = self._get_dummy_header_url(original_request)
if url:
url_info = urlparse(url)
... | [
"def",
"_get_dummy_headers",
"(",
"self",
",",
"original_request",
"=",
"None",
")",
":",
"url",
"=",
"self",
".",
"_get_dummy_header_url",
"(",
"original_request",
")",
"if",
"url",
":",
"url_info",
"=",
"urlparse",
"(",
"url",
")",
"hostname",
"=",
"url_in... | [
2004,
4
] | [
2062,
27
] | python | en | ['en', 'error', 'th'] | False |
Page._get_dummy_header_url | (self, original_request=None) |
Return the URL that _get_dummy_headers() should use to set META headers
for the faked HttpRequest.
|
Return the URL that _get_dummy_headers() should use to set META headers
for the faked HttpRequest.
| def _get_dummy_header_url(self, original_request=None):
"""
Return the URL that _get_dummy_headers() should use to set META headers
for the faked HttpRequest.
"""
return self.full_url | [
"def",
"_get_dummy_header_url",
"(",
"self",
",",
"original_request",
"=",
"None",
")",
":",
"return",
"self",
".",
"full_url"
] | [
2064,
4
] | [
2069,
28
] | python | en | ['en', 'error', 'th'] | False |
Page.preview_modes | (self) |
A list of (internal_name, display_name) tuples for the modes in which
this page can be displayed for preview/moderation purposes. Ordinarily a page
will only have one display mode, but subclasses of Page can override this -
for example, a page containing a form might have a default view... |
A list of (internal_name, display_name) tuples for the modes in which
this page can be displayed for preview/moderation purposes. Ordinarily a page
will only have one display mode, but subclasses of Page can override this -
for example, a page containing a form might have a default view... | def preview_modes(self):
"""
A list of (internal_name, display_name) tuples for the modes in which
this page can be displayed for preview/moderation purposes. Ordinarily a page
will only have one display mode, but subclasses of Page can override this -
for example, a page contain... | [
"def",
"preview_modes",
"(",
"self",
")",
":",
"return",
"Page",
".",
"DEFAULT_PREVIEW_MODES"
] | [
2074,
4
] | [
2082,
41
] | python | en | ['en', 'error', 'th'] | False |
Page.default_preview_mode | (self) |
The preview mode to use in workflows that do not give the user the option of selecting a
mode explicitly, e.g. moderator approval. Will raise IndexError if preview_modes is empty
|
The preview mode to use in workflows that do not give the user the option of selecting a
mode explicitly, e.g. moderator approval. Will raise IndexError if preview_modes is empty
| def default_preview_mode(self):
"""
The preview mode to use in workflows that do not give the user the option of selecting a
mode explicitly, e.g. moderator approval. Will raise IndexError if preview_modes is empty
"""
return self.preview_modes[0][0] | [
"def",
"default_preview_mode",
"(",
"self",
")",
":",
"return",
"self",
".",
"preview_modes",
"[",
"0",
"]",
"[",
"0",
"]"
] | [
2085,
4
] | [
2090,
39
] | 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.