INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
pHYs chunk in PNG image, or |None| if not present | def pHYs(self):
"""
pHYs chunk in PNG image, or |None| if not present
"""
match = lambda chunk: chunk.type_name == PNG_CHUNK_TYPE.pHYs # noqa
return self._find_first(match) |
Generate a |_Chunk| subclass instance for each chunk in this parser's
PNG stream, in the order encountered in the stream. | def iter_chunks(self):
"""
Generate a |_Chunk| subclass instance for each chunk in this parser's
PNG stream, in the order encountered in the stream.
"""
for chunk_type, offset in self._iter_chunk_offsets():
chunk = _ChunkFactory(chunk_type, self._stream_rdr, offset)
... |
Generate a (chunk_type, chunk_offset) 2-tuple for each of the chunks
in the PNG image stream. Iteration stops after the IEND chunk is
returned. | def _iter_chunk_offsets(self):
"""
Generate a (chunk_type, chunk_offset) 2-tuple for each of the chunks
in the PNG image stream. Iteration stops after the IEND chunk is
returned.
"""
chunk_offset = 8
while True:
chunk_data_len = self._stream_rdr.read_l... |
Return an _IHDRChunk instance containing the image dimensions
extracted from the IHDR chunk in *stream* at *offset*. | def from_offset(cls, chunk_type, stream_rdr, offset):
"""
Return an _IHDRChunk instance containing the image dimensions
extracted from the IHDR chunk in *stream* at *offset*.
"""
px_width = stream_rdr.read_long(offset)
px_height = stream_rdr.read_long(offset, 4)
r... |
Return a _pHYsChunk instance containing the image resolution
extracted from the pHYs chunk in *stream* at *offset*. | def from_offset(cls, chunk_type, stream_rdr, offset):
"""
Return a _pHYsChunk instance containing the image resolution
extracted from the pHYs chunk in *stream* at *offset*.
"""
horz_px_per_unit = stream_rdr.read_long(offset)
vert_px_per_unit = stream_rdr.read_long(offset... |
Return the int value of the byte at the file position defined by
self._base_offset + *base* + *offset*. If *base* is None, the byte is
read from the current position in the stream. | def read_byte(self, base, offset=0):
"""
Return the int value of the byte at the file position defined by
self._base_offset + *base* + *offset*. If *base* is None, the byte is
read from the current position in the stream.
"""
fmt = 'B'
return self._read_int(fmt, b... |
Return the int value of the four bytes at the file position defined by
self._base_offset + *base* + *offset*. If *base* is None, the long is
read from the current position in the stream. The endian setting of
this instance is used to interpret the byte layout of the long. | def read_long(self, base, offset=0):
"""
Return the int value of the four bytes at the file position defined by
self._base_offset + *base* + *offset*. If *base* is None, the long is
read from the current position in the stream. The endian setting of
this instance is used to inter... |
Return the int value of the two bytes at the file position determined
by *base* and *offset*, similarly to ``read_long()`` above. | def read_short(self, base, offset=0):
"""
Return the int value of the two bytes at the file position determined
by *base* and *offset*, similarly to ``read_long()`` above.
"""
fmt = b'<H' if self._byte_order is LITTLE_ENDIAN else b'>H'
return self._read_int(fmt, base, off... |
Return a string containing the *char_count* bytes at the file
position determined by self._base_offset + *base* + *offset*. | def read_str(self, char_count, base, offset=0):
"""
Return a string containing the *char_count* bytes at the file
position determined by self._base_offset + *base* + *offset*.
"""
def str_struct(char_count):
format_ = '%ds' % char_count
return Struct(forma... |
Load the image part collection with all the image parts in package. | def _gather_image_parts(self):
"""Load the image part collection with all the image parts in package."""
for rel in self.iter_rels():
if rel.is_external:
continue
if rel.reltype != RT.IMAGE:
continue
if rel.target_part in self.image_par... |
Return |ImagePart| object containing image identified by *image_descriptor*.
The image-part is newly created if a matching one is not present in the
collection. | def get_or_add_image_part(self, image_descriptor):
"""Return |ImagePart| object containing image identified by *image_descriptor*.
The image-part is newly created if a matching one is not present in the
collection.
"""
image = Image.from_file(image_descriptor)
matching_i... |
Return an |ImagePart| instance newly created from image and appended
to the collection. | def _add_image_part(self, image):
"""
Return an |ImagePart| instance newly created from image and appended
to the collection.
"""
partname = self._next_image_partname(image.ext)
image_part = ImagePart.from_image(image, partname)
self.append(image_part)
ret... |
Return the image part in this collection having a SHA1 hash matching
*sha1*, or |None| if not found. | def _get_by_sha1(self, sha1):
"""
Return the image part in this collection having a SHA1 hash matching
*sha1*, or |None| if not found.
"""
for image_part in self._image_parts:
if image_part.sha1 == sha1:
return image_part
return None |
The next available image partname, starting from
``/word/media/image1.{ext}`` where unused numbers are reused. The
partname is unique by number, without regard to the extension. *ext*
does not include the leading period. | def _next_image_partname(self, ext):
"""
The next available image partname, starting from
``/word/media/image1.{ext}`` where unused numbers are reused. The
partname is unique by number, without regard to the extension. *ext*
does not include the leading period.
"""
... |
Return HeaderPart or FooterPart object for this section.
If this header/footer inherits its content, the part for the prior header/footer
is returned; this process continue recursively until a definition is found. If
the definition cannot be inherited (because the header/footer belongs to the
... | def _get_or_add_definition(self):
"""Return HeaderPart or FooterPart object for this section.
If this header/footer inherits its content, the part for the prior header/footer
is returned; this process continue recursively until a definition is found. If
the definition cannot be inherite... |
Return newly-added footer part. | def _add_definition(self):
"""Return newly-added footer part."""
footer_part, rId = self._document_part.add_footer_part()
self._sectPr.add_footerReference(self._hdrftr_index, rId)
return footer_part |
|FooterPart| object containing content of this footer. | def _definition(self):
"""|FooterPart| object containing content of this footer."""
footerReference = self._sectPr.get_footerReference(self._hdrftr_index)
return self._document_part.footer_part(footerReference.rId) |
Remove footer definition (footer part) associated with this section. | def _drop_definition(self):
"""Remove footer definition (footer part) associated with this section."""
rId = self._sectPr.remove_footerReference(self._hdrftr_index)
self._document_part.drop_rel(rId) |
True if a footer is defined for this section. | def _has_definition(self):
"""True if a footer is defined for this section."""
footerReference = self._sectPr.get_footerReference(self._hdrftr_index)
return False if footerReference is None else True |
|_Footer| proxy on prior sectPr element or None if this is first section. | def _prior_headerfooter(self):
"""|_Footer| proxy on prior sectPr element or None if this is first section."""
preceding_sectPr = self._sectPr.preceding_sectPr
return (
None if preceding_sectPr is None
else _Footer(preceding_sectPr, self._document_part, self._hdrftr_index... |
Return newly-added header part. | def _add_definition(self):
"""Return newly-added header part."""
header_part, rId = self._document_part.add_header_part()
self._sectPr.add_headerReference(self._hdrftr_index, rId)
return header_part |
|HeaderPart| object containing content of this header. | def _definition(self):
"""|HeaderPart| object containing content of this header."""
headerReference = self._sectPr.get_headerReference(self._hdrftr_index)
return self._document_part.header_part(headerReference.rId) |
Remove header definition associated with this section. | def _drop_definition(self):
"""Remove header definition associated with this section."""
rId = self._sectPr.remove_headerReference(self._hdrftr_index)
self._document_part.drop_header_part(rId) |
True if a header is explicitly defined for this section. | def _has_definition(self):
"""True if a header is explicitly defined for this section."""
headerReference = self._sectPr.get_headerReference(self._hdrftr_index)
return False if headerReference is None else True |
|_Header| proxy on prior sectPr element or None if this is first section. | def _prior_headerfooter(self):
"""|_Header| proxy on prior sectPr element or None if this is first section."""
preceding_sectPr = self._sectPr.preceding_sectPr
return (
None if preceding_sectPr is None
else _Header(preceding_sectPr, self._document_part, self._hdrftr_index... |
Return a heading paragraph newly added to the end of the document.
The heading paragraph will contain *text* and have its paragraph style
determined by *level*. If *level* is 0, the style is set to `Title`. If *level*
is 1 (or omitted), `Heading 1` is used. Otherwise the style is set to `Headin... | def add_heading(self, text="", level=1):
"""Return a heading paragraph newly added to the end of the document.
The heading paragraph will contain *text* and have its paragraph style
determined by *level*. If *level* is 0, the style is set to `Title`. If *level*
is 1 (or omitted), `Headi... |
Return newly |Paragraph| object containing only a page break. | def add_page_break(self):
"""Return newly |Paragraph| object containing only a page break."""
paragraph = self.add_paragraph()
paragraph.add_run().add_break(WD_BREAK.PAGE)
return paragraph |
Return a new picture shape added in its own paragraph at the end of
the document. The picture contains the image at
*image_path_or_stream*, scaled based on *width* and *height*. If
neither width nor height is specified, the picture appears at its
native size. If only one is specified, it... | def add_picture(self, image_path_or_stream, width=None, height=None):
"""
Return a new picture shape added in its own paragraph at the end of
the document. The picture contains the image at
*image_path_or_stream*, scaled based on *width* and *height*. If
neither width nor height ... |
Return a |Section| object representing a new section added at the end
of the document. The optional *start_type* argument must be a member
of the :ref:`WdSectionStart` enumeration, and defaults to
``WD_SECTION.NEW_PAGE`` if not provided. | def add_section(self, start_type=WD_SECTION.NEW_PAGE):
"""
Return a |Section| object representing a new section added at the end
of the document. The optional *start_type* argument must be a member
of the :ref:`WdSectionStart` enumeration, and defaults to
``WD_SECTION.NEW_PAGE`` ... |
Add a table having row and column counts of *rows* and *cols*
respectively and table style of *style*. *style* may be a paragraph
style object or a paragraph style name. If *style* is |None|, the
table inherits the default table style of the document. | def add_table(self, rows, cols, style=None):
"""
Add a table having row and column counts of *rows* and *cols*
respectively and table style of *style*. *style* may be a paragraph
style object or a paragraph style name. If *style* is |None|, the
table inherits the default table st... |
Return a |Length| object specifying the width of available "writing"
space between the margins of the last section of this document. | def _block_width(self):
"""
Return a |Length| object specifying the width of available "writing"
space between the margins of the last section of this document.
"""
section = self.sections[-1]
return Emu(
section.page_width - section.left_margin - section.righ... |
The |_Body| instance containing the content for this document. | def _body(self):
"""
The |_Body| instance containing the content for this document.
"""
if self.__body is None:
self.__body = _Body(self._element.body, self)
return self.__body |
Register *cls* to be constructed when the oxml parser encounters an
element with matching *tag*. *tag* is a string of the form
``nspfx:tagroot``, e.g. ``'w:document'``. | def register_element_cls(tag, cls):
"""
Register *cls* to be constructed when the oxml parser encounters an
element with matching *tag*. *tag* is a string of the form
``nspfx:tagroot``, e.g. ``'w:document'``.
"""
nspfx, tagroot = tag.split(':')
namespace = element_class_lookup.get_namespace(... |
Return a 'loose' lxml element having the tag specified by *nsptag_str*.
*nsptag_str* must contain the standard namespace prefix, e.g. 'a:tbl'.
The resulting element is an instance of the custom element class for this
tag name if one is defined. A dictionary of attribute values may be
provided as *attrs*... | def OxmlElement(nsptag_str, attrs=None, nsdecls=None):
"""
Return a 'loose' lxml element having the tag specified by *nsptag_str*.
*nsptag_str* must contain the standard namespace prefix, e.g. 'a:tbl'.
The resulting element is an instance of the custom element class for this
tag name if one is defin... |
Return an |_IfdEntry| subclass instance containing the value of the
directory entry at *offset* in *stream_rdr*. | def _IfdEntryFactory(stream_rdr, offset):
"""
Return an |_IfdEntry| subclass instance containing the value of the
directory entry at *offset* in *stream_rdr*.
"""
ifd_entry_classes = {
TIFF_FLD.ASCII: _AsciiIfdEntry,
TIFF_FLD.SHORT: _ShortIfdEntry,
TIFF_FLD.LONG: _L... |
Return a |Tiff| instance containing the properties of the TIFF image
in *stream*. | def from_stream(cls, stream):
"""
Return a |Tiff| instance containing the properties of the TIFF image
in *stream*.
"""
parser = _TiffParser.parse(stream)
px_width = parser.px_width
px_height = parser.px_height
horz_dpi = parser.horz_dpi
vert_dpi ... |
Return an instance of |_TiffParser| containing the properties parsed
from the TIFF image in *stream*. | def parse(cls, stream):
"""
Return an instance of |_TiffParser| containing the properties parsed
from the TIFF image in *stream*.
"""
stream_rdr = cls._make_stream_reader(stream)
ifd0_offset = stream_rdr.read_long(4)
ifd_entries = _IfdEntries.from_stream(stream_rd... |
Return either BIG_ENDIAN or LITTLE_ENDIAN depending on the endian
indicator found in the TIFF *stream* header, either 'MM' or 'II'. | def _detect_endian(cls, stream):
"""
Return either BIG_ENDIAN or LITTLE_ENDIAN depending on the endian
indicator found in the TIFF *stream* header, either 'MM' or 'II'.
"""
stream.seek(0)
endian_str = stream.read(2)
return BIG_ENDIAN if endian_str == b'MM' else LI... |
Return the dpi value calculated for *resolution_tag*, which can be
either TIFF_TAG.X_RESOLUTION or TIFF_TAG.Y_RESOLUTION. The
calculation is based on the values of both that tag and the
TIFF_TAG.RESOLUTION_UNIT tag in this parser's |_IfdEntries| instance. | def _dpi(self, resolution_tag):
"""
Return the dpi value calculated for *resolution_tag*, which can be
either TIFF_TAG.X_RESOLUTION or TIFF_TAG.Y_RESOLUTION. The
calculation is based on the values of both that tag and the
TIFF_TAG.RESOLUTION_UNIT tag in this parser's |_IfdEntries... |
Return a |StreamReader| instance with wrapping *stream* and having
"endian-ness" determined by the 'MM' or 'II' indicator in the TIFF
stream header. | def _make_stream_reader(cls, stream):
"""
Return a |StreamReader| instance with wrapping *stream* and having
"endian-ness" determined by the 'MM' or 'II' indicator in the TIFF
stream header.
"""
endian = cls._detect_endian(stream)
return StreamReader(stream, endia... |
Return a new |_IfdEntries| instance parsed from *stream* starting at
*offset*. | def from_stream(cls, stream, offset):
"""
Return a new |_IfdEntries| instance parsed from *stream* starting at
*offset*.
"""
ifd_parser = _IfdParser(stream, offset)
entries = dict((e.tag, e.value) for e in ifd_parser.iter_entries())
return cls(entries) |
Generate an |_IfdEntry| instance corresponding to each entry in the
directory. | def iter_entries(self):
"""
Generate an |_IfdEntry| instance corresponding to each entry in the
directory.
"""
for idx in range(self._entry_count):
dir_entry_offset = self._offset + 2 + (idx*12)
ifd_entry = _IfdEntryFactory(self._stream_rdr, dir_entry_offs... |
Return an |_IfdEntry| subclass instance containing the tag and value
of the tag parsed from *stream_rdr* at *offset*. Note this method is
common to all subclasses. Override the ``_parse_value()`` method to
provide distinctive behavior based on field type. | def from_stream(cls, stream_rdr, offset):
"""
Return an |_IfdEntry| subclass instance containing the tag and value
of the tag parsed from *stream_rdr* at *offset*. Note this method is
common to all subclasses. Override the ``_parse_value()`` method to
provide distinctive behavior... |
Return the ASCII string parsed from *stream_rdr* at *value_offset*.
The length of the string, including a terminating '\x00' (NUL)
character, is in *value_count*. | def _parse_value(cls, stream_rdr, offset, value_count, value_offset):
"""
Return the ASCII string parsed from *stream_rdr* at *value_offset*.
The length of the string, including a terminating '\x00' (NUL)
character, is in *value_count*.
"""
return stream_rdr.read_str(valu... |
Return the short int value contained in the *value_offset* field of
this entry. Only supports single values at present. | def _parse_value(cls, stream_rdr, offset, value_count, value_offset):
"""
Return the short int value contained in the *value_offset* field of
this entry. Only supports single values at present.
"""
if value_count == 1:
return stream_rdr.read_short(offset, 8)
e... |
Return the long int value contained in the *value_offset* field of
this entry. Only supports single values at present. | def _parse_value(cls, stream_rdr, offset, value_count, value_offset):
"""
Return the long int value contained in the *value_offset* field of
this entry. Only supports single values at present.
"""
if value_count == 1:
return stream_rdr.read_long(offset, 8)
els... |
Return the rational (numerator / denominator) value at *value_offset*
in *stream_rdr* as a floating-point number. Only supports single
values at present. | def _parse_value(cls, stream_rdr, offset, value_count, value_offset):
"""
Return the rational (numerator / denominator) value at *value_offset*
in *stream_rdr* as a floating-point number. Only supports single
values at present.
"""
if value_count == 1:
numerat... |
Return (footer_part, rId) pair for newly-created footer part. | def add_footer_part(self):
"""Return (footer_part, rId) pair for newly-created footer part."""
footer_part = FooterPart.new(self.package)
rId = self.relate_to(footer_part, RT.FOOTER)
return footer_part, rId |
Return (header_part, rId) pair for newly-created header part. | def add_header_part(self):
"""Return (header_part, rId) pair for newly-created header part."""
header_part = HeaderPart.new(self.package)
rId = self.relate_to(header_part, RT.HEADER)
return header_part, rId |
A |NumberingPart| object providing access to the numbering
definitions for this document. Creates an empty numbering part if one
is not present. | def numbering_part(self):
"""
A |NumberingPart| object providing access to the numbering
definitions for this document. Creates an empty numbering part if one
is not present.
"""
try:
return self.part_related_by(RT.NUMBERING)
except KeyError:
... |
A |SettingsPart| object providing access to the document-level
settings for this document. Creates a default settings part if one is
not present. | def _settings_part(self):
"""
A |SettingsPart| object providing access to the document-level
settings for this document. Creates a default settings part if one is
not present.
"""
try:
return self.part_related_by(RT.SETTINGS)
except KeyError:
... |
Instance of |StylesPart| for this document. Creates an empty styles
part if one is not present. | def _styles_part(self):
"""
Instance of |StylesPart| for this document. Creates an empty styles
part if one is not present.
"""
try:
return self.part_related_by(RT.STYLES)
except KeyError:
styles_part = StylesPart.default(self.package)
... |
Return string containing the contents of the file at *relpath* relative to
this file. | def text_of(relpath):
"""
Return string containing the contents of the file at *relpath* relative to
this file.
"""
thisdir = os.path.dirname(__file__)
file_path = os.path.join(thisdir, os.path.normpath(relpath))
with open(file_path) as f:
text = f.read()
return text |
Write a physical package (.pptx file) to *pkg_file* containing
*pkg_rels* and *parts* and a content types stream based on the
content types of the parts. | def write(pkg_file, pkg_rels, parts):
"""
Write a physical package (.pptx file) to *pkg_file* containing
*pkg_rels* and *parts* and a content types stream based on the
content types of the parts.
"""
phys_writer = PhysPkgWriter(pkg_file)
PackageWriter._write_conte... |
Write ``[Content_Types].xml`` part to the physical package with an
appropriate content type lookup target for each part in *parts*. | def _write_content_types_stream(phys_writer, parts):
"""
Write ``[Content_Types].xml`` part to the physical package with an
appropriate content type lookup target for each part in *parts*.
"""
cti = _ContentTypesItem.from_parts(parts)
phys_writer.write(CONTENT_TYPES_URI, ... |
Write the blob of each part in *parts* to the package, along with a
rels item for its relationships if and only if it has any. | def _write_parts(phys_writer, parts):
"""
Write the blob of each part in *parts* to the package, along with a
rels item for its relationships if and only if it has any.
"""
for part in parts:
phys_writer.write(part.partname, part.blob)
if len(part._rels):
... |
Add a content type for the part with *partname* and *content_type*,
using a default or override as appropriate. | def _add_content_type(self, partname, content_type):
"""
Add a content type for the part with *partname* and *content_type*,
using a default or override as appropriate.
"""
ext = partname.ext
if (ext.lower(), content_type) in default_content_types:
self._defau... |
Return content types XML mapping each part in *parts* to the
appropriate content type and suitable for storage as
``[Content_Types].xml`` in an OPC package. | def from_parts(cls, parts):
"""
Return content types XML mapping each part in *parts* to the
appropriate content type and suitable for storage as
``[Content_Types].xml`` in an OPC package.
"""
cti = cls()
cti._defaults['rels'] = CT.OPC_RELATIONSHIPS
cti._d... |
Return XML form of this content types item, suitable for storage as
``[Content_Types].xml`` in an OPC package. Although the sequence of
elements is not strictly significant, as an aid to testing and
readability Default elements are sorted by extension and Override
elements are sorted by ... | def _element(self):
"""
Return XML form of this content types item, suitable for storage as
``[Content_Types].xml`` in an OPC package. Although the sequence of
elements is not strictly significant, as an aid to testing and
readability Default elements are sorted by extension and ... |
Mixed here meaning it contains ``<w:tab/>``, ``<w:cr/>``, etc. elements. | def given_a_run_having_mixed_text_content(context):
"""
Mixed here meaning it contains ``<w:tab/>``, ``<w:cr/>``, etc. elements.
"""
r_xml = """\
<w:r %s>
<w:t>abc</w:t>
<w:tab/>
<w:t>def</w:t>
<w:cr/>
<w:t>ghi</w:t>
<w:drawing/>
... |
Return `w:sectPr` element for new section added at end of document.
The last `w:sectPr` becomes the second-to-last, with the new `w:sectPr` being an
exact clone of the previous one, except that all header and footer references
are removed (and are therefore now "inherited" from the prior sectio... | def add_section_break(self):
"""Return `w:sectPr` element for new section added at end of document.
The last `w:sectPr` becomes the second-to-last, with the new `w:sectPr` being an
exact clone of the previous one, except that all header and footer references
are removed (and are therefo... |
Remove all content child elements from this <w:body> element. Leave
the <w:sectPr> element if it is present. | def clear_content(self):
"""
Remove all content child elements from this <w:body> element. Leave
the <w:sectPr> element if it is present.
"""
if self.sectPr is not None:
content_elms = self[:-1]
else:
content_elms = self[:]
for content_elm ... |
Return a |BaseImageHeader| subclass instance that knows how to parse the
headers of the image in *stream*. | def _ImageHeaderFactory(stream):
"""
Return a |BaseImageHeader| subclass instance that knows how to parse the
headers of the image in *stream*.
"""
from docx.image import SIGNATURES
def read_32(stream):
stream.seek(0)
return stream.read(32)
header = read_32(stream)
for ... |
Return a new |Image| subclass instance parsed from the image binary
contained in *blob*. | def from_blob(cls, blob):
"""
Return a new |Image| subclass instance parsed from the image binary
contained in *blob*.
"""
stream = BytesIO(blob)
return cls._from_stream(stream, blob) |
Return a new |Image| subclass instance loaded from the image file
identified by *image_descriptor*, a path or file-like object. | def from_file(cls, image_descriptor):
"""
Return a new |Image| subclass instance loaded from the image file
identified by *image_descriptor*, a path or file-like object.
"""
if is_string(image_descriptor):
path = image_descriptor
with open(path, 'rb') as f... |
Return a (cx, cy) 2-tuple representing the native dimensions of this
image scaled by applying the following rules to *width* and *height*.
If both *width* and *height* are specified, the return value is
(*width*, *height*); no scaling is performed. If only one is
specified, it is used to... | def scaled_dimensions(self, width=None, height=None):
"""
Return a (cx, cy) 2-tuple representing the native dimensions of this
image scaled by applying the following rules to *width* and *height*.
If both *width* and *height* are specified, the return value is
(*width*, *height*)... |
Return an instance of the |Image| subclass corresponding to the
format of the image in *stream*. | def _from_stream(cls, stream, blob, filename=None):
"""
Return an instance of the |Image| subclass corresponding to the
format of the image in *stream*.
"""
image_header = _ImageHeaderFactory(stream)
if filename is None:
filename = 'image.%s' % image_header.de... |
Append a run to this paragraph containing *text* and having character
style identified by style ID *style*. *text* can contain tab
(``\\t``) characters, which are converted to the appropriate XML form
for a tab. *text* can also include newline (``\\n``) or carriage
return (``\\r``) chara... | def add_run(self, text=None, style=None):
"""
Append a run to this paragraph containing *text* and having character
style identified by style ID *style*. *text* can contain tab
(``\\t``) characters, which are converted to the appropriate XML form
for a tab. *text* can also includ... |
Return a newly created paragraph, inserted directly before this
paragraph. If *text* is supplied, the new paragraph contains that
text in a single run. If *style* is provided, that style is assigned
to the new paragraph. | def insert_paragraph_before(self, text=None, style=None):
"""
Return a newly created paragraph, inserted directly before this
paragraph. If *text* is supplied, the new paragraph contains that
text in a single run. If *style* is provided, that style is assigned
to the new paragrap... |
Read/Write. |_ParagraphStyle| object representing the style assigned
to this paragraph. If no explicit style is assigned to this
paragraph, its value is the default paragraph style for the document.
A paragraph style name can be assigned in lieu of a paragraph style
object. Assigning |No... | def style(self):
"""
Read/Write. |_ParagraphStyle| object representing the style assigned
to this paragraph. If no explicit style is assigned to this
paragraph, its value is the default paragraph style for the document.
A paragraph style name can be assigned in lieu of a paragrap... |
String formed by concatenating the text of each run in the paragraph.
Tabs and line breaks in the XML are mapped to ``\\t`` and ``\\n``
characters respectively.
Assigning text to this property causes all existing paragraph content
to be replaced with a single run containing the assigned... | def text(self):
"""
String formed by concatenating the text of each run in the paragraph.
Tabs and line breaks in the XML are mapped to ``\\t`` and ``\\n``
characters respectively.
Assigning text to this property causes all existing paragraph content
to be replaced with ... |
Return a newly created paragraph, inserted directly before this
paragraph. | def _insert_paragraph_before(self):
"""
Return a newly created paragraph, inserted directly before this
paragraph.
"""
p = self._p.add_p_before()
return Paragraph(p, self._parent) |
Serialize *element* to human-readable XML suitable for tests. No XML
declaration. | def serialize_for_reading(element):
"""
Serialize *element* to human-readable XML suitable for tests. No XML
declaration.
"""
xml = etree.tostring(element, encoding='unicode', pretty_print=True)
return XmlString(xml) |
Return a sequence of attribute strings parsed from *attrs*. Each
attribute string is stripped of whitespace on both ends. | def _attr_seq(self, attrs):
"""
Return a sequence of attribute strings parsed from *attrs*. Each
attribute string is stripped of whitespace on both ends.
"""
attrs = attrs.strip()
attr_lst = attrs.split()
return sorted(attr_lst) |
Return True if the element in *line_2* is XML equivalent to the
element in *line*. | def _eq_elm_strs(self, line, line_2):
"""
Return True if the element in *line_2* is XML equivalent to the
element in *line*.
"""
front, attrs, close, text = self._parse_line(line)
front_2, attrs_2, close_2, text_2 = self._parse_line(line_2)
if front != front_2:
... |
Return front, attrs, close, text 4-tuple result of parsing XML element
string *line*. | def _parse_line(cls, line):
"""
Return front, attrs, close, text 4-tuple result of parsing XML element
string *line*.
"""
match = cls._xml_elm_line_patt.match(line)
front, attrs, close, text = [match.group(n) for n in range(1, 5)]
return front, attrs, close, text |
Add the appropriate methods to *element_cls*. | def populate_class_members(self, element_cls, prop_name):
"""
Add the appropriate methods to *element_cls*.
"""
self._element_cls = element_cls
self._prop_name = prop_name
self._add_attr_property() |
Add a read/write ``{prop_name}`` property to the element class that
returns the interpreted value of this attribute on access and changes
the attribute value to its ST_* counterpart on assignment. | def _add_attr_property(self):
"""
Add a read/write ``{prop_name}`` property to the element class that
returns the interpreted value of this attribute on access and changes
the attribute value to its ST_* counterpart on assignment.
"""
property_ = property(self._getter, se... |
Return a function object suitable for the "get" side of the attribute
property descriptor. | def _getter(self):
"""
Return a function object suitable for the "get" side of the attribute
property descriptor.
"""
def get_attr_value(obj):
attr_str_value = obj.get(self._clark_name)
if attr_str_value is None:
return self._default
... |
Return a function object suitable for the "set" side of the attribute
property descriptor. | def _setter(self):
"""
Return a function object suitable for the "set" side of the attribute
property descriptor.
"""
def set_attr_value(obj, value):
if value is None or value == self._default:
if self._clark_name in obj.attrib:
del... |
Return a function object suitable for the "get" side of the attribute
property descriptor. | def _getter(self):
"""
Return a function object suitable for the "get" side of the attribute
property descriptor.
"""
def get_attr_value(obj):
attr_str_value = obj.get(self._clark_name)
if attr_str_value is None:
raise InvalidXmlError(
... |
Return a function object suitable for the "set" side of the attribute
property descriptor. | def _setter(self):
"""
Return a function object suitable for the "set" side of the attribute
property descriptor.
"""
def set_attr_value(obj, value):
str_value = self._simple_type.to_xml(value)
obj.set(self._clark_name, str_value)
return set_attr_v... |
Add an ``_add_x()`` method to the element class for this child
element. | def _add_adder(self):
"""
Add an ``_add_x()`` method to the element class for this child
element.
"""
def _add_child(obj, **attrs):
new_method = getattr(obj, self._new_method_name)
child = new_method()
for key, value in attrs.items():
... |
Add a ``_new_{prop_name}()`` method to the element class that creates
a new, empty element of the correct type, having no attributes. | def _add_creator(self):
"""
Add a ``_new_{prop_name}()`` method to the element class that creates
a new, empty element of the correct type, having no attributes.
"""
creator = self._creator
creator.__doc__ = (
'Return a "loose", newly created ``<%s>`` element ... |
Add a read-only ``{prop_name}`` property to the element class for
this child element. | def _add_getter(self):
"""
Add a read-only ``{prop_name}`` property to the element class for
this child element.
"""
property_ = property(self._getter, None, None)
# assign unconditionally to overwrite element name definition
setattr(self._element_cls, self._prop_... |
Add an ``_insert_x()`` method to the element class for this child
element. | def _add_inserter(self):
"""
Add an ``_insert_x()`` method to the element class for this child
element.
"""
def _insert_child(obj, child):
obj.insert_element_before(child, *self._successors)
return child
_insert_child.__doc__ = (
'Retu... |
Add a read-only ``{prop_name}_lst`` property to the element class to
retrieve a list of child elements matching this type. | def _add_list_getter(self):
"""
Add a read-only ``{prop_name}_lst`` property to the element class to
retrieve a list of child elements matching this type.
"""
prop_name = '%s_lst' % self._prop_name
property_ = property(self._list_getter, None, None)
setattr(self._... |
Add a public ``add_x()`` method to the parent element class. | def _add_public_adder(self):
"""
Add a public ``add_x()`` method to the parent element class.
"""
def add_child(obj):
private_add_method = getattr(obj, self._add_method_name)
child = private_add_method()
return child
add_child.__doc__ = (
... |
Add *method* to the target class as *name*, unless *name* is already
defined on the class. | def _add_to_class(self, name, method):
"""
Add *method* to the target class as *name*, unless *name* is already
defined on the class.
"""
if hasattr(self._element_cls, name):
return
setattr(self._element_cls, name, method) |
Return a function object suitable for the "get" side of the property
descriptor. This default getter returns the child element with
matching tag name or |None| if not present. | def _getter(self):
"""
Return a function object suitable for the "get" side of the property
descriptor. This default getter returns the child element with
matching tag name or |None| if not present.
"""
def get_child_element(obj):
return obj.find(qn(self._nspt... |
Return a function object suitable for the "get" side of a list
property descriptor. | def _list_getter(self):
"""
Return a function object suitable for the "get" side of a list
property descriptor.
"""
def get_child_element_list(obj):
return obj.findall(qn(self._nsptagname))
get_child_element_list.__doc__ = (
'A list containing each... |
Add the appropriate methods to *element_cls*. | def populate_class_members(
self, element_cls, group_prop_name, successors):
"""
Add the appropriate methods to *element_cls*.
"""
self._element_cls = element_cls
self._group_prop_name = group_prop_name
self._successors = successors
self._add_getter()... |
Add a ``get_or_change_to_x()`` method to the element class for this
child element. | def _add_get_or_change_to_method(self):
"""
Add a ``get_or_change_to_x()`` method to the element class for this
child element.
"""
def get_or_change_to_child(obj):
child = getattr(obj, self._prop_name)
if child is not None:
return child
... |
Calculate property name from tag name, e.g. a:schemeClr -> schemeClr. | def _prop_name(self):
"""
Calculate property name from tag name, e.g. a:schemeClr -> schemeClr.
"""
if ':' in self._nsptagname:
start = self._nsptagname.index(':') + 1
else:
start = 0
return self._nsptagname[start:] |
Add the appropriate methods to *element_cls*. | def populate_class_members(self, element_cls, prop_name):
"""
Add the appropriate methods to *element_cls*.
"""
super(OneAndOnlyOne, self).populate_class_members(
element_cls, prop_name
)
self._add_getter() |
Add the appropriate methods to *element_cls*. | def populate_class_members(self, element_cls, prop_name):
"""
Add the appropriate methods to *element_cls*.
"""
super(OneOrMore, self).populate_class_members(
element_cls, prop_name
)
self._add_list_getter()
self._add_creator()
self._add_insert... |
Add the appropriate methods to *element_cls*. | def populate_class_members(self, element_cls, prop_name):
"""
Add the appropriate methods to *element_cls*.
"""
super(ZeroOrOne, self).populate_class_members(element_cls, prop_name)
self._add_getter()
self._add_creator()
self._add_inserter()
self._add_adde... |
Add a ``get_or_add_x()`` method to the element class for this
child element. | def _add_get_or_adder(self):
"""
Add a ``get_or_add_x()`` method to the element class for this
child element.
"""
def get_or_add_child(obj):
child = getattr(obj, self._prop_name)
if child is None:
add_method = getattr(obj, self._add_method_... |
Add a ``_remove_x()`` method to the element class for this child
element. | def _add_remover(self):
"""
Add a ``_remove_x()`` method to the element class for this child
element.
"""
def _remove_child(obj):
obj.remove_all(self._nsptagname)
_remove_child.__doc__ = (
'Remove all ``<%s>`` child elements.'
) % self._nsp... |
Add the appropriate methods to *element_cls*. | def populate_class_members(self, element_cls, prop_name):
"""
Add the appropriate methods to *element_cls*.
"""
super(ZeroOrOneChoice, self).populate_class_members(
element_cls, prop_name
)
self._add_choice_getter()
for choice in self._choices:
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.