Skip to content

Commit

Permalink
Removed encode_params from PR, as discussed in #269
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Mar 19, 2018
1 parent 04372d4 commit f1c20d4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 37 deletions.
10 changes: 5 additions & 5 deletions fbchat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
32 changes: 0 additions & 32 deletions fbchat/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 comments on commit f1c20d4

@gave92
Copy link
Contributor

@gave92 gave92 commented on f1c20d4 Mar 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hei I believe you forgot to change True to 'true' in markAsRead :)

@madsmtm
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, can't believe I forgot that... I'll fix it right away!

Please sign in to comment.