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:
  • collection_urn (str) – Collection to use for filtering the textgroups
  • textgroup_urn (str) – Textgroup to use for filtering the works
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:
  • collection_urn (str) – Collection to use for filtering the textgroups
  • textgroup_urn (str) – Textgroup to use for filtering the works
  • work_urn (str) – Work to use for filtering the texts
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:
  • collection_urn (str) – Collection to use for filtering the textgroups
  • textgroup_urn (str) – Textgroup to use for filtering the works
  • work_urn (str) – Work identifier to use for filtering texts
  • version_urn (str) – Version identifier
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:
  • collection (str) – Collection identifier
  • textgroup (str) – Textgroup identifier
  • work (str) – Work identifier
  • version (str) – Version identifier
Returns:

Text with its metadata, callback function to retrieve validreffs

Return type:

(MyCapytains.resources.texts.api.Text, lambda: [str])

Nemo.get_passage(collection, textgroup, work, version, passage_identifier)[source]

Retrieve the passage identified by the parameters

Parameters:
  • collection (str) – Collection identifier
  • textgroup (str) – Textgroup identifier
  • work (str) – Work identifier
  • version (str) – Version identifier
  • passage_identifier (str) – Reference Identifier
Returns:

A Passage object containing informations about the passage

Return type:

MyCapytain.resources.texts.api.Passage

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:

str

Nemo.transform_urn(urn)[source]

Transform urn according to configurable function

Parameters:urn (URN) – URN to transform
Returns:the URN (transformed or not)
Return type:URN

Shared methods

Nemo.render(template, **kwargs)[source]

Render a route template and adds information to this route.

Parameters:
  • template (str) – Template name
  • kwargs (dict) – dictionary of named arguments used to be passed to the template
Returns:

Http Response with rendered template

Return type:

flask.Response

Nemo.make_breadcrumbs(**kwargs)[source]

Make breadcrumbs for a route

Parameters:kwargs (dict) – dictionary of named arguments used to construct the view
Returns:List of dict items the view can use to construct the link.
Return type:list({ “link”: str, “title”, str, “args”, dict})
Nemo.view_maker(name)[source]

Create a view

Parameters:name (str) – Name of the route function to use for the view.
Returns:Route function which makes use of Nemo context (such as menu informations)
Return type:function
Nemo.route(fn, **kwargs)[source]

Route helper : apply fn function but keep the calling object, ie kwargs, for other functions

Parameters:
  • fn (function) – Function to run the route with
  • kwargs (dict) – Parsed url arguments
Returns:

HTTP Response with rendered template

Return type:

flask.Response

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:
  • collection (str) – Collection identifier
  • textgroup (str) – Textgroup Identifier
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:
  • collection (str) – Collection identifier
  • textgroup (str) – Textgroup Identifier
  • work (str) – Work identifier
  • version (str) – Version identifier
Returns:

Template, version inventory object and references urn parts

Return type:

{ “template” : str, “version”: MyCapytains.resources.inventory.Text, “reffs”: [str] }

Nemo.r_passage(collection, textgroup, work, version, passage_identifier)[source]

Retrieve the text of the passage

Parameters:
  • collection (str) – Collection identifier
  • textgroup (str) – Textgroup Identifier
  • work (str) – Work identifier
  • version (str) – Version identifier
  • passage_identifier (str) – Reference identifier
Returns:

Template, version inventory object and Markup object representing the text

Return type:

{str: Any}

Nemo.r_assets(type, asset)[source]

Route for specific assets.

Parameters:asset – Filename of an asset
Returns:Response

Statics

Filters

Filters follow a naming convention : they should always start with “f_

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
static Nemo.f_order_text_edition_translation(versions_list)[source]

Takes a list of versions and put translations after editions

Parameters:versions_list ([Text]) – List of text versions
Returns:List where first members will be editions
Return type:[Text]
static Nemo.f_i18n_citation_type(string, lang='eng')[source]

Take a string of form %citation_type|passage% and format it for human

Parameters:
  • string – String of formation %citation_type|passage%
  • lang – Language to translate to
Returns:

Human Readable string

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:
  • items (MyCapytains.resources.inventory.Resource) – Inventory object
  • query (str) – Part of urn to check against
  • part_of_urn (int) – Identifier of the part of the urn
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:
  • item – Inventory object
  • query (str) – Part of urn to check against
  • part_of_urn (int) – Identifier of the part of the urn
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:
  • identifier (str) – URL Identifier of one kind of element (Textgroup, work, etc.)
  • collection (str) – Resource identifier of one kind of element (Textgroup, work, etc.)
  • kwargs ({str: Any}) – Arguments passed to a template
Returns:

Indicator of presence of required informations

Return type:

bool

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)