Skip to content

Commit dd73010

Browse files
committed
w3lib.utils: deprecate functions not needed for Python 3
1 parent ef5c110 commit dd73010

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

w3lib/url.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
urlunsplit,
2525
)
2626
from urllib.request import pathname2url, url2pathname
27-
from w3lib.util import to_bytes, to_native_str, to_unicode
27+
from w3lib.util import to_bytes, to_unicode
2828

2929

3030
# error handling function for bytes-to-Unicode decoding errors with URLs
@@ -85,13 +85,13 @@ def safe_url_string(url, encoding='utf8', path_encoding='utf8', quote_path=True)
8585
if quote_path:
8686
path = quote(to_bytes(parts.path, path_encoding), _path_safe_chars)
8787
else:
88-
path = to_native_str(parts.path)
88+
path = to_unicode(parts.path)
8989

9090
# quote() in Python2 return type follows input type;
9191
# quote() in Python3 always returns Unicode (native str)
9292
return urlunsplit((
93-
to_native_str(parts.scheme),
94-
to_native_str(netloc).rstrip(':'),
93+
to_unicode(parts.scheme),
94+
to_unicode(netloc).rstrip(':'),
9595
path,
9696
# encoding of query and fragment follows page encoding
9797
# or form-charset (if known and passed)
@@ -415,8 +415,8 @@ def _safe_ParseResult(parts, encoding='utf8', path_encoding='utf8'):
415415
netloc = parts.netloc
416416

417417
return (
418-
to_native_str(parts.scheme),
419-
to_native_str(netloc),
418+
to_unicode(parts.scheme),
419+
to_unicode(netloc),
420420

421421
# default encoding for path component SHOULD be UTF-8
422422
quote(to_bytes(parts.path, path_encoding), _path_safe_chars),

w3lib/util.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
1+
from warnings import warn
2+
3+
14
def str_to_unicode(text, encoding=None, errors='strict'):
5+
warn(
6+
"The w3lib.utils.str_to_unicode function is deprecated and "
7+
"will be removed in a future release.",
8+
DeprecationWarning
9+
)
210
if encoding is None:
311
encoding = 'utf-8'
412
if isinstance(text, bytes):
513
return text.decode(encoding, errors)
614
return text
715

816
def unicode_to_str(text, encoding=None, errors='strict'):
17+
warn(
18+
"The w3lib.utils.unicode_to_str function is deprecated and "
19+
"will be removed in a future release.",
20+
DeprecationWarning
21+
)
922
if encoding is None:
1023
encoding = 'utf-8'
1124
if isinstance(text, str):
@@ -38,4 +51,10 @@ def to_bytes(text, encoding=None, errors='strict'):
3851

3952
def to_native_str(text, encoding=None, errors='strict'):
4053
""" Return str representation of `text` """
54+
warn(
55+
"The w3lib.utils.to_native_str function is deprecated and "
56+
"will be removed in a future release. Please use "
57+
"w3lib.utils.to_unicode instead.",
58+
DeprecationWarning
59+
)
4160
return to_unicode(text, encoding, errors)

0 commit comments

Comments
 (0)