Skip to content

Commit

Permalink
Merge 9fc22fb into d0ad06e
Browse files Browse the repository at this point in the history
  • Loading branch information
mindflayer committed Jun 15, 2019
2 parents d0ad06e + 9fc22fb commit 8c2250a
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 118 deletions.
14 changes: 8 additions & 6 deletions mocket/compat.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import codecs
import os
import sys
import shlex
import sys

import six

encoding = os.getenv("MOCKET_ENCODING", 'utf-8')
encoding = os.getenv("MOCKET_ENCODING", "utf-8")

text_type = six.text_type
byte_type = six.binary_type
Expand All @@ -28,6 +29,7 @@ def unquote_utf8(qs):
else:
from http.server import BaseHTTPRequestHandler
from urllib.parse import urlsplit, parse_qs, unquote as unquote_utf8

FileNotFoundError = FileNotFoundError

try:
Expand All @@ -36,15 +38,15 @@ def unquote_utf8(qs):
JSONDecodeError = ValueError


def encode_to_bytes(s, charset=encoding):
def encode_to_bytes(s, encoding=encoding):
if isinstance(s, text_type):
s = s.encode(charset)
s = s.encode(encoding)
return byte_type(s)


def decode_from_bytes(s, charset=encoding):
def decode_from_bytes(s, encoding=encoding):
if isinstance(s, byte_type):
s = s.decode(charset)
s = codecs.decode(s, encoding=encoding, errors="ignore")
return text_type(s)


Expand Down

0 comments on commit 8c2250a

Please sign in to comment.