ConfigObj quoting issues

R

Roopesh

Hi,

I am using ConfigObj to write email addresses, as a list. I am using
email module functions to extract email addresses:

to_address = header.get_all('To', [])
address_list = getaddresses(to_address)
to = map(lambda address: '"'+address[0]+'"
<'+address[1]+'>' ,address_list)
conf_obj['to'] = to

But quite often I am getting the error "cannot be safely quoted.".
This error is because of the presence of \', \", \n etc.

I had to do the following to make it work.
address.replace("\'",'').replace('\"','').replace('\n','')

[making list_all=False doesn't work properly(it fails when the first
character is a double quote). ]

I don't want to do the above, as it modifies the email address (name).
In brief, my question is how to save a list of strings which might
have quotes, double quotes to a file using ConfigObj.

Any idea what is to be done.

Thanks
Roopesh
 
T

TheSaint

This error is because of the presence of \', \", \n etc.

I had to do the following to make it work.
address.replace("\'",'').replace('\"','').replace('\n','')

it's rather ugly :)
I suggest use re module as follow:

import re
address = re.sub('(`|"|\n)',re.MULTILINE,address)

if you've a big chunck of email it'd be fine to compile the regex.

match = re.compile(`|"|\n)
address = match.sub(address)

I think there would be a problem with unicode email addresses. But I doubt
the existance of unicode addresses nowadays.
Unsure for the syntax, pls check
http://www.python.org/doc/2.4/lib/re-syntax.html
^^^ according your version, but they're quite the
same
 

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,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top