Use faster (non-regex) version of is_url.

This commit is contained in:
John Garland 2010-02-25 02:01:08 +11:00
parent 4a7782af28
commit 50ae65b58a
2 changed files with 4 additions and 4 deletions

View file

@ -354,7 +354,7 @@ def fdate(seconds):
def is_url(url):
"""
A simple regex test to check if the URL is valid
A simple test to check if the URL is valid
:param url: the url to test
:type url: string
@ -367,8 +367,7 @@ def is_url(url):
True
"""
import re
return bool(re.search('^(https?|ftp|udp)://', url))
return url.partition('://')[0] in ("http", "https", "ftp", "udp")
def is_magnet(uri):
"""

View file

@ -48,6 +48,7 @@ from deluge.log import LOG as log
from deluge.plugins.pluginbase import CorePluginBase
import deluge.component as component
import deluge.configmanager
from deluge.common import is_url
from deluge.core.rpcserver import export
from deluge.httpdownloader import download_file
from detect import detect_compression, detect_format, create_reader, UnknownFormatError
@ -136,7 +137,7 @@ class Core(CorePluginBase):
self.up_to_date = False
if force:
self.reader = None
self.is_url = self.config["url"].split("://")[0] in ("http", "https")
self.is_url = is_url(self.config["url"])
# Start callback chain
if self.is_url: