By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,767 Members | 1,310 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,767 IT Pros & Developers. It's quick & easy.

Regex'ing null bytes

P: n/a
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

Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.