desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'Read/write tri-state value. When |True|, causes the text in the run to appear with double strikethrough.'
@property def double_strike(self):
return self._get_bool_prop(u'dstrike')
'Read/write tri-state value. When |True|, causes the text in the run to appear as if raised off the page in relief.'
@property def emboss(self):
return self._get_bool_prop(u'emboss')
'Read/write tri-state value. When |True|, causes the text in the run to be hidden from display, unless applications settings force hidden text to be shown.'
@property def hidden(self):
return self._get_bool_prop(u'vanish')
'A member of :ref:`WdColorIndex` indicating the color of highlighting applied, or `None` if no highlighting is applied.'
@property def highlight_color(self):
rPr = self._element.rPr if (rPr is None): return None return rPr.highlight_val
'Read/write tri-state value. When |True|, causes the text of the run to appear in italics. |None| indicates the effective value is inherited from the style hierarchy.'
@property def italic(self):
return self._get_bool_prop(u'i')
'Read/write tri-state value. When |True|, causes the text in the run to appear as if pressed into the page.'
@property def imprint(self):
return self._get_bool_prop(u'imprint')
'Read/write tri-state value. When |True|, specifies this run contains WML that should be handled as though it was Office Open XML Math.'
@property def math(self):
return self._get_bool_prop(u'oMath')
'Get or set the typeface name for this |Font| instance, causing the text it controls to appear in the named font, if a matching font is found. |None| indicates the typeface is inherited from the style hierarchy.'
@property def name(self):
rPr = self._element.rPr if (rPr is None): return None return rPr.rFonts_ascii
'Read/write tri-state value. When |True|, specifies that the contents of this run should not report any errors when the document is scanned for spelling and grammar.'
@property def no_proof(self):
return self._get_bool_prop(u'noProof')
'Read/write tri-state value. When |True| causes the characters in the run to appear as if they have an outline, by drawing a one pixel wide border around the inside and outside borders of each character glyph.'
@property def outline(self):
return self._get_bool_prop(u'outline')
'Read/write tri-state value. When |True| causes the text in the run to have right-to-left characteristics.'
@property def rtl(self):
return self._get_bool_prop(u'rtl')
'Read/write tri-state value. When |True| causes the text in the run to appear as if each character has a shadow.'
@property def shadow(self):
return self._get_bool_prop(u'shadow')
'Read/write |Length| value or |None|, indicating the font height in English Metric Units (EMU). |None| indicates the font size should be inherited from the style hierarchy. |Length| is a subclass of |int| having properties for convenient conversion into points or other length units. The :class:`docx.shared.Pt` class allows convenient specification of point values:: >> font.size = Pt(24) >> font.size 304800 >> font.size.pt 24.0'
@property def size(self):
rPr = self._element.rPr if (rPr is None): return None return rPr.sz_val
'Read/write tri-state value. When |True| causes the lowercase characters in the run to appear as capital letters two points smaller than the font size specified for the run.'
@property def small_caps(self):
return self._get_bool_prop(u'smallCaps')
'Read/write tri-state value. When |True| causes the run to use the document grid characters per line settings defined in the docGrid element when laying out the characters in this run.'
@property def snap_to_grid(self):
return self._get_bool_prop(u'snapToGrid')
'A member of the :ref:`WdParagraphAlignment` enumeration specifying the justification setting for this paragraph. A value of |None| indicates paragraph alignment is inherited from the style hierarchy.'
@property def alignment(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.jc_val
'|Length| value specifying the relative difference in indentation for the first line of the paragraph. A positive value causes the first line to be indented. A negative value produces a hanging indent. |None| indicates first line indentation is inherited from the style hierarchy.'
@property def first_line_indent(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.first_line_indent
'|True| if the paragraph should be kept "in one piece" and not broken across a page boundary when the document is rendered. |None| indicates its effective value is inherited from the style hierarchy.'
@property def keep_together(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.keepLines_val
'|True| if the paragraph should be kept on the same page as the subsequent paragraph when the document is rendered. For example, this property could be used to keep a section heading on the same page as its first paragraph. |None| indicates its effective value is inherited from the style hierarchy.'
@property def keep_with_next(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.keepNext_val
'|Length| value specifying the space between the left margin and the left side of the paragraph. |None| indicates the left indent value is inherited from the style hierarchy. Use an |Inches| value object as a convenient way to apply indentation in units of inches.'
@property def left_indent(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.ind_left
'|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 spacing is a fixed height. The |Pt| value class is a convenient way to apply line spacing in units of points. Assigning |None| resets line spacing to inherit from the style hierarchy.'
@property def line_spacing(self):
pPr = self._element.pPr if (pPr is None): return None return self._line_spacing(pPr.spacing_line, pPr.spacing_lineRule)
'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.'
@property def line_spacing_rule(self):
pPr = self._element.pPr if (pPr is None): return None return self._line_spacing_rule(pPr.spacing_line, pPr.spacing_lineRule)
'|True| if the paragraph should appear at the top of the page following the prior paragraph. |None| indicates its effective value is inherited from the style hierarchy.'
@property def page_break_before(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.pageBreakBefore_val
'|Length| value specifying the space between the right margin and the right side of the paragraph. |None| indicates the right indent value is inherited from the style hierarchy. Use a |Cm| value object as a convenient way to apply indentation in units of centimeters.'
@property def right_indent(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.ind_right
'|Length| value specifying the spacing to appear between this paragraph and the subsequent paragraph. |None| indicates this value is inherited from the style hierarchy. |Length| objects provide convenience properties, such as :attr:`~.Length.pt` and :attr:`~.Length.inches`, that allow easy conversion to various length units.'
@property def space_after(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.spacing_after
'|Length| value specifying the spacing to appear between this paragraph and the prior paragraph. |None| indicates this value is inherited from the style hierarchy. |Length| objects provide convenience properties, such as :attr:`~.Length.pt` and :attr:`~.Length.cm`, that allow easy conversion to various length units.'
@property def space_before(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.spacing_before
'|TabStops| object providing access to the tab stops defined for this paragraph format.'
@lazyproperty def tab_stops(self):
pPr = self._element.get_or_add_pPr() return TabStops(pPr)
'|True| if the first and last lines in the paragraph remain on the same page as the rest of the paragraph when Word repaginates the document. |None| indicates its effective value is inherited from the style hierarchy.'
@property def widow_control(self):
pPr = self._element.pPr if (pPr is None): return None return pPr.widowControl_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|.'
@staticmethod def _line_spacing(spacing_line, spacing_lineRule):
if (spacing_line is None): return None if (spacing_lineRule == WD_LINE_SPACING.MULTIPLE): return (spacing_line / Pt(12)) return spacing_line
'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.'
@staticmethod def _line_spacing_rule(line, lineRule):
if (lineRule == WD_LINE_SPACING.MULTIPLE): if (line == Twips(240)): return WD_LINE_SPACING.SINGLE if (line == Twips(360)): return WD_LINE_SPACING.ONE_POINT_FIVE if (line == Twips(480)): return WD_LINE_SPACING.DOUBLE return lineRule
'Remove the tab at offset *idx* in this sequence.'
def __delitem__(self, idx):
tabs = self._pPr.tabs try: tabs.remove(tabs[idx]) except (AttributeError, IndexError): raise IndexError(u'tab index out of range') if (len(tabs) == 0): self._pPr.remove(tabs)
'Enables list-style access by index.'
def __getitem__(self, idx):
tabs = self._pPr.tabs if (tabs is None): raise IndexError(u'TabStops object is empty') tab = tabs.tab_lst[idx] return TabStop(tab)
'Generate a TabStop object for each of the w:tab elements, in XML document order.'
def __iter__(self):
tabs = self._pPr.tabs if (tabs is not None): for tab in tabs.tab_lst: (yield TabStop(tab))
'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:`WdTabAlignment` enumeration as *alignment*. An optional leader character can be specified by passing a member of the :ref:`WdTabLeader` enumeration as *leader*.'
def add_tab_stop(self, position, alignment=WD_TAB_ALIGNMENT.LEFT, leader=WD_TAB_LEADER.SPACES):
tabs = self._pPr.get_or_add_tabs() tab = tabs.insert_tab_in_order(position, alignment, leader) return TabStop(tab)
'Remove all custom tab stops.'
def clear_all(self):
self._pPr._remove_tabs()
'A member of :ref:`WdTabAlignment` specifying the alignment setting for this tab stop. Read/write.'
@property def alignment(self):
return self._tab.val
'A member of :ref:`WdTabLeader` specifying a repeating character used as a "leader", filling in the space spanned by this tab. Assigning |None| produces the same result as assigning `WD_TAB_LEADER.SPACES`. Read/write.'
@property def leader(self):
return self._tab.leader
'A |Length| object representing the distance of this tab stop from the inside edge of the paragraph. May be positive or negative. Read/write.'
@property def position(self):
return self._tab.pos
'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):
(type_, clear) = {WD_BREAK.LINE: (None, None), WD_BREAK.PAGE: (u'page', None), WD_BREAK.COLUMN: (u'column', None), WD_BREAK.LINE_CLEAR_LEFT: (u'textWrapping', u'left'), WD_BREAK.LINE_CLEAR_RIGHT: (u'textWrapping', u'right'), WD_BREAK.LINE_CLEAR_ALL: (u'textWrapping', u'all')}[break_type] br = self._r.add_br() if (type_ is not None): br.type = type_ if (clear is not None): br.clear = clear
'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 native size. If only one is specified, it is used to compute a scaling factor that is then applied to the unspecified dimension, preserving the aspect ratio of the image. The native size of the picture is calculated using the dots-per-inch (dpi) value specified in the image file, defaulting to 72 dpi if no value is specified, as is often the case.'
def add_picture(self, image_path_or_stream, width=None, height=None):
inline = self.part.new_pic_inline(image_path_or_stream, width, height) self._r.add_drawing(inline) return InlineShape(inline)
'Add a ``<w:tab/>`` element at the end of the run, which Word interprets as a tab character.'
def add_tab(self):
self._r._add_tab()
'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):
t = self._r.add_t(text) return _Text(t)
'Read/write. Causes the text of the run to appear in bold.'
@property def bold(self):
return self.font.bold
'Return reference to this run after removing all its content. All run formatting is preserved.'
def clear(self):
self._r.clear_content() return self
'The |Font| object providing access to the character formatting properties for this run, such as font name and size.'
@property def font(self):
return Font(self._element)
'Read/write tri-state value. When |True|, causes the text of the run to appear in italics.'
@property def italic(self):
return self.font.italic
'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-applied character style.'
@property def style(self):
style_id = self._r.style return self.part.get_style(style_id, WD_STYLE_TYPE.CHARACTER)
'String formed by concatenating the text equivalent of each run content child element into a Python string. Each ``<w:t>`` element adds the text characters it contains. A ``<w:tab/>`` element adds a ``\t`` character. A ``<w:cr/>`` or ``<w:br>`` element each add a ``\n`` character. Note that a ``<w:br>`` element can indicate a page break or column break as well as a line break. All ``<w:br>`` elements translate to a single ``\n`` character regardless of their type. All other content child elements, such as ``<w:drawing>``, are ignored. Assigning text to this property has the reverse effect, translating each ``\t`` character to a ``<w:tab/>`` element and each ``\n`` or ``\r`` character to a ``<w:cr/>`` element. Any existing run content is replaced. Run formatting is preserved.'
@property def text(self):
return self._r.text
'The underline style for this |Run|, one of |None|, |True|, |False|, or a value from :ref:`WdUnderline`. A value of |None| indicates the run has no directly-applied underline value and so will inherit the underline value of its containing paragraph. Assigning |None| to this property removes any directly-applied underline value. A value of |False| indicates a directly-applied setting of no underline, overriding any inherited value. A value of |True| indicates single underline. The values from :ref:`WdUnderline` are used to specify other outline styles such as double, wavy, and dotted.'
@property def underline(self):
return self.font.underline
'The RestructuredText documentation page for the enumeration. This is the only API member for the class.'
@property def page_str(self):
tmpl = '.. _%s:\n\n%s\n\n%s\n\n----\n\n%s' components = (self._ms_name, self._page_title, self._intro_text, self._member_defs) return (tmpl % components)
'The docstring of the enumeration, formatted for use at the top of the documentation page'
@property def _intro_text(self):
try: cls_docstring = self._clsdict['__doc__'] except KeyError: cls_docstring = '' return textwrap.dedent(cls_docstring).strip()
'Return an individual member definition formatted as an RST glossary entry, wrapped to fit within 78 columns.'
def _member_def(self, member):
member_docstring = textwrap.dedent(member.docstring).strip() member_docstring = textwrap.fill(member_docstring, width=78, initial_indent=(' ' * 4), subsequent_indent=(' ' * 4)) return ('%s\n%s\n' % (member.name, member_docstring))
'A single string containing the aggregated member definitions section of the documentation page'
@property def _member_defs(self):
members = self._clsdict['__members__'] member_defs = [self._member_def(member) for member in members if (member.name is not None)] return '\n'.join(member_defs)
'The Microsoft API name for this enumeration'
@property def _ms_name(self):
return self._clsdict['__ms_name__']
'The title for the documentation page, formatted as code (surrounded in double-backtics) and underlined with \'=\' characters'
@property def _page_title(self):
title_underscore = ('=' * (len(self._clsname) + 4)) return ('``%s``\n%s' % (self._clsname, title_underscore))
'Dispatch ``.add_to_enum()`` call to each member so it can do its thing to properly add itself to the enumeration class. This delegation allows member sub-classes to add specialized behaviors.'
@classmethod def _add_enum_members(meta, clsdict):
enum_members = clsdict['__members__'] for member in enum_members: member.add_to_enum(clsdict)
'Return a sequence containing the enumeration values that are valid assignment values. Return-only values are excluded.'
@classmethod def _collect_valid_settings(meta, clsdict):
enum_members = clsdict['__members__'] valid_settings = [] for member in enum_members: valid_settings.extend(member.valid_settings) clsdict['_valid_settings'] = valid_settings
'Return the RST documentation page for the enumeration.'
@classmethod def _generate_docs_page(meta, clsname, clsdict):
clsdict['__docs_rst__'] = _DocsPageFormatter(clsname, clsdict).page_str
'Raise |ValueError| if *value* is not an assignable value.'
@classmethod def validate(cls, value):
if (value not in cls._valid_settings): raise ValueError(('%s not a member of %s enumeration' % (value, cls.__name__)))
'Return the enumeration member corresponding to the XML value *xml_val*.'
@classmethod def from_xml(cls, xml_val):
if (xml_val not in cls._xml_to_member): raise InvalidXmlError(("attribute value '%s' not valid for this type" % xml_val)) return cls._xml_to_member[xml_val]
'Return the XML value of the enumeration value *enum_val*.'
@classmethod def to_xml(cls, enum_val):
if (enum_val not in cls._member_to_xml): raise ValueError(("value '%s' not in enumeration %s" % (enum_val, cls.__name__))) return cls._member_to_xml[enum_val]
'Add a name to *clsdict* for this member.'
def add_to_enum(self, clsdict):
self.register_name(clsdict)
'The description of this member'
@property def docstring(self):
return self._docstring
'The distinguishing name of this member within the enumeration class, e.g. \'MIDDLE\' for MSO_VERTICAL_ANCHOR.MIDDLE, if this is a named member. Otherwise the primitive value such as |None|, |True| or |False|.'
@property def name(self):
return self._name
'Add a member name to the class dict *clsdict* containing the value of this member object. Where the name of this object is None, do nothing; this allows out-of-band values to be defined without adding a name to the class dict.'
def register_name(self, clsdict):
if (self.name is None): return clsdict[self.name] = self.value
'A sequence containing the values valid for assignment for this member. May be zero, one, or more in number.'
@property def valid_settings(self):
return (self._value,)
'The enumeration value for this member, often an instance of EnumValue, but may be a primitive value such as |None|.'
@property def value(self):
return self._value
'The description of this enumeration member'
@property def __doc__(self):
return self._docstring.strip()
'The symbolic name and string value of this member, e.g. \'MIDDLE (3)\''
def __str__(self):
return ('%s (%d)' % (self._member_name, int(self)))
'No settings are valid for a return-only value.'
@property def valid_settings(self):
return ()
'Compile XML mappings in addition to base add behavior.'
def add_to_enum(self, clsdict):
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):
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) xml_to_member[self.xml_value] = self.value
'The XML attribute value that corresponds to this enumeration value'
@property def xml_value(self):
return self._xml_value
'Add the enum -> xml value mapping to the enumeration class state'
@staticmethod def _get_or_add_member_to_xml(clsdict):
if ('_member_to_xml' not in clsdict): clsdict['_member_to_xml'] = dict() return clsdict['_member_to_xml']
'Add the xml -> enum value mapping to the enumeration class state'
@staticmethod def _get_or_add_xml_to_member(clsdict):
if ('_xml_to_member' not in clsdict): clsdict['_xml_to_member'] = dict() return clsdict['_xml_to_member']
'Return a new |CorePropertiesPart| object initialized with default values for its base properties.'
@classmethod def default(cls, package):
core_properties_part = cls._new(package) core_properties = core_properties_part.core_properties core_properties.title = u'Word Document' core_properties.last_modified_by = u'python-docx' core_properties.revision = 1 core_properties.modified = datetime.utcnow() return core_properties_part
'A |CoreProperties| object providing read/write access to the core properties contained in this core properties part.'
@property def core_properties(self):
return CoreProperties(self.element)
'Return a |PackURI| instance containing the absolute pack URI formed by translating *relative_ref* onto *baseURI*.'
@staticmethod def from_rel_ref(baseURI, relative_ref):
joined_uri = posixpath.join(baseURI, relative_ref) abs_uri = posixpath.abspath(joined_uri) return PackURI(abs_uri)
'The base URI of this pack URI, the directory portion, roughly speaking. E.g. ``\'/ppt/slides\'`` for ``\'/ppt/slides/slide1.xml\'``. For the package pseudo-partname \'/\', baseURI is \'/\'.'
@property def baseURI(self):
return posixpath.split(self)[0]
'The extension portion of this pack URI, e.g. ``\'xml\'`` for ``\'/word/document.xml\'``. Note the period is not included.'
@property def ext(self):
raw_ext = posixpath.splitext(self)[1] return (raw_ext[1:] if raw_ext.startswith('.') else raw_ext)
'The "filename" portion of this pack URI, e.g. ``\'slide1.xml\'`` for ``\'/ppt/slides/slide1.xml\'``. For the package pseudo-partname \'/\', filename is \'\'.'
@property def filename(self):
return posixpath.split(self)[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\'``.'
@property def idx(self):
filename = self.filename if (not filename): return None name_part = posixpath.splitext(filename)[0] match = self._filename_re.match(name_part) if (match is None): return None if match.group(2): return int(match.group(2)) return None
'The pack URI with the leading slash stripped off, the form used as the Zip file membername for the package item. Returns \'\' for the package pseudo-partname \'/\'.'
@property def membername(self):
return self[1:]
'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):
if (baseURI == '/'): relpath = self[1:] else: relpath = posixpath.relpath(self, baseURI) return relpath
'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 \'/\'.'
@property def rels_uri(self):
rels_filename = ('%s.rels' % self.filename) rels_uri_str = posixpath.join(self.baseURI, '_rels', rels_filename) return PackURI(rels_uri_str)
'*path* is the path to a directory containing an expanded package.'
def __init__(self, path):
super(_DirPkgReader, self).__init__() self._path = os.path.abspath(path)
'Return contents of file corresponding to *pack_uri* in package directory.'
def blob_for(self, pack_uri):
path = os.path.join(self._path, pack_uri.membername) with open(path, 'rb') as f: blob = f.read() return blob
'Provides interface consistency with |ZipFileSystem|, but does nothing, a directory file system doesn\'t need closing.'
def close(self):
pass
'Return the `[Content_Types].xml` blob from the package.'
@property def content_types_xml(self):
return self.blob_for(CONTENT_TYPES_URI)
'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):
try: rels_xml = self.blob_for(source_uri.rels_uri) except IOError: rels_xml = None return rels_xml
'Return blob corresponding to *pack_uri*. Raises |ValueError| if no matching member is present in zip archive.'
def blob_for(self, pack_uri):
return self._zipf.read(pack_uri.membername)
'Close the zip archive, releasing any resources it is using.'
def close(self):
self._zipf.close()
'Return the `[Content_Types].xml` blob from the zip package.'
@property def content_types_xml(self):
return self.blob_for(CONTENT_TYPES_URI)
'Return rels item XML for source with *source_uri* or None if no rels item is present.'
def rels_xml_for(self, source_uri):
try: rels_xml = self.blob_for(source_uri.rels_uri) except KeyError: rels_xml = None return rels_xml
'Close the zip archive, flushing any pending physical writes and releasing any resources it\'s using.'
def close(self):
self._zipf.close()
'Write *blob* to this zip package with the membername corresponding to *pack_uri*.'
def write(self, pack_uri, blob):
self._zipf.writestr(pack_uri.membername, blob)
'Return a newly added |_Relationship| instance.'
def add_relationship(self, reltype, target, rId, is_external=False):
rel = _Relationship(rId, reltype, target, self._baseURI, is_external) self[rId] = rel if (not is_external): self._target_parts_by_rId[rId] = target return rel
'Return relationship of *reltype* to *target_part*, newly added if not already present in collection.'
def get_or_add(self, reltype, target_part):
rel = self._get_matching(reltype, target_part) if (rel is None): rId = self._next_rId rel = self.add_relationship(reltype, target_part, rId) return rel
'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):
rel = self._get_matching(reltype, target_ref, is_external=True) if (rel is None): rId = self._next_rId rel = self.add_relationship(reltype, target_ref, rId, is_external=True) return rel.rId
'Return target part of rel with matching *reltype*, raising |KeyError| if not found and |ValueError| if more than one matching relationship is found.'
def part_with_reltype(self, reltype):
rel = self._get_rel_of_type(reltype) return rel.target_part