From 64d20c8955a8b5ff98c7cd8cc642cf124d9b7b73 Mon Sep 17 00:00:00 2001 From: thedark10rd Date: Tue, 7 Mar 2017 05:44:26 +0530 Subject: [PATCH] encoding done --- pattern/vector/__init__.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pattern/vector/__init__.py b/pattern/vector/__init__.py index adb602db..5f0dc987 100644 --- a/pattern/vector/__init__.py +++ b/pattern/vector/__init__.py @@ -102,6 +102,16 @@ def decode_string(v, encoding="utf-8"): return unicode(v) +def encode_string(v, encoding="utf-8"): + encoding = ((encoding,),) + (("windows-1252",), ("utf-8", "ignore"),("utf-16",)) + for e in encoding: + try: + return v.encode(*e) + except: + pass + return v +''' + def encode_string(v, encoding="utf-8"): """Returns the given value as a Python byte string (if possible).""" if isinstance(encoding, basestring): @@ -114,7 +124,7 @@ def encode_string(v, encoding="utf-8"): pass return v return str(v) - +''' decode_utf8 = decode_string encode_utf8 = encode_string