From f1c20d490ec07292db16c74a3a46b20b41b40b2f Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Mon, 19 Mar 2018 21:15:23 +0100 Subject: [PATCH] Removed `encode_params` from PR, as discussed in #269 --- fbchat/client.py | 10 +++++----- fbchat/utils.py | 32 -------------------------------- 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/fbchat/client.py b/fbchat/client.py index 46f50f54..045cd0d0 100644 --- a/fbchat/client.py +++ b/fbchat/client.py @@ -107,7 +107,7 @@ def _fix_fb_errors(self, error_code): def _get(self, url, query=None, timeout=30, fix_request=False, as_json=False, error_retries=3): payload = self._generatePayload(query) - r = self._session.get(url, headers=self._header, params=encode_params(payload), timeout=timeout, verify=self.ssl_verify) + r = self._session.get(url, headers=self._header, params=payload, timeout=timeout, verify=self.ssl_verify) if not fix_request: return r try: @@ -119,7 +119,7 @@ def _get(self, url, query=None, timeout=30, fix_request=False, as_json=False, er def _post(self, url, query=None, timeout=30, fix_request=False, as_json=False, error_retries=3): payload = self._generatePayload(query) - r = self._session.post(url, headers=self._header, data=encode_params(payload), timeout=timeout, verify=self.ssl_verify) + r = self._session.post(url, headers=self._header, data=payload, timeout=timeout, verify=self.ssl_verify) if not fix_request: return r try: @@ -139,17 +139,17 @@ def _graphql(self, payload, error_retries=3): raise e def _cleanGet(self, url, query=None, timeout=30): - return self._session.get(url, headers=self._header, params=encode_params(query), timeout=timeout, verify=self.ssl_verify) + return self._session.get(url, headers=self._header, params=query, timeout=timeout, verify=self.ssl_verify) def _cleanPost(self, url, query=None, timeout=30): self.req_counter += 1 - return self._session.post(url, headers=self._header, data=encode_params(query), timeout=timeout, verify=self.ssl_verify) + return self._session.post(url, headers=self._header, data=query, timeout=timeout, verify=self.ssl_verify) def _postFile(self, url, files=None, query=None, timeout=30, fix_request=False, as_json=False, error_retries=3): payload=self._generatePayload(query) # Removes 'Content-Type' from the header headers = dict((i, self._header[i]) for i in self._header if i != 'Content-Type') - r = self._session.post(url, headers=headers, data=encode_params(payload), timeout=timeout, files=files, verify=self.ssl_verify) + r = self._session.post(url, headers=headers, data=payload, timeout=timeout, files=files, verify=self.ssl_verify) if not fix_request: return r try: diff --git a/fbchat/utils.py b/fbchat/utils.py index 6a9535fd..87eef262 100644 --- a/fbchat/utils.py +++ b/fbchat/utils.py @@ -233,35 +233,3 @@ def get_emojisize_from_tags(tags): except (KeyError, IndexError): log.exception('Could not determine emoji size from {} - {}'.format(tags, tmp)) return None - -def encode_params(data): - """Encode parameters in a piece of data. - - Will successfully encode parameters when passed as a dict or a list of - 2-tuples. Order is retained if data is a list of 2-tuples but arbitrary - if parameters are supplied as a dict. - """ - - if isinstance(data, (str, bytes)): - return data - elif hasattr(data, 'read'): - return data - elif hasattr(data, '__iter__'): - result = [] - for k, vs in list(data.items()): - if isinstance(vs, basestring) or not hasattr(vs, '__iter__'): - vs = [vs] - for v in vs: - if v is not None: - if isinstance(v, bool): - result.append( - (k.encode('utf-8') if isinstance(k, str) else k, - str(v).lower())) - else: - result.append( - (k.encode('utf-8') if isinstance(k, str) else k, - v.encode('utf-8') if isinstance(v, str) else v)) - return urlencode(result, doseq=True) - else: - return data -