summaryrefslogtreecommitdiffstats
path: root/pyload/utils/__init__.py
diff options
context:
space:
mode:
authorGravatar Walter Purcaro <vuolter@gmail.com> 2014-09-08 01:34:05 +0200
committerGravatar Walter Purcaro <vuolter@gmail.com> 2014-09-14 11:03:47 +0200
commit3d4f8e55ce4c87f3f3bb3ea49acb76ca607bfc8d (patch)
tree140b2f75e4e445c4aa899488439fa91e775a85d2 /pyload/utils/__init__.py
parentNew printer (windows compatible) (diff)
downloadpyload-3d4f8e55ce4c87f3f3bb3ea49acb76ca607bfc8d.tar.xz
JsEngine rewritten + utils updated
Diffstat (limited to 'pyload/utils/__init__.py')
-rw-r--r--pyload/utils/__init__.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/pyload/utils/__init__.py b/pyload/utils/__init__.py
index b9eb8c88e..a13aa75d5 100644
--- a/pyload/utils/__init__.py
+++ b/pyload/utils/__init__.py
@@ -10,6 +10,15 @@ from os.path import join
from string import maketrans
from htmlentitydefs import name2codepoint
+# abstraction layer for json operations
+try:
+ import simplejson as json
+except ImportError:
+ import json
+
+json_loads = json.loads
+json_dumps = json.dumps
+
def chmod(*args):
try:
@@ -19,10 +28,18 @@ def chmod(*args):
def decode(string):
- """ decode string with utf if possible """
- try:
+ """ Decode string to unicode with utf8 """
+ if type(string) == str:
return string.decode("utf8", "replace")
- except:
+ else:
+ return string
+
+
+def encode(string):
+ """ Decode string to utf8 """
+ if type(string) == unicode:
+ return string.encode("utf8", "replace")
+ else:
return string
@@ -145,10 +162,10 @@ def fs_bsize(path):
def uniqify(seq): #: Originally by Dave Kirby
- """ removes duplicates from list, preserve order """
- seen = set()
- seen_add = seen.add
- return [x for x in seq if x not in seen and not seen_add(x)]
+ """ Remove duplicates from list preserving order """
+ seen = set()
+ seen_add = seen.add
+ return [x for x in seq if x not in seen and not seen_add(x)]
def parseFileSize(string, unit=None): #returns bytes