Regex'ing null bytes

Jonas Galvez jonas at jonasgalvez.com
Wed Apr 21 00:12:12 EDT 2004


Nevermind, I decided to not use regexes at all.


Jonas


"Jonas Galvez" <jonas at jonasgalvez.com> escreveu na mensagem news:c64nve$kut$1 at 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







More information about the Python-list mailing list