Index: ahttp.py ================================================================== --- ahttp.py +++ ahttp.py @@ -2,38 +2,20 @@ # encoding: UTF-8 # api: streamtuner2 # type: functions # title: http download / methods # description: http utility -# version: 1.3 +# version: 1.4 # # Provides a http GET method with gtk.statusbar() callback. # And a function to add trailings slashes on http URLs. # -# The latter code is pretty much unreadable. But let's put the -# blame on urllib2, the most braindamaged code in the Python -# standard library. -# - - -# Python 2.x -try: - import urllib2 - from urllib import urlencode - import urlparse - import cookielib - from StringIO import StringIO -# Python 3.x -except: - import urllib.request as urllib2 - from urllib.parse import urlencode - import urllib.parse as urlparse - from http import cookiejar as cookielib - from io import StringIO - -from gzip import GzipFile - +# + + +from compat2and3 import urllib2, urlencode, urlparse, cookielib, StringIO, xrange +from gzip import GzipFile from config import conf, __print__, dbg #-- url download --------------------------------------------- Index: channels/_generic.py ================================================================== --- channels/_generic.py +++ channels/_generic.py @@ -181,11 +181,11 @@ # load data, # update treeview content def load(self, category, force=False): # get data from cache or download - if (force or not self.streams.has_key(category)): + if (force or not category in self.streams): new_streams = self.update_streams(category) if new_streams: # modify @@ -235,11 +235,11 @@ # finds differences in new/old streamlist, marks deleted with flag def deleted_streams(self, new, old): diff = [] new = [row.get("url","http://example.com/") for row in new] for row in old: - if (row.has_key("url") and (row.get("url") not in new)): + if (url in row and (row.get("url") not in new)): row["deleted"] = 1 diff.append(row) return diff Index: channels/links.py ================================================================== --- channels/links.py +++ channels/links.py @@ -56,23 +56,23 @@ bookmarks.streams[self.module] = [] bookmarks.add_category(self.module) # collect links from channel plugins - for name,channel in parent.channels.iteritems(): + for name,channel in parent.channels.items(): try: self.streams.append({ "favourite": 1, "title": channel.title, "homepage": channel.homepage, }) except: pass - for title,homepage in self.default.iteritems(): + for title,homepage in self.default.items(): self.streams.append({ "title": title, "homepage": homepage, }) # add to bookmarks bookmarks.streams[self.module] = self.streams Index: channels/myoggradio.py ================================================================== --- channels/myoggradio.py +++ channels/myoggradio.py @@ -24,11 +24,11 @@ from config import conf from action import action import re import json -from StringIO import StringIO +from compat2and3 import StringIO import copy # open source radio sharing stie Index: channels/shoutcast.py ================================================================== --- channels/shoutcast.py +++ channels/shoutcast.py @@ -64,15 +64,15 @@ html = http.get(self.base_url) self.categories = [] __print__( dbg.DATA, html ) #

Radio Genres

