replacing \n characters in a hash
Larry Bates
larry.bates at websafe.com
Thu Jan 26 10:18:43 EST 2006
Johhny wrote:
> Hello,
>
> I am currently trying to write some scripts to get information from the
> xmlrpc for redhat network. One of the issues I am having is trying to
> strip off the special characters in the hash that is returned. Here is
> an example of the information returned within the hash :
>
> ===SNIP===
> {'errata_update_date': '2005-12-06', 'errata_topic': 'Updated
> libc-client packages that fix a buffer overflow issue are
> now\navailable.\n\nThis update has been rated as having moderate
> security impact by the Red\nHat Security Response Team.',
> 'errata_type': 'Security Advisory', 'errata_notes': '',
> 'errata_synopsis': 'Moderate: libc-client security update',
> 'errata_references': '', 'errata_last_modified_date': '2006-01-25
> 10:37:24', 'errata_issue_date': '2005-12-06', 'errata_description':
> 'C-client is a common API for accessing mailboxes.\n\nA buffer overflow
> flaw was discovered in the way C-client parses user\nsupplied
> mailboxes. If an authenticated user requests a specially
> crafted\nmailbox name, it may be possible to execute arbitrary code on
> a server that\nuses C-client to access mailboxes. The Common
> Vulnerabilities and Exposures\nproject has assigned the name
> CVE-2005-2933 to this issue.\n\nAll users of libc-client should upgrade
> to these updated packages, which\ncontain a backported patch that
> resolves this issue.'}
> ===SNIP===
>
>
> What I would like to do is remove the \n characters from
> 'errata_topic'. Which is this section of the hash.
>
> Updated libc-client packages that fix a buffer overflow issue are
> now\navailable.\n\nThis update has been rated as having moderate
> security impact by the Red\nHat Security Response Team.
>
> What I had attempted to do is use the replace() function but it
> consistantly comes up with the following errors:
>
> Traceback (most recent call last):
> File "rhn_errata.py", line 63, in ?
> errata_package = errata_package.strip('\n','')
> AttributeError: 'dict' object has no attribute 'strip'
>
> where errata_package is JUST the errata_topic hash value.
>
> Any advice would be great on how to do that.
>
> Regards,
>
> Johhny
>
You must use 'errata_topic' as index into your dictionary
to get the string and then replace the \n chars.
Example assumes that the dict is pointed to by d):
errata_topic_text=d['errata_topic'].replace('\n',' ')
Hope this helps.
Larry Bates
More information about the Python-list
mailing list