1
0
mirror of https://github.com/webrecorder/pywb.git synced 2025-03-15 00:03:28 +01:00

views: cleanup view filters, remove obsolete, add tests for format_ts

and is_wb_handler
This commit is contained in:
Ilya Kreymer 2015-01-11 23:02:48 -08:00
parent 438f9c3e5c
commit 7610d9deb7
2 changed files with 22 additions and 12 deletions

View File

@ -0,0 +1,20 @@
"""
>>> format_ts('201412261010')
'Fri, Dec 26 2014 10:10:59'
>>> format_ts('201412261010', '%s')
1419617459000
>>> is_wb_handler(DebugEchoHandler())
False
"""
from pywb.webapp.views import format_ts, is_wb_handler
from pywb.webapp.handlers import DebugEchoHandler
if __name__ == "__main__":
import doctest
doctest.testmod()

View File

@ -23,11 +23,7 @@ class template_filter(object):
Otherwise, the func name is the filter name
"""
def __init__(self, param=None):
if hasattr(param, '__call__'):
self.name = None
self.__call__(param)
else:
self.name = param
self.name = param
def __call__(self, func):
name = self.name
@ -40,7 +36,7 @@ class template_filter(object):
#=================================================================
# Filters
@template_filter
@template_filter()
def format_ts(value, format_='%a, %b %d %Y %H:%M:%S'):
value = timestamp_to_datetime(value)
if format_ == '%s':
@ -55,17 +51,11 @@ def get_urlsplit(url):
return split
@template_filter()
def request_hostname(env):
return env.get('HTTP_HOST', 'localhost')
@template_filter()
def is_wb_handler(obj):
if not hasattr(obj, 'handler'):
return False
#return isinstance(obj.handler, WBHandler)
return obj.handler.__class__.__name__ == "WBHandler"