Parsing error for ConfigParser

A

Andrew Z.

Is there a way to parse RealPlayer's realplayerrc in Python? I need
to support Python 2.5 - 2.7

Example code

import urllib2
import ConfigParser
f = urllib2.urlopen('http://pastebin.com/download.php?i=N1AcUg3w')
config = ConfigParser.RawConfigParser()
config.readfp(f)


Error
Traceback (most recent call last):
File "test_config_parser_real_player.py", line 6, in <module>
config.readfp(f)
File "/usr/lib/python2.6/ConfigParser.py", line 305, in readfp
self._read(fp, filename)
File "/usr/lib/python2.6/ConfigParser.py", line 510, in _read
raise e
ConfigParser.ParsingError: File contains parsing errors: <???>
[line 31]: '%0aCopyright (c) 1995-2000 Macromedia, Inc. All
rights reserved.\r\n'
[line 34]: '%0a\r\n'
 
P

Philip Semanchuk

Is there a way to parse RealPlayer's realplayerrc in Python? I need
to support Python 2.5 - 2.7

Example code

import urllib2
import ConfigParser
f = urllib2.urlopen('http://pastebin.com/download.php?i=N1AcUg3w')
config = ConfigParser.RawConfigParser()
config.readfp(f)


Error
Traceback (most recent call last):
File "test_config_parser_real_player.py", line 6, in <module>
config.readfp(f)
File "/usr/lib/python2.6/ConfigParser.py", line 305, in readfp
self._read(fp, filename)
File "/usr/lib/python2.6/ConfigParser.py", line 510, in _read
raise e
ConfigParser.ParsingError: File contains parsing errors: <???>
[line 31]: '%0aCopyright (c) 1995-2000 Macromedia, Inc. All
rights reserved.\r\n'
[line 34]: '%0a\r\n'

Hi Andrew,
Hopefully someone familiar with the topic of RealPlayer file formats will step in, but while you're waiting here's my $.02.

Looks like this is an INI file, and since there's no defined standard for INI files, it's hard for anyone to write a parser that is guaranteed to work with all INI files.

In this particular case you've got a multiline entry in the INI file which apparently ConfigParser doesn't like. One approach would be to subclass ConfigParser and massage the lines it doesn't like into something ConfigParser finds more palatable. Or if you're not interested in those lines, parse the error message, delete the offending lines and re-run the INI file through ConfigParser.

Good luck
Philip
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top