Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[feat] rename Uri to URI
[fix]  improve database uri parsing

git-svn-id: http://devedge.bour.cc/svn/tentacles/trunk@210 ff29af12-de15-47db-b328-d843b730dfdc
  • Loading branch information
Guillaume Bour committed May 17, 2011
1 parent 1421b9a commit 0477064
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions tentacles/database.py
Expand Up @@ -22,13 +22,30 @@
import sys, re, inspect, types


class Uri(object):
class URI(object):
"""
Parse database URI, and extract composantes as object fields
"""
def __init__(self, raw):
m = re.match('^(?P<scheme>\w+):(//((?P<username>[\w]+):(?P<password>[\w]+)@)?(?P<host>[\w.]+)(?P<port>\d+)?/)?(?P<db>[\w:/.]+)', raw, re.U|re.L)
m = re.match(r"""^(?P<scheme>\w+):
(//
(
(?P<username>\w+):(?P<password>\w+)
@)?
(?P<host>[\w.-]+)
(:(?P<port>\d+))?
/)?
(?P<db>[\w:/._-]+)$""", raw, re.U|re.L|re.X)

if m is None:
raise Exception("Invalid URI")

for k, v in m.groupdict().iteritems():
setattr(self, k, v)

if hasattr(self, 'port') and self.port is not None:
self.port = int(self.port)


class Storage(object):
__instance__ = None
Expand All @@ -40,7 +57,7 @@ class Storage(object):
__inheritems__ = []

def __init__(self, uri):
self.uri = Uri(uri)
self.uri = URI(uri)

modname = "tentacles.backends.%s" % self.uri.scheme
if not sys.modules.has_key(modname):
Expand Down

0 comments on commit 0477064

Please sign in to comment.