Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
107
Merge Requests
107
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
slapos
Commits
d881c7e8
Commit
d881c7e8
authored
Mar 03, 2022
by
Arnaud Fontaine
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Zope 4.x: Fix OFS.Image PUT() for Python 2 (upstream patch for #1015, #1016).
parent
8cd7a917
Pipeline
#19974
failed with stage
in 0 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
26 deletions
+99
-26
component/egg-patch/Zope/0001-Fix-PUT-for-Python-2-1015.patch
...onent/egg-patch/Zope/0001-Fix-PUT-for-Python-2-1015.patch
+0
-25
component/egg-patch/Zope/0001-fix-OFS.Image.File.PUT-Issue-1015.patch
...g-patch/Zope/0001-fix-OFS.Image.File.PUT-Issue-1015.patch
+98
-0
stack/erp5/buildout.cfg
stack/erp5/buildout.cfg
+1
-1
No files found.
component/egg-patch/Zope/0001-Fix-PUT-for-Python-2-1015.patch
deleted
100644 → 0
View file @
8cd7a917
From 9a603533bacd9311ee634d8509c090037112b637 Mon Sep 17 00:00:00 2001
From: Arnaud Fontaine <arnaud.fontaine@nexedi.com>
Date: Fri, 25 Feb 2022 14:46:34 +0100
Subject: [PATCH] Fix PUT() for Python 2 (#1015).
---
src/OFS/Image.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/OFS/Image.py b/src/OFS/Image.py
index d81d2a0fa..c33ef68a5 100644
--- a/src/OFS/Image.py
+++ b/src/OFS/Image.py
@@ -661,7 +661,7 @@
class File(
file = REQUEST['BODYFILE']
data, size = self._read_data(file)
- if isinstance(data, str):
+ if isinstance(data, text_type):
data = data.encode('UTF-8')
content_type = self._get_content_type(file, data, self.__name__,
type or self.content_type)
--
2.35.1
component/egg-patch/Zope/0001-fix-OFS.Image.File.PUT-Issue-1015.patch
0 → 100644
View file @
d881c7e8
From d3885eadb919abfcc86a82431deb9b9916127602 Mon Sep 17 00:00:00 2001
From: dieter <dieter@handshake.de>
Date: Wed, 2 Mar 2022 08:31:58 +0100
Subject: [PATCH] fix `OFS.Image.File.PUT` -- Issue 1015
work around `cgi` bug
make `flake8` happy
---
src/OFS/Image.py | 47 ++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 44 insertions(+), 3 deletions(-)
diff --git a/src/OFS/Image.py b/src/OFS/Image.py
index c7b012a5e..fde006deb 100644
--- a/src/OFS/Image.py
+++ b/src/OFS/Image.py
@@ -16,6 +16,8 @@
import struct
from email.generator import _make_boundary
from io import BytesIO
+from io import TextIOBase
+from tempfile import TemporaryFile
from warnings import warn
from six import PY2
@@ -568,6 +570,16 @@
class File(
self, REQUEST, manage_tabs_message=msg)
def _get_content_type(self, file, body, id, content_type=None):
+ """return content type or ``None``.
+
+ *file* usually is a ``FileUpload`` (like) instance; if this
+ specifies a content type, it is used. If *file*
+ is not ``FileUpload`` like, it is ignored and the
+ content type is guessed from the other parameters.
+
+ *body* is either a ``bytes`` or a ``Pdata`` instance
+ and assumed to be the *file* data.
+ """
headers = getattr(file, 'headers', None)
if headers and 'content-type' in headers:
content_type = headers['content-type']
@@ -579,6 +591,13 @@
class File(
return content_type
def _read_data(self, file):
+ """return the data and size of *file* as tuple *data*, *size*.
+
+ *file* can be a ``bytes``, ``Pdata``, ``FileUpload`` or
+ (binary) file like instance.
+
+ For large files, *data* is a ``Pdata``, otherwise a ``bytes`` instance.
+ """
import transaction
n = 1 << 16
@@ -656,13 +675,35 @@
class File(
"""Handle HTTP PUT requests"""
self.dav__init(REQUEST, RESPONSE)
self.dav__simpleifhandler(REQUEST, RESPONSE, refresh=1)
- type = REQUEST.get_header('content-type', None)
+ type = REQUEST.get_header('content-type', None)
file = REQUEST['BODYFILE']
+ # Work around ``cgi`` bug
+ # ``cgi`` can turn the request body into a text file using
+ # the default encoding. ``File``, however, insists to work
+ # with bytes and binary files and forbids text.
+ # Convert back.
+ tfile = None
+ if isinstance(file, TextIOBase): # ``cgi`` bug
+ if hasattr(file, "buffer"):
+ file = file.buffer # underlying binary buffer
+ else:
+ from ZPublisher.HTTPRequest import default_encoding
+ tfile = TemporaryFile("wb+")
+ bufsize = 1 << 16
+ while True:
+ data = file.read(bufsize)
+ if not data:
+ break
+ tfile.write(data.encode(default_encoding))
+ file.seek(0, 0)
+ tfile.seek(0, 0)
+ file = tfile
+
data, size = self._read_data(file)
- if isinstance(data, str):
- data = data.encode('UTF-8')
+ if tfile is not None:
+ tfile.close()
content_type = self._get_content_type(file, data, self.__name__,
type or self.content_type)
self.update_data(data, content_type, size)
--
2.35.1
stack/erp5/buildout.cfg
View file @
d881c7e8
...
...
@@ -617,7 +617,7 @@ python-magic-patch-options = -p1
# Zope 4 patches
Zope-patches =
${:_profile_base_location_}/../../component/egg-patch/Zope/0001-OFS-XMLExportImport.patch#12a9b9db76b3cd9035b6032d516143e0
${:_profile_base_location_}/../../component/egg-patch/Zope/0001-
Fix-PUT-for-Python-2-1015.patch#e81c46a1de8916b05abc653209722c0b
${:_profile_base_location_}/../../component/egg-patch/Zope/0001-
fix-OFS.Image.File.PUT-Issue-1015.patch#c706e2f572ad8cd37ed033fb5f873cbe
Zope-patch-options = -p1
[eggs-all-scripts]
...
...
Jérome Perrin
@jerome
mentioned in merge request
erp5!1545 (merged)
·
Apr 11, 2022
mentioned in merge request
erp5!1545 (merged)
mentioned in merge request erp5!1545
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment