⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uri.py

📁 Python的一个ORM,现在很火
💻 PY
字号:
## Copyright (c) 2006, 2007 Canonical## Written by Gustavo Niemeyer <gustavo@niemeyer.net>## This file is part of Storm Object Relational Mapper.## Storm is free software; you can redistribute it and/or modify# it under the terms of the GNU Lesser General Public License as# published by the Free Software Foundation; either version 2.1 of# the License, or (at your option) any later version.## Storm is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU Lesser General Public License for more details.## You should have received a copy of the GNU Lesser General Public License# along with this program.  If not, see <http://www.gnu.org/licenses/>.#from storm.exceptions import URIErrorclass URI(object):    username = None    password = None    host = None    port = None    database = None    def __init__(self, uri_str):        try:            self.scheme, rest = uri_str.split(":", 1)        except ValueError:            raise URIError("URI has no scheme: %s" % repr(uri_str))        self.options = {}        if "?" in rest:            rest, options = rest.split("?", 1)            for pair in options.split("&"):                key, value = pair.split("=", 1)                self.options[unescape(key)] = unescape(value)        if rest:            if not rest.startswith("//"):                self.database = unescape(rest)            else:                rest = rest[2:]                if "/" in rest:                    rest, database = rest.split("/", 1)                    self.database = unescape(database)                if "@" in rest:                    userpass, hostport = rest.split("@", 1)                else:                    userpass = None                    hostport = rest                if hostport:                    if ":" in hostport:                        host, port = hostport.rsplit(":", 1)                        self.host = unescape(host)                        if port:                            self.port = int(port)                    else:                        self.host = unescape(hostport)                if userpass is not None:                    if ":" in userpass:                        username, password = userpass.rsplit(":", 1)                        self.username = unescape(username)                        self.password = unescape(password)                    else:                        self.username = unescape(userpass)    def copy(self):        uri = object.__new__(self.__class__)        uri.__dict__.update(self.__dict__)        uri.options = self.options.copy()        return uridef unescape(s):    if "%" not in s:        return s    i = 0    j = s.find("%")    r = []    while j != -1:        r.append(s[i:j])        i = j+3        r.append(chr(int(s[j+1:i], 16)))        j = s.find("%", i)    r.append(s[i:])    return "".join(r)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -