本文整理汇总了Python中urllib.splitpasswd方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.splitpasswd方法的具体用法?Python urllib.splitpasswd怎么用?Python urllib.splitpasswd使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib
的用法示例。
在下文中一共展示了urllib.splitpasswd方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_splitpasswd
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitpasswd [as 别名]
def test_splitpasswd(self):
# Some of the password examples are not sensible, but it is added to
# confirming to RFC2617 and addressing issue4675.
splitpasswd = urllib.splitpasswd
self.assertEqual(splitpasswd('user:ab'), ('user', 'ab'))
self.assertEqual(splitpasswd('user:a\nb'), ('user', 'a\nb'))
self.assertEqual(splitpasswd('user:a\tb'), ('user', 'a\tb'))
self.assertEqual(splitpasswd('user:a\rb'), ('user', 'a\rb'))
self.assertEqual(splitpasswd('user:a\fb'), ('user', 'a\fb'))
self.assertEqual(splitpasswd('user:a\vb'), ('user', 'a\vb'))
self.assertEqual(splitpasswd('user:a:b'), ('user', 'a:b'))
self.assertEqual(splitpasswd('user:a b'), ('user', 'a b'))
self.assertEqual(splitpasswd('user 2:ab'), ('user 2', 'ab'))
self.assertEqual(splitpasswd('user+1:a+b'), ('user+1', 'a+b'))
self.assertEqual(splitpasswd('user:'), ('user', ''))
self.assertEqual(splitpasswd('user'), ('user', None))
self.assertEqual(splitpasswd(':ab'), ('', 'ab'))
示例2: test_splitpasswd
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitpasswd [as 别名]
def test_splitpasswd(self):
"""Some of the password examples are not sensible, but it is added to
confirming to RFC2617 and addressing issue4675.
"""
self.assertEqual(('user', 'ab'),urllib.splitpasswd('user:ab'))
self.assertEqual(('user', 'a\nb'),urllib.splitpasswd('user:a\nb'))
self.assertEqual(('user', 'a\tb'),urllib.splitpasswd('user:a\tb'))
self.assertEqual(('user', 'a\rb'),urllib.splitpasswd('user:a\rb'))
self.assertEqual(('user', 'a\fb'),urllib.splitpasswd('user:a\fb'))
self.assertEqual(('user', 'a\vb'),urllib.splitpasswd('user:a\vb'))
self.assertEqual(('user', 'a:b'),urllib.splitpasswd('user:a:b'))
self.assertEqual(('user', 'a b'),urllib.splitpasswd('user:a b'))
self.assertEqual(('user 2', 'ab'),urllib.splitpasswd('user 2:ab'))
self.assertEqual(('user+1', 'a+b'),urllib.splitpasswd('user+1:a+b'))
示例3: urlSplit
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import splitpasswd [as 别名]
def urlSplit(url, defaultPort = None):
"""A function to split a URL in the format
<scheme>://<user>:<pass>@<host>:<port>/<path>;<params>#<fragment>
into a tuple
(<scheme>, <user>, <pass>, <host>, <port>, <path>, <params>, <fragment>)
Any missing pieces (user/pass) will be set to None.
If the port is missing, it will be set to defaultPort; otherwise, the port
should be a numeric value.
"""
scheme, netloc, path, query, fragment = urlparse.urlsplit(url)
userpass, hostport = urllib.splituser(netloc)
if scheme == 'lookaside':
# Always a local path, sometimes the first part will have a colon in it
# but it isn't a port, e.g. "lp:lightdm".
host, port = hostport, None
else:
host, port = networking.splitHostPort(hostport)
if port is None:
port = defaultPort
if userpass:
user, passwd = urllib.splitpasswd(userpass)
if sys.version_info[:2] == (2, 7):
# splituser is considered internal and changed
# behavior in 2.7. New behavior is right because
# it allows : in password, but we must deal with
# the old 2.6 behavior and not double-unquote
user = urllib.unquote(user)
if passwd:
passwd = urllib.unquote(passwd)
if passwd:
passwd = ProtectedString(passwd)
else:
user, passwd = None, None
return scheme, user, passwd, host, port, path, \
query or None, fragment or None