Nemo API¶
-
class
flask.ext.nemo.
Nemo
(name=None, app=None, api_url='/', retriever=None, base_url='/nemo', cache=None, expire=3600, template_folder=None, static_folder=None, static_url_path=None, urls=None, inventory=None, transform=None, urntransform=None, chunker=None, prevnext=None, css=None, js=None, templates=None, statics=None)[source]¶ Nemo is an extension for Flask python micro-framework which provides a User Interface to your app for dealing with CTS API.
Parameters: - app (Flask) – Flask application
- api_url (str) – URL of the API Endpoint
- retriever (MyCapytain.retrievers.proto.CTS) – CTS Retriever (Will be defaulted to api_url using cts5 retriever if necessary)
- base_url (str) – Base URL to use when registering the endpoint
- cache – SQLITE cache file name
- expire – TIme before expiration of cache, default 3600
- template_folder (str) – Folder in which the templates can be found
- static_folder (str) – Folder in which statics file can be found
- static_url_path (str) – Base url to use for assets
- urls ([(str, str, [str])]) – Function and routes to register (See Nemo.ROUTES)
- inventory (str) – Default inventory to use
- transform (bool|dict) – Dictionary of XSL filepath or transform function where default key is the default applied function
- urntransform (bool|dict) – Dictionary of urn transform functions where default key is the default applied function
- chunker ({str: function(str, function(int))}) – Dictionary of function to group responses of GetValidReff
- prevnext ({str: function(str, function())}) – Dictionary of function to execute GetPrevNext
- css ([str]) – Path to additional stylesheets to load
- js ([str]) – Path to additional javascripts to load
- templates ({str: str}) – Register or override templates (Dictionary of index / path)
- statics ([str]) – Path to additional statics such as picture to load
Warning
Until a C libxslt error is fixed ( https://bugzilla.gnome.org/show_bug.cgi?id=620102 ), it is not possible to use strip spaces in the xslt given to this application. See strip-spaces
Controller¶
Specific methods¶
-
Nemo.
get_inventory
()[source]¶ Request the api endpoint to retrieve information about the inventory
Returns: The text inventory Return type: MyCapytain.resources.inventory.TextInventory
-
Nemo.
get_collections
()[source]¶ Filter inventory and make a list of available collections
Returns: A set of CTS Namespaces Return type: set(str)
-
Nemo.
get_textgroups
(collection_urn=None)[source]¶ Retrieve textgroups
Parameters: collection_urn (str) – Collection to use for filtering the textgroups Returns: List of textgroup filtered by collection Return type: [MyCapytain.resources.inventory.Textgroup]
-
Nemo.
get_works
(collection_urn=None, textgroup_urn=None)[source]¶ Retrieve works
Parameters: Returns: List of work filtered by collection/Textgroup
Return type: [MyCapytain.resources.inventory.Work]
-
Nemo.
get_texts
(collection_urn=None, textgroup_urn=None, work_urn=None)[source]¶ Retrieve texts
Parameters: Returns: List of texts filtered by parameters
Return type: [MyCapytain.resources.inventory.Text]
-
Nemo.
get_text
(collection_urn, textgroup_urn, work_urn, version_urn)[source]¶ Retrieve one version of a Text
Parameters: Returns: A Text represented by the various parameters
Return type: MyCapytain.resources.inventory.Text
-
Nemo.
get_reffs
(collection, textgroup, work, version)[source]¶ Get the setup for valid reffs.
Returns the inventory text object with its metadata and a callback function taking a level parameter and returning a list of strings.
Parameters: Returns: Text with its metadata, callback function to retrieve validreffs
Return type: (MyCapytains.resources.texts.api.Text, lambda: [str])
Customization appliers¶
-
Nemo.
chunk
(text, reffs)[source]¶ Handle a list of references depending on the text identifier using the chunker dictionary.
Parameters: - text (MyCapytains.resources.texts.api.Text) – Text object from which comes the references
- reffs (callback(level)) – Callback function to retrieve a list of string with a level parameter
Returns: Transformed list of references
Return type: [str]
-
Nemo.
getprevnext
(passage, callback)[source]¶ Retrieve previous and next passage using
Parameters: - text (MyCapytains.resources.texts.api.Passage) – Text object from which comes the references
- reffs (callback()) – Callback function to retrieve a tuple where first element is the previous passage, and second the next
Returns: Reference of previous passage, reference of next passage
Return type: (str, str)
-
Nemo.
transform
(work, xml)[source]¶ Transform input according to potentiallyregistered XSLT
Note
Due to XSLT not being able to be used twice, we rexsltise the xml at every call of xslt
Warning
Until a C libxslt error is fixed ( https://bugzilla.gnome.org/show_bug.cgi?id=620102 ), it is not possible to use strip tags in the xslt given to this application
Parameters: - work (MyCapytains.resources.inventory.Text) – Work object containing metadata about the xml
- xml (etree._Element) – XML to transform
Returns: String representation of transformed resource
Return type:
Routes¶
-
Nemo.
r_index
()[source]¶ Homepage route function
Returns: Template to use for Home page Return type: {str: str}
-
Nemo.
r_collection
(collection)[source]¶ Collection content browsing route function
Parameters: collection (str) – Collection identifier Returns: Template and textgroups contained in given collections Return type: {str: Any}
-
Nemo.
r_texts
(collection, textgroup)[source]¶ Textgroup content browsing route function
Parameters: Returns: Template and texts contained in given textgroup
Return type: {str: Any}
-
Nemo.
r_version
(collection, textgroup, work, version)[source]¶ Text exemplar references browsing route function
Parameters: Returns: Template, version inventory object and references urn parts
Return type: { “template” : str, “version”: MyCapytains.resources.inventory.Text, “reffs”: [str] }
Statics¶
Filters¶
Filters follow a naming convention : they should always start with “f_“
-
static
Nemo.
f_active_link
(string, url)[source]¶ Check if current string is in the list of names
Parameters: string – String to check for in url Returns: CSS class “active” if valid Return type: str
-
static
Nemo.
f_collection_i18n
(string)[source]¶ Return a i18n human readable version of a CTS domain such as latinLit
Parameters: string (str) – CTS Domain identifier Returns: Human i18n readable version of the CTS Domain Return type: str
-
static
Nemo.
f_formatting_passage_reference
(string)[source]¶ Get the first part only of a two parts reference
Parameters: string (str) – A urn reference part Returns: First part only of the two parts reference Return type: str
Helpers¶
-
static
Nemo.
map_urns
(items, query, part_of_urn=1, attr='textgroups')[source]¶ Small function to map urns to filter out a list of items or on a parent item
Parameters: Returns: Items corresponding to the object children filtered by the query
Return type: list(items.children)
-
static
Nemo.
filter_urn
(item, part_of_urn, query)[source]¶ Small function to map urns to filter out a list of items or on a parent item
Parameters: Returns: Items corresponding to the object children filtered by the query
Return type: list(items.children)
-
static
Nemo.
in_and_not_in
(identifier, collection, kwargs)[source]¶ Check if an element identified by identifier is in kwargs but not the collection containing it
Parameters: Returns: Indicator of presence of required informations
Return type:
-
static
Nemo.
prevnext_callback_generator
(passage)[source]¶ Default callback generator to retrieve prev and next value of a passage
Parameters: passage (MyCapytains.resources.texts.api.Passage) – Passage for which to get previous and following reference Returns: Function to retrieve those information Return type: function
Chunkers¶
-
static
Nemo.
default_chunker
(text, getreffs)[source]¶ This is the default chunker which will resolve the reference giving a callback (getreffs) and a text object with its metadata
Parameters: - text (MyCapytains.resources.inventory.Text) – Text Object representing either an edition or a translation
- getreffs (function) – callback function which retrieves a list of references
Returns: List of urn references with their human readable version
Return type: [(str, str)]
-
static
Nemo.
line_chunker
(text, getreffs, lines=30)[source]¶ Groups line reference together
Parameters: - text (MyCapytains.resources.text.api) – Text object
- getreffs (function(level)) – Callback function to retrieve text
- lines (int) – Number of lines to use by group
Returns: List of grouped urn references with their human readable version
Return type: [(str, str)]
-
static
Nemo.
scheme_chunker
(text, getreffs)[source]¶ This is the scheme chunker which will resolve the reference giving a callback (getreffs) and a text object with its metadata
Parameters: - text (MyCapytains.resources.inventory.Text) – Text Object representing either an edition or a translation
- getreffs (function) – callback function which retrieves a list of references
Returns: List of urn references with their human readable version
Return type: [(str, str)]
PrevNexter¶
-
static
Nemo.
default_prevnext
(passage, callback)[source]¶ Default deliver of prevnext informations
Parameters: - passage (MyCapytains.resources.texts.api.Passage) – Passage for which to get previous and following reference
- callback (function) – Function to retrieve those information
Returns: Tuple representing previous and following reference
Return type: (str, str)