Skip to content

Commit

Permalink
Merge pull request #27 from plone/maurits-replace-cgi-fieldstorage
Browse files Browse the repository at this point in the history
Replace deprecated cgi.FieldStorage class with a simple one.
  • Loading branch information
mauritsvanrees authored Dec 7, 2023
2 parents fa22765 + 4cb94be commit 683649e
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 18 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ indent_size = 2
[*.{json,jsonl,js,jsx,ts,tsx,css,less,scss,html}] # Frontend development
# 2 space indentation
indent_size = 2
max_line_length = 80

[{Makefile,.gitmodules}]
# Tab indentation (no size specified, but view as 4 spaces)
Expand Down
42 changes: 41 additions & 1 deletion .github/workflows/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ on:
- main
workflow_dispatch:

##
# To set environment variables for all jobs, add in .meta.toml:
# [github]
# env = """
# debug: 1
# image-name: 'org/image'
# image-tag: 'latest'
# """
##

jobs:
qa:
uses: plone/meta/.github/workflows/qa.yml@main
Expand All @@ -22,7 +32,37 @@ jobs:
uses: plone/meta/.github/workflows/coverage.yml@main
dependencies:
uses: plone/meta/.github/workflows/dependencies.yml@main
release-ready:
release_ready:
uses: plone/meta/.github/workflows/release_ready.yml@main
circular:
uses: plone/meta/.github/workflows/circular.yml@main

##
# To modify the list of default jobs being created add in .meta.toml:
# [github]
# jobs = [
# "qa",
# "test",
# "coverage",
# "dependencies",
# "release_ready",
# "circular",
# ]
##

##
# To request that some OS level dependencies get installed
# when running tests/coverage jobs, add in .meta.toml:
# [github]
# os_dependencies = "git libxml2 libxslt"
##


##
# Specify additional jobs in .meta.toml:
# [github]
# extra_lines = """
# another:
# uses: org/repo/.github/workflows/file.yml@main
# """
##
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
*.pyc
*.pyo

# translation related
*.mo

# tools related
build/
.coverage
.*project
coverage.xml
dist/
docs/_build
Expand Down
3 changes: 2 additions & 1 deletion .meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# See the inline comments on how to expand/tweak this configuration file
[meta]
template = "default"
commit-id = "cfffba8c"
commit-id = "8c30aa23"

[pyproject]
check_manifest_ignores = """
"*.cfg",
"""
codespell_ignores = "fo,"
dependencies_ignores = "['five.pt']"
24 changes: 17 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:

repos:
- repo: https://github.com/asottile/pyupgrade
rev: v3.4.0
rev: v3.15.0
hooks:
- id: pyupgrade
args: [--py38-plus]
Expand All @@ -16,11 +16,11 @@ repos:
hooks:
- id: isort
- repo: https://github.com/psf/black
rev: 23.3.0
rev: 23.10.1
hooks:
- id: black
- repo: https://github.com/collective/zpretty
rev: 3.1.0a2
rev: 3.1.0
hooks:
- id: zpretty

Expand All @@ -32,7 +32,7 @@ repos:
# """
##
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8

Expand All @@ -44,7 +44,7 @@ repos:
# """
##
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies:
Expand All @@ -66,15 +66,25 @@ repos:
hooks:
- id: pyroma
- repo: https://github.com/mgedmin/check-python-versions
rev: "0.21.2"
rev: "0.22.0"
hooks:
- id: check-python-versions
args: ['--only', 'setup.py,pyproject.toml']
- repo: https://github.com/collective/i18ndude
rev: "6.0.0"
rev: "6.1.0"
hooks:
- id: i18ndude


##
# Add extra configuration options in .meta.toml:
# [pre_commit]
# i18ndude_extra_lines = """
# _your own configuration lines_
# """
##


##
# Add extra configuration options in .meta.toml:
# [pre_commit]
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ There are a few other reasons why you may want to use the wrapper view, even
in later versions of Zope:

* To support both an earlier version of Zope and Zope 2.12+
* To re-use the same form in multiple views or viewlets
* To reuse the same form in multiple views or viewlets
* To use the ``IPageTemplate`` adapter lookup semantics from z3c.form to
provide a different default or override template for the overall page
layout, while retaining (or indeed customising independently) the default
Expand Down
3 changes: 3 additions & 0 deletions news/1.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Replace deprecated ``cgi.FieldStorage`` class with a simple one.
This is only used for converting a ``ZPublisher`` ``FileUpload`` to a ``zope.publisher`` one.
[maurits]
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Generated from:
# https://github.com/plone/meta/tree/master/config/default
# See the inline comments on how to expand/tweak this configuration file
[build-system]
requires = ["setuptools>=68.2"]

[tool.towncrier]
directory = "news/"
filename = "CHANGES.rst"
Expand Down Expand Up @@ -116,6 +119,7 @@ Zope = [
'Products.CMFCore', 'Products.CMFDynamicViewFTI',
]
python-dateutil = ['dateutil']
ignore-packages = ['five.pt']

##
# Add extra configuration options in .meta.toml:
Expand All @@ -125,7 +129,6 @@ python-dateutil = ['dateutil']
# "gitpython = ['git']",
# "pygithub = ['github']",
# ]
# """
##

[tool.check-manifest]
Expand Down
19 changes: 14 additions & 5 deletions src/plone/z3cform/converter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import cgi
import z3c.form.converter
import z3c.form.interfaces
import zope.publisher.browser
import ZPublisher.HTTPRequest


class _SimpleFieldStorage:
"""Replacement for cgi.FieldStorage.
The cgi module is deprecated and will be removed in Python 3.13.
This simple class implements only what is needed for the converter below.
"""

def __init__(self, value):
self.file = value
self.headers = value.headers
self.filename = value.filename


class FileUploadDataConverter(z3c.form.converter.FileUploadDataConverter):
"""Although ZPublisher's and zope.publisher's FileUpload
implementations are almost identical, ``FileUploadDataConverter``
Expand All @@ -18,10 +30,7 @@ class FileUploadDataConverter(z3c.form.converter.FileUploadDataConverter):
def toFieldValue(self, value):
"""See interfaces.IDataConverter"""
if isinstance(value, ZPublisher.HTTPRequest.FileUpload):
fieldstorage = cgi.FieldStorage()
fieldstorage.file = value
fieldstorage.headers = value.headers
fieldstorage.filename = value.filename
fieldstorage = _SimpleFieldStorage(value)
value = zope.publisher.browser.FileUpload(fieldstorage)

return super().toFieldValue(value)
31 changes: 29 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ commands =
echo "Unrecognized environment name {envname}"
false

##
# Add extra configuration options in .meta.toml:
# [tox]
# testenv_options = """
# basepython = /usr/bin/python3.8
# """
##

[testenv:init]
description = Prepare environment
skip_install = true
commands =
echo "Initial setup complete"


[testenv:format]
description = automatically reformat code
skip_install = true
Expand All @@ -58,7 +73,7 @@ deps =
build
z3c.dependencychecker==2.11
commands =
python -m build --sdist --no-isolation
python -m build --sdist
dependencychecker

[testenv:dependencies-graph]
Expand Down Expand Up @@ -86,11 +101,20 @@ set_env =
# test_environment_variables = """
# PIP_EXTRA_INDEX_URL=https://my-pypi.my-server.com/
# """
#
# Set constrain_package_deps .meta.toml:
# [tox]
# constrain_package_deps = "false"
##
deps =
zope.testrunner
-c https://dist.plone.org/release/6.0-dev/constraints.txt

##
# Specify additional deps in .meta.toml:
# [tox]
# test_deps_additional = "-esources/plonegovbr.portal_base[test]"
#
# Specify a custom constraints file in .meta.toml:
# [tox]
# constraints_file = "https://my-server.com/constraints.txt"
Expand Down Expand Up @@ -128,6 +152,7 @@ deps =
coverage
zope.testrunner
-c https://dist.plone.org/release/6.0-dev/constraints.txt

commands =
coverage run --branch --source plone.z3cform {envbindir}/zope-testrunner --quiet --all --test-path={toxinidir}/src -s plone.z3cform {posargs}
coverage report -m --format markdown
Expand All @@ -144,12 +169,13 @@ deps =
build
towncrier
-c https://dist.plone.org/release/6.0-dev/constraints.txt

commands =
# fake version to not have to install the package
# we build the change log as news entries might break
# the README that is displayed on PyPI
towncrier build --version=100.0.0 --yes
python -m build --sdist --no-isolation
python -m build --sdist
twine check dist/*

[testenv:circular]
Expand All @@ -171,6 +197,7 @@ deps =
pipdeptree
pipforester
-c https://dist.plone.org/release/6.0-dev/constraints.txt

commands =
# Generate the full dependency tree
sh -c 'pipdeptree -j > forest.json'
Expand Down

0 comments on commit 683649e

Please sign in to comment.