Skip to content

Commit e6b23f8

Browse files
committed
Add various import, spacing and nomenclature fixes in different parts of the codebase.
1 parent 7ecd494 commit e6b23f8

File tree

7 files changed

+47
-46
lines changed

7 files changed

+47
-46
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ for better ongoing support to start in August 2018.
1414
Homepage (available soon): http://claird.github.io/PyPDF4/.
1515

1616
## Examples
17-
Please see the `samplecode` folder.
17+
Please see the `samplecode/` folder.
1818

1919
## Documentation
2020
Documentation soon will be available, although probably not at

pypdf4/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from pypdf4.pdf import PdfFileReader, PdfFileWriter
22
from pypdf4.merger import PdfFileMerger
3+
from pypdf4.pagerange import PageRange
34
from pypdf4._version import __version__
45

5-
__all__ = ["PdfFileReader", "PdfFileWriter", "PdfFileMerger"]
6+
__all__ = ["PdfFileReader", "PdfFileWriter", "PdfFileMerger", "PageRange"]

pypdf4/filters.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def encode(data, decodeParms=None):
489489
return LZWCodec.Encoder(data).encode()
490490

491491
@staticmethod
492-
def decode(data, decode_params=None):
492+
def decode(data, decodeParms=None):
493493
return LZWCodec.Decoder(data).decode()
494494

495495

