Skip to content

Commit

Permalink
Se integra compatibilidad con Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdzul committed Apr 28, 2015
1 parent e00ca09 commit 51b034f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pyql/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@
"""
__author__ = 'Alex Dzul'
import json
import six
import sys
from pyql.settings import YAHOO_URL
from pyql.errors import YQLRequestError, format_sys_errors


if six.PY2:
# Obtenemos la versió de Python que estamos ejecutando
MY_PY2 = sys.version_info[0] == 2
MY_PY3 = sys.version_info[0] == 3
# Importamos la librería que utilizaremos dependiendo de la versión Python.
if MY_PY2:
from urllib2 import urlopen
if six.PY3:
if MY_PY3:
import codecs
from urllib.request import urlopen
from pyql.settings import YAHOO_URL
from pyql.errors import YQLRequestError, format_sys_errors


class YQLConector():
Expand All @@ -31,7 +35,11 @@ def request(self, my_query, format_response="json"):
url = self.yql_to_url(my_query, format_response)
try:
if format_response == "json":
obj = json.load(urlopen(url))
if MY_PY2:
obj = json.load(urlopen(url))
if MY_PY3:
reader = codecs.getreader("utf-8")
obj = json.load(reader(urlopen(url)))
if format_response == "xml":
obj = urlopen(url).read()
return obj
Expand Down

0 comments on commit 51b034f

Please sign in to comment.