urls.py 853 B

123456789101112131415161718192021222324
  1. #-*- coding: utf-8 -*-
  2. import re
  3. from urlparse import urlparse
  4. from django.conf import settings
  5. from misago.utils.strings import html_escape
  6. URL_RE = re.compile(r'^(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))$', re.UNICODE)
  7. def is_url(string):
  8. return URL_RE.search(string.strip()) != None
  9. def is_inner(string):
  10. return urlparse(string.strip()).netloc.lower() == urlparse(settings.BOARD_ADDRESS.lower()).netloc
  11. def clean_inner(string):
  12. parsed = urlparse(string.strip())
  13. href = parsed.path
  14. if parsed.query:
  15. href += '?%s' % parsed.query
  16. if parsed.fragment:
  17. href += '#%s' % parsed.fragment
  18. return html_escape(href)