Commits

Peter Sanchez committed a8a97ae

Updated restlib/filters.py for proper base64 encoding. Updated restlib/restlib.py to apply filters before altering request data

  • Participants
  • Parent commits bc1d46c
  • Branches trunk

Comments (0)

Files changed (2)

webutils/restlib/filters.py

         self.credentials = (username, password)
 
     def pre_request(self, client):
-        encode = base64.encodestring("%s:%s" % self.credentials)
+        encode = base64.b64encode('%s:%s' % self.credentials)
         client.headers.update({'Authorization': 'Basic %s' %  encode})
 
 
     def post_request(self, client):
         rdata = client.response.response_data
         client.response.parsed_data = \
-                    self.parser.parse(rdata) if rdata else None
+                    self.parser.parse(rdata) if rdata else None

webutils/restlib/restlib.py

                      request=None, headers={}, opts={}, check_func=None):
         ''' Construct and send request to remote host.
         '''
-        if isinstance(request, dict):
-            request = urllib.urlencode(encode_dict(request))
         self.request = request
+
+        # Apply any filters before request
+        self.filters.apply(self)
+
+        if isinstance(self.request, dict):
+            self.request = urllib.urlencode(encode_dict(self.request))
         
         if isinstance(headers, dict):
             self.headers.update(headers)
         )
         conn = conn_cls(self.host, self.port, timeout=self.timeout)
 
-        # Apply any filters before request
-        self.filters.apply(self)
-
         if self.debug:
             print 'DEBUG (method): ', method
             print 'DEBUG (path): ', path
             path=path,
             request=request,
             **kwargs
-        )
+        )