470,849 Members | 1,014 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,849 developers. It's quick & easy.

ConfigObj quoting issues

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[i].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
Jun 27 '08 #1
1 901
On 14:25, martedì 03 giugno 2008 Roopesh wrote:
This error is because of the presence of \', \", \n etc.

I had to do the following to make it work.
address[i].replace("\'",'').replace('\"','').replace('\n','' )
it's rather ugly :)
I suggest use re module as follow:

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

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

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

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 quitethe
same

--
Mailsweeper Home : http://it.geocities.com/call_me_not_now/index.html
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Fuzzyman | last post: by
22 posts views Thread by Jane Withnolastname | last post: by
27 posts views Thread by Ron Adam | last post: by
1 post views Thread by Bruce | last post: by
7 posts views Thread by Steven W. Orr | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.