/lib/variables.py
Python | 40 lines | 31 code | 5 blank | 4 comment | 3 complexity | c04a53669e1d836b627b2745506a139a MD5 | raw file
- #!/usr/bin/env python
- # coding=utf-8
- #
- # Copyright 2013 3n1b.com
- import time
- import re
- import random
- from htmlentity import unescape
- from HTMLParser import HTMLParser
- def date(timestamp, formatter):
- return time.strftime(formatter, time.gmtime(float(timestamp)))
- def build_uri(uri, param, value):
- regx = re.compile("[\?&](%s=[^\?&]*)" % param)
- find = regx.search(uri)
- split = "&" if re.search(r"\?", uri) else "?"
- if not find: return "%s%s%s=%s" % (uri, split, param, value)
- return re.sub(find.group(1), "%s=%s" % (param, value), uri)
- def strip_tags(html):
- html = html.strip()
- html = html.strip("\n")
- result = []
- parse = HTMLParser()
- parse.handle_data = result.append
- parse.feed(html)
- parse.close()
- return "".join(result)
- def gen_random():
- return random.random()
- template_variables = {}
- template_variables["build_uri"] = build_uri
- template_variables["date"] = date
- template_variables["strip_tags"] = strip_tags