By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

ConfigObj quoting issues

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.