# -*- encoding: utf-8 -*- from __future__ import unicode_literals import re import cgi import time import functools from datetime import datetime, timedelta from itsdangerous import SignatureExpired, BadSignature from werkzeug.http import dump_cookie from werkzeug.wsgi import get_current_url from werkzeug.utils import redirect from werkzeug.routing import Rule from werkzeug.wrappers import Response from werkzeug.exceptions import BadRequest, Forbidden, NotFound from isso.compat import text_type as str from isso import utils, local from isso.utils import (http, parse, JSONResponse as JSON, render_template) from isso.views import requires from isso.utils.hash import sha1 # from Django appearently, looks good to me *duck* __url_re = re.compile( r'^' r'(https?://)?' r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' # domain... r'localhost|' # localhost... r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip r'(?::\d+)?' # optional port r'(?:/?|[/?]\S+)' r'$', re.IGNORECASE) def isurl(text): return __url_re.match(text) is not None def normalize(url): if not url.startswith(("http://", "https://")): return "http://" + url return url def xhr(func): """A decorator to check for CSRF on POST/PUT/DELETE using a