From 25fc2de6430ca76b93054fc440f41e3cd93e67dd Mon Sep 17 00:00:00 2001 From: James Vega Date: Thu, 15 Oct 2009 21:56:26 -0400 Subject: [PATCH] utils.web: Provide access to the raw httpUrlRe/urlRe strings Using the compiled regexps for a PluginRegexp method's __doc__ doesn't work. Closes Sourceforge #2879862 Signed-off-by: James Vega --- plugins/ShrinkUrl/plugin.py | 2 +- plugins/Web/plugin.py | 2 +- src/utils/web.py | 17 +++++++++-------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/plugins/ShrinkUrl/plugin.py b/plugins/ShrinkUrl/plugin.py index 205f4d6c0..47e9cb66c 100644 --- a/plugins/ShrinkUrl/plugin.py +++ b/plugins/ShrinkUrl/plugin.py @@ -136,7 +136,7 @@ class ShrinkUrl(callbacks.PluginRegexp): if m is not None: m.tag('shrunken') shrinkSnarfer = urlSnarfer(shrinkSnarfer) - shrinkSnarfer.__doc__ = utils.web.httpUrlRe + shrinkSnarfer.__doc__ = utils.web._httpUrlRe def _getLnUrl(self, url): url = utils.web.urlquote(url) diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index 94744018c..6a332c792 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -105,7 +105,7 @@ class Web(callbacks.PluginRegexp): s = format('Title: %s (at %s)', title, domain) irc.reply(s, prefixNick=False) titleSnarfer = urlSnarfer(titleSnarfer) - titleSnarfer.__doc__ = utils.web.httpUrlRe + titleSnarfer.__doc__ = utils.web._httpUrlRe def headers(self, irc, msg, args, url): """ diff --git a/src/utils/web.py b/src/utils/web.py index a0e8f35a4..1fcae3d96 100644 --- a/src/utils/web.py +++ b/src/utils/web.py @@ -47,15 +47,16 @@ urlencode = urllib.urlencode class Error(Exception): pass -octet = r'(?:2(?:[0-4]\d|5[0-5])|1\d\d|\d{1,2})' -ipAddr = r'%s(?:\.%s){3}' % (octet, octet) +_octet = r'(?:2(?:[0-4]\d|5[0-5])|1\d\d|\d{1,2})' +_ipAddr = r'%s(?:\.%s){3}' % (_octet, _octet) # Base domain regex off RFC 1034 and 1738 -label = r'[0-9a-z][-0-9a-z]*[0-9a-z]?' -domain = r'%s(?:\.%s)*\.[a-z][-0-9a-z]*[a-z]?' % (label, label) -urlRe = re.compile(r'(\w+://(?:%s|%s)(?::\d+)?(?:/[^\])>\s]*)?)' - % (domain, ipAddr), re.I) -httpUrlRe = re.compile(r'(https?://(?:%s|%s)(?::\d+)?(?:/[^\])>\s]*)?)' - % (domain, ipAddr), re.I) +_label = r'[0-9a-z][-0-9a-z]*[0-9a-z]?' +_domain = r'%s(?:\.%s)*\.[a-z][-0-9a-z]*[a-z]?' % (_label, _label) +_urlRe = r'(\w+://(?:%s|%s)(?::\d+)?(?:/[^\])>\s]*)?)' % (_domain, _ipAddr) +urlRe = re.compile(_urlRe, re.I) +_httpUrlRe = r'(https?://(?:%s|%s)(?::\d+)?(?:/[^\])>\s]*)?)' % (_domain, + _ipAddr) +httpUrlRe = re.compile(_httpUrlRe, re.I) REFUSED = 'Connection refused.' TIMED_OUT = 'Connection timed out.'