Tayra

Template. Script. Distribute

Helper functions in template context

This module is automatically made available inside the template script as h. And the entire namespace is accessible as h.<attr>.

1
2
3
4
<head>
<body>
  ${ h.parsecsv( 'one, two, three' ) }
  ${ h.parsecsvlines( 'one, \n two, three' ) }

Instead of importing python stdlib modules directly in template scripts it is better to access them via this module, so that in future when sandboxing feature is added, your scripts can remain compatible.

Module contents

tayra.h.parse_assetspec(spec, pname)

Parse the asset specification spec in the context of package name pname. If pname is package object, it is resolved as pname.__name__. Return a tuple of (packagename, filename), where packagename is the name of the package relative to which the file asset filename is located.

tayra.h.asset_spec_from_abspath(abspath, papackages)

Use the dictionary of papackages, gathered during platform boot time by calling package() entrypoint and convert abspath to asset-specification format.

tayra.h.abspath_from_asset_spec(spec, pname='', relativeto=None)

Convert assert sepcification into absolute path. if pname is supplied, it will be used to parse the asset-spec

tayra.h.settingsfor(prefix, sett)

Filter settings keys sett.keys() starting with prefix and return a dictionary of corresponding options. Prefix is pruned of from returned settings’ keys.

tayra.h.plugin2sec(pluginname)

Convert pluginname to plugin section name in ini-file. For Eg, for plugin-name httpepollserver, will return plugin:httpepollserver.

tayra.h.sec2plugin(secname)

Reverse of plugin2sec().

tayra.h.json_encode(value, encoding=None)

JSON-encodes the given Python object. If encoding is supplied, then the resulting json encoded string will be converted to bytes and return the same, otherwise, json encodied string is returned as is.

tayra.h.json_decode(value, encoding=None)

Convert json encoded value to Python object. If encoding is not supplied value is assumed to be in string, otherwise, value is expected in bytes and converted to string.

Return the python object.

tayra.h.parsecsv(line)

Parse a single line of comma separated values, into a list of strings

tayra.h.parsecsvlines(lines)

Parse a multi-line text where each line contains comma separated values.

tayra.h.asbool(val, default=None)

Convert a string representation of boolean value to boolean type.

tayra.h.asint(val, default=None)

Convert string representation of integer value to integer type.

tayra.h.asfloat(val, default=None)

Convert string representation of float value to floating type.

tayra.h.docstr(obj)

Return the doc-string for the object.

tayra.h.reseed_random()

If os.urandom is available, this method does the same thing as random.seed ! (at least as of python 2.6). If os.urandom is not available, we mix in the pid in addition to a timestamp.

tayra.h.mergedict(*args)

For a list of dictionaries in args return a new dictionary containing super-imposed key,value pairs from args

tayra.h.takewhile(pred, lst)

Iterate over lst until pred is True and return only the iterated elements.

tayra.h.dropwhile(pred, lst)

Iterate over lst until pred is True and return the remaining elements in lst.

tayra.h.flatten(lst)

Flatten nested list lst into a flat list.

class tayra.h.ConfigDict(*args, **kwargs)

Bases: builtins.dict

A collection of configuration settings. When a fresh key, a.k.a configuration parameter is added to this dictionary, it can be provided as ConfigItem object or as a dictionary containing key,value pairs similar to ConfigItem.

Used as return type for default_settings() method specified in pluggdapps.plugin.ISettings

Table Of Contents

Related Topics

This Page