mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
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.)
This commit is contained in:
parent
a401ae4010
commit
65230a2de7
15 changed files with 44 additions and 72 deletions
|
@ -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"):
|
||||
def _is_unicode(x):
|
||||
return isinstance(x, unicode)
|
||||
else:
|
||||
try:
|
||||
unicode
|
||||
except NameError:
|
||||
def _is_unicode(x):
|
||||
return 0
|
||||
else:
|
||||
def _is_unicode(x):
|
||||
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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue