Python3 compatibility - #10
Open
rsaccani wants to merge 5 commits into
Open
Conversation
…s extension are frequent" This reverts commit ea55f0c.
Full Python 2 → Python 3 migration. All core scanner functionality tested and working with Python 3.x (26 demo files analyzed correctly). Changes: - print statements → print() calls throughout - raise X, msg → raise X(msg) syntax - except X, e → except X as e syntax - import renames: ConfigParser→configparser, StringIO→io, Queue→queue, urlparse→urllib.parse, HTMLParser→html.parser, htmlentitydefs→html.entities - bytes vs str: binary file parsing updated to use bytes literals (b"..."), bytes comparisons, and proper encode/decode at boundaries - Implicit relative imports → explicit (from . import Filtre) in Filtres/ - OleFileIO_PL: StringIO→io.BytesIO, i16/i32 via struct.unpack_from, string.join→b"".join, L-suffix integers removed, __cmp__→__lt__ - pdfid_PL: binary read loop, EOF check with b"", bytes writes - pyclamd: base64 module usage, socket bytes encode/decode - path.py: octal literals 0755→0o755, basestring→str, file→open - plx.py: unistr/str_lat1 updated for Python 3 str/bytes model - RechercherRemplacer: str/bytes regex normalization in Motif.__init__ - cherrypy wsgiserver: queue, io, urllib.parse, exec syntax, 3-arg raise - HTML/__init__.py: relative import fix - HTMLParser_PL: Python 3 html.parser API Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Python 3 compatibility
Full port of ExeFilter from Python 2 to Python 3. All core scanner
functionality is working and tested against the included demo files
(26 files analyzed: 7 clean, 14 cleaned, 5 blocked, 0 errors).
Changes
Syntax
printstatements →print()callsraise X, msg→raise X(msg)except X, e→except X as e0755→0o7550xFFFFFFFFL→0xFFFFFFFLStandard library renames
ConfigParser→configparserStringIO→io/io.BytesIOQueue→queueurlparse→urllib.parseHTMLParser/htmlentitydefs→html.parser/html.entitiesstring.join→str.joinbytes vs str
b"...")debut.startswith(...)anddebut.find(...)calls use bytes argumentsbase64module replaces.decode('base64')string methodImports
Filtres/package replaced withexplicit
from . import Filtresyntax (required by Python 3)from HTML import *→from .HTML import *Key modules
OleFileIO_PL:StringIO→io.BytesIO,i16/i32viastruct.unpack_from,__cmp__→__lt__,has_key→inpdfid_PL: binary read loop,b""EOF check, bytes writespath.py:basestring→str,file→open, octal literalsplx.py:unistr/str_lat1updated for Python 3 str/bytes modelRechercherRemplacer: str/bytes regex normalization inMotif.__init__cherrypy wsgiserver:queue,io,urllib.parse,execstatementsyntax, 3-argument
raisereplacedTesting
Tested with
python3 ExeFilter.py -b demo_files/:Notes
xfweb.py/ CherryProxy depends onrfc822andsocket._fileobjectwhich were removed in Python 3. The HTTP proxy mode is not functional
in Python 3; the core file scanner (
ExeFilter.py) is fully working.iso-8859-1encoding declaration.