Re: replacing \n characters in a hash
(since this is a newsgroup, can you please quote the message you're replying to). Johhny wrote: > In response to that the output is this : > > '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.' means that it *is* a string, after all. looks like you didn't post the code you were using :-( replacing the print statement with errata_package = errata_package.replace("\n", " ") should do what you want. -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Hello All, thanks for your help. I got it working and learnt some more things which is always great. Your assitance has been very useful. Regards, Johhny -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Hello, In response to that the output is this : '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.' -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Johhny wrote: > Hello, > > Here is the code (minus my details section). > > server = xmlrpclib.ServerProxy(url) > > session = server.auth.login(username,password) > > #functions. > > def getErrata(): > > channel_label = 'rhel-i386-as-4' > > errata = > server.channel.software.list_errata(session,channel_label,start_date,end_date) > > return errata > > > > def getPackage(advisory): > > Package = server.errata.get_details(session,advisory) > > return Package > > > > errata = getErrata() > > for vals in errata: > > print "%s\t\t%s\t\t%s\t%s\t%s" % > (vals['errata_advisory'],vals['errata_issue_date'],vals['errata_update_date'],vals['errata_last_modified_date'],vals['errata_type'],) > > errata_info = getPackage(vals['errata_advisory'],) > > print errata_info['errata_topic'] > > errata_package = errata_info['errata_topic'] errata_package = errata_info['errata_topic'].replace('\n', " ") > > print getPackage(vals['errata_advisory']) > > I have not got any of the section in to replace the \n's as I was > trying to work out why its not seeing what I thought was a string as a > dict. > regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Johhny wrote: > for vals in errata: > > print "%s\t\t%s\t\t%s\t%s\t%s" % > (vals['errata_advisory'],vals['errata_issue_date'],vals['errata_update_date'],vals['errata_last_modified_date'],vals['errata_type'], ) > > errata_info = getPackage(vals['errata_advisory'],) > > print errata_info['errata_topic'] > > errata_package = errata_info['errata_topic'] add print type(errata_package), repr(errata_package) here, and let us know what it prints. > print getPackage(vals['errata_advisory']) -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Hello, Here is the code (minus my details section). server = xmlrpclib.ServerProxy(url) session = server.auth.login(username,password) #functions. def getErrata(): channel_label = 'rhel-i386-as-4' errata = server.channel.software.list_errata(session,channel_label,start_date,end_date) return errata def getPackage(advisory): Package = server.errata.get_details(session,advisory) return Package errata = getErrata() for vals in errata: print "%s\t\t%s\t\t%s\t%s\t%s" % (vals['errata_advisory'],vals['errata_issue_date'],vals['errata_update_date'],vals['errata_last_modified_date'],vals['errata_type'],) errata_info = getPackage(vals['errata_advisory'],) print errata_info['errata_topic'] errata_package = errata_info['errata_topic'] print getPackage(vals['errata_advisory']) I have not got any of the section in to replace the \n's as I was trying to work out why its not seeing what I thought was a string as a dict. -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
On Thu, 2006-01-26 at 09:49, Johhny wrote: > Hello, > > Thankyou for your response, > If I check that the errara_package value is with a print I get the > following. > > ===SNIP=== > Updated libc-client packages that fix a buffer overflow issue are now > available. > > This update has been rated as having moderate security impact by the > Red > Hat Security Response Team. > ===SNIP=== > > Notice that it has formatted the output with the \n's. > > So i dont understand why its reporting as a dictionary rather than just > the string. Posting relevant bits of your code might help. -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
Hello, Thankyou for your response, If I check that the errara_package value is with a print I get the following. ===SNIP=== Updated libc-client packages that fix a buffer overflow issue are now available. This update has been rated as having moderate security impact by the Red Hat Security Response Team. ===SNIP=== Notice that it has formatted the output with the \n's. So i dont understand why its reporting as a dictionary rather than just the string. -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing \n characters in a hash
On Thu, 2006-01-26 at 09:24, 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.', > > [...] > > 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. errata_package is obviously not just the errata_topic hash value, because that would be a string, and python for some reason seems to believe that errata_package is a dictionary. Also note that once you correct that problem, python will complain that strip() doesn't take 2 parameters, since you actually mean replace(). -Carsten -- http://mail.python.org/mailman/listinfo/python-list
replacing \n characters in a hash
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 -- http://mail.python.org/mailman/listinfo/python-list