INSTRUCTION stringlengths 1 46.3k | RESPONSE stringlengths 75 80.2k |
|---|---|
Filename from which this image part was originally created. A generic
name, e.g. 'image.png', is substituted if no name is available, for
example when the image was loaded from an unnamed stream. In that
case a default extension is applied based on the detected MIME type
of the image. | def filename(self):
"""
Filename from which this image part was originally created. A generic
name, e.g. 'image.png', is substituted if no name is available, for
example when the image was loaded from an unnamed stream. In that
case a default extension is applied based on the det... |
Return an |ImagePart| instance newly created from *image* and
assigned *partname*. | def from_image(cls, image, partname):
"""
Return an |ImagePart| instance newly created from *image* and
assigned *partname*.
"""
return ImagePart(partname, image.content_type, image.blob, image) |
Called by ``docx.opc.package.PartFactory`` to load an image part from
a package being opened by ``Document(...)`` call. | def load(cls, partname, content_type, blob, package):
"""
Called by ``docx.opc.package.PartFactory`` to load an image part from
a package being opened by ``Document(...)`` call.
"""
return cls(partname, content_type, blob) |
Add a new tab stop at *position*, a |Length| object specifying the
location of the tab stop relative to the paragraph edge. A negative
*position* value is valid and appears in hanging indentation. Tab
alignment defaults to left, but may be specified by passing a member
of the :ref:`WdTab... | def add_tab_stop(self, position, alignment=WD_TAB_ALIGNMENT.LEFT,
leader=WD_TAB_LEADER.SPACES):
"""
Add a new tab stop at *position*, a |Length| object specifying the
location of the tab stop relative to the paragraph edge. A negative
*position* value is valid and ap... |
Set val attribute of <w:rStyle> child element to *style*, adding a
new element if necessary. If *style* is |None|, remove the <w:rStyle>
element if present. | def style(self, style):
"""
Set val attribute of <w:rStyle> child element to *style*, adding a
new element if necessary. If *style* is |None|, remove the <w:rStyle>
element if present.
"""
if style is None:
self._remove_rStyle()
elif self.rStyle is Non... |
|True| if `w:vertAlign/@w:val` is 'subscript'. |False| if
`w:vertAlign/@w:val` contains any other value. |None| if
`w:vertAlign` is not present. | def subscript(self):
"""
|True| if `w:vertAlign/@w:val` is 'subscript'. |False| if
`w:vertAlign/@w:val` contains any other value. |None| if
`w:vertAlign` is not present.
"""
vertAlign = self.vertAlign
if vertAlign is None:
return None
if vertAl... |
|True| if `w:vertAlign/@w:val` is 'superscript'. |False| if
`w:vertAlign/@w:val` contains any other value. |None| if
`w:vertAlign` is not present. | def superscript(self):
"""
|True| if `w:vertAlign/@w:val` is 'superscript'. |False| if
`w:vertAlign/@w:val` contains any other value. |None| if
`w:vertAlign` is not present.
"""
vertAlign = self.vertAlign
if vertAlign is None:
return None
if ve... |
Return the value of the boolean child element having *name*, e.g.
'b', 'i', and 'smallCaps'. | def _get_bool_val(self, name):
"""
Return the value of the boolean child element having *name*, e.g.
'b', 'i', and 'smallCaps'.
"""
element = getattr(self, name)
if element is None:
return None
return element.val |
The underline type corresponding to the ``w:val`` attribute value. | def val(self):
"""
The underline type corresponding to the ``w:val`` attribute value.
"""
val = self.get(qn('w:val'))
underline = WD_UNDERLINE.from_xml(val)
if underline == WD_UNDERLINE.SINGLE:
return True
if underline == WD_UNDERLINE.NONE:
... |
Return newly created footer part. | def new(cls, package):
"""Return newly created footer part."""
partname = package.next_partname("/word/footer%d.xml")
content_type = CT.WML_FOOTER
element = parse_xml(cls._default_footer_xml())
return cls(partname, content_type, element, package) |
Return newly created header part. | def new(cls, package):
"""Return newly created header part."""
partname = package.next_partname("/word/header%d.xml")
content_type = CT.WML_HEADER
element = parse_xml(cls._default_header_xml())
return cls(partname, content_type, element, package) |
Return a newly created styles part, containing a default set of
elements. | def default(cls, package):
"""
Return a newly created styles part, containing a default set of
elements.
"""
partname = PackURI('/word/styles.xml')
content_type = CT.WML_STYLES
element = parse_xml(cls._default_styles_xml())
return cls(partname, content_typ... |
Return a bytestream containing XML for a default styles part. | def _default_styles_xml(cls):
"""
Return a bytestream containing XML for a default styles part.
"""
path = os.path.join(
os.path.split(__file__)[0], '..', 'templates',
'default-styles.xml'
)
with open(path, 'rb') as f:
xml_bytes = f.rea... |
Return newly added CT_HdrFtrRef element of *type_* with *rId*.
The element tag is `w:footerReference`. | def add_footerReference(self, type_, rId):
"""Return newly added CT_HdrFtrRef element of *type_* with *rId*.
The element tag is `w:footerReference`.
"""
footerReference = self._add_footerReference()
footerReference.type_ = type_
footerReference.rId = rId
return f... |
Return newly added CT_HdrFtrRef element of *type_* with *rId*.
The element tag is `w:headerReference`. | def add_headerReference(self, type_, rId):
"""Return newly added CT_HdrFtrRef element of *type_* with *rId*.
The element tag is `w:headerReference`.
"""
headerReference = self._add_headerReference()
headerReference.type_ = type_
headerReference.rId = rId
return h... |
Return footerReference element of *type_* or None if not present. | def get_footerReference(self, type_):
"""Return footerReference element of *type_* or None if not present."""
path = "./w:footerReference[@w:type='%s']" % WD_HEADER_FOOTER.to_xml(type_)
footerReferences = self.xpath(path)
if not footerReferences:
return None
return fo... |
Return headerReference element of *type_* or None if not present. | def get_headerReference(self, type_):
"""Return headerReference element of *type_* or None if not present."""
matching_headerReferences = self.xpath(
"./w:headerReference[@w:type='%s']" % WD_HEADER_FOOTER.to_xml(type_)
)
if len(matching_headerReferences) == 0:
ret... |
The member of the ``WD_ORIENTATION`` enumeration corresponding to the
value of the ``orient`` attribute of the ``<w:pgSz>`` child element,
or ``WD_ORIENTATION.PORTRAIT`` if not present. | def orientation(self):
"""
The member of the ``WD_ORIENTATION`` enumeration corresponding to the
value of the ``orient`` attribute of the ``<w:pgSz>`` child element,
or ``WD_ORIENTATION.PORTRAIT`` if not present.
"""
pgSz = self.pgSz
if pgSz is None:
r... |
Return rId of w:footerReference child of *type_* after removing it. | def remove_footerReference(self, type_):
"""Return rId of w:footerReference child of *type_* after removing it."""
footerReference = self.get_footerReference(type_)
rId = footerReference.rId
self.remove(footerReference)
return rId |
Return rId of w:headerReference child of *type_* after removing it. | def remove_headerReference(self, type_):
"""Return rId of w:headerReference child of *type_* after removing it."""
headerReference = self.get_headerReference(type_)
rId = headerReference.rId
self.remove(headerReference)
return rId |
The member of the ``WD_SECTION_START`` enumeration corresponding to
the value of the ``val`` attribute of the ``<w:type>`` child element,
or ``WD_SECTION_START.NEW_PAGE`` if not present. | def start_type(self):
"""
The member of the ``WD_SECTION_START`` enumeration corresponding to
the value of the ``val`` attribute of the ``<w:type>`` child element,
or ``WD_SECTION_START.NEW_PAGE`` if not present.
"""
type = self.type
if type is None or type.val is... |
Return the boolean value of the attribute having *attr_name*, or
|False| if not present. | def bool_prop(self, attr_name):
"""
Return the boolean value of the attribute having *attr_name*, or
|False| if not present.
"""
value = getattr(self, attr_name)
if value is None:
return False
return value |
Sibling CT_Style element this style is based on or |None| if no base
style or base style not found. | def base_style(self):
"""
Sibling CT_Style element this style is based on or |None| if no base
style or base style not found.
"""
basedOn = self.basedOn
if basedOn is None:
return None
styles = self.getparent()
base_style = styles.get_by_id(bas... |
Sibling CT_Style element identified by the value of `w:name/@w:val`
or |None| if no value is present or no style with that style id
is found. | def next_style(self):
"""
Sibling CT_Style element identified by the value of `w:name/@w:val`
or |None| if no value is present or no style with that style id
is found.
"""
next = self.next
if next is None:
return None
styles = self.getparent()
... |
Return a newly added `w:style` element having *name* and
*style_type*. `w:style/@customStyle` is set based on the value of
*builtin*. | def add_style_of_type(self, name, style_type, builtin):
"""
Return a newly added `w:style` element having *name* and
*style_type*. `w:style/@customStyle` is set based on the value of
*builtin*.
"""
style = self.add_style()
style.type = style_type
style.cus... |
Return `w:style[@w:type="*{style_type}*][-1]` or |None| if not found. | def default_for(self, style_type):
"""
Return `w:style[@w:type="*{style_type}*][-1]` or |None| if not found.
"""
default_styles_for_type = [
s for s in self._iter_styles()
if s.type == style_type and s.default
]
if not default_styles_for_type:
... |
Add a break element of *break_type* to this run. *break_type* can
take the values `WD_BREAK.LINE`, `WD_BREAK.PAGE`, and
`WD_BREAK.COLUMN` where `WD_BREAK` is imported from `docx.enum.text`.
*break_type* defaults to `WD_BREAK.LINE`. | def add_break(self, break_type=WD_BREAK.LINE):
"""
Add a break element of *break_type* to this run. *break_type* can
take the values `WD_BREAK.LINE`, `WD_BREAK.PAGE`, and
`WD_BREAK.COLUMN` where `WD_BREAK` is imported from `docx.enum.text`.
*break_type* defaults to `WD_BREAK.LINE... |
Return an |InlineShape| instance containing the image identified by
*image_path_or_stream*, added to the end of this run.
*image_path_or_stream* can be a path (a string) or a file-like object
containing a binary image. If neither width nor height is specified,
the picture appears at its ... | def add_picture(self, image_path_or_stream, width=None, height=None):
"""
Return an |InlineShape| instance containing the image identified by
*image_path_or_stream*, added to the end of this run.
*image_path_or_stream* can be a path (a string) or a file-like object
containing a b... |
Returns a newly appended |_Text| object (corresponding to a new
``<w:t>`` child element) to the run, containing *text*. Compare with
the possibly more friendly approach of assigning text to the
:attr:`Run.text` property. | def add_text(self, text):
"""
Returns a newly appended |_Text| object (corresponding to a new
``<w:t>`` child element) to the run, containing *text*. Compare with
the possibly more friendly approach of assigning text to the
:attr:`Run.text` property.
"""
t = self.... |
Read/write. A |_CharacterStyle| object representing the character
style applied to this run. The default character style for the
document (often `Default Character Font`) is returned if the run has
no directly-applied character style. Setting this property to |None|
removes any directly-... | def style(self):
"""
Read/write. A |_CharacterStyle| object representing the character
style applied to this run. The default character style for the
document (often `Default Character Font`) is returned if the run has
no directly-applied character style. Setting this property to... |
A |Length| value calculated from the values of `w:ind/@w:firstLine`
and `w:ind/@w:hanging`. Returns |None| if the `w:ind` child is not
present. | def first_line_indent(self):
"""
A |Length| value calculated from the values of `w:ind/@w:firstLine`
and `w:ind/@w:hanging`. Returns |None| if the `w:ind` child is not
present.
"""
ind = self.ind
if ind is None:
return None
hanging = ind.hangin... |
The value of `w:spacing/@w:lineRule` as a member of the
:ref:`WdLineSpacing` enumeration. Only the `MULTIPLE`, `EXACTLY`, and
`AT_LEAST` members are used. It is the responsibility of the client
to calculate the use of `SINGLE`, `DOUBLE`, and `MULTIPLE` based on
the value of `w:spacing/@w... | def spacing_lineRule(self):
"""
The value of `w:spacing/@w:lineRule` as a member of the
:ref:`WdLineSpacing` enumeration. Only the `MULTIPLE`, `EXACTLY`, and
`AT_LEAST` members are used. It is the responsibility of the client
to calculate the use of `SINGLE`, `DOUBLE`, and `MULTI... |
Set val attribute of <w:pStyle> child element to *style*, adding a
new element if necessary. If *style* is |None|, remove the <w:pStyle>
element if present. | def style(self, style):
"""
Set val attribute of <w:pStyle> child element to *style*, adding a
new element if necessary. If *style* is |None|, remove the <w:pStyle>
element if present.
"""
if style is None:
self._remove_pStyle()
return
pSty... |
Insert a newly created `w:tab` child element in *pos* order. | def insert_tab_in_order(self, pos, align, leader):
"""
Insert a newly created `w:tab` child element in *pos* order.
"""
new_tab = self._new_tab()
new_tab.pos, new_tab.val, new_tab.leader = pos, align, leader
for tab in self.tab_lst:
if new_tab.pos < tab.pos:
... |
Return a new ``<wp:inline>`` element populated with the values passed
as parameters. | def new(cls, cx, cy, shape_id, pic):
"""
Return a new ``<wp:inline>`` element populated with the values passed
as parameters.
"""
inline = parse_xml(cls._inline_xml())
inline.extent.cx = cx
inline.extent.cy = cy
inline.docPr.id = shape_id
inline.do... |
Return a new `wp:inline` element containing the `pic:pic` element
specified by the argument values. | def new_pic_inline(cls, shape_id, rId, filename, cx, cy):
"""
Return a new `wp:inline` element containing the `pic:pic` element
specified by the argument values.
"""
pic_id = 0 # Word doesn't seem to use this, but does not omit it
pic = CT_Picture.new(pic_id, filename, r... |
Return a new ``<pic:pic>`` element populated with the minimal
contents required to define a viable picture element, based on the
values passed as parameters. | def new(cls, pic_id, filename, rId, cx, cy):
"""
Return a new ``<pic:pic>`` element populated with the minimal
contents required to define a viable picture element, based on the
values passed as parameters.
"""
pic = parse_xml(cls._pic_xml())
pic.nvPicPr.cNvPr.id ... |
Return a newly added style object of *style_type* and identified
by *name*. A builtin style can be defined by passing True for the
optional *builtin* argument. | def add_style(self, name, style_type, builtin=False):
"""
Return a newly added style object of *style_type* and identified
by *name*. A builtin style can be defined by passing True for the
optional *builtin* argument.
"""
style_name = BabelFish.ui2internal(name)
i... |
Return the default style for *style_type* or |None| if no default is
defined for that type (not common). | def default(self, style_type):
"""
Return the default style for *style_type* or |None| if no default is
defined for that type (not common).
"""
style = self._element.default_for(style_type)
if style is None:
return None
return StyleFactory(style) |
Return the style of *style_type* matching *style_id*.
Returns the default for *style_type* if *style_id* is not found or is |None|, or
if the style having *style_id* is not of *style_type*. | def get_by_id(self, style_id, style_type):
"""Return the style of *style_type* matching *style_id*.
Returns the default for *style_type* if *style_id* is not found or is |None|, or
if the style having *style_id* is not of *style_type*.
"""
if style_id is None:
return... |
Return the id of the style corresponding to *style_or_name*, or
|None| if *style_or_name* is |None|. If *style_or_name* is not
a style object, the style is looked up using *style_or_name* as
a style name, raising |ValueError| if no style with that name is
defined. Raises |ValueError| if ... | def get_style_id(self, style_or_name, style_type):
"""
Return the id of the style corresponding to *style_or_name*, or
|None| if *style_or_name* is |None|. If *style_or_name* is not
a style object, the style is looked up using *style_or_name* as
a style name, raising |ValueError|... |
Return the style of *style_type* matching *style_id*. Returns the
default for *style_type* if *style_id* is not found or if the style
having *style_id* is not of *style_type*. | def _get_by_id(self, style_id, style_type):
"""
Return the style of *style_type* matching *style_id*. Returns the
default for *style_type* if *style_id* is not found or if the style
having *style_id* is not of *style_type*.
"""
style = self._element.get_by_id(style_id)
... |
Return the id of *style*, or |None| if it is the default style of
*style_type*. Raises |ValueError| if style is not of *style_type*. | def _get_style_id_from_style(self, style, style_type):
"""
Return the id of *style*, or |None| if it is the default style of
*style_type*. Raises |ValueError| if style is not of *style_type*.
"""
if style.type != style_type:
raise ValueError(
"assigned... |
Return a new instance from an RGB color hex string like ``'3C2F80'``. | def from_string(cls, rgb_hex_str):
"""
Return a new instance from an RGB color hex string like ``'3C2F80'``.
"""
r = int(rgb_hex_str[:2], 16)
g = int(rgb_hex_str[2:4], 16)
b = int(rgb_hex_str[4:], 16)
return cls(r, g, b) |
Generate exactly one reference to each relationship in the package by
performing a depth-first traversal of the rels graph. | def iter_rels(self):
"""
Generate exactly one reference to each relationship in the package by
performing a depth-first traversal of the rels graph.
"""
def walk_rels(source, visited=None):
visited = [] if visited is None else visited
for rel in source.rel... |
Generate exactly one reference to each of the parts in the package by
performing a depth-first traversal of the rels graph. | def iter_parts(self):
"""
Generate exactly one reference to each of the parts in the package by
performing a depth-first traversal of the rels graph.
"""
def walk_parts(source, visited=list()):
for rel in source.rels.values():
if rel.is_external:
... |
Return newly added |_Relationship| instance of *reltype* between this
part and *target* with key *rId*. Target mode is set to
``RTM.EXTERNAL`` if *is_external* is |True|. Intended for use during
load from a serialized package, where the rId is well known. Other
methods exist for adding a... | def load_rel(self, reltype, target, rId, is_external=False):
"""
Return newly added |_Relationship| instance of *reltype* between this
part and *target* with key *rId*. Target mode is set to
``RTM.EXTERNAL`` if *is_external* is |True|. Intended for use during
load from a serializ... |
Return a |PackURI| instance representing partname matching *template*.
The returned part-name has the next available numeric suffix to distinguish it
from other parts of its type. *template* is a printf (%)-style template string
containing a single replacement item, a '%d' to be used to insert ... | def next_partname(self, template):
"""Return a |PackURI| instance representing partname matching *template*.
The returned part-name has the next available numeric suffix to distinguish it
from other parts of its type. *template* is a printf (%)-style template string
containing a single ... |
Return an |OpcPackage| instance loaded with the contents of
*pkg_file*. | def open(cls, pkg_file):
"""
Return an |OpcPackage| instance loaded with the contents of
*pkg_file*.
"""
pkg_reader = PackageReader.from_file(pkg_file)
package = cls()
Unmarshaller.unmarshal(pkg_reader, package, PartFactory)
return package |
Return rId key of relationship to *part*, from the existing
relationship if there is one, otherwise a newly created one. | def relate_to(self, part, reltype):
"""
Return rId key of relationship to *part*, from the existing
relationship if there is one, otherwise a newly created one.
"""
rel = self.rels.get_or_add(reltype, part)
return rel.rId |
Save this package to *pkg_file*, where *file* can be either a path to
a file (a string) or a file-like object. | def save(self, pkg_file):
"""
Save this package to *pkg_file*, where *file* can be either a path to
a file (a string) or a file-like object.
"""
for part in self.parts:
part.before_marshal()
PackageWriter.write(pkg_file, self.rels, self.parts) |
|CorePropertiesPart| object related to this package. Creates
a default core properties part if one is not present (not common). | def _core_properties_part(self):
"""
|CorePropertiesPart| object related to this package. Creates
a default core properties part if one is not present (not common).
"""
try:
return self.part_related_by(RT.CORE_PROPERTIES)
except KeyError:
core_prop... |
Construct graph of parts and realized relationships based on the
contents of *pkg_reader*, delegating construction of each part to
*part_factory*. Package relationships are added to *pkg*. | def unmarshal(pkg_reader, package, part_factory):
"""
Construct graph of parts and realized relationships based on the
contents of *pkg_reader*, delegating construction of each part to
*part_factory*. Package relationships are added to *pkg*.
"""
parts = Unmarshaller._unm... |
Return a dictionary of |Part| instances unmarshalled from
*pkg_reader*, keyed by partname. Side-effect is that each part in
*pkg_reader* is constructed using *part_factory*. | def _unmarshal_parts(pkg_reader, package, part_factory):
"""
Return a dictionary of |Part| instances unmarshalled from
*pkg_reader*, keyed by partname. Side-effect is that each part in
*pkg_reader* is constructed using *part_factory*.
"""
parts = {}
for partname, ... |
Add a relationship to the source object corresponding to each of the
relationships in *pkg_reader* with its target_part set to the actual
target part in *parts*. | def _unmarshal_relationships(pkg_reader, package, parts):
"""
Add a relationship to the source object corresponding to each of the
relationships in *pkg_reader* with its target_part set to the actual
target part in *parts*.
"""
for source_uri, srel in pkg_reader.iter_srel... |
Return a newly created settings part, containing a default
`w:settings` element tree. | def default(cls, package):
"""
Return a newly created settings part, containing a default
`w:settings` element tree.
"""
partname = PackURI('/word/settings.xml')
content_type = CT.WML_SETTINGS
element = parse_xml(cls._default_settings_xml())
return cls(par... |
Return a newly added |_LatentStyle| object to override the inherited
defaults defined in this latent styles object for the built-in style
having *name*. | def add_latent_style(self, name):
"""
Return a newly added |_LatentStyle| object to override the inherited
defaults defined in this latent styles object for the built-in style
having *name*.
"""
lsdException = self._element.add_lsdException()
lsdException.name = B... |
Return rId key of relationship of *reltype* to *target*, from an
existing relationship if there is one, otherwise a newly created one. | def relate_to(self, target, reltype, is_external=False):
"""
Return rId key of relationship of *reltype* to *target*, from an
existing relationship if there is one, otherwise a newly created one.
"""
if is_external:
return self.rels.get_or_add_ext_rel(reltype, target)... |
Return the count of references in this part's XML to the relationship
identified by *rId*. | def _rel_ref_count(self, rId):
"""
Return the count of references in this part's XML to the relationship
identified by *rId*.
"""
rIds = self._element.xpath('//@r:id')
return len([_rId for _rId in rIds if _rId == rId]) |
Return the custom part class registered for *content_type*, or the
default part class if no custom class is registered for
*content_type*. | def _part_cls_for(cls, content_type):
"""
Return the custom part class registered for *content_type*, or the
default part class if no custom class is registered for
*content_type*.
"""
if content_type in cls.part_type_for:
return cls.part_type_for[content_type... |
Return a newly added ``<w:t>`` element containing *text*. | def add_t(self, text):
"""
Return a newly added ``<w:t>`` element containing *text*.
"""
t = self._add_t(text=text)
if len(text.strip()) < len(text):
t.set(qn('xml:space'), 'preserve')
return t |
Return a newly appended ``CT_Drawing`` (``<w:drawing>``) child
element having *inline_or_anchor* as its child. | def add_drawing(self, inline_or_anchor):
"""
Return a newly appended ``CT_Drawing`` (``<w:drawing>``) child
element having *inline_or_anchor* as its child.
"""
drawing = self._add_drawing()
drawing.append(inline_or_anchor)
return drawing |
Remove all child elements except the ``<w:rPr>`` element if present. | def clear_content(self):
"""
Remove all child elements except the ``<w:rPr>`` element if present.
"""
content_child_elms = self[1:] if self.rPr is not None else self[:]
for child in content_child_elms:
self.remove(child) |
A string representing the textual content of this run, with content
child elements like ``<w:tab/>`` translated to their Python
equivalent. | def text(self):
"""
A string representing the textual content of this run, with content
child elements like ``<w:tab/>`` translated to their Python
equivalent.
"""
text = ''
for child in self:
if child.tag == qn('w:t'):
t_text = child.t... |
Create a "one-shot" ``_RunContentAppender`` instance and use it to
append the run content elements corresponding to *text* to the
``<w:r>`` element *r*. | def append_to_run_from_text(cls, r, text):
"""
Create a "one-shot" ``_RunContentAppender`` instance and use it to
append the run content elements corresponding to *text* to the
``<w:r>`` element *r*.
"""
appender = cls(r)
appender.add_text(text) |
Append the run content elements corresponding to *text* to the
``<w:r>`` element of this instance. | def add_text(self, text):
"""
Append the run content elements corresponding to *text* to the
``<w:r>`` element of this instance.
"""
for char in text:
self.add_char(char)
self.flush() |
Process the next character of input through the translation finite
state maching (FSM). There are two possible states, buffer pending
and not pending, but those are hidden behind the ``.flush()`` method
which must be called at the end of text to ensure any pending
``<w:t>`` element is wr... | def add_char(self, char):
"""
Process the next character of input through the translation finite
state maching (FSM). There are two possible states, buffer pending
and not pending, but those are hidden behind the ``.flush()`` method
which must be called at the end of text to ensu... |
Return a new |CorePropertiesPart| object initialized with default
values for its base properties. | def default(cls, package):
"""
Return a new |CorePropertiesPart| object initialized with default
values for its base properties.
"""
core_properties_part = cls._new(package)
core_properties = core_properties_part.core_properties
core_properties.title = 'Word Docum... |
Return the value of boolean child of `w:rPr` having *name*. | def _get_bool_prop(self, name):
"""
Return the value of boolean child of `w:rPr` having *name*.
"""
rPr = self._element.rPr
if rPr is None:
return None
return rPr._get_bool_val(name) |
Assign *value* to the boolean child *name* of `w:rPr`. | def _set_bool_prop(self, name, value):
"""
Assign *value* to the boolean child *name* of `w:rPr`.
"""
rPr = self._element.get_or_add_rPr()
rPr._set_bool_val(name, value) |
Return a |_Column| object of *width*, newly added rightmost to the
table. | def add_column(self, width):
"""
Return a |_Column| object of *width*, newly added rightmost to the
table.
"""
tblGrid = self._tbl.tblGrid
gridCol = tblGrid.add_gridCol()
gridCol.w = width
for tr in self._tbl.tr_lst:
tc = tr.add_tc()
... |
Return a |_Row| instance, newly added bottom-most to the table. | def add_row(self):
"""
Return a |_Row| instance, newly added bottom-most to the table.
"""
tbl = self._tbl
tr = tbl.add_tr()
for gridCol in tbl.tblGrid.gridCol_lst:
tc = tr.add_tc()
tc.width = gridCol.w
return _Row(tr, self) |
Return |_Cell| instance correponding to table cell at *row_idx*,
*col_idx* intersection, where (0, 0) is the top, left-most cell. | def cell(self, row_idx, col_idx):
"""
Return |_Cell| instance correponding to table cell at *row_idx*,
*col_idx* intersection, where (0, 0) is the top, left-most cell.
"""
cell_idx = col_idx + (row_idx * self._column_count)
return self._cells[cell_idx] |
Sequence of cells in the column at *column_idx* in this table. | def column_cells(self, column_idx):
"""
Sequence of cells in the column at *column_idx* in this table.
"""
cells = self._cells
idxs = range(column_idx, len(cells), self._column_count)
return [cells[idx] for idx in idxs] |
Sequence of cells in the row at *row_idx* in this table. | def row_cells(self, row_idx):
"""
Sequence of cells in the row at *row_idx* in this table.
"""
column_count = self._column_count
start = row_idx * column_count
end = start + column_count
return self._cells[start:end] |
Read/write. A |_TableStyle| object representing the style applied to
this table. The default table style for the document (often `Normal
Table`) is returned if the table has no directly-applied style.
Assigning |None| to this property removes any directly-applied table
style causing it t... | def style(self):
"""
Read/write. A |_TableStyle| object representing the style applied to
this table. The default table style for the document (often `Normal
Table`) is returned if the table has no directly-applied style.
Assigning |None| to this property removes any directly-app... |
A sequence of |_Cell| objects, one for each cell of the layout grid.
If the table contains a span, one or more |_Cell| object references
are repeated. | def _cells(self):
"""
A sequence of |_Cell| objects, one for each cell of the layout grid.
If the table contains a span, one or more |_Cell| object references
are repeated.
"""
col_count = self._column_count
cells = []
for tc in self._tbl.iter_tcs():
... |
Return a paragraph newly added to the end of the content in this
cell. If present, *text* is added to the paragraph in a single run.
If specified, the paragraph style *style* is applied. If *style* is
not specified or is |None|, the result is as though the 'Normal'
style was applied. Not... | def add_paragraph(self, text='', style=None):
"""
Return a paragraph newly added to the end of the content in this
cell. If present, *text* is added to the paragraph in a single run.
If specified, the paragraph style *style* is applied. If *style* is
not specified or is |None|, t... |
Return a table newly added to this cell after any existing cell
content, having *rows* rows and *cols* columns. An empty paragraph is
added after the table because Word requires a paragraph element as
the last element in every cell. | def add_table(self, rows, cols):
"""
Return a table newly added to this cell after any existing cell
content, having *rows* rows and *cols* columns. An empty paragraph is
added after the table because Word requires a paragraph element as
the last element in every cell.
""... |
Return a merged cell created by spanning the rectangular region
having this cell and *other_cell* as diagonal corners. Raises
|InvalidSpanError| if the cells do not define a rectangular region. | def merge(self, other_cell):
"""
Return a merged cell created by spanning the rectangular region
having this cell and *other_cell* as diagonal corners. Raises
|InvalidSpanError| if the cells do not define a rectangular region.
"""
tc, tc_2 = self._tc, other_cell._tc
... |
Write-only. Set entire contents of cell to the string *text*. Any
existing content or revisions are replaced. | def text(self, text):
"""
Write-only. Set entire contents of cell to the string *text*. Any
existing content or revisions are replaced.
"""
tc = self._tc
tc.clear_content()
p = tc.add_p()
r = p.add_r()
r.text = text |
Return (rId, image) pair for image identified by *image_descriptor*.
*rId* is the str key (often like "rId7") for the relationship between this story
part and the image part, reused if already present, newly created if not.
*image* is an |Image| instance providing access to the properties of th... | def get_or_add_image(self, image_descriptor):
"""Return (rId, image) pair for image identified by *image_descriptor*.
*rId* is the str key (often like "rId7") for the relationship between this story
part and the image part, reused if already present, newly created if not.
*image* is an ... |
Return a newly-created `w:inline` element.
The element contains the image specified by *image_descriptor* and is scaled
based on the values of *width* and *height*. | def new_pic_inline(self, image_descriptor, width, height):
"""Return a newly-created `w:inline` element.
The element contains the image specified by *image_descriptor* and is scaled
based on the values of *width* and *height*.
"""
rId, image = self.get_or_add_image(image_descrip... |
Next available positive integer id value in this story XML document.
The value is determined by incrementing the maximum existing id value. Gaps in
the existing id sequence are not filled. The id attribute value is unique in the
document, without regard to the element type it appears on. | def next_id(self):
"""Next available positive integer id value in this story XML document.
The value is determined by incrementing the maximum existing id value. Gaps in
the existing id sequence are not filled. The id attribute value is unique in the
document, without regard to the elem... |
Return |_Marker| or subclass instance appropriate for marker at *offset*
in *stream* having *marker_code*. | def _MarkerFactory(marker_code, stream, offset):
"""
Return |_Marker| or subclass instance appropriate for marker at *offset*
in *stream* having *marker_code*.
"""
if marker_code == JPEG_MARKER_CODE.APP0:
marker_cls = _App0Marker
elif marker_code == JPEG_MARKER_CODE.APP1:
marker_... |
Return |Exif| instance having header properties parsed from Exif
image in *stream*. | def from_stream(cls, stream):
"""
Return |Exif| instance having header properties parsed from Exif
image in *stream*.
"""
markers = _JfifMarkers.from_stream(stream)
# print('\n%s' % markers)
px_width = markers.sof.px_width
px_height = markers.sof.px_heigh... |
Return a |_JfifMarkers| instance containing a |_JfifMarker| subclass
instance for each marker in *stream*. | def from_stream(cls, stream):
"""
Return a |_JfifMarkers| instance containing a |_JfifMarker| subclass
instance for each marker in *stream*.
"""
marker_parser = _MarkerParser.from_stream(stream)
markers = []
for marker in marker_parser.iter_markers():
... |
First APP0 marker in image markers. | def app0(self):
"""
First APP0 marker in image markers.
"""
for m in self._markers:
if m.marker_code == JPEG_MARKER_CODE.APP0:
return m
raise KeyError('no APP0 marker in image') |
First APP1 marker in image markers. | def app1(self):
"""
First APP1 marker in image markers.
"""
for m in self._markers:
if m.marker_code == JPEG_MARKER_CODE.APP1:
return m
raise KeyError('no APP1 marker in image') |
First start of frame (SOFn) marker in this sequence. | def sof(self):
"""
First start of frame (SOFn) marker in this sequence.
"""
for m in self._markers:
if m.marker_code in JPEG_MARKER_CODE.SOF_MARKER_CODES:
return m
raise KeyError('no start of frame (SOFn) marker in image') |
Generate a (marker_code, segment_offset) 2-tuple for each marker in
the JPEG *stream*, in the order they occur in the stream. | def iter_markers(self):
"""
Generate a (marker_code, segment_offset) 2-tuple for each marker in
the JPEG *stream*, in the order they occur in the stream.
"""
marker_finder = _MarkerFinder.from_stream(self._stream)
start = 0
marker_code = None
while marker_... |
Return a (marker_code, segment_offset) 2-tuple identifying and
locating the first marker in *stream* occuring after offset *start*.
The returned *segment_offset* points to the position immediately
following the 2-byte marker code, the start of the marker segment,
for those markers that h... | def next(self, start):
"""
Return a (marker_code, segment_offset) 2-tuple identifying and
locating the first marker in *stream* occuring after offset *start*.
The returned *segment_offset* points to the position immediately
following the 2-byte marker code, the start of the marke... |
Return an offset, byte 2-tuple for the next byte in *stream* that is
not '\xFF', starting with the byte at offset *start*. If the byte at
offset *start* is not '\xFF', *start* and the returned *offset* will
be the same. | def _next_non_ff_byte(self, start):
"""
Return an offset, byte 2-tuple for the next byte in *stream* that is
not '\xFF', starting with the byte at offset *start*. If the byte at
offset *start* is not '\xFF', *start* and the returned *offset* will
be the same.
"""
... |
Return the offset of the next '\xFF' byte in *stream* starting with
the byte at offset *start*. Returns *start* if the byte at that
offset is a hex 255; it does not necessarily advance in the stream. | def _offset_of_next_ff_byte(self, start):
"""
Return the offset of the next '\xFF' byte in *stream* starting with
the byte at offset *start*. Returns *start* if the byte at that
offset is a hex 255; it does not necessarily advance in the stream.
"""
self._stream.seek(star... |
Return a generic |_Marker| instance for the marker at *offset* in
*stream* having *marker_code*. | def from_stream(cls, stream, marker_code, offset):
"""
Return a generic |_Marker| instance for the marker at *offset* in
*stream* having *marker_code*.
"""
if JPEG_MARKER_CODE.is_standalone(marker_code):
segment_length = 0
else:
segment_length = st... |
Return dots per inch corresponding to *density* value. | def _dpi(self, density):
"""
Return dots per inch corresponding to *density* value.
"""
if self._density_units == 1:
dpi = density
elif self._density_units == 2:
dpi = int(round(density * 2.54))
else:
dpi = 72
return dpi |
Return an |_App0Marker| instance for the APP0 marker at *offset* in
*stream*. | def from_stream(cls, stream, marker_code, offset):
"""
Return an |_App0Marker| instance for the APP0 marker at *offset* in
*stream*.
"""
# field off type notes
# ------------------ --- ----- -------------------
# segment length 0 short
... |
Extract the horizontal and vertical dots-per-inch value from the APP1
header at *offset* in *stream*. | def from_stream(cls, stream, marker_code, offset):
"""
Extract the horizontal and vertical dots-per-inch value from the APP1
header at *offset* in *stream*.
"""
# field off len type notes
# -------------------- --- --- ----- -----------------------... |
Return True if the APP1 segment at *offset* in *stream* is NOT an
Exif segment, as determined by the ``'Exif\x00\x00'`` signature at
offset 2 in the segment. | def _is_non_Exif_APP1_segment(cls, stream, offset):
"""
Return True if the APP1 segment at *offset* in *stream* is NOT an
Exif segment, as determined by the ``'Exif\x00\x00'`` signature at
offset 2 in the segment.
"""
stream.seek(offset+2)
exif_signature = stream.... |
Return a |Tiff| instance parsed from the Exif APP1 segment of
*segment_length* at *offset* in *stream*. | def _tiff_from_exif_segment(cls, stream, offset, segment_length):
"""
Return a |Tiff| instance parsed from the Exif APP1 segment of
*segment_length* at *offset* in *stream*.
"""
# wrap full segment in its own stream and feed to Tiff()
stream.seek(offset+8)
segment... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.