irclog.web — Web IRC log view¶
-
class
irclog.web.Application(archive, template_path, path_prefix='', encoding='utf-8', debug=False)[source]¶ Bases:
objectWSGI 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 isFalse
-
STATIC_PATH_PATTERN¶
-
PATH_MAP¶ The
list: oftuplecontains template name, routing pattern and object getting function.Form is like following:
[("template.html", re.compile("url regex"), lambda app, ...: ...)]
-
template_path¶ The path of template files.
-
template_environment¶ The Jinja2 template environment. A
jinja2.Environmentinstance.
-
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
- template_name (
-
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
- archive (
-
class
irclog.web.Environment(application, environment)[source]¶ Bases:
dictHTTP 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
Applicationinstance.
-
app¶ Alias of
application.
The
tuplethat contains credential pair: user and password.>>> assert isinstance(env, Environment) >>> env['HTTP_AUTHORIZATION'] 'Basic dXNlcjpwYXNz' >>> env.authorization ('user', 'pass')
It is
Nonewhen there’s no'HTTP_AUTHORIZATION'key:>>> assert isinstance(env2, Environment) >>> 'HTTP_AUTHORIZATION' in env False >>> print env.auth None
- application (
-
irclog.web.setup_template_environment(environment)[source]¶ Sets up the Jinja2 environment.
Parameters: environment ( jinja2.Environment) – a Jinja2 environment