Skip to content

Python3 compatibility - #10

Open
rsaccani wants to merge 5 commits into
decalage2:masterfrom
rsaccani:python3-compatibility
Open

Python3 compatibility#10
rsaccani wants to merge 5 commits into
decalage2:masterfrom
rsaccani:python3-compatibility

Conversation

@rsaccani

Copy link
Copy Markdown

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

  • print statements → print() calls
  • raise X, msgraise X(msg)
  • except X, eexcept X as e
  • Octal literals: 07550o755
  • Long integer literals: 0xFFFFFFFFL0xFFFFFFFL

Standard library renames

  • ConfigParserconfigparser
  • StringIOio / io.BytesIO
  • Queuequeue
  • urlparseurllib.parse
  • HTMLParser / htmlentitydefshtml.parser / html.entities
  • string.joinstr.join

bytes vs str

  • Binary file parsing updated throughout to use bytes literals (b"...")
  • debut.startswith(...) and debut.find(...) calls use bytes arguments
  • Socket send/recv in pyclamd encoded/decoded at the boundary
  • base64 module replaces .decode('base64') string method

Imports

  • Implicit relative imports in the Filtres/ package replaced with
    explicit from . import Filtre syntax (required by Python 3)
  • from HTML import *from .HTML import *

Key modules

  • OleFileIO_PL: StringIOio.BytesIO, i16/i32 via
    struct.unpack_from, __cmp____lt__, has_keyin
  • pdfid_PL: binary read loop, b"" EOF check, bytes writes
  • path.py: basestringstr, fileopen, octal literals
  • 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 statement
    syntax, 3-argument raise replaced

Testing

Tested with python3 ExeFilter.py -b demo_files/:

File Result
Word 2003 normal.doc Allowed and clean
Word 2003 VBA macro.doc Contains active content that can be cleaned
Word 2003 OLE Package EXE.doc Cannot be analyzed or cleaned
PDF Launch calc.pdf Contains active content that can be cleaned
RTF OLE Package EXE.rtf Contains active content that can be cleaned
GIF Picture.gif Allowed and clean
Zipped JPEG and EXE.zip Contains active content that can be cleaned
HTML normal.html Allowed and clean
*.exe File extension not allowed

Notes

  • xfweb.py / CherryProxy depends on rfc822 and socket._fileobject
    which were removed in Python 3. The HTTP proxy mode is not functional
    in Python 3; the core file scanner (ExeFilter.py) is fully working.
  • Files retain their original iso-8859-1 encoding declaration.

Rodolfo Saccani and others added 5 commits October 26, 2017 10:54
…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>
@decalage2
decalage2 self-requested a review June 12, 2026 20:32
@decalage2 decalage2 self-assigned this Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants