diff options
author | Tomás Touceda <chiiph@leap.se> | 2013-10-28 14:26:37 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2013-10-28 14:26:37 -0300 |
commit | f6873fa53593a5fa04e733fc8f4cfbeafc4fb1ee (patch) | |
tree | 0157266651959675d358cce75e0bfc083ea733fd /client/src/leap/soledad | |
parent | f50f192cd1cf6133084bafb9921ef20b48cbd37a (diff) | |
parent | 605d3ed81f8ad0d0c947916dcfdcc748c59b2373 (diff) |
Merge remote-tracking branch 'kali/feature/use-chardet-as-fallback' into develop
Diffstat (limited to 'client/src/leap/soledad')
-rw-r--r-- | client/src/leap/soledad/client/__init__.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/client/src/leap/soledad/client/__init__.py b/client/src/leap/soledad/client/__init__.py index e38aa939..2900c43f 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): """ |