Re: Regex'ing null bytes

From: Jonas Galvez (jonas_at_jonasgalvez.com)
Date: 04/21/04


Date: Wed, 21 Apr 2004 01:12:12 -0300
To: python-list@python.org

Nevermind, I decided to not use regexes at all.

Jonas

"Jonas Galvez" <jonas@jonasgalvez.com> escreveu na mensagem news:c64nve$kut$1@sea.gmane.org...
> Hi,
>
> I'm trying to parse some binary data with regexes. It works well in
> the latest Python build, but I need to run this on Python 1.5.2. The
> binary data has a pattern like this:
>
> keyName1\002..(.*)\000.*keyName2\002..(.*)\000
> (I'm using regex syntax to illustrate)
>
> So I wrote the following script:
>
> def amfKey(str):
> return "%s\002..([^\000]*)" % str
>
> keys = re.compile(amfKey("key"), re.DOTALL).findall(amfStr)
>
> Works on 2.3.3, but produces the following error on 1.5.2:
>
> Traceback (innermost last):
> File "test.py", line 26, in ?
> keys = re.compile(amfKey("key"), re.DOTALL).findall(amfStr)
> File "C:\Python152\Lib\re.py", line 79, in compile
> code=pcre_compile(pattern, flags, groupindex)
> TypeError: argument 1: expected string without null bytes, string found
>
> Does anyone know a workaround? The type of binary data I'm trying to
> parse is AMF (Action Message Format), Macromedia's proprietary format
> for fast communication between the Flash Player and their "Flash
> Remoting" servers (ColdFusion/.NET/Java implementations). But there
> are opensource "Flash Remoting" implementations in PHP (amfphp.org),
> Perl (simonf.com/flap/) and Java (openamf.org) already - I've
> started to work on the Python port.
>
> And I wanted to keep this Python 1.5.2-compatible...
>
>
>
> Thanks in advance,
>
>
> =-
> Jonas Galvez
> jonasgalvez.com/blog
> macromedia.com/go/team



Relevant Pages

  • Regexing null bytes
    ... I'm trying to parse some binary data with regexes. ... the latest Python build, but I need to run this on Python 1.5.2. ... for fast communication between the Flash Player and their "Flash ...
    (comp.lang.python)
  • Character set woes with binary data
    ... I am attempting to piece together a Python client for Fotobilder, ... The protocol calls for binary data to be transmitted, ... together to transmit them. ...
    (comp.lang.python)
  • Re: ANN: New 6502 cross-compiler designed for the Apple II
    ... unpack the SPL compiler. ... Now I want to create a new SPL program to run on the Apple II.  I open ... Assuming that Python is installed (almost always true with any ... Now, we don't have to output only binary data, instead we can create a ...
    (comp.sys.apple2)
  • Re: ANN: New 6502 cross-compiler designed for the Apple II
    ... language called "Python", that outputs 6502 assembler, and that output ... disk image file in any Apple II emulator and run the file there. ... Now, we don't have to output only binary data, instead we can create a ...
    (comp.sys.apple2)
  • Re: ANN: New 6502 cross-compiler designed for the Apple II
    ... language called "Python", that outputs 6502 assembler, and that output ... disk image file in any Apple II emulator and run the file there. ... The second is the binary data generated ...
    (comp.sys.apple2)