Regex'ing null bytes

Discussion in 'Python' started by Jonas Galvez, Apr 21, 2004.

  1. Jonas Galvez

    Jonas Galvez Guest

    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
    Jonas Galvez, Apr 21, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    26,617
    Mike Schilling
    Mar 29, 2006
  2. Dan Stromberg

    html parsing? Or just simple regex'ing?

    Dan Stromberg, Nov 10, 2004, in forum: Python
    Replies:
    7
    Views:
    382
    Michael J. Fromberger
    Nov 16, 2004
  3. Replies:
    3
    Views:
    754
    Reedick, Andrew
    Jul 1, 2008
  4. Rahul
    Replies:
    0
    Views:
    662
    Rahul
    Mar 17, 2010
  5. Sanjay  Dahiya
    Replies:
    4
    Views:
    301
    Sanjay Dahiya
    Apr 10, 2005
Loading...

Share This Page