Skip to content
Myr

Move the code to encode the request data into a static helper method - I think this makes the code clearer, but it also prepares the way for reusing the encoding code

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Richard Boulton · committed by Richard Boulton · parent 4320f81 · Browse files · 1 file+23 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+23 added−10 removed

  • other:+23 added−10 removed

1 file+23 added−10 removed

modified:requests/models.py+23 added-10 removed
50 unmodified lines
51 self.redirect = redirect52 #: Set to True if full redirects are allowed (e.g. re-POST-ing of data at new ``Location``)53 self.allow_redirects = allow_redirects5455 if hasattr(data, 'items'):56 for (k, v) in data.items():57 self.data.update({58 k.encode('utf-8') if isinstance(k, unicode) else k:59 v.encode('utf-8') if isinstance(v, unicode) else v60 })61 self._enc_data = urllib.urlencode(self.data)62 else:63 self._enc_data = self.data = data6455 self.data, self._enc_data = self._encode_params(data)56 #: :class:`Response <models.Response>` instance, containing57 #: content and metadata of HTTP Response, once :attr:`sent <send>`.58 self.response = Response()59
135 unmodified lines
195 self.response = r196197198 @staticmethod199 def _encode_params(data):200 """Encode parameters in a piece of data.201202 If the data supplied is a dictionary, encodes each parameter in it, and203 returns the dictionary of encoded parameters, and a urlencoded version204 of that.205206 Otherwise, assumes the data is already encoded appropriately, and207 returns it twice.208209 """210 if hasattr(data, 'items'):211 result = {}212 for (k, v) in data.items():213 result[k.encode('utf-8') if isinstance(k, unicode) else k] \214 = v.encode('utf-8') if isinstance(v, unicode) else v215 return result, urllib.urlencode(result)216 else:217 return data, data218219220 @staticmethod221 def _build_url(url, data=None):222 """Build URLs."""223224 if urlparse(url).query:
298 unmodified lines