Skip to content

Commit

Permalink
finish removing six
Browse files Browse the repository at this point in the history
  • Loading branch information
a-detiste committed Mar 16, 2024
1 parent 19d14bb commit 4274f02
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
# All configuration values have a default value; values that are commented out
# serve to show the default value.

import sys

# If your extensions are in another directory, add it here.
#import sys
#sys.path.append('some/directory')

# General configuration
Expand Down
9 changes: 7 additions & 2 deletions paste/cgiapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@
import select
except ImportError:
select = None
import six

from paste.util import converters

__all__ = ['CGIError', 'CGIApplication']

def ensure_text(s, encoding='utf-8', errors='strict'):
if type(s) is str:
return s
else:
return s.decode(encoding, errors)

class CGIError(Exception):
"""
Raised when the CGI script can't be found or doesn't
Expand Down Expand Up @@ -252,7 +257,7 @@ def proc_communicate(proc, stdin=None, stdout=None, stderr=None):
read_set.remove(proc.stderr)
if trans_nl:
data = proc._translate_newlines(data)
stderr.write(six.ensure_text(data))
stderr.write(ensure_text(data))

try:
proc.wait()
Expand Down
5 changes: 3 additions & 2 deletions paste/exceptions/serial_number_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
except ImportError:
from md5 import md5

import six
import operator
byte2int = operator.itemgetter(0)

good_characters = "23456789abcdefghjkmnpqrtuvwxyz"

Expand Down Expand Up @@ -71,7 +72,7 @@ def hash_identifier(s, length, pad=True, hasher=md5, prefix='',
modulo = base ** length
number = 0
for c in list(bin_hash):
number = (number * 256 + six.byte2int([c])) % modulo
number = (number * 256 + byte2int([c])) % modulo
ident = make_identifier(number)
if pad:
ident = good_characters[0]*(length-len(ident)) + ident
Expand Down
21 changes: 16 additions & 5 deletions paste/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,23 @@
from urllib.parse import urlencode
from urllib import parse as urlparse
from http.cookies import BaseCookie
import six

from paste import wsgilib
from paste import lint
from paste.response import HeaderDict

def ensure_binary(s):
if isinstance(s, bytes):
return s
else:
return s.encode('utf-8')

def ensure_str(s, encoding='utf-8', errors='strict'):
if type(s) is str:
return s
else:
return s.decode(encoding, errors)

def tempnam_no_warning(*args):
"""
An os.tempnam with the warning turned off, because sometimes
Expand Down Expand Up @@ -333,18 +344,18 @@ def encode_multipart(self, params, files):
lines = []
for key, value in params:
lines.append(b'--'+boundary)
line = b'Content-Disposition: form-data; name="%s"' % six.ensure_binary(key)
line = b'Content-Disposition: form-data; name="%s"' % ensure_binary(key)
lines.append(line)
lines.append(b'')
line = six.ensure_binary(value)
line = ensure_binary(value)
lines.append(line)
for file_info in files:
key, filename, value = self._get_file_info(file_info)
lines.append(b'--'+boundary)
line = (b'Content-Disposition: form-data; name="%s"; filename="%s"'
% (six.ensure_binary(key), six.ensure_binary(filename)))
% (ensure_binary(key), ensure_binary(filename)))
lines.append(line)
fcontent = mimetypes.guess_type(six.ensure_str(filename, 'ascii', 'ignore'))[0]
fcontent = mimetypes.guess_type(ensure_str(filename, 'ascii', 'ignore'))[0]
line = (b'Content-Type: %s'
% (fcontent.encode('ascii') if fcontent else b'application/octet-stream'))
lines.append(line)
Expand Down
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
zip_safe=False,
install_requires=[
'setuptools', # pkg_resources
'six>=1.4.0',
],
extras_require={
'subprocess': [],
Expand Down

0 comments on commit 4274f02

Please sign in to comment.