Skip to content

Commit

Permalink
Add to_bytes methods
Browse files Browse the repository at this point in the history
  • Loading branch information
lepture committed Dec 20, 2013
1 parent 0b587a2 commit c31ff03
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions flask_oauthlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ def extract_params():
return uri, http_method, body, headers


def decode_base64(text):
"""Decode base64 string."""
# make sure it is bytes
def to_bytes(text, encoding='utf-8'):
"""Make sure text is bytes type."""
if not isinstance(text, bytes_type):
text = text.encode('utf-8')
return to_unicode(base64.b64decode(text), 'utf-8')
text = text.encode(encoding)
return text


def decode_base64(text, encoding='utf-8'):
"""Decode base64 string."""
text = to_bytes(text, encoding)
return to_unicode(base64.b64decode(text), encoding)


def create_response(headers, body, status):
Expand Down

0 comments on commit c31ff03

Please sign in to comment.