Controller

Basic Controllers

class controllers.base.BaseController(path='', **kwargs)[source]

Bases: Resource

Web Base Controller

__init__(path='', **kwargs)[source]
Args:
  • path: Base path

  • session: (?) Session instance

  • withMainTemplate: (?)

  • isJson: responses shall be JSON encoded

  • isCustom: (?)

  • isGZ: responses shall be GZIP compressed

  • isImage: (?) responses shall image

error404(request)[source]

Perform HTTP Error 404

Args:

request (twisted.web.server.Request): HTTP request object

getChild(path, request)[source]

Retrieve a ‘child’ resource from me.

Implement this to create dynamic resource generation – resources which are always available may be registered with self.putChild().

This will not be called if the class-level variable ‘isLeaf’ is set in your subclass; instead, the ‘postpath’ attribute of the request will be left as a list of the remaining path elements.

For example, the URL /foo/bar/baz will normally be:

| site.resource.getChild('foo').getChild('bar').getChild('baz').

However, if the resource returned by ‘bar’ has isLeaf set to true, then the getChild call will never be made on it.

Parameters and return value have the same meaning and requirements as those defined by L{IResource.getChildWithDefault}.

render(request)[source]

Render a given resource. See L{IResource}’s render method.

I delegate to methods of self with the form ‘render_METHOD’ where METHOD is the HTTP that was used to make the request. Examples: render_GET, render_HEAD, render_POST, and so on. Generally you should implement those methods instead of overriding this one.

render_METHOD methods are expected to return a byte string which will be the rendered page, unless the return value is C{server.NOT_DONE_YET}, in which case it is this class’s responsibility to write the results using C{request.write(data)} and then call C{request.finish()}.

Old code that overrides render() directly is likewise expected to return a byte string or NOT_DONE_YET.

@see: L{IResource.render}

controllers.utilities.NS = {'DVB-C': 4294901760, 'DVB-T': 4008574976}

Label:Namespace map

controllers.utilities.NS_DVB_C = 4294901760

Namespace - DVB-C services

controllers.utilities.NS_DVB_T = 4008574976

Namespace - DVB-T services

controllers.utilities.NS_LOOKUP = {4008574976: 'DVB-T', 4294901760: 'DVB-C'}

Namespace:Label lookup map

controllers.utilities.create_servicereference(*args, **kwargs)[source]

Generate a (Enigma2 style) service reference string representation.

Parameters:
  • args[0] (dict) – Service Reference Parameter as dict

  • service_type (int) – Service Type

  • sid (int) – SID

  • tsid (int) – TSID

  • oid (int) – OID

  • ns (int) – Enigma2 Namespace

controllers.utilities.get_config_attribute(path, root_obj, head=None)[source]

Determine attribute of root_obj to be accessed by path in a (somewhat) safe manner. This implementation will allow key and index based accessing too (e.g. config.some_list[0] or config.some_dict['some_key']) The path value needs to start with head (default=’config’).

Args:

path: character string specifying which attribute is to be accessed root_obj: An object whose attributes are to be accessed. head: Value of the first portion of path

Returns:

Attribute of root_obj

Raises:

ValueError: If path is invalid. AttributeError: If attribute cannot be accessed

controllers.utilities.lenient_decode(value, encoding=None)[source]

Decode an encoded string and convert it to an unicode string.

Args:

value: input value encoding: string encoding, defaults to utf-8

Returns:

(unicode) decoded value

>>> lenient_decode("Hallo")
u'Hallo'
>>> lenient_decode(u"Hallo")
u'Hallo'
>>> lenient_decode("HällöÜ")
u'H\xe4ll\xf6\xdc'
controllers.utilities.lenient_force_utf_8(value)[source]
Args:

value: input value

Returns:

(basestring) utf-8 encoded value

>>> isinstance(lenient_force_utf_8(''), basestring)
True
>>> lenient_force_utf_8(u"Hallo")
'Hallo'
>>> lenient_force_utf_8("HällöÜ")
'H\xc3\xa4ll\xc3\xb6\xc3\x9c'
controllers.utilities.parse_servicereference(serviceref)[source]

Parse a Enigma2 style service reference string representation.

Parameters:

serviceref (string) – Enigma2 style service reference

>>> sref = '1:0:1:300:7:85:00c00000:0:0:0:'
>>> result = parse_servicereference(sref)
>>> result
{'service_type': 1, 'oid': 133, 'tsid': 7, 'ns': 12582912, 'sid': 768}
>>> sref_g = create_servicereference(**result)
>>> sref_g
'1:0:1:300:7:85:00c00000:0:0:0:'
>>> sref_g2 = create_servicereference(result)
>>> sref_g2
'1:0:1:300:7:85:00c00000:0:0:0:'
>>> sref == sref_g
True
>>> sref2 = '1:64:A:0:0:0:0:0:0:0::SKY Sport'
>>> result2 = parse_servicereference(sref2)
>>> result2
{'service_type': 10, 'oid': 0, 'tsid': 0, 'ns': 0, 'sid': 0}
>>> sref3 = '1:0:0:0:0:0:0:0:0:0:/media/hdd/movie/20170921 2055 - DASDING - DASDING Sprechstunde - .ts'
>>> result3 = parse_servicereference(sref3)
>>> result3
{'service_type': 0, 'oid': 0, 'tsid': 0, 'ns': 0, 'sid': 0}
controllers.utilities.sanitise_filename_slashes(value)[source]
Args:

value: input value

Returns:

value w/o multiple slashes

>>> in_value = "///tmp/x/y/z"
>>> expected = sub("^/+", "/", "///tmp/x/y/z")
>>> sanitise_filename_slashes(in_value) == expected
True

Web Controllers