turbofeeds.util

Package turbofeeds :: Module util |
[hide private]

# Source Code for Module turbofeeds.util

     1  # -*- coding: UTF-8 -*-
     2  """TurboFeed utility functions."""
     3  __docformat__ = 'restructuredtext'
     4
     5  __all__ = [
     6      'absolute_url',
     7      'xml_stylesheet',
     8  ]
     9
    10  import cherrypy
    11  import turbogears
    12
    13  from kid import ProcessingInstruction
    14
    15 -def absolute_url(suffix='', params=None, **kw):
    16      """Returns the absolute URL to this server, appending 'suffix' if given."""
    17
    18      aurl = 'http://%s/' % cherrypy.request.headers['Host']
    19      if suffix:
    20          aurl += turbogears.url(suffix, params, **kw).lstrip('/')
    21      return aurl
    22
    23 -def xml_stylesheet(href, type='text/css'):
    24      """Returns an xml-stylesheet processing instruction element for given URL.
    25
    26      ``href`` can be a string with the URL to the stylesheet or a dict with
    27      members ``href`` and ``type`` (see below) or a callable returning either.
    28
    29      ``type`` specifies the value of the "type" atribute of the PI.
    30      The default type is 'text/css'.
    31      """
    32
    33      if callable(href):
    34          href = href()
    35      if isinstance(href, dict):
    36          href = href['href']
    37          type = href.get('type', type)
    38      return ProcessingInstruction('xml-stylesheet'
    39          ' type="%s" href="%s"' % (type, href))
    40