@@ -552,9 +552,8 @@ def decode(data, decodeParms=None):
552552
553553
:param data: a str or bytes sequence of ASCII85-encoded characters.
554554
:return: bytes for Python 3, str for Python 2.
555-
556-
TO-DO Add check for missing '~>' EOD marker.
557555
"""
556+
# TO-DO Add check for missing '~>' EOD marker.
558557
group_index = b = 0
559558
out = bytearray()
560559

@@ -602,7 +601,7 @@ def encode(data, decodeParms=None):
602601
raise NotImplementedError()
603602

604603
@staticmethod
605-
def decode(data, decode_params=None):
604+
def decode(data, decodeParms=None):
606605
"""
607606
TO-DO Implement this filter.
608607
"""

pypdf4/generic.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@
3737

3838
from . import filters
3939
from . import utils
40-
from .utils import PdfStreamError
41-
from .utils import pypdfBytes as b_, pypdfUnicode as u_, pypdfChr, pypdfOrd
42-
from .utils import readNonWhitespace, RC4Encrypt, skipOverComment
40+
from pypdf4.utils import PdfStreamError
41+
from pypdf4.utils import pypdfBytes as b_, pypdfUnicode as u_, pypdfChr,\
42+
pypdfOrd
43+
from pypdf4.utils import readNonWhitespace, RC4Encrypt, skipOverComment
4344

4445

4546
__author__ = "Mathieu Fenniak"
@@ -100,6 +101,7 @@ def getObject(self):
100101
return self
101102

102103

104+
# TO-DO Add __repr_() implementations to the *Object classes
103105
class NullObject(PdfObject):
104106
def writeToStream(self, stream, encryption_key):
105107
stream.write(b_("null"))

pypdf4/pagerange.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import re
1111

12-
from .utils import isString
12+
from pypdf4.utils import isString
1313

1414
_INT_RE = r"(0|-?[1-9]\d*)" # A decimal int, don't allow "-0".
1515
PAGE_RANGE_RE = "^({int}|({int}?(:{int}?(:{int}?)?)))$".format(int=_INT_RE)
@@ -89,12 +89,10 @@ def __init__(self, arg):
8989
__init__.__doc__.format(page_range_help=PAGE_RANGE_HELP)
9090

9191
@staticmethod
92-
def valid(input_value):
92+
def valid(input):
9393
""" True if input is a valid initializer for a PageRange. """
94-
return isinstance(input_value, slice) or \
95-
isinstance(input_value, PageRange) or \
96-
(isString(input_value)
97-
and bool(re.match(PAGE_RANGE_RE, input_value)))
94+
return isinstance(input, slice) or isinstance(input, PageRange) or\
95+
(isString(input) and bool(re.match(PAGE_RANGE_RE, input)))
9896

9997
def toSlice(self):
10098
""" Return the slice equivalent of this page range. """

pypdf4/xmp.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ def _getText(self, element):
100100

101101
return text
102102

103-
def _converter_string(value):
103+
def _converterString(value):
104104
return value
105105

106-
def _converter_date(value):
106+
def _converterDate(value):
107107
m = iso8601.match(value)
108108
year = int(m.group("year"))
109109
month = int(m.group("month") or "1")
@@ -127,9 +127,9 @@ def _converter_date(value):
127127

128128
return dt
129129

130-
_test_converter_date = staticmethod(_converter_date)
130+
_test_converter_date = staticmethod(_converterDate)
131131

132-
def _getter_bag(namespace, name, converter):
132+
def _getterBag(namespace, name, converter):
133133
def get(self):
134134
cached = self.cache.get(namespace, {}).get(name)
135135
retval = []
@@ -156,7 +156,7 @@ def get(self):
156156

157157
return get
158158

159-
def _getter_seq(namespace, name, converter):
159+
def _getterSeq(namespace, name, converter):
160160
def get(self):
161161
cached = self.cache.get(namespace, {}).get(name)
162162
retval = []
@@ -186,7 +186,7 @@ def get(self):
186186

187187
return get
188188

189-
def _getter_langalt(namespace, name, converter):
189+
def _getterLangalt(namespace, name, converter):
190190
def get(self):
191191
cached = self.cache.get(namespace, {}).get(name)
192192
retval = {}
@@ -213,7 +213,7 @@ def get(self):
213213

214214
return get
215215

216-
def _getter_single(namespace, name, converter):
216+
def _getterSingle(namespace, name, converter):
217217
def get(self):
218218
cached = self.cache.get(namespace, {}).get(name)
219219

@@ -240,174 +240,174 @@ def get(self):
240240
return get
241241

242242
dc_contributor = property(
243-
_getter_bag(DC_NAMESPACE, "contributor", _converter_string)
243+
_getterBag(DC_NAMESPACE, "contributor", _converterString)
244244
)
245245
"""
246246
Contributors to the resource (other than the authors). An unsorted array of
247247
names.
248248
"""
249249

250250
dc_coverage = property(
251-
_getter_single(DC_NAMESPACE, "coverage", _converter_string)
251+
_getterSingle(DC_NAMESPACE, "coverage", _converterString)
252252
)
253253
"""
254254
Text describing the extent or scope of the resource.
255255
"""
256256

257257
dc_creator = property(
258-
_getter_seq(DC_NAMESPACE, "creator", _converter_string)
258+
_getterSeq(DC_NAMESPACE, "creator", _converterString)
259259
)
260260
"""
261261
A sorted array of names of the authors of the resource, listed in order of
262262
precedence.
263263
"""
264264

265-
dc_date = property(_getter_seq(DC_NAMESPACE, "date", _converter_date))
265+
dc_date = property(_getterSeq(DC_NAMESPACE, "date", _converterDate))
266266
"""
267267
A sorted array of dates (``datetime.datetime`` instances) of significance
268268
to the resource. The dates and times are in UTC.
269269
"""
270270

271271
dc_description = property(
272-
_getter_langalt(DC_NAMESPACE, "description", _converter_string)
272+
_getterLangalt(DC_NAMESPACE, "description", _converterString)
273273
)
274274
"""
275275
A language-keyed dictionary of textual descriptions of the content of the
276276
resource.
277277
"""
278278

279279
dc_format = property(
280-
_getter_single(DC_NAMESPACE, "format", _converter_string)
280+
_getterSingle(DC_NAMESPACE, "format", _converterString)
281281
)
282282
"""
283283
The mime-type of the resource.
284284
"""
285285

286286
dc_identifier = property(
287-
_getter_single(DC_NAMESPACE, "identifier", _converter_string)
287+
_getterSingle(DC_NAMESPACE, "identifier", _converterString)
288288
)
289289
"""
290290
Unique identifier of the resource.
291291
"""
292292

293293
dc_language = property(
294-
_getter_bag(DC_NAMESPACE, "language", _converter_string)
294+
_getterBag(DC_NAMESPACE, "language", _converterString)
295295
)
296296
"""
297297
An unordered array specifying the languages used in the resource.
298298
"""
299299

300300
dc_publisher = property(
301-
_getter_bag(DC_NAMESPACE, "publisher", _converter_string)
301+
_getterBag(DC_NAMESPACE, "publisher", _converterString)
302302
)
303303
"""
304304
An unordered array of publisher names.
305305
"""
306306

307307
dc_relation = property(
308-
_getter_bag(DC_NAMESPACE, "relation", _converter_string)
308+
_getterBag(DC_NAMESPACE, "relation", _converterString)
309309
)
310310
"""
311311
An unordered array of text descriptions of relationships to other
312312
documents.
313313
"""
314314

315315
dc_rights = property(
316-
_getter_langalt(DC_NAMESPACE, "rights", _converter_string)
316+
_getterLangalt(DC_NAMESPACE, "rights", _converterString)
317317
)
318318
"""
319319
A language-keyed dictionary of textual descriptions of the rights the user
320320
has to this resource.
321321
"""
322322

323323
dc_source = property(
324-
_getter_single(DC_NAMESPACE, "source", _converter_string)
324+
_getterSingle(DC_NAMESPACE, "source", _converterString)
325325
)
326326
"""
327327
Unique identifier of the work from which this resource was derived.
328328
"""
329329

330330
dc_subject = property(
331-
_getter_bag(DC_NAMESPACE, "subject", _converter_string)
331+
_getterBag(DC_NAMESPACE, "subject", _converterString)
332332
)
333333
"""
334334
An unordered array of descriptive phrases or keywrods that specify the
335335
topic of the content of the resource.
336336
"""
337337

338338
dc_title = property(
339-
_getter_langalt(DC_NAMESPACE, "title", _converter_string)
339+
_getterLangalt(DC_NAMESPACE, "title", _converterString)
340340
)
341341
"""
342342
A language-keyed dictionary of the title of the resource.
343343
"""
344344

345-
dc_type = property(_getter_bag(DC_NAMESPACE, "type", _converter_string))
345+
dc_type = property(_getterBag(DC_NAMESPACE, "type", _converterString))
346346
"""
347347
An unordered array of textual descriptions of the document type.
348348
"""
349349

350350
pdf_keywords = property(
351-
_getter_single(PDF_NAMESPACE, "Keywords", _converter_string)
351+
_getterSingle(PDF_NAMESPACE, "Keywords", _converterString)
352352
)
353353
"""
354354
An unformatted text string representing document keywords.
355355
"""
356356

357357
pdf_pdfversion = property(
358-
_getter_single(PDF_NAMESPACE, "PDFVersion", _converter_string)
358+
_getterSingle(PDF_NAMESPACE, "PDFVersion", _converterString)
359359
)
360360
"""
361361
The PDF file version, for example ``1.0``, ``1.3``.
362362
"""
363363

364364
pdf_producer = property(
365-
_getter_single(PDF_NAMESPACE, "Producer", _converter_string)
365+
_getterSingle(PDF_NAMESPACE, "Producer", _converterString)
366366
)
367367
"""
368368
The name of the tool that created the PDF document.
369369
"""
370370

371371
xmp_createDate = property(
372-
_getter_single(XMP_NAMESPACE, "CreateDate", _converter_date)
372+
_getterSingle(XMP_NAMESPACE, "CreateDate", _converterDate)
373373
)
374374
"""
375375
The date and time the resource was originally created. The date and time
376376
are returned as a UTC ``datetime.datetime`` object.
377377
"""
378378

379379
xmp_modifyDate = property(
380-
_getter_single(XMP_NAMESPACE, "ModifyDate", _converter_date)
380+
_getterSingle(XMP_NAMESPACE, "ModifyDate", _converterDate)
381381
)
382382
"""
383383
The date and time the resource was last modified. The date and time are
384384
returned as a UTC ``datetime.datetime`` object.
385385
"""
386386

387387
xmp_metadataDate = property(
388-
_getter_single(XMP_NAMESPACE, "MetadataDate", _converter_date)
388+
_getterSingle(XMP_NAMESPACE, "MetadataDate", _converterDate)
389389
)
390390
"""
391391
The date and time that any metadata for this resource was last changed. The
392392
date and time are returned as a UTC ``datetime.datetime`` object.
393393
"""
394394

395395
xmp_creatorTool = property(
396-
_getter_single(XMP_NAMESPACE, "CreatorTool", _converter_string)
396+
_getterSingle(XMP_NAMESPACE, "CreatorTool", _converterString)
397397
)
398398
"""
399399
The name of the first known tool used to create the resource.
400400
"""
401401

402402
xmpmm_documentId = property(
403-
_getter_single(XMPMM_NAMESPACE, "DocumentID", _converter_string)
403+
_getterSingle(XMPMM_NAMESPACE, "DocumentID", _converterString)
404404
)
405405
"""
406406
The common identifier for all versions and renditions of this resource.
407407
"""
408408

409409
xmpmm_instanceId = property(
410-
_getter_single(XMPMM_NAMESPACE, "InstanceID", _converter_string)
410+
_getterSingle(XMPMM_NAMESPACE, "InstanceID", _converterString)
411411
)
412412
"""
413413
An identifier for a specific incarnation of a document, updated each time a

samplecode/basic_features.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,6 @@ def main():
100100

101101
print("Output successfully written to", output)
102102

103+
103104
if __name__ == "__main__":
104105
main()

0 commit comments

Comments
 (0)