alcuni fix py3

This commit is contained in:
marco
2020-02-06 17:40:57 +01:00
parent c262c9d528
commit 7f4844646e
4 changed files with 29 additions and 18 deletions
+17 -9
View File
@@ -11,7 +11,6 @@ try:
import json import json
except: except:
logger.info("json incluido en el interprete **NO** disponible") logger.info("json incluido en el interprete **NO** disponible")
try: try:
import simplejson as json import simplejson as json
except: except:
@@ -26,8 +25,13 @@ except:
logger.info("Usando simplejson en el directorio lib") logger.info("Usando simplejson en el directorio lib")
else: else:
logger.info("Usando simplejson incluido en el interprete") logger.info("Usando simplejson incluido en el interprete")
else: # ~ else:
logger.info("Usando json incluido en el interprete") # ~ logger.info("Usando json incluido en el interprete")
import sys
PY3 = False
if sys.version_info[0] >= 3: PY3 = True; unicode = str; unichr = chr; long = int
def load(*args, **kwargs): def load(*args, **kwargs):
@@ -46,12 +50,12 @@ def load(*args, **kwargs):
def dump(*args, **kwargs): def dump(*args, **kwargs):
if not kwargs: if not kwargs:
kwargs = {"indent": 4, "skipkeys": True, "sort_keys": True, "ensure_ascii": False} kwargs = {"indent": 4, "skipkeys": True, "sort_keys": True, "ensure_ascii": True}
try: try:
value = json.dumps(*args, **kwargs) value = json.dumps(*args, **kwargs)
except: except:
logger.error("**NO** se ha podido cargar el JSON") logger.error("**NO** se ha podido guardar el JSON")
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
value = "" value = ""
return value return value
@@ -59,11 +63,15 @@ def dump(*args, **kwargs):
def to_utf8(dct): def to_utf8(dct):
if isinstance(dct, dict): if isinstance(dct, dict):
return dict((to_utf8(key), to_utf8(value)) for key, value in dct.iteritems()) return dict((to_utf8(key), to_utf8(value)) for key, value in dct.items())
elif isinstance(dct, list): elif isinstance(dct, list):
return [to_utf8(element) for element in dct] return [to_utf8(element) for element in dct]
elif isinstance(dct, unicode): elif isinstance(dct, unicode):
return dct.encode('utf-8') dct = dct.encode("utf8")
if PY3: dct = dct.decode("utf8")
return dct
elif PY3 and isinstance(dct, bytes):
return dct.decode('utf-8')
else: else:
return dct return dct
@@ -104,7 +112,7 @@ def get_node_from_file(name_file, node, path=None):
if node in dict_data: if node in dict_data:
dict_node = dict_data[node] dict_node = dict_data[node]
#logger.debug("dict_node: %s" % dict_node) # logger.debug("dict_node: %s" % dict_node)
return dict_node return dict_node
@@ -189,4 +197,4 @@ def update_node(dict_node, name_file, node, path=None):
except: except:
logger.error("No se ha podido actualizar %s" % fname) logger.error("No se ha podido actualizar %s" % fname)
return result, json_data return result, json_data
+9 -5
View File
@@ -5,9 +5,11 @@ import base64
import inspect import inspect
import os import os
import re import re
import urllib try:
import urlparse import urllib.request as urllib
import xbmcaddon import urllib.parse as urlparse
except ImportError:
import urllib, urlparse
from channelselector import thumb from channelselector import thumb
from core import httptools, scrapertools, servertools, tmdb, channeltools from core import httptools, scrapertools, servertools, tmdb, channeltools
@@ -65,9 +67,11 @@ def hdpass_get_servers(item):
def url_decode(url_enc): def url_decode(url_enc):
from past.utils import old_div
lenght = len(url_enc) lenght = len(url_enc)
if lenght % 2 == 0: if lenght % 2 == 0:
len2 = lenght / 2 len2 = old_div(lenght, 2)
first = url_enc[0:len2] first = url_enc[0:len2]
last = url_enc[len2:lenght] last = url_enc[len2:lenght]
url_enc = last + first url_enc = last + first
@@ -78,7 +82,7 @@ def url_decode(url_enc):
url_enc[lenght - 1] = ' ' url_enc[lenght - 1] = ' '
url_enc = url_enc.strip() url_enc = url_enc.strip()
len1 = len(url_enc) len1 = len(url_enc)
len2 = len1 / 2 len2 = old_div(len1, 2)
first = url_enc[0:len2] first = url_enc[0:len2]
last = url_enc[len2:len1] last = url_enc[len2:len1]
url_enc = last + first url_enc = last + first
+1 -2
View File
@@ -9,7 +9,6 @@ has been tested with Python2.7 and Python 3.4.
from __future__ import print_function from __future__ import print_function
import argparse
import os import os
import stat import stat
import sys import sys
@@ -75,7 +74,7 @@ def blob_hash(stream, size):
while True: while True:
# We read just 64K at a time to be kind to # We read just 64K at a time to be kind to
# runtime storage requirements. # runtime storage requirements.
data = stream.read(65536) data = stream.read(65536).encode('ascii')
if data == b'': if data == b'':
break break
nread += len(data) nread += len(data)
+2 -2
View File
@@ -2,7 +2,7 @@
import io import io
import os import os
import shutil import shutil
from cStringIO import StringIO from lib.six import StringIO
from core import filetools from core import filetools
from platformcode import logger, platformtools from platformcode import logger, platformtools
@@ -426,4 +426,4 @@ def _pbhook(numblocks, blocksize, filesize, url, dp):
dp.update(percent) dp.update(percent)
except: except:
percent = 90 percent = 90
dp.update(percent) dp.update(percent)