-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
61 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
basicauth==0.4.1 | ||
beautifulsoup4==4.8.1 | ||
colorlog==4.0.2 | ||
email_validator==1.0.4 | ||
email_validator==1.0.5 | ||
html5lib==1.0.1 | ||
psycopg2-binary==2.8.3 | ||
psycopg2-binary==2.8.4 | ||
pyaml==19.4.1 | ||
ratelimit==2.2.1 | ||
six==1.12.0 | ||
sshtunnel==0.1.5 | ||
tabulator==1.27.0 | ||
tabulator==1.28.0 | ||
typing==3.7.4.1 | ||
yamlloader==0.5.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Encoding utilities""" | ||
|
||
import base64 | ||
|
||
|
||
def str_to_base64(string): | ||
# type: (str) -> str | ||
""" | ||
Base 64 encode string | ||
Args: | ||
string (str): String to encode | ||
Returns: | ||
str: Base 64 encoded string | ||
""" | ||
return base64.urlsafe_b64encode(string.encode('utf-8')).decode('utf-8') | ||
|
||
|
||
def base64_to_str(bstring): | ||
# type: (str) -> str | ||
""" | ||
Base 64 decode string | ||
Args: | ||
bstring (str): Base 64 encoded string to encode | ||
Returns: | ||
str: Decoded string | ||
""" | ||
return base64.urlsafe_b64decode(bstring.encode('utf-8')).decode('utf-8') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.8.5 | ||
1.8.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- coding: UTF-8 -*- | ||
"""Encoding Utility Tests""" | ||
from hdx.utilities.encoding import str_to_base64, base64_to_str | ||
|
||
|
||
class TestEncoding: | ||
def test_base64(self): | ||
string = 'hello' | ||
result = str_to_base64(string) | ||
assert result == 'aGVsbG8=' | ||
assert base64_to_str(result) == string |