summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2013-10-28 13:40:26 -0200
committerKali Kaneko <kali@leap.se>2013-10-30 16:00:32 -0200
commit6008c15b85f75e2ed0255bedc4e28bb25058ee13 (patch)
tree13082ca65bad7b031e64187fb3c746dbf248b2fe /client
parentd75de135b33186e91251ae7400891d4433a668c1 (diff)
use chardet as fallback
Diffstat (limited to 'client')
-rw-r--r--client/changes/feature-use-chardet-as-fallback1
-rw-r--r--client/src/leap/soledad/client/__init__.py13
2 files changed, 9 insertions, 5 deletions
diff --git a/client/changes/feature-use-chardet-as-fallback b/client/changes/feature-use-chardet-as-fallback
new file mode 100644
index 00000000..f96a959c
--- /dev/null
+++ b/client/changes/feature-use-chardet-as-fallback
@@ -0,0 +1 @@
+ o Use chardet as fallback if cchardet not found.
diff --git a/client/src/leap/soledad/client/__init__.py b/client/src/leap/soledad/client/__init__.py
index 13a3b68f..7c7e0468 100644
--- a/client/src/leap/soledad/client/__init__.py
+++ b/client/src/leap/soledad/client/__init__.py
@@ -32,10 +32,13 @@ import socket
import ssl
import urlparse
-import cchardet
-
from hashlib import sha256
+try:
+ import cchardet as chardet
+except ImportError:
+ import chardet
+
from u1db.remote import http_client
from u1db.remote.ssl_match_hostname import match_hostname
@@ -771,12 +774,11 @@ class Soledad(object):
:rtype: object
"""
-
if isinstance(content, unicode):
return content
elif isinstance(content, str):
try:
- result = cchardet.detect(content)
+ result = chardet.detect(content)
content = content.decode(result["encoding"]).encode("utf-8")\
.decode("utf-8")
except UnicodeError:
@@ -800,7 +802,8 @@ class Soledad(object):
:return: the new document
:rtype: SoledadDocument
"""
- return self._db.create_doc(self._convert_to_utf8(content), doc_id=doc_id)
+ return self._db.create_doc(
+ self._convert_to_utf8(content), doc_id=doc_id)
def create_doc_from_json(self, json, doc_id=None):
"""