summaryrefslogtreecommitdiffstats
path: root/Lib/urllib.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2002-06-03 15:58:32 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2002-06-03 15:58:32 (GMT)
commit65230a2de758fbde57b3893c402436ae0202ada3 (patch)
tree4b0b8431990125dd567b23c4ad3325959dc91a2e /Lib/urllib.py
parenta401ae4010eeb385a0775c505637bbc332bc184c (diff)
downloadcpython-65230a2de758fbde57b3893c402436ae0202ada3.zip
cpython-65230a2de758fbde57b3893c402436ae0202ada3.tar.gz
cpython-65230a2de758fbde57b3893c402436ae0202ada3.tar.bz2
Remove uses of the string and types modules:
x in string.whitespace => x.isspace() type(x) in types.StringTypes => isinstance(x, basestring) isinstance(x, types.StringTypes) => isinstance(x, basestring) type(x) is types.StringType => isinstance(x, str) type(x) == types.StringType => isinstance(x, str) string.split(x, ...) => x.split(...) string.join(x, y) => y.join(x) string.zfill(x, ...) => x.zfill(...) string.count(x, ...) => x.count(...) hasattr(types, "UnicodeType") => try: unicode except NameError: type(x) != types.TupleTuple => not isinstance(x, tuple) isinstance(x, types.TupleType) => isinstance(x, tuple) type(x) is types.IntType => isinstance(x, int) Do not mention the string module in the rlcompleter docstring. This partially applies SF patch http://www.python.org/sf/562373 (with basestring instead of string). (It excludes the changes to unittest.py and does not change the os.stat stuff.)
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r--Lib/urllib.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 0720125..381d54e 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -27,7 +27,6 @@ import socket
import os
import time
import sys
-import types
__all__ = ["urlopen", "URLopener", "FancyURLopener", "urlretrieve",
"urlcleanup", "quote", "quote_plus", "unquote", "unquote_plus",
@@ -254,7 +253,7 @@ class URLopener:
"""Use HTTP protocol."""
import httplib
user_passwd = None
- if type(url) is types.StringType:
+ if isinstance(url, str):
host, selector = splithost(url)
if host:
user_passwd, host = splituser(host)
@@ -332,7 +331,7 @@ class URLopener:
"""Use HTTPS protocol."""
import httplib
user_passwd = None
- if type(url) is types.StringType:
+ if isinstance(url, str):
host, selector = splithost(url)
if host:
user_passwd, host = splituser(host)
@@ -906,12 +905,14 @@ def basejoin(base, url):
# unquote('abc%20def') -> 'abc def'
# quote('abc def') -> 'abc%20def')
-if hasattr(types, "UnicodeType"):
+try:
+ unicode
+except NameError:
def _is_unicode(x):
- return isinstance(x, unicode)
+ return 0
else:
def _is_unicode(x):
- return 0
+ return isinstance(x, unicode)
def toBytes(url):
"""toBytes(u"URL") --> 'URL'."""
@@ -1173,7 +1174,7 @@ def urlencode(query,doseq=0):
try:
# non-sequence items should not work with len()
# non-empty strings will fail this
- if len(query) and type(query[0]) != types.TupleType:
+ if len(query) and not isinstance(query[0], tuple):
raise TypeError
# zero-length sequences of all types will get here and succeed,
# but that's a minor nit - since the original implementation
@@ -1193,7 +1194,7 @@ def urlencode(query,doseq=0):
else:
for k, v in query:
k = quote_plus(str(k))
- if type(v) == types.StringType:
+ if isinstance(v, str):
v = quote_plus(v)
l.append(k + '=' + v)
elif _is_unicode(v):