epublib.ncx package¶
- class NCXMeta(soup: S, tag: ~bs4.element.Tag = <sentinel/>, *, name: ~typing.Annotated[str, ~epublib.xml_element.XMLAttribute(init_name=None, sync=<SyncType.ATTR: 1>, get=None, create=None, prefix=)], content: ~typing.Annotated[str, ~epublib.xml_element.XMLAttribute(init_name=None, sync=<SyncType.ATTR: 1>, get=None, create=None, prefix=)])¶
Bases:
XMLElement[NCXSoup]A metadata item in the NCX head section.
- Parameters:
soup – The NCX soup this element belongs to.
name – The name of the meta item.
content – The content of the meta item.
- class NCXHead(soup: S, tag: ~bs4.element.Tag = <sentinel/>)¶
Bases:
XMLParent[NCXMeta,NCXSoup]The head section of the NCX file, a container of NCXMeta items.
- Parameters:
soup – The NCX soup this element belongs to.
- add(name: str, content: str) NCXMeta¶
Add a new meta item to the head section.
- Parameters:
name – The name of the meta item.
content – The content of the meta item.
- Returns:
The newly created NCXMeta item.
- property uid: str¶
Return the unique identifier of the publication.
- property depth: int¶
Return the depth of the navigation map structure.
- property total_page_count: int | None¶
Return the total page count of the publication.
If there are no navigable pages (represented as 0), return None.
- property max_page_number: int | None¶
Return the largest value attribute on page targets in the page list.
If there are no navigable pages (represented as 0), return None.
- class NCXDocData(soup: S, tag: bs4.element.Tag = <sentinel/>, *, text: Annotated[str, XMLAttribute(init_name=None, sync=<SyncType.STRING: 2>, get='text', create='text', prefix='')], id: Annotated[str | None, XMLAttribute(init_name=None, sync=<SyncType.ATTR: 1>, get=None, create=None, prefix='')] = None)¶
Bases:
XMLElement[NCXSoup],ABC
- class NCXAuthor(soup: S, tag: ~bs4.element.Tag = <sentinel/>, *, text: ~typing.Annotated[str, ~epublib.xml_element.XMLAttribute(init_name=None, sync=<SyncType.STRING: 2>, get=text, create=text, prefix=)], id: ~typing.Annotated[str | None, ~epublib.xml_element.XMLAttribute(init_name=None, sync=<SyncType.ATTR: 1>, get=None, create=None, prefix=)] = None)¶
Bases:
NCXDocDataAn authorship in the NCX file.
- Parameters:
soup – The NCX soup this element belongs to.
text – The name of the author.
id – An optional identifier for the author.
- class NCXTitle(soup: S, tag: ~bs4.element.Tag = <sentinel/>, *, text: ~typing.Annotated[str, ~epublib.xml_element.XMLAttribute(init_name=None, sync=<SyncType.STRING: 2>, get=text, create=text, prefix=)], id: ~typing.Annotated[str | None, ~epublib.xml_element.XMLAttribute(init_name=None, sync=<SyncType.ATTR: 1>, get=None, create=None, prefix=)] = None)¶
Bases:
NCXDocDataThe title of the publication in the NCX file.
- Parameters:
soup – The NCX soup this element belongs to.
text – The title of the publication.
id – An optional identifier for the title.
- class NCXHrefElement(soup: S, tag: bs4.element.Tag = <sentinel/>, *, filename: str, href: Annotated[str, XMLAttribute(init_name='src', sync=<SyncType.ATTR: 1>, get='content', create=<staticmethod(<function NCXHrefElement.create_href_tag at 0x7a1fb1fadda0>)>, prefix='')] = '', own_filename: str, id: Annotated[str, XMLAttribute(init_name=None, sync=<SyncType.ATTR: 1>, get=None, create=None, prefix='')], text: Annotated[str, XMLAttribute(init_name=None, sync=<SyncType.STRING: 2>, get=<function NCXHrefElement.<lambda> at 0x7a1fb1fade40>, create=functools.partial(<function create_ncx_text_tag at 0x7a1fb1f4c0e0>, 'navLabel'), prefix='')])¶
Bases:
HrefElement[NCXSoup],ABC
- class NCXWithInfo(
- *,
- info: Annotated[str | None,
- XMLAttribute(init_name=None,
- sync=<SyncType.STRING: 2>,
- get=<function NCXWithInfo.<lambda> at 0x7a1fb1fadf80>,
- create=functools.partial(<function create_ncx_text_tag at 0x7a1fb1f4c0e0>,
- 'navInfo'),
- prefix='')] = None,
Bases:
object
Bases:
NCXHrefElement,HrefRecursiveElement[NCXNavPoint,NCXSoup],NCXWithInfoA navigation point in NCX table of contents.
- Parameters:
soup – The NCX soup this element belongs to.
href – The href of the navPoint. May include a fragment. If empty, will be calculated from filename and own_filename. One of href or filename must be given.
filename – The filename the navPoint points to. May include a fragment. If empty, will be calculated from href and own_filename. One of href or filename must be given.
own_filename – The filename of the NCX file this element belongs to.
id – The identifier of the navPoint.
text – The label of the navPoint.
play_order – The play order of the navPoint.
info – An optional info text for the navPoint.
- text: str,
- filename: str | Path,
- id: str | None = None,
- info: str | None = None,
Add a new navPoint to this element.
- Parameters:
text – The label of the new navPoint.
filename – The filename the new navPoint points to. May include a fragment.
id – The identifier of the new navPoint. If None, a new identifier will be generated.
info – An optional info text for the new navPoint.
- Returns:
The newly created NCXNavPoint item.
- position: int | None,
- text: str,
- filename: str | Path,
- id: str | None = None,
- info: str | None = None,
Insert a new navPoint in a specific position of this element.
- Parameters:
position – The position to insert the new navPoint at. If None, the new navPoint will be added at the end.
text – The label of the new navPoint.
filename – The filename the new navPoint points to. May include a fragment.
id – The identifier of the new navPoint. If None, a new identifier will be generated.
info – An optional info text for the new navPoint.
- text: str,
- filename: str | Path,
- id: str | None = None,
- info: str | None = None,
Add a new navPoint in this element’s parent, after this one.
- Parameters:
text – The label of the new navPoint.
filename – The filename the new navPoint points to. May include a fragment.
id – The identifier of the new navPoint. If None, a new identifier will be generated.
info – An optional info text for the new navPoint.
- Raises:
EPUBError – If this element has no parent.
- soup: S,
- tag: ~bs4.element.Tag = <sentinel/>,
- *,
- info: ~typing.Annotated[str | None,
- ~epublib.xml_element.XMLAttribute(init_name=None,
- sync=<SyncType.STRING: 2>,
- get=~epublib.ncx.NCXWithInfo.<lambda>,
- create=functools.partial(<function create_ncx_text_tag at 0x7a1fb1f4c0e0>,
- 'navInfo'),
- prefix=)] = None,
- own_filename: str,
- text: ~typing.Annotated[str | None,
- ~epublib.xml_element.XMLAttribute(init_name=None,
- sync=<SyncType.STRING: 2>,
- get=~epublib.ncx.NCXNavList.<lambda>,
- create=functools.partial(<function create_ncx_text_tag at 0x7a1fb1f4c0e0>,
- 'navLabel'),
- prefix=)] = None,
Bases:
HrefRoot[NCXNavPoint,NCXSoup],XMLElement[NCXSoup],NCXWithInfoA navigation list in the NCX file.
- Parameters:
soup – The NCX soup this element belongs to.
own_filename – The filename of the NCX file this element belongs to.
text – The label of the navList.
info – An optional info text for the navList.
- text: str,
- filename: str | Path,
- id: str | None = None,
- info: str | None = None,
Add a new navPoint to this navList.
- Parameters:
text – The label of the new navPoint.
filename – The filename the new navPoint points to. May include a fragment.
id – The identifier of the new navPoint. If None, a new identifier will be generated.
info – An optional info text for the new navPoint.
- Returns:
The newly created NCXNavPoint item.
- position: int | None,
- text: str,
- filename: str | Path,
- id: str | None = None,
- info: str | None = None,
Insert a new navPoint to this navList in a specific position.
- Parameters:
position – The position to insert the new navPoint at. If None, the new navPoint will appended.
text – The label of the new navPoint.
filename – The filename the new navPoint points to. May include a fragment.
id – The identifier of the new navPoint. If None, a new identifier will be generated.
info – An optional info text for the new navPoint.
- Returns:
The newly created NCXNavPoint item.
- class NumberUpdating(*args, **kwargs)¶
Bases:
Protocol
- soup: S,
- tag: ~bs4.element.Tag = <sentinel/>,
- *,
- info: ~typing.Annotated[str | None,
- ~epublib.xml_element.XMLAttribute(init_name=None,
- sync=<SyncType.STRING: 2>,
- get=~epublib.ncx.NCXWithInfo.<lambda>,
- create=functools.partial(<function create_ncx_text_tag at 0x7a1fb1f4c0e0>,
- 'navInfo'),
- prefix=)] = None,
- own_filename: str,
- text: ~typing.Annotated[str | None,
- ~epublib.xml_element.XMLAttribute(init_name=None,
- sync=<SyncType.STRING: 2>,
- get=~epublib.ncx.NCXNavList.<lambda>,
- create=functools.partial(<function create_ncx_text_tag at 0x7a1fb1f4c0e0>,
- 'navLabel'),
- prefix=)] = None,
- parent: ~epublib.ncx.NumberUpdating,
Bases:
NCXNavListThe navigation map in the NCX file.
- Parameters:
soup – The NCX soup this element belongs to.
own_filename – The filename of the NCX file this element belongs to.
text – The label of the navMap.
parent – The parent object that will be notified when the navMap changes, so it can update numbers accordingly.
info – An optional info text for the navMap.
- soup: NCXSoup,
- tag: Tag,
- own_filename: str | Path,
- parent: NumberUpdating,
Create this XMLElement from an existing tag.
Any attributes that are not represented in the tag are passed as keyword arguments.
- Parameters:
soup – The BeautifulSoup this element is part of.
tag – The existing tag to use.
**kwargs – Any attributes that are not represented in the tag.
- Returns:
An instance of this XMLElement.
- text: str,
- filename: str | Path,
- id: str | None = None,
- info: str | None = None,
Add a new navPoint to this navMap.
- Parameters:
text – The label of the new navPoint.
filename – The filename the new navPoint points to. May include a fragment.
id – The identifier of the new navPoint. If None, a new identifier will be generated.
info – An optional info text for the new navPoint.
- Returns:
The newly created NCXNavPoint item.
- position: int | None,
- text: str,
- filename: str | Path,
- id: str | None = None,
- info: str | None = None,
Insert a new navPoint to the navMap in a specific position.
- Parameters:
position – The position to insert the new navPoint at. If None, the new navPoint will appended.
text – The label of the new navPoint.
filename – The filename the new navPoint points to. May include a fragment.
id – The identifier of the new navPoint. If None, a new identifier will be generated.
info – An optional info text for the new navPoint.
- Returns:
The newly created NCXNavPoint item.
- class NCXPageTarget(soup: S, tag: ~bs4.element.Tag = <sentinel/>, *, filename: str, href: ~typing.Annotated[str, ~epublib.xml_element.XMLAttribute(init_name=src, sync=<SyncType.ATTR: 1>, get=content, create=~epublib.ncx.NCXHrefElement.create_href_tag, prefix=)] = '', own_filename: str, id: ~typing.Annotated[str, ~epublib.xml_element.XMLAttribute(init_name=None, sync=<SyncType.ATTR: 1>, get=None, create=None, prefix=)], text: ~typing.Annotated[str, ~epublib.xml_element.XMLAttribute(init_name=None, sync=<SyncType.STRING: 2>, get=~epublib.ncx.NCXHrefElement.<lambda>, create=functools.partial(<function create_ncx_text_tag at 0x7a1fb1f4c0e0>, 'navLabel'), prefix=)], type: ~typing.Annotated[~typing.Literal['front', 'normal', 'special'] | None, ~epublib.xml_element.XMLAttribute(init_name=None, sync=<SyncType.ATTR: 1>, get=None, create=None, prefix=)] = None)¶
Bases:
NCXHrefElementA page target in the NCX page list.
- Parameters:
soup – The NCX soup this element belongs to.
filename – The filename the pageTarget points to. May include a fragment. If empty, will be calculated from href and own_filename. One of href or filename must be given.
href – The href the pageTarget points to. May include a fragment. If empty, will be calculated from filename and own_filename. One of href or filename must be given.
own_filename – The filename of the NCX file this element belongs to.
id – The identifier of the pageTarget.
text – The label of the pageTarget.
type – The type of the pageTarget. If None, it will be inferred from the text. Can be “front” (for roman numerals), “normal” (for arabic numerals) or “special” (for anything else).
- class NCXPageList(
- soup: S,
- tag: ~bs4.element.Tag = <sentinel/>,
- *,
- info: ~typing.Annotated[str | None,
- ~epublib.xml_element.XMLAttribute(init_name=None,
- sync=<SyncType.STRING: 2>,
- get=~epublib.ncx.NCXWithInfo.<lambda>,
- create=functools.partial(<function create_ncx_text_tag at 0x7a1fb1f4c0e0>,
- 'navInfo'),
- prefix=)] = None,
- own_filename: str,
- parent: ~epublib.ncx.NumberUpdating,
Bases:
ParentOfHref[NCXPageTarget,NCXSoup],XMLElement[NCXSoup],NCXWithInfoThe page list in the NCX file.
- Parameters:
soup – The NCX soup this element belongs to.
info – An optional info text for the pageList.
own_filename – The filename of the NCX file this element belongs to.
parent – The parent object that will be notified when the pageList changes, so it can update numbers accordingly.
- property largest_page_number: int | None¶
Return the largest page number in the page list.
- classmethod from_tag(
- soup: NCXSoup,
- tag: Tag,
- own_filename: str | Path,
- parent: NumberUpdating,
Create this XMLElement from an existing tag.
Any attributes that are not represented in the tag are passed as keyword arguments.
- Parameters:
soup – The BeautifulSoup this element is part of.
tag – The existing tag to use.
**kwargs – Any attributes that are not represented in the tag.
- Returns:
An instance of this XMLElement.
- add(
- text: str,
- filename: str | Path,
- id: str | None = None,
- type: Literal['front', 'normal', 'special'] | None = None,
Add a new pageTarget to the pageList.
- Parameters:
text – The label of the new pageTarget.
filename – The filename the new pageTarget points to. May include a fragment.
id – The identifier of the new pageTarget. If None, a new identifier will be generated.
type – The type of the new pageTarget. If None, it will be inferred from the text. Can be “front” (for roman numerals), “normal” (for arabic numerals) or “special” (for anything else).
- Returns:
The newly created NCXPageTarget item.
- insert(
- position: int,
- text: str,
- filename: str | Path,
- id: str | None = None,
- type: Literal['front', 'normal', 'special'] | None = None,
Insert a new pageTarget to the pageList at a specific position.
- Parameters:
position – The position to insert the new pageTarget at.
text – The label of the new pageTarget.
filename – The filename the new pageTarget points to. May include a fragment.
id – The identifier of the new pageTarget. If None, a new identifier will be generated.
type – The type of the new pageTarget. If None, it will be inferred from the text. Can be “front” (for roman numerals), “normal” (for arabic numerals) or “special” (for anything else).
- Returns:
The newly created NCXPageTarget item.
Submodules¶
- epublib.ncx.reset module
- epublib.ncx.resource module
NCXFileNCXFile.soup_classNCXFile.headNCXFile.titleNCXFile.authorsNCXFile.nav_mapNCXFile.page_listNCXFile.nav_listsNCXFile.remove()NCXFile.get_author()NCXFile.add_author()NCXFile.remove_author()NCXFile.add_nav_list()NCXFile.reset_page_list()NCXFile.update_total_page_count()NCXFile.update_depth()NCXFile.update_max_page_number()NCXFile.update_play_order()NCXFile.update_numbers()NCXFile.sync_head()NCXFile.sync_toc()NCXFile.sync_page_list()NCXFile.on_soup_change()NCXFile.on_content_change()