- rx = re.compile(r'[\w\s]+', re.S) + rx = re.compile(r'[\w\s]+', re.S) sub = [] for uu in rx.findall(html): __print__( dbg.DATA, uu ) - (main,name,id) = uu + (main,name,id) = uu name = urllib.unquote(name) # main category if main: if sub: Index: channels/timer.py ================================================================== --- channels/timer.py +++ channels/timer.py @@ -18,10 +18,11 @@ # are stored in the description field, and can thus be edited. However, after editing # times manually, streamtuner2 must be restarted for the changes to take effect. # +from config import __print__, dbg from channels import * import kronos from mygtk import mygtk from action import action import copy @@ -74,11 +75,11 @@ # prepare spool self.sched = kronos.ThreadedScheduler() for row in self.streams: try: self.queue(row) - except Exception,e: print("queuing error", e) + except Exception as e: __print__(dbg.ERR, "queuing error", e) self.sched.start() # display GUI for setting timespec def edit_timer(self, *w): ADDED compat2and3.py Index: compat2and3.py ================================================================== --- compat2and3.py +++ compat2and3.py @@ -0,0 +1,58 @@ +# +# encoding: UTF-8 +# api: python +# type: functions +# title: Python2 and Python3 compatibility +# version: 0.1 +# +# Renames some Python3 modules into their Py2 equivalent. +# Slim local alternative to `six` module. +# + + +import sys + + +# Python 2 +if sys.version_info < (3,0): + + # version tags + PY2 = 1 + PY3 = 0 + + # basic functions + xrange = xrange + range = xrange + + # urllib modules + import urllib + import urllib2 + from urllib import urlencode + import urlparse + import cookielib + + # filesys + from StringIO import StringIO + + +# Python 3 +else: + + # version tags + PY2 = 0 + PY3 = 1 + + # basic functions + xrange = range + + # urllib modules + import urllib.request as urllib + import urllib.request as urllib2 + from urllib.parse import urlencode + import urllib.parse as urlparse + from http import cookiejar as cookielib + + # filesys + from io import StringIO + + Index: favicon.py ================================================================== --- favicon.py +++ favicon.py @@ -26,11 +26,11 @@ delete_google_stub = 1 # don't keep placeholder images google_placeholder_filesizes = (726,896) import os, os.path -import urllib +from compat2and3 import xrange, urllib import re from config import conf try: from processing import Process as Thread except: from threading import Thread import ahttp Index: kronos.py ================================================================== --- kronos.py +++ kronos.py @@ -272,11 +272,11 @@ def _run(self): # Low-level run method to do the actual scheduling loop. while self.running: try: self.sched.run() - except Exception,x: + except Exception as x: print >>sys.stderr, "ERROR DURING SCHEDULER EXECUTION",x print >>sys.stderr, "".join( traceback.format_exception(*sys.exc_info())) print >>sys.stderr, "-" * 20 # queue is empty; sleep a short while before checking again @@ -296,11 +296,11 @@ def __call__(self, schedulerref): """Execute the task action in the scheduler's thread.""" try: self.execute() - except Exception,x: + except Exception as x: self.handle_exception(x) self.reschedule(schedulerref()) def reschedule(self, scheduler): """This method should be defined in one of the sub classes!""" @@ -464,11 +464,11 @@ def threadedcall(self): # This method is run within its own thread, so we have to # do the execute() call and exception handling here. try: self.execute() - except Exception,x: + except Exception as x: self.handle_exception(x) class ThreadedIntervalTask(ThreadedTaskMixin, IntervalTask): """Interval Task that executes in its own thread.""" pass @@ -531,11 +531,11 @@ pid = os.fork() if pid == 0: # we are the child try: self.execute() - except Exception,x: + except Exception as x: self.handle_exception(x) os._exit(0) else: # we are the parent self.reschedule(schedulerref()) Index: pq.py ================================================================== --- pq.py +++ pq.py @@ -17,11 +17,11 @@ from pyquery import PyQuery as pq # pq.each_pq = lambda self,func: self.each( lambda i,html: func( pq(html, parser="html") ) ) -except Exception, e: +except Exception as e: # disable use pq = None config.conf.pyquery = False Index: st2.py ================================================================== --- st2.py +++ st2.py @@ -218,11 +218,11 @@ "true": lambda w,*args: True, "streamedit_open": streamedit.open, "streamedit_save": streamedit.save, "streamedit_new": streamedit.new, "streamedit_cancel": streamedit.cancel, - }.items() + self.add_signals.items() )) + }.items() | self.add_signals.items() )) # actually display main window gui_startup(99/100.0) self.win_streamtuner2.show() @@ -523,11 +523,11 @@ # end application and gtk+ main loop def gtk_main_quit(self, widget, *x): if conf.auto_save_appstate: - try: # doesn't work with gtk3 yet + try: # doesn't work with gtk3 yet (probably just hooking at the wrong time) self.app_state(widget) except: None gtk.main_quit()