Sign In/My Account | View Cart  
advertisement

Article:
 Just Use Media Types?
Subject: Quoting issues
Date: 2006-05-12 17:33:48
From: OReillyAnon

> We can decompose a media-type into its component parts using Python code like this:


> (mime_type, parameter) = media_type.split(";"); (type, subtype) = mime_type.split("/")


No, you can't. Parameters may include quoted strings as values, and quoted strings may include separators such as ';', ',', and '/', as well as backslash-escaped characters including escaped quotes "\"".


Previous Message Previous Message   Next Message No Next Message


Titles Only Titles Only Newest First
  • Quoting issues
    2006-11-01 23:07:55 Popopo [Reply]

    Personally, I can see the appeal in deliberately failing to parse those requests properly, just to discourage it. I'm for standards as much as the next guy, but if the difference between 99% and 100% compliance is five hours work and a parsing routine that's an order of magnitude more complex, well...


    It's like those people who produce hideous but technically well-formed RFC2822 addresses and expect the rest of us to deal with them. It's the sort of idiocy that leads to the "short" email-matching regular expression in Friedl's book needing 4724 characters, and even then it doesn't cover every case.

  • Quoting issues
    2006-06-08 02:49:41 hamish_lawson [Reply]

    Use the csv module to do the splitting - it takes care of quoting.


Sponsored By: