Skip to content

Commit

Permalink
Merge pull request #6 from cornershop/develop
Browse files Browse the repository at this point in the history
fix(api_auth.signature): always use en_US locale
  • Loading branch information
genaromadrid committed Nov 7, 2018
2 parents dab23d9 + 93e71eb commit 677aff3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: python

python:
- 3.3
- 3.4
- 3.5
- 3.6

install:
- pip install -r requirements.txt
Expand Down
16 changes: 16 additions & 0 deletions mifiel/api_auth/context_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import locale
import threading

from contextlib import contextmanager

LOCALE_LOCK = threading.Lock()


@contextmanager
def setlocale(name):
with LOCALE_LOCK:
saved = locale.setlocale(locale.LC_ALL)
try:
yield locale.setlocale(locale.LC_ALL, name)
finally:
locale.setlocale(locale.LC_ALL, saved)
6 changes: 5 additions & 1 deletion mifiel/api_auth/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import base64
import hashlib
import datetime

from mifiel.api_auth.context_manager import setlocale

try:
from urllib.parse import urlparse
except:
Expand Down Expand Up @@ -36,7 +39,8 @@ def build(self, method, url, body, content_md5=None, content_type=None, httpdate
self.httpdate = httpdate
if not self.httpdate:
now = datetime.datetime.utcnow()
self.httpdate = now.strftime('%a, %d %b %Y %H:%M:%S GMT')
with setlocale('en_US.UTF-8'):
self.httpdate = now.strftime('%a, %d %b %Y %H:%M:%S GMT')

url = urlparse(url)
path = url.path
Expand Down

0 comments on commit 677aff3

Please sign in to comment.