Skip to content

Add Python 3 port (unwrap_py3.py)#3

Open
DenisStark77 wants to merge 1 commit into
DarkAngelStrike:masterfrom
DenisStark77:python3-port
Open

Add Python 3 port (unwrap_py3.py)#3
DenisStark77 wants to merge 1 commit into
DarkAngelStrike:masterfrom
DenisStark77:python3-port

Conversation

@DenisStark77

Copy link
Copy Markdown

Summary

Adds a Python 3 port of the unwrapper as a sibling file (unwrap_py3.py); leaves the original unwrap.py in place for Python 2 users.

Why

The original unwrap.py is Python 2 only:

  • print decode_base64_package(...) — Py2 statement form
  • base64.decodestring — removed in Py3
  • chr(charmap[ord(byte)]) — relies on Py2's "string = bytes" semantics

On Python 3 it fails at parse time with SyntaxError. The port preserves the original algorithm (and the embedded charmap[] substitution table — copied verbatim) but uses the Py3-native APIs:

  • print(...) function form
  • base64.b64decode + an explicit bytes(charmap[b] for b in base64dec) construction
  • explicit file encodings: latin-1 input, utf-8 decoded output
  • preserves the original loop semantics — len(base64str) < base64len includes embedded newlines, which are stripped just before decoding — so the parser recognizes the same wrapped-block layout the original handles

Testing

Smoke-tested against ~460 real Oracle PL/SQL wrapped package bodies (Way4 / OpenWay distribution) on Python 3.9:

  • 459 / 459 packages decoded cleanly
  • ~900,000 lines of readable PL/SQL output
  • no decode errors, no parser hangs

What this PR does not do

  • Doesn't remove unwrap.py — keeps both files so existing Py2 invocations still work.
  • Doesn't refactor or otherwise modify the original algorithm; the charmap[] table is byte-for-byte identical.
  • Doesn't add tests, packaging, or CI — minimal-surface contribution.

If you'd prefer the port to replace unwrap.py rather than coexist, happy to push that as a follow-up commit.

unwrap.py targets Python 2: print statement, base64.decodestring,
chr() returning bytes. This commit adds a sibling unwrap_py3.py that
preserves the original algorithm (including the embedded charmap[]
substitution table) but is compatible with Python 3:

- print(...) function-call form
- base64.b64decode + explicit bytes() construction over the charmap
- file opens with explicit encoding (latin-1 input, utf-8 output)
- preserves the original loop's "len(base64str) < base64len includes
  embedded newlines, strip newlines before decode" semantics so the
  parser still recognizes the same wrapped blocks.

unwrap.py is left in place for legacy Python 2 users; the README now
documents both invocations.

Smoke-tested against ~460 real Way4 (OpenWay) wrapped Oracle PL/SQL
package bodies on Python 3.9 — 459/459 packages decoded cleanly, ~900k
total lines of readable output, no decode errors.
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.

1 participant