Skip to content

Commit

Permalink
Patch PyPDF2
Browse files Browse the repository at this point in the history
PyPDF2 overwrites `warning.showwarning` and this is already confirmed as a major flaw: py-pdf/pypdf#67 (comment)

But, this is never applied in PyPDF2.

To fix this issue in ERP5, we will copy the patch to our stack and apply it.

See merge request !746
  • Loading branch information
Gabriel Monnerat committed May 12, 2020
2 parents 9db68bf + 787bc9f commit 1e81c41
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
@@ -0,0 +1,63 @@
From f8ef2a193edf565d61aa628232f0e46e55a6aa6f Mon Sep 17 00:00:00 2001
From: Pavel Brych <pavel@brych.cz>
Date: Thu, 3 Sep 2015 08:04:53 +0200
Subject: [PATCH] Custom implementation of warnings.formatwarning removed

---
PyPDF2/pdf.py | 15 ++-------------
PyPDF2/utils.py | 6 ------
2 files changed, 2 insertions(+), 19 deletions(-)

diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py
index f54680a..3554f40 100644
--- a/PyPDF2/pdf.py
+++ b/PyPDF2/pdf.py
@@ -63,7 +63,7 @@ import warnings
import codecs
from .generic import *
from .utils import readNonWhitespace, readUntilWhitespace, ConvertFunctionsToVirtualList
-from .utils import isString, b_, u_, ord_, chr_, str_, formatWarning
+from .utils import isString, b_, u_, ord_, chr_, str_

if version_info < ( 2, 4 ):
from sets import ImmutableSet as frozenset
@@ -1039,18 +1039,7 @@ class PdfFileReader(object):
``warnings.py`` module with a custom implementation (defaults to
``True``).
"""
- def __init__(self, stream, strict=True, warndest = None, overwriteWarnings = True):
- if overwriteWarnings:
- # have to dynamically override the default showwarning since there are no
- # public methods that specify the 'file' parameter
- def _showwarning(message, category, filename, lineno, file=warndest, line=None):
- if file is None:
- file = sys.stderr
- try:
- file.write(formatWarning(message, category, filename, lineno, line))
- except IOError:
- pass
- warnings.showwarning = _showwarning
+ def __init__(self, stream, strict=True):
self.strict = strict
self.flattenedPages = None
self.resolvedObjects = {}
diff --git a/PyPDF2/utils.py b/PyPDF2/utils.py
index 718a875..7bcb9ce 100644
--- a/PyPDF2/utils.py
+++ b/PyPDF2/utils.py
@@ -64,12 +64,6 @@ def isBytes(b):
return isinstance(b, bytes_type)


-#custom implementation of warnings.formatwarning
-def formatWarning(message, category, filename, lineno, line=None):
- file = filename.replace("/", "\\").rsplit("\\", 1)[1] # find the file name
- return "%s: %s [%s:%s]\n" % (category.__name__, message, file, lineno)
-
-
def readUntilWhitespace(stream, maxchars=None):
"""
Reads non-whitespace characters and returns them.
--
2.23.0

9 changes: 8 additions & 1 deletion software/slapos-sr-testing/software.cfg
Expand Up @@ -198,6 +198,11 @@ scripts =
interpreter=
python_for_test

# patches for eggs
patch-binary = ${patch:location}/bin/patch
PyPDF2-patches = ${:_profile_base_location_}/../../component/egg-patch/PyPDF2/0001-Custom-implementation-of-warnings.formatwarning-remo.patch#d25bb0f5dde7f3337a0a50c2f986f5c8
PyPDF2-patch-options = -p1

[git-clone-repository]
recipe = slapos.recipe.build:gitclone
git-executable = ${git:location}/bin/git
Expand Down Expand Up @@ -265,6 +270,9 @@ requests-toolbelt = 0.8.0
selenium = 3.141.0
slapos.recipe.template = 4.4

# Patched eggs
PyPDF2 = 1.26.0+SlapOSPatched001

# modern versions for SSL fixed support
requests = 2.20.0
certifi = 2018.10.15
Expand All @@ -291,7 +299,6 @@ backports.lzma = 0.0.13
mock = 2.0.0
testfixtures = 6.11
funcsigs = 1.0.2
PyPDF2 = 1.26.0
mysqlclient = 1.3.12
pexpect = 4.8.0
ptyprocess = 0.6.0
6 changes: 4 additions & 2 deletions stack/erp5/buildout.cfg
Expand Up @@ -410,7 +410,7 @@ eggs = ${neoppod:eggs}
paramiko
ply
pyflakes
pypdf2
PyPDF2
python-magic
python-memcached
pytz
Expand Down Expand Up @@ -528,6 +528,8 @@ extra-paths =

# patches for eggs
patch-binary = ${patch:location}/bin/patch
PyPDF2-patches = ${:_profile_base_location_}/../../component/egg-patch/PyPDF2/0001-Custom-implementation-of-warnings.formatwarning-remo.patch#d25bb0f5dde7f3337a0a50c2f986f5c8
PyPDF2-patch-options = -p1
Acquisition-patches = ${:_profile_base_location_}/../../component/egg-patch/Acquisition/aq_dynamic.patch#1d9a56e9af4371f5b6951ebf217a15d7
Acquisition-patch-options = -p1
Products.DCWorkflow-patches = ${:_profile_base_location_}/../../component/egg-patch/Products.DCWorkflow/workflow_method.patch#975b49e96bae33ac8563454fe5fa9899
Expand Down Expand Up @@ -576,6 +578,7 @@ ocropy = 1.0+SlapOSPatched001
pysvn = 1.7.10+SlapOSPatched002
python-ldap = 2.4.32+SlapOSPatched001
python-magic = 0.4.12+SlapOSPatched001
PyPDF2 = 1.26.0+SlapOSPatched001
## https://lab.nexedi.com/nexedi/slapos/merge_requests/648
pylint = 1.4.4

Expand Down Expand Up @@ -623,7 +626,6 @@ Products.MimetypesRegistry = 2.0.10
Products.PluginRegistry = 1.4
Products.TIDStorage = 5.5.0
pyPdf = 1.13
PyPDF2 = 1.26.0
PyStemmer = 1.3.0
PyXML = 0.8.5
Pympler = 0.4.3
Expand Down

0 comments on commit 1e81c41

Please sign in to comment.