Skip to content

Commit 67b4ea3

Browse files
committed
Remove py2
1 parent 86b51ad commit 67b4ea3

2 files changed

Lines changed: 19 additions & 32 deletions

File tree

resources/lib/api.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,8 @@
2121
import random
2222
import xbmc
2323

24-
# avoid using named attributes since they were introduced with python 2.7 only
25-
PY3 = sys.version_info[0] >= 3
26-
27-
if PY3:
28-
from urllib.parse import urlencode
29-
from urllib.request import urlopen, Request, HTTPError, URLError
30-
else:
31-
from urllib import urlencode
32-
from urllib2 import urlopen, Request, HTTPError, URLError
24+
from urllib.parse import urlencode
25+
from urllib.request import urlopen, Request, HTTPError, URLError
3326

3427

3528
class RadioApiError(Exception):
@@ -369,9 +362,7 @@ def __check_redirect(stream_url):
369362

370363
@staticmethod
371364
def __versioned_string(string):
372-
if PY3:
373-
return bytearray(string, 'utf-8')
374-
return string
365+
return bytearray(string, 'utf-8')
375366

376367
@staticmethod
377368
def log(text):

resources/lib/plugin.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818
#
1919
from xbmcswift2 import Plugin, xbmc, listitem
20-
from resources.lib.api import RadioApi, RadioApiError, PY3
20+
from resources.lib.api import RadioApi, RadioApiError
2121

2222
STRINGS = {
2323
'editorials_recommendations': 30100,
@@ -178,7 +178,7 @@ def custom_my_station(station_id):
178178
heading = _('please_enter') % _(param)
179179
station[param] = plugin.keyboard(station.get(param, ''), heading) or ''
180180
station_name = station.get('name', 'custom')
181-
station_id = station_name if PY3 else station_name.decode('ascii', 'ignore').encode('ascii')
181+
station_id = station_name
182182
station['id'] = station_id
183183
station['is_custom'] = '1'
184184
if station_id:
@@ -207,13 +207,13 @@ def show_genres():
207207
items = []
208208
for genre in genres:
209209
items.append({
210-
'label': __encode(genre["systemEnglish"]),
210+
'label': genre["systemEnglish"],
211211
'icon': plugin.icon,
212212
'fanart': __get_plugin_fanart(),
213213
'path': plugin.url_for(
214214
'show_popular_and_az',
215215
category='genres',
216-
value=__encode(genre["systemEnglish"])
216+
value=genre["systemEnglish"]
217217
),
218218
})
219219
finish_kwargs = {
@@ -229,13 +229,13 @@ def show_topics():
229229
items = []
230230
for topic in topics:
231231
items.append({
232-
'label': __encode(topic["systemEnglish"]),
232+
'label': topic["systemEnglish"],
233233
'icon': plugin.icon,
234234
'fanart': __get_plugin_fanart(),
235235
'path': plugin.url_for(
236236
'show_popular_and_az',
237237
category='topics',
238-
value=__encode(topic["systemEnglish"])
238+
value=topic["systemEnglish"]
239239
),
240240
})
241241
finish_kwargs = {
@@ -251,13 +251,13 @@ def show_countries():
251251
items = []
252252
for country in countries:
253253
items.append({
254-
'label': __encode(country["systemEnglish"]),
254+
'label': country["systemEnglish"],
255255
'icon': plugin.icon,
256256
'fanart': __get_plugin_fanart(),
257257
'path': plugin.url_for(
258258
'show_popular_and_az',
259259
category='countries',
260-
value=__encode(country["systemEnglish"])
260+
value=country["systemEnglish"]
261261
),
262262
})
263263
finish_kwargs = {
@@ -273,13 +273,13 @@ def show_languages():
273273
items = []
274274
for lang in languages:
275275
items.append({
276-
'label': __encode(lang["systemEnglish"]),
276+
'label': lang["systemEnglish"],
277277
'icon': plugin.icon,
278278
'fanart': __get_plugin_fanart(),
279279
'path': plugin.url_for(
280280
'show_popular_and_az',
281281
category='languages',
282-
value=__encode(lang["systemEnglish"])
282+
value=lang["systemEnglish"]
283283
),
284284
})
285285
finish_kwargs = {
@@ -317,25 +317,25 @@ def show_cities_list(option):
317317
countries = radio_api.get_countries()
318318
for country in countries:
319319
items.append({
320-
'label': __encode(country["systemEnglish"]),
320+
'label': country["systemEnglish"],
321321
'icon': plugin.icon,
322322
'fanart': __get_plugin_fanart(),
323323
'path': plugin.url_for(
324324
'show_cities_by_country',
325-
country = __encode(country["systemEnglish"]),
325+
country = country["systemEnglish"],
326326
),
327327
})
328328
else:
329329
cities = radio_api.get_cities()
330330
for city in cities:
331331
items.append({
332-
'label': __encode(city["systemEnglish"]),
332+
'label': city["systemEnglish"],
333333
'icon': plugin.icon,
334334
'fanart': __get_plugin_fanart(),
335335
'path': plugin.url_for(
336336
'show_popular_and_az',
337337
category = 'cities',
338-
value = __encode(city["systemEnglish"]),
338+
value = city["systemEnglish"],
339339
),
340340
})
341341
finish_kwargs = {
@@ -351,13 +351,13 @@ def show_cities_by_country(country):
351351
cities = radio_api.get_cities(country=country)
352352
for city in cities:
353353
items.append({
354-
'label': __encode(city["systemEnglish"]),
354+
'label': city["systemEnglish"],
355355
'icon': plugin.icon,
356356
'fanart': __get_plugin_fanart(),
357357
'path': plugin.url_for(
358358
'show_popular_and_az',
359359
category = 'cities',
360-
value = __encode(city["systemEnglish"]),
360+
value = city["systemEnglish"],
361361
)
362362
})
363363
finish_kwargs = {
@@ -593,10 +593,6 @@ def __log(text):
593593
def __get_plugin_fanart():
594594
return plugin.fanart if not plugin.get_setting('hide-fanart', bool) else ''
595595

596-
def __encode(string):
597-
if PY3:
598-
return string
599-
return string.encode('utf-8')
600596

601597
def _(string_id):
602598
if string_id in STRINGS:

0 commit comments

Comments
 (0)