Skip to content

Protect cgi#176

Merged
Cito merged 1 commit into
formencode:mainfrom
sqlobject:remove-cgi-py313
Nov 10, 2023
Merged

Protect cgi#176
Cito merged 1 commit into
formencode:mainfrom
sqlobject:remove-cgi-py313

Conversation

@phdru

@phdru phdru commented Nov 16, 2022

Copy link
Copy Markdown
Contributor

Protect classes that requires cgi module

Only define FieldStorageUploadConverter and FileUploadKeeper if cgi module exist. It was declared obsolete in Python 3.11 and will be removed in 3.13.

@Cito Cito left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I made some suggestions.

Comment thread src/formencode/validators.py Outdated
Comment thread src/formencode/validators.py Outdated
Comment thread src/formencode/validators.py Outdated
Comment thread src/formencode/validators.py Outdated
Comment thread src/formencode/validators.py Outdated
Module `cgi` was declared obsolete in Python 3.11
and will be removed in 3.13.

Fixes: #175.
@Cito
Cito merged commit 43edbb5 into formencode:main Nov 10, 2023
lambacck added a commit that referenced this pull request Jan 31, 2025
In Python 3.13 and later the cgi module has been removed and this meant
that importing the `cgi` module started making it so
`formencode.validators` could not be imported. This was resolved in #176
by detecting the import error, setting `cgi` to `None`, and then
skipping behaviour that used `cgi.FieldStorage`. Using
`FieldStorageUploadConverter` without `cgi.FieldStorage` does not make
sense. This change adds a check to
`FieldStorageUploadConverter.__classinit__` to prevent instantiating it
like we do for DNS validators so that using it doesn't silently do
nothing.

Probably if you are using FieldStorageUploadConverter then you'll have
`legacy-cgi` installed because you are either already using it directly,
or you are getting it transitively through something like WebOb.
lambacck added a commit that referenced this pull request Jan 31, 2025
In Python 3.13 and later the cgi module has been removed and this meant
that importing the `cgi` module started making it so
`formencode.validators` could not be imported. This was resolved in #176
by detecting the import error, setting `cgi` to `None`, and then
skipping behaviour that used `cgi.FieldStorage`. Using
`FieldStorageUploadConverter` without `cgi.FieldStorage` does not make
sense. This change adds a check to
`FieldStorageUploadConverter.__classinit__` to prevent instantiating it
like we do for DNS validators so that using it doesn't silently do
nothing.

Probably if you are using FieldStorageUploadConverter then you'll have
`legacy-cgi` installed because you are either already using it directly,
or you are getting it transitively through something like WebOb.
lambacck added a commit that referenced this pull request Jan 31, 2025
In Python 3.13 and later the cgi module has been removed and this meant
that importing the `cgi` module started making it so
`formencode.validators` could not be imported. This was resolved in #176
by detecting the import error, setting `cgi` to `None`, and then
skipping behaviour that used `cgi.FieldStorage`. Using
`FieldStorageUploadConverter` without `cgi.FieldStorage` does not make
sense. This change adds a check to
`FieldStorageUploadConverter.__init_` to prevent instantiating it
like we do for DNS validators so that using it doesn't silently do
nothing.

Probably if you are using FieldStorageUploadConverter then you'll have
`legacy-cgi` installed because you are either already using it directly,
or you are getting it transitively through something like WebOb.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants