INSTRUCTION stringlengths 1 8.43k | RESPONSE stringlengths 75 104k |
|---|---|
Compile XML mappings in addition to base add behavior. | def add_to_enum(self, clsdict):
"""
Compile XML mappings in addition to base add behavior.
"""
super(XmlMappedEnumMember, self).add_to_enum(clsdict)
self.register_xml_mapping(clsdict) |
Add XML mappings to the enumeration class state for this member. | def register_xml_mapping(self, clsdict):
"""
Add XML mappings to the enumeration class state for this member.
"""
member_to_xml = self._get_or_add_member_to_xml(clsdict)
member_to_xml[self.value] = self.xml_value
xml_to_member = self._get_or_add_xml_to_member(clsdict)
... |
Return a |Document| object loaded from * docx * where * docx * can be either a path to a. docx file ( a string ) or a file - like object. If * docx * is missing or None the built - in default document template is loaded. | def Document(docx=None):
"""
Return a |Document| object loaded from *docx*, where *docx* can be
either a path to a ``.docx`` file (a string) or a file-like object. If
*docx* is missing or ``None``, the built-in default document "template"
is loaded.
"""
docx = _default_docx_path() if docx is... |
Return the path to the built - in default. docx package. | def _default_docx_path():
"""
Return the path to the built-in default .docx package.
"""
_thisdir = os.path.split(__file__)[0]
return os.path.join(_thisdir, 'templates', 'default-docx-template') |
|float| or |Length| value specifying the space between baselines in successive lines of the paragraph. A value of |None| indicates line spacing is inherited from the style hierarchy. A float value e. g. 2. 0 or 1. 75 indicates spacing is applied in multiples of line heights. A |Length| value such as Pt ( 12 ) indicates... | def line_spacing(self):
"""
|float| or |Length| value specifying the space between baselines in
successive lines of the paragraph. A value of |None| indicates line
spacing is inherited from the style hierarchy. A float value, e.g.
``2.0`` or ``1.75``, indicates spacing is applied... |
A member of the: ref: WdLineSpacing enumeration indicating how the value of: attr: line_spacing should be interpreted. Assigning any of the: ref: WdLineSpacing members: attr: SINGLE: attr: DOUBLE or: attr: ONE_POINT_FIVE will cause the value of: attr: line_spacing to be updated to produce the corresponding line spacing... | def line_spacing_rule(self):
"""
A member of the :ref:`WdLineSpacing` enumeration indicating how the
value of :attr:`line_spacing` should be interpreted. Assigning any of
the :ref:`WdLineSpacing` members :attr:`SINGLE`, :attr:`DOUBLE`, or
:attr:`ONE_POINT_FIVE` will cause the val... |
Return the line spacing value calculated from the combination of * spacing_line * and * spacing_lineRule *. Returns a |float| number of lines when * spacing_lineRule * is WD_LINE_SPACING. MULTIPLE otherwise a |Length| object of absolute line height is returned. Returns |None| when * spacing_line * is |None|. | def _line_spacing(spacing_line, spacing_lineRule):
"""
Return the line spacing value calculated from the combination of
*spacing_line* and *spacing_lineRule*. Returns a |float| number of
lines when *spacing_lineRule* is ``WD_LINE_SPACING.MULTIPLE``,
otherwise a |Length| object of... |
Return the line spacing rule value calculated from the combination of * line * and * lineRule *. Returns special members of the: ref: WdLineSpacing enumeration when line spacing is single double or 1. 5 lines. | def _line_spacing_rule(line, lineRule):
"""
Return the line spacing rule value calculated from the combination of
*line* and *lineRule*. Returns special members of the
:ref:`WdLineSpacing` enumeration when line spacing is single, double,
or 1.5 lines.
"""
if lineR... |
Return a new <w: num > element having numId of * num_id * and having a <w: abstractNumId > child with val attribute set to * abstractNum_id *. | def new(cls, num_id, abstractNum_id):
"""
Return a new ``<w:num>`` element having numId of *num_id* and having
a ``<w:abstractNumId>`` child with val attribute set to
*abstractNum_id*.
"""
num = OxmlElement('w:num')
num.numId = num_id
abstractNumId = CT_De... |
Return a newly added CT_Num ( <w: num > ) element referencing the abstract numbering definition identified by * abstractNum_id *. | def add_num(self, abstractNum_id):
"""
Return a newly added CT_Num (<w:num>) element referencing the
abstract numbering definition identified by *abstractNum_id*.
"""
next_num_id = self._next_numId
num = CT_Num.new(next_num_id, abstractNum_id)
return self._insert_... |
Return the <w: num > child element having numId attribute matching * numId *. | def num_having_numId(self, numId):
"""
Return the ``<w:num>`` child element having ``numId`` attribute
matching *numId*.
"""
xpath = './w:num[@w:numId="%d"]' % numId
try:
return self.xpath(xpath)[0]
except IndexError:
raise KeyError('no <w:... |
The first numId unused by a <w: num > element starting at 1 and filling any gaps in numbering between existing <w: num > elements. | def _next_numId(self):
"""
The first ``numId`` unused by a ``<w:num>`` element, starting at
1 and filling any gaps in numbering between existing ``<w:num>``
elements.
"""
numId_strs = self.xpath('./w:num/@w:numId')
num_ids = [int(numId_str) for numId_str in numId_... |
Return a newly added |_Relationship| instance. | def add_relationship(self, reltype, target, rId, is_external=False):
"""
Return a newly added |_Relationship| instance.
"""
rel = _Relationship(rId, reltype, target, self._baseURI, is_external)
self[rId] = rel
if not is_external:
self._target_parts_by_rId[rId]... |
Return relationship of * reltype * to * target_part * newly added if not already present in collection. | def get_or_add(self, reltype, target_part):
"""
Return relationship of *reltype* to *target_part*, newly added if not
already present in collection.
"""
rel = self._get_matching(reltype, target_part)
if rel is None:
rId = self._next_rId
rel = self.... |
Return rId of external relationship of * reltype * to * target_ref * newly added if not already present in collection. | def get_or_add_ext_rel(self, reltype, target_ref):
"""
Return rId of external relationship of *reltype* to *target_ref*,
newly added if not already present in collection.
"""
rel = self._get_matching(reltype, target_ref, is_external=True)
if rel is None:
rId =... |
Serialize this relationship collection into XML suitable for storage as a. rels file in an OPC package. | def xml(self):
"""
Serialize this relationship collection into XML suitable for storage
as a .rels file in an OPC package.
"""
rels_elm = CT_Relationships.new()
for rel in self.values():
rels_elm.add_rel(
rel.rId, rel.reltype, rel.target_ref, r... |
Return relationship of matching * reltype * * target * and * is_external * from collection or None if not found. | def _get_matching(self, reltype, target, is_external=False):
"""
Return relationship of matching *reltype*, *target*, and
*is_external* from collection, or None if not found.
"""
def matches(rel, reltype, target, is_external):
if rel.reltype != reltype:
... |
Return single relationship of type * reltype * from the collection. Raises |KeyError| if no matching relationship is found. Raises |ValueError| if more than one matching relationship is found. | def _get_rel_of_type(self, reltype):
"""
Return single relationship of type *reltype* from the collection.
Raises |KeyError| if no matching relationship is found. Raises
|ValueError| if more than one matching relationship is found.
"""
matching = [rel for rel in self.valu... |
Next available rId in collection starting from rId1 and making use of any gaps in numbering e. g. rId2 for rIds [ rId1 rId3 ]. | def _next_rId(self):
"""
Next available rId in collection, starting from 'rId1' and making use
of any gaps in numbering, e.g. 'rId2' for rIds ['rId1', 'rId3'].
"""
for n in range(1, len(self)+2):
rId_candidate = 'rId%d' % n # like 'rId19'
if rId_candidate... |
Return a new CT_DecimalNumber element having tagname * nsptagname * and val attribute set to * val *. | def new(cls, nsptagname, val):
"""
Return a new ``CT_DecimalNumber`` element having tagname *nsptagname*
and ``val`` attribute set to *val*.
"""
return OxmlElement(nsptagname, attrs={qn('w:val'): str(val)}) |
Return a new CT_String element with tagname * nsptagname * and val attribute set to * val *. | def new(cls, nsptagname, val):
"""
Return a new ``CT_String`` element with tagname *nsptagname* and
``val`` attribute set to *val*.
"""
elm = OxmlElement(nsptagname)
elm.val = val
return elm |
Return a style object of the appropriate |BaseStyle| subclass according to the type of * style_elm *. | def StyleFactory(style_elm):
"""
Return a style object of the appropriate |BaseStyle| subclass, according
to the type of *style_elm*.
"""
style_cls = {
WD_STYLE_TYPE.PARAGRAPH: _ParagraphStyle,
WD_STYLE_TYPE.CHARACTER: _CharacterStyle,
WD_STYLE_TYPE.TABLE: _TableStyle,
... |
The UI name of this style. | def name(self):
"""
The UI name of this style.
"""
name = self._element.name_val
if name is None:
return None
return BabelFish.internal2ui(name) |
Member of: ref: WdStyleType corresponding to the type of this style e. g. WD_STYLE_TYPE. PARAGRAPH. | def type(self):
"""
Member of :ref:`WdStyleType` corresponding to the type of this style,
e.g. ``WD_STYLE_TYPE.PARAGRAPH``.
"""
type = self._element.type
if type is None:
return WD_STYLE_TYPE.PARAGRAPH
return type |
|_ParagraphStyle| object representing the style to be applied automatically to a new paragraph inserted after a paragraph of this style. Returns self if no next paragraph style is defined. Assigning |None| or * self * removes the setting such that new paragraphs are created using this same style. | def next_paragraph_style(self):
"""
|_ParagraphStyle| object representing the style to be applied
automatically to a new paragraph inserted after a paragraph of this
style. Returns self if no next paragraph style is defined. Assigning
|None| or *self* removes the setting such tha... |
Integer value of revision property. | def revision_number(self):
"""
Integer value of revision property.
"""
revision = self.revision
if revision is None:
return 0
revision_str = revision.text
try:
revision = int(revision_str)
except ValueError:
# non-intege... |
Set revision property to string value of integer * value *. | def revision_number(self, value):
"""
Set revision property to string value of integer *value*.
"""
if not isinstance(value, int) or value < 1:
tmpl = "revision property requires positive int, got '%s'"
raise ValueError(tmpl % value)
revision = self.get_or... |
Return element returned by get_or_add_ method for * prop_name *. | def _get_or_add(self, prop_name):
"""
Return element returned by 'get_or_add_' method for *prop_name*.
"""
get_or_add_method_name = 'get_or_add_%s' % prop_name
get_or_add_method = getattr(self, get_or_add_method_name)
element = get_or_add_method()
return element |
Return a |datetime| instance that is offset from datetime * dt * by the timezone offset specified in * offset_str * a string like - 07: 00. | def _offset_dt(cls, dt, offset_str):
"""
Return a |datetime| instance that is offset from datetime *dt* by
the timezone offset specified in *offset_str*, a string like
``'-07:00'``.
"""
match = cls._offset_pattern.match(offset_str)
if match is None:
ra... |
Set date/ time value of child element having * prop_name * to * value *. | def _set_element_datetime(self, prop_name, value):
"""
Set date/time value of child element having *prop_name* to *value*.
"""
if not isinstance(value, datetime):
tmpl = (
"property requires <type 'datetime.datetime'> object, got %s"
)
... |
Set string value of * name * property to * value *. | def _set_element_text(self, prop_name, value):
"""Set string value of *name* property to *value*."""
if not is_string(value):
value = str(value)
if len(value) > 255:
tmpl = (
"exceeded 255 char limit for property, got:\n\n'%s'"
)
r... |
Return the text in the element matching * property_name * or an empty string if the element is not present or contains no text. | def _text_of_element(self, property_name):
"""
Return the text in the element matching *property_name*, or an empty
string if the element is not present or contains no text.
"""
element = getattr(self, property_name)
if element is None:
return ''
if el... |
Return |Gif| instance having header properties parsed from GIF image in * stream *. | def from_stream(cls, stream):
"""
Return |Gif| instance having header properties parsed from GIF image
in *stream*.
"""
px_width, px_height = cls._dimensions_from_stream(stream)
return cls(px_width, px_height, 72, 72) |
Return contents of file corresponding to * pack_uri * in package directory. | def blob_for(self, pack_uri):
"""
Return contents of file corresponding to *pack_uri* in package
directory.
"""
path = os.path.join(self._path, pack_uri.membername)
with open(path, 'rb') as f:
blob = f.read()
return blob |
Return rels item XML for source with * source_uri * or None if the item has no rels item. | def rels_xml_for(self, source_uri):
"""
Return rels item XML for source with *source_uri*, or None if the
item has no rels item.
"""
try:
rels_xml = self.blob_for(source_uri.rels_uri)
except IOError:
rels_xml = None
return rels_xml |
Return rels item XML for source with * source_uri * or None if no rels item is present. | def rels_xml_for(self, source_uri):
"""
Return rels item XML for source with *source_uri* or None if no rels
item is present.
"""
try:
rels_xml = self.blob_for(source_uri.rels_uri)
except KeyError:
rels_xml = None
return rels_xml |
Write * blob * to this zip package with the membername corresponding to * pack_uri *. | def write(self, pack_uri, blob):
"""
Write *blob* to this zip package with the membername corresponding to
*pack_uri*.
"""
self._zipf.writestr(pack_uri.membername, blob) |
Return |Bmp| instance having header properties parsed from the BMP image in * stream *. | def from_stream(cls, stream):
"""
Return |Bmp| instance having header properties parsed from the BMP
image in *stream*.
"""
stream_rdr = StreamReader(stream, LITTLE_ENDIAN)
px_width = stream_rdr.read_long(0x12)
px_height = stream_rdr.read_long(0x16)
horz... |
Stands for qualified name a utility function to turn a namespace prefixed tag name into a Clark - notation qualified tag name for lxml. For example qn ( p: cSld ) returns { http:// schemas.../ main } cSld. | def qn(tag):
"""
Stands for "qualified name", a utility function to turn a namespace
prefixed tag name into a Clark-notation qualified tag name for lxml. For
example, ``qn('p:cSld')`` returns ``'{http://schemas.../main}cSld'``.
"""
prefix, tagroot = tag.split(':')
uri = nsmap[prefix]
ret... |
Remove all child elements except the <w: pPr > element if present. | def clear_content(self):
"""
Remove all child elements, except the ``<w:pPr>`` element if present.
"""
for child in self[:]:
if child.tag == qn('w:pPr'):
continue
self.remove(child) |
Unconditionally replace or add * sectPr * as a grandchild in the correct sequence. | def set_sectPr(self, sectPr):
"""
Unconditionally replace or add *sectPr* as a grandchild in the
correct sequence.
"""
pPr = self.get_or_add_pPr()
pPr._remove_sectPr()
pPr._insert_sectPr(sectPr) |
Return a |PackageReader| instance loaded with contents of * pkg_file *. | def from_file(pkg_file):
"""
Return a |PackageReader| instance loaded with contents of *pkg_file*.
"""
phys_reader = PhysPkgReader(pkg_file)
content_types = _ContentTypeMap.from_xml(phys_reader.content_types_xml)
pkg_srels = PackageReader._srels_for(phys_reader, PACKAGE_U... |
Generate a 4 - tuple ( partname content_type reltype blob ) for each of the serialized parts in the package. | def iter_sparts(self):
"""
Generate a 4-tuple `(partname, content_type, reltype, blob)` for each
of the serialized parts in the package.
"""
for s in self._sparts:
yield (s.partname, s.content_type, s.reltype, s.blob) |
Generate a 2 - tuple ( source_uri srel ) for each of the relationships in the package. | def iter_srels(self):
"""
Generate a 2-tuple `(source_uri, srel)` for each of the relationships
in the package.
"""
for srel in self._pkg_srels:
yield (PACKAGE_URI, srel)
for spart in self._sparts:
for srel in spart.srels:
yield (sp... |
Return |_SerializedRelationships| instance populated with relationships for source identified by * source_uri *. | def _srels_for(phys_reader, source_uri):
"""
Return |_SerializedRelationships| instance populated with
relationships for source identified by *source_uri*.
"""
rels_xml = phys_reader.rels_xml_for(source_uri)
return _SerializedRelationships.load_from_xml(
sourc... |
Return a new |_ContentTypeMap| instance populated with the contents of * content_types_xml *. | def from_xml(content_types_xml):
"""
Return a new |_ContentTypeMap| instance populated with the contents
of *content_types_xml*.
"""
types_elm = parse_xml(content_types_xml)
ct_map = _ContentTypeMap()
for o in types_elm.overrides:
ct_map._add_override(... |
|PackURI| instance containing partname targeted by this relationship. Raises ValueError on reference if target_mode is External. Use: attr: target_mode to check before referencing. | def target_partname(self):
"""
|PackURI| instance containing partname targeted by this relationship.
Raises ``ValueError`` on reference if target_mode is ``'External'``.
Use :attr:`target_mode` to check before referencing.
"""
if self.is_external:
msg = ('targ... |
Return |_SerializedRelationships| instance loaded with the relationships contained in * rels_item_xml *. Returns an empty collection if * rels_item_xml * is |None|. | def load_from_xml(baseURI, rels_item_xml):
"""
Return |_SerializedRelationships| instance loaded with the
relationships contained in *rels_item_xml*. Returns an empty
collection if *rels_item_xml* is |None|.
"""
srels = _SerializedRelationships()
if rels_item_xml ... |
Return a |PackURI| instance containing the absolute pack URI formed by translating * relative_ref * onto * baseURI *. | def from_rel_ref(baseURI, relative_ref):
"""
Return a |PackURI| instance containing the absolute pack URI formed by
translating *relative_ref* onto *baseURI*.
"""
joined_uri = posixpath.join(baseURI, relative_ref)
abs_uri = posixpath.abspath(joined_uri)
return Pac... |
The extension portion of this pack URI e. g. xml for/ word/ document. xml. Note the period is not included. | def ext(self):
"""
The extension portion of this pack URI, e.g. ``'xml'`` for
``'/word/document.xml'``. Note the period is not included.
"""
# raw_ext is either empty string or starts with period, e.g. '.xml'
raw_ext = posixpath.splitext(self)[1]
return raw_ext[1:... |
Return partname index as integer for tuple partname or None for singleton partname e. g. 21 for/ ppt/ slides/ slide21. xml and |None| for/ ppt/ presentation. xml. | def idx(self):
"""
Return partname index as integer for tuple partname or None for
singleton partname, e.g. ``21`` for ``'/ppt/slides/slide21.xml'`` and
|None| for ``'/ppt/presentation.xml'``.
"""
filename = self.filename
if not filename:
return None
... |
Return string containing relative reference to package item from * baseURI *. E. g. PackURI (/ ppt/ slideLayouts/ slideLayout1. xml ) would return../ slideLayouts/ slideLayout1. xml for baseURI/ ppt/ slides. | def relative_ref(self, baseURI):
"""
Return string containing relative reference to package item from
*baseURI*. E.g. PackURI('/ppt/slideLayouts/slideLayout1.xml') would
return '../slideLayouts/slideLayout1.xml' for baseURI '/ppt/slides'.
"""
# workaround for posixpath bu... |
The pack URI of the. rels part corresponding to the current pack URI. Only produces sensible output if the pack URI is a partname or the package pseudo - partname/. | def rels_uri(self):
"""
The pack URI of the .rels part corresponding to the current pack URI.
Only produces sensible output if the pack URI is a partname or the
package pseudo-partname '/'.
"""
rels_filename = '%s.rels' % self.filename
rels_uri_str = posixpath.joi... |
Return a new <Default > element with attributes set to parameter values. | def new(ext, content_type):
"""
Return a new ``<Default>`` element with attributes set to parameter
values.
"""
xml = '<Default xmlns="%s"/>' % nsmap['ct']
default = parse_xml(xml)
default.set('Extension', ext)
default.set('ContentType', content_type)
... |
Return a new <Override > element with attributes set to parameter values. | def new(partname, content_type):
"""
Return a new ``<Override>`` element with attributes set to parameter
values.
"""
xml = '<Override xmlns="%s"/>' % nsmap['ct']
override = parse_xml(xml)
override.set('PartName', partname)
override.set('ContentType', cont... |
Return a new <Relationship > element. | def new(rId, reltype, target, target_mode=RTM.INTERNAL):
"""
Return a new ``<Relationship>`` element.
"""
xml = '<Relationship xmlns="%s"/>' % nsmap['pr']
relationship = parse_xml(xml)
relationship.set('Id', rId)
relationship.set('Type', reltype)
relations... |
Add a child <Relationship > element with attributes set according to parameter values. | def add_rel(self, rId, reltype, target, is_external=False):
"""
Add a child ``<Relationship>`` element with attributes set according
to parameter values.
"""
target_mode = RTM.EXTERNAL if is_external else RTM.INTERNAL
relationship = CT_Relationship.new(rId, reltype, targe... |
Add a child <Default > element with attributes set to parameter values. | def add_default(self, ext, content_type):
"""
Add a child ``<Default>`` element with attributes set to parameter
values.
"""
default = CT_Default.new(ext, content_type)
self.append(default) |
Add a child <Override > element with attributes set to parameter values. | def add_override(self, partname, content_type):
"""
Add a child ``<Override>`` element with attributes set to parameter
values.
"""
override = CT_Override.new(partname, content_type)
self.append(override) |
Return a paragraph newly added to the end of the content in this container having * text * in a single run if present and having paragraph style * style *. If * style * is |None| no paragraph style is applied which has the same effect as applying the Normal style. | def add_paragraph(self, text='', style=None):
"""
Return a paragraph newly added to the end of the content in this
container, having *text* in a single run if present, and having
paragraph style *style*. If *style* is |None|, no paragraph style is
applied, which has the same effe... |
Return a table of * width * having * rows * rows and * cols * columns newly appended to the content in this container. * width * is evenly distributed between the table columns. | def add_table(self, rows, cols, width):
"""
Return a table of *width* having *rows* rows and *cols* columns,
newly appended to the content in this container. *width* is evenly
distributed between the table columns.
"""
from .table import Table
tbl = CT_Tbl.new_tbl... |
A list containing the tables in this container in document order. Read - only. | def tables(self):
"""
A list containing the tables in this container, in document order.
Read-only.
"""
from .table import Table
return [Table(tbl, self) for tbl in self._element.tbl_lst] |
Return a |_Chunk| subclass instance appropriate to * chunk_type * parsed from * stream_rdr * at * offset *. | def _ChunkFactory(chunk_type, stream_rdr, offset):
"""
Return a |_Chunk| subclass instance appropriate to *chunk_type* parsed
from *stream_rdr* at *offset*.
"""
chunk_cls_map = {
PNG_CHUNK_TYPE.IHDR: _IHDRChunk,
PNG_CHUNK_TYPE.pHYs: _pHYsChunk,
}
chunk_cls = chunk_cls_map.get... |
Integer dots per inch for the width of this image. Defaults to 72 when not present in the file as is often the case. | def horz_dpi(self):
"""
Integer dots per inch for the width of this image. Defaults to 72
when not present in the file, as is often the case.
"""
pHYs = self._chunks.pHYs
if pHYs is None:
return 72
return self._dpi(pHYs.units_specifier, pHYs.horz_px_pe... |
Integer dots per inch for the height of this image. Defaults to 72 when not present in the file as is often the case. | def vert_dpi(self):
"""
Integer dots per inch for the height of this image. Defaults to 72
when not present in the file, as is often the case.
"""
pHYs = self._chunks.pHYs
if pHYs is None:
return 72
return self._dpi(pHYs.units_specifier, pHYs.vert_px_p... |
Return a |_Chunks| instance containing the PNG chunks in * stream *. | def from_stream(cls, stream):
"""
Return a |_Chunks| instance containing the PNG chunks in *stream*.
"""
chunk_parser = _ChunkParser.from_stream(stream)
chunks = [chunk for chunk in chunk_parser.iter_chunks()]
return cls(chunks) |
IHDR chunk in PNG image | def IHDR(self):
"""
IHDR chunk in PNG image
"""
match = lambda chunk: chunk.type_name == PNG_CHUNK_TYPE.IHDR # noqa
IHDR = self._find_first(match)
if IHDR is None:
raise InvalidImageStreamError('no IHDR chunk in PNG image')
return IHDR |
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 *. | 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. | 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. | 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 is used to compute a scaling... | 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(... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.