Skip to content

Commit 5cb952f

Browse files
committed
rfctr: remove Python 2 compatibility layer
1 parent c8aad1c commit 5cb952f

File tree

20 files changed

+89
-182
lines changed

20 files changed

+89
-182
lines changed

ref/xsd/vml-wordprocessingDrawing.xsd

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
2+
<xsd:schema
33
xmlns="urn:schemas-microsoft-com:office:word"
4-
targetNamespace="urn:schemas-microsoft-com:office:word" elementFormDefault="qualified"
5-
attributeFormDefault="unqualified">
4+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5+
attributeFormDefault="unqualified"
6+
elementFormDefault="qualified"
7+
targetNamespace="urn:schemas-microsoft-com:office:word"
8+
>
69
<xsd:element name="bordertop" type="CT_Border"/>
710
<xsd:element name="borderleft" type="CT_Border"/>
811
<xsd:element name="borderright" type="CT_Border"/>

src/docx/compat.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/docx/image/image.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
"""
66

77
import hashlib
8+
import io
89
import os
910

10-
from docx.compat import BytesIO, is_string
1111
from docx.image.exceptions import UnrecognizedImageError
1212
from docx.shared import Emu, Inches, lazyproperty
1313

@@ -30,7 +30,7 @@ def from_blob(cls, blob):
3030
Return a new |Image| subclass instance parsed from the image binary
3131
contained in *blob*.
3232
"""
33-
stream = BytesIO(blob)
33+
stream = io.BytesIO(blob)
3434
return cls._from_stream(stream, blob)
3535

3636
@classmethod
@@ -39,11 +39,11 @@ def from_file(cls, image_descriptor):
3939
Return a new |Image| subclass instance loaded from the image file
4040
identified by *image_descriptor*, a path or file-like object.
4141
"""
42-
if is_string(image_descriptor):
42+
if isinstance(image_descriptor, str):
4343
path = image_descriptor
4444
with open(path, "rb") as f:
4545
blob = f.read()
46-
stream = BytesIO(blob)
46+
stream = io.BytesIO(blob)
4747
filename = os.path.basename(path)
4848
else:
4949
stream = image_descriptor

src/docx/image/jpeg.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
# encoding: utf-8
1+
"""Objects related to parsing headers of JPEG image streams.
22
3-
"""
4-
Objects related to parsing headers of JPEG image streams, both JFIF and Exif
5-
sub-formats.
3+
Includes both JFIF and Exif sub-formats.
64
"""
75

8-
from __future__ import absolute_import, division, print_function
6+
import io
97

10-
from ..compat import BytesIO
11-
from .constants import JPEG_MARKER_CODE, MIME_TYPE
12-
from .helpers import BIG_ENDIAN, StreamReader
13-
from .image import BaseImageHeader
14-
from .tiff import Tiff
8+
from docx.image.constants import JPEG_MARKER_CODE, MIME_TYPE
9+
from docx.image.helpers import BIG_ENDIAN, StreamReader
10+
from docx.image.image import BaseImageHeader
11+
from docx.image.tiff import Tiff
1512

1613

1714
class Jpeg(BaseImageHeader):
@@ -460,7 +457,7 @@ def _tiff_from_exif_segment(cls, stream, offset, segment_length):
460457
# wrap full segment in its own stream and feed to Tiff()
461458
stream.seek(offset + 8)
462459
segment_bytes = stream.read(segment_length - 8)
463-
substream = BytesIO(segment_bytes)
460+
substream = io.BytesIO(segment_bytes)
464461
return Tiff.from_stream(substream)
465462

466463

src/docx/opc/compat.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/docx/opc/part.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
"""Open Packaging Convention (OPC) objects related to package parts."""
22

3-
from docx.opc.compat import cls_method_fn
43
from docx.opc.oxml import serialize_part_xml
54
from docx.opc.packuri import PackURI
65
from docx.opc.rel import Relationships
7-
from docx.opc.shared import lazyproperty
6+
from docx.opc.shared import cls_method_fn, lazyproperty
87
from docx.oxml import parse_xml
98

109

src/docx/opc/phys_pkg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
from zipfile import ZIP_DEFLATED, ZipFile, is_zipfile
55

6-
from docx.opc.compat import is_string
76
from docx.opc.exceptions import PackageNotFoundError
87
from docx.opc.packuri import CONTENT_TYPES_URI
98

@@ -15,7 +14,7 @@ class PhysPkgReader(object):
1514

1615
def __new__(cls, pkg_file):
1716
# if *pkg_file* is a string, treat it as a path
18-
if is_string(pkg_file):
17+
if isinstance(pkg_file, str):
1918
if os.path.isdir(pkg_file):
2019
reader_cls = _DirPkgReader
2120
elif is_zipfile(pkg_file):

src/docx/opc/shared.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
# encoding: utf-8
2-
3-
"""
4-
Objects shared by opc modules.
5-
"""
6-
7-
from __future__ import absolute_import, print_function, unicode_literals
1+
"""Objects shared by opc modules."""
82

93

104
class CaseInsensitiveDict(dict):
@@ -26,6 +20,11 @@ def __setitem__(self, key, value):
2620
return super(CaseInsensitiveDict, self).__setitem__(key.lower(), value)
2721

2822

23+
def cls_method_fn(cls: type, method_name: str):
24+
"""Return method of `cls` having `method_name`."""
25+
return getattr(cls, method_name)
26+
27+
2928
def lazyproperty(f):
3029
"""
3130
@lazyprop decorator. Decorated method will be called only on first access

src/docx/oxml/coreprops.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import re
44
from datetime import datetime, timedelta
55

6-
from docx.compat import is_string
76
from docx.oxml import parse_xml
87
from docx.oxml.ns import nsdecls, qn
98
from docx.oxml.xmlchemy import BaseOxmlElement, ZeroOrOne
@@ -281,7 +280,7 @@ def _set_element_datetime(self, prop_name, value):
281280

282281
def _set_element_text(self, prop_name, value):
283282
"""Set string value of *name* property to *value*."""
284-
if not is_string(value):
283+
if not isinstance(value, str):
285284
value = str(value)
286285

287286
if len(value) > 255:

src/docx/oxml/settings.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
# encoding: utf-8
2-
31
"""Custom element classes related to document settings"""
42

5-
from __future__ import absolute_import, division, print_function, unicode_literals
6-
73
from docx.oxml.xmlchemy import BaseOxmlElement, ZeroOrOne
84

95

0 commit comments

Comments
 (0)