mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
views: cleanup view filters, remove obsolete, add tests for format_ts
and is_wb_handler
This commit is contained in:
parent
438f9c3e5c
commit
7610d9deb7
20
pywb/webapp/test/test_view_filters.py
Normal file
20
pywb/webapp/test/test_view_filters.py
Normal 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()
|
@ -23,11 +23,7 @@ class template_filter(object):
|
|||||||
Otherwise, the func name is the filter name
|
Otherwise, the func name is the filter name
|
||||||
"""
|
"""
|
||||||
def __init__(self, param=None):
|
def __init__(self, param=None):
|
||||||
if hasattr(param, '__call__'):
|
self.name = param
|
||||||
self.name = None
|
|
||||||
self.__call__(param)
|
|
||||||
else:
|
|
||||||
self.name = param
|
|
||||||
|
|
||||||
def __call__(self, func):
|
def __call__(self, func):
|
||||||
name = self.name
|
name = self.name
|
||||||
@ -40,7 +36,7 @@ class template_filter(object):
|
|||||||
|
|
||||||
#=================================================================
|
#=================================================================
|
||||||
# Filters
|
# Filters
|
||||||
@template_filter
|
@template_filter()
|
||||||
def format_ts(value, format_='%a, %b %d %Y %H:%M:%S'):
|
def format_ts(value, format_='%a, %b %d %Y %H:%M:%S'):
|
||||||
value = timestamp_to_datetime(value)
|
value = timestamp_to_datetime(value)
|
||||||
if format_ == '%s':
|
if format_ == '%s':
|
||||||
@ -55,17 +51,11 @@ def get_urlsplit(url):
|
|||||||
return split
|
return split
|
||||||
|
|
||||||
|
|
||||||
@template_filter()
|
|
||||||
def request_hostname(env):
|
|
||||||
return env.get('HTTP_HOST', 'localhost')
|
|
||||||
|
|
||||||
|
|
||||||
@template_filter()
|
@template_filter()
|
||||||
def is_wb_handler(obj):
|
def is_wb_handler(obj):
|
||||||
if not hasattr(obj, 'handler'):
|
if not hasattr(obj, 'handler'):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
#return isinstance(obj.handler, WBHandler)
|
|
||||||
return obj.handler.__class__.__name__ == "WBHandler"
|
return obj.handler.__class__.__name__ == "WBHandler"
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user