~sidnei/storm/mssql-support

« back to all changes in this revision

Viewing changes to storm/uri.py

  • Committer: Sidnei da Silva
  • Date: 2008-05-23 06:53:19 UTC
  • mfrom: (173.2.54 trunk)
  • Revision ID: sidnei@enfoldsystems.com-20080523065319-6rao99dgz5iil8mf
- Merged from trunk
- Renamed connect() to raw_connect() and adjusted
- Added 'selfref' table to setup

Tests are now pretty much at the same state they were in September. Yay!

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# You should have received a copy of the GNU Lesser General Public License
19
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
#
 
21
from urllib import quote
 
22
 
21
23
from storm.exceptions import URIError
22
24
 
23
25
 
77
79
        uri.options = self.options.copy()
78
80
        return uri
79
81
 
 
82
    def __str__(self):
 
83
        tokens = [self.scheme, ":"]
 
84
        append = tokens.append
 
85
        if (self.username is not None or self.password is not None or
 
86
            self.host is not None or self.port is not None):
 
87
            append("//")
 
88
            if self.username is not None or self.password is not None:
 
89
                if self.username is not None:
 
90
                    append(escape(self.username))
 
91
                if self.password is not None:
 
92
                    append(":")
 
93
                    append(escape(self.password))
 
94
                append("@")
 
95
            if self.host is not None:
 
96
                append(escape(self.host))
 
97
            if self.port is not None:
 
98
                append(":")
 
99
                append(str(self.port))
 
100
            append("/")
 
101
        if self.database is not None:
 
102
            append(escape(self.database, "/"))
 
103
        if self.options:
 
104
            options = ["%s=%s" % (escape(key), escape(value))
 
105
                       for key, value in sorted(self.options.iteritems())]
 
106
            append("?")
 
107
            append("&".join(options))
 
108
        return "".join(tokens)
 
109
 
 
110
 
 
111
def escape(s, safe=""):
 
112
    return quote(s, safe)
 
113
 
80
114
 
81
115
def unescape(s):
82
116
    if "%" not in s: