Skip to content

Commit 625c6c1

Browse files
committed
Drop python 2 and make python 3.8 be the minimum.
Python 3.7 is end-of-life: https://devguide.python.org/versions/
1 parent daab62f commit 625c6c1

File tree

4 files changed

+45
-108
lines changed

4 files changed

+45
-108
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
python-version: ["2.7.18", "3.5.10", "3.6.15", "3.7.17", "3.8.18", "3.9.18", "3.10.13", "3.11.7", "3.12.1", "3.13.0a2"]
19+
python-version: ["3.8.18", "3.9.18", "3.10.13", "3.11.7", "3.12.1", "3.13.0a2"]
2020

2121
runs-on: ubuntu-latest
2222
container:

setup.cfg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ keywords = gis, geospatial, geographic, shapefile, shapefiles
1616
classifiers =
1717
Development Status :: 5 - Production/Stable
1818
Programming Language :: Python
19-
Programming Language :: Python :: 2.7
2019
Programming Language :: Python :: 3
2120
Topic :: Scientific/Engineering :: GIS
2221
Topic :: Software Development :: Libraries
2322
Topic :: Software Development :: Libraries :: Python Modules
2423

2524
[options]
2625
py_modules = shapefile
27-
python_requires = >=2.7
26+
python_requires = >=3.8
2827

2928
[bdist_wheel]
3029
universal=1

shapefile.py

Lines changed: 40 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -74,112 +74,55 @@
7474
5: 'RING'}
7575

7676

77-
# Python 2-3 handling
77+
xrange = range
78+
izip = zip
7879

79-
PYTHON3 = sys.version_info[0] == 3
80-
81-
if PYTHON3:
82-
xrange = range
83-
izip = zip
84-
85-
from urllib.parse import urlparse, urlunparse
86-
from urllib.error import HTTPError
87-
from urllib.request import urlopen, Request
80+
from urllib.parse import urlparse, urlunparse
81+
from urllib.error import HTTPError
82+
from urllib.request import urlopen, Request
8883

89-
else:
90-
from itertools import izip
91-
92-
from urlparse import urlparse, urlunparse
93-
from urllib2 import HTTPError
94-
from urllib2 import urlopen, Request
95-
96-
9784
# Helpers
9885

9986
MISSING = [None,'']
10087
NODATA = -10e38 # as per the ESRI shapefile spec, only used for m-values.
10188

102-
if PYTHON3:
103-
def b(v, encoding='utf-8', encodingErrors='strict'):
104-
if isinstance(v, str):
105-
# For python 3 encode str to bytes.
106-
return v.encode(encoding, encodingErrors)
107-
elif isinstance(v, bytes):
108-
# Already bytes.
109-
return v
110-
elif v is None:
111-
# Since we're dealing with text, interpret None as ""
112-
return b""
113-
else:
114-
# Force string representation.
115-
return str(v).encode(encoding, encodingErrors)
116-
117-
def u(v, encoding='utf-8', encodingErrors='strict'):
118-
if isinstance(v, bytes):
119-
# For python 3 decode bytes to str.
120-
return v.decode(encoding, encodingErrors)
121-
elif isinstance(v, str):
122-
# Already str.
123-
return v
124-
elif v is None:
125-
# Since we're dealing with text, interpret None as ""
126-
return ""
127-
else:
128-
# Force string representation.
129-
return bytes(v).decode(encoding, encodingErrors)
130-
131-
def is_string(v):
132-
return isinstance(v, str)
133-
134-
else:
135-
def b(v, encoding='utf-8', encodingErrors='strict'):
136-
if isinstance(v, unicode):
137-
# For python 2 encode unicode to bytes.
138-
return v.encode(encoding, encodingErrors)
139-
elif isinstance(v, bytes):
140-
# Already bytes.
141-
return v
142-
elif v is None:
143-
# Since we're dealing with text, interpret None as ""
144-
return ""
145-
else:
146-
# Force string representation.
147-
return unicode(v).encode(encoding, encodingErrors)
148-
149-
def u(v, encoding='utf-8', encodingErrors='strict'):
150-
if isinstance(v, bytes):
151-
# For python 2 decode bytes to unicode.
152-
return v.decode(encoding, encodingErrors)
153-
elif isinstance(v, unicode):
154-
# Already unicode.
155-
return v
156-
elif v is None:
157-
# Since we're dealing with text, interpret None as ""
158-
return u""
159-
else:
160-
# Force string representation.
161-
return bytes(v).decode(encoding, encodingErrors)
89+
def b(v, encoding='utf-8', encodingErrors='strict'):
90+
if isinstance(v, str):
91+
# For python 3 encode str to bytes.
92+
return v.encode(encoding, encodingErrors)
93+
elif isinstance(v, bytes):
94+
# Already bytes.
95+
return v
96+
elif v is None:
97+
# Since we're dealing with text, interpret None as ""
98+
return b""
99+
else:
100+
# Force string representation.
101+
return str(v).encode(encoding, encodingErrors)
102+
103+
def u(v, encoding='utf-8', encodingErrors='strict'):
104+
if isinstance(v, bytes):
105+
# For python 3 decode bytes to str.
106+
return v.decode(encoding, encodingErrors)
107+
elif isinstance(v, str):
108+
# Already str.
109+
return v
110+
elif v is None:
111+
# Since we're dealing with text, interpret None as ""
112+
return ""
113+
else:
114+
# Force string representation.
115+
return bytes(v).decode(encoding, encodingErrors)
162116

163-
def is_string(v):
164-
return isinstance(v, basestring)
117+
def is_string(v):
118+
return isinstance(v, str)
165119

166-
if sys.version_info[0:2] >= (3, 6):
167-
def pathlike_obj(path):
168-
if isinstance(path, os.PathLike):
169-
return os.fsdecode(path)
170-
else:
171-
return path
172-
else:
173-
def pathlike_obj(path):
174-
if is_string(path):
175-
return path
176-
elif hasattr(path, "__fspath__"):
177-
return path.__fspath__()
178-
else:
179-
try:
180-
return str(path)
181-
except:
182-
return path
120+
121+
def pathlike_obj(path):
122+
if isinstance(path, os.PathLike):
123+
return os.fsdecode(path)
124+
else:
125+
return path
183126

184127

185128
# Begin

test_shapefile.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
This module tests the functionality of shapefile.py.
33
"""
44
# std lib imports
5+
import datetime
6+
import json
57
import os.path
6-
import sys
7-
if sys.version_info.major == 3:
8-
from pathlib import Path
8+
from pathlib import Path
99

1010
# third party imports
1111
import pytest
12-
import json
13-
import datetime
14-
if sys.version_info.major == 2:
15-
# required by pytest for python <36
16-
from pathlib2 import Path
1712

1813
# our imports
1914
import shapefile

0 commit comments

Comments
 (0)