irclog.web — Web IRC log view

class irclog.web.Application(archive, template_path, path_prefix='', encoding='utf-8', debug=False)[source]

Bases: object

WSGI application.

import os, os.path
path = os.path.join(
    os.environ["HOME"],
    ".irssi/logs/<server>/<channel>/<date:%Y-%m-%d>.log"
)
app = Application(path)
Parameters:
  • archive (Archive, FilenamePattern, basestring) – an archive object or path
  • template_path (basestring) – a path of template files
  • path_prefix (basestring) – a prefix for the path. default is an empty string
  • encoding (basestring) – an encoding of response text. default is "utf-8"
  • debug (bool) – a debug flag. default is False
STATIC_PATH_PATTERN
PATH_MAP

The list: of tuple contains template name, routing pattern and object getting function.

Form is like following:

[("template.html", re.compile("url regex"), lambda app, ...: ...)]
archive

The Archive object.

template_path

The path of template files.

template_environment

The Jinja2 template environment. A jinja2.Environment instance.

path_prefix

The prefix of the path.

encoding

The encoding of response text.

debug

The debug flag.

classmethod route(template_name, pattern_string)[source]

Registers a function as request handler.

>>> __tmp__ = Application.PATH_MAP
>>> Application.PATH_MAP = []
>>> Application.PATH_MAP
[]
>>> @Application.route("myhandler.html", r"^/(?P<a>.)/(?P<b>.)/?$")
... def myhandler(app, a, b):
...     return {"a": a, "b": b}
...
>>> Application.PATH_MAP  
[('myhandler.html', <_sre.SRE_Pattern object at ...>,
  <function myhandler at ...>)]
>>> Application.PATH_MAP = __tmp__
Parameters:
  • template_name (basestring) – a template filename
  • pattern_string (basestring) – a pattern of URL to route
classmethod redirect(pattern_string, status_code=307)[source]

Registers a redirection handler.

>>> __tmp__ = Application.PATH_MAP
>>> Application.PATH_MAP = []
>>> Application.PATH_MAP
[]
>>> @Application.redirect(r"^/(?P<a>.)/(?P<b>.)/?$", 301)
... def redirect(app, a, b):
...     return "/url/{0}/{1}".format(a, b)
...
>>> Application.PATH_MAP  
[(301, <_sre.SRE_Pattern object at ...>,
  <function redirect at ...>)]
>>> Application.PATH_MAP = __tmp__
Parameters:pattern_string (basestring) – a pattern of URL to route
class irclog.web.Environment(application, environment)[source]

Bases: dict

HTTP request environment. It contains WSGI environment values, and is a subtype of dict.

Parameters:
  • application (Application) – an application
  • environment (dict) – a WSGI environment dictionary
application

The Application instance.

app

Alias of application.

authorization

The tuple that contains credential pair: user and password.

>>> assert isinstance(env, Environment)  
>>> env['HTTP_AUTHORIZATION']  
'Basic dXNlcjpwYXNz'
>>> env.authorization  
('user', 'pass')

It is None when there’s no 'HTTP_AUTHORIZATION' key:

>>> assert isinstance(env2, Environment)  
>>> 'HTTP_AUTHORIZATION' in env  
False
>>> print env.auth  
None
irclog.web.setup_template_environment(environment)[source]

Sets up the Jinja2 environment.

Parameters:environment (jinja2.Environment) – a Jinja2 environment
irclog.web.quote_url(object)[source]

Quotes as URL.

>>> quote_url(1)
'1'
>>> quote_url("hello world")
'hello%20world'
Parameters:object – an object to be quoted
Returns:a quoted string
irclog.web.url_for(object)[source]

Makes an URL for the object.

Parameters:object – an object to create URL
Returns:an URL