[yum-commits] urlgrabber/grabber.py

skvidal at osuosl.org skvidal at osuosl.org
Thu Aug 13 15:44:40 UTC 2009


 urlgrabber/grabber.py |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

New commits:
commit cb29da0d279384ba1cdf0de54227e0e9e55253e8
Author: Seth Vidal <skvidal at fedoraproject.org>
Date:   Thu Aug 13 11:41:39 2009 -0400

    add _to_utf8() method to pycurlfileobject
    make sure postfield data is to_utf8'd before setting the option
    otherwise pycurl is unhappy if the postfield data is a unicode object
    instead of a string object.
    closes rh bug https://bugzilla.redhat.com/show_bug.cgi?id=515797

diff --git a/urlgrabber/grabber.py b/urlgrabber/grabber.py
index 471f0ec..062dae2 100644
--- a/urlgrabber/grabber.py
+++ b/urlgrabber/grabber.py
@@ -1621,7 +1621,7 @@ class PyCurlFileObject():
         #posts - simple - expects the fields as they are
         if opts.data:
             self.curl_obj.setopt(pycurl.POST, True)
-            self.curl_obj.setopt(pycurl.POSTFIELDS, opts.data)
+            self.curl_obj.setopt(pycurl.POSTFIELDS, self._to_utf8(opts.data))
             
         # our url
         self.curl_obj.setopt(pycurl.URL, self.url)
@@ -1887,7 +1887,13 @@ class PyCurlFileObject():
                 downloaded += self._reget_length
                 self.opts.progress_obj.update(downloaded)
 
-
+    def _to_utf8(self, obj, errors='replace'):
+        '''convert 'unicode' to an encoded utf-8 byte string '''
+        # stolen from yum.i18n
+        if isinstance(obj, unicode):
+            obj = obj.encode('utf-8', errors)
+        return obj
+        
     def read(self, amt=None):
         self._fill_buffer(amt)
         if amt is None:


More information about the Yum-commits mailing list