Merge branch 'develop'

This commit is contained in:
Ruud committed 2014-12-22 22:02:05 +01:00
commit 0288cc8848
4 files changed
+27 -27

No files matched your search

+20 -21
View File
@@ -7,6 +7,7 @@ import urllib
from couchpotato.core.helpers.request import getParams from couchpotato.core.helpers.request import getParams
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler, asynchronous from tornado.web import RequestHandler, asynchronous
@@ -50,24 +51,22 @@ class NonBlockHandler(RequestHandler):
start, stop = api_nonblock[route] start, stop = api_nonblock[route]
self.stopper = stop self.stopper = stop
start(self.onNewMessage, last_id = self.get_argument('last_id', None)) start(self.sendData, last_id = self.get_argument('last_id', None))
def onNewMessage(self, response): def sendData(self, response):
if self.request.connection.stream.closed(): if not self.request.connection.stream.closed():
self.on_connection_close() try:
return self.finish(response)
except:
log.debug('Failed doing nonblock request, probably already closed: %s', (traceback.format_exc()))
try: self.finish({'success': False, 'error': 'Failed returning results'})
except: pass
try: self.removeStopper()
self.finish(response)
except:
log.debug('Failed doing nonblock request, probably already closed: %s', (traceback.format_exc()))
try: self.finish({'success': False, 'error': 'Failed returning results'})
except: pass
def on_connection_close(self):
def removeStopper(self):
if self.stopper: if self.stopper:
self.stopper(self.onNewMessage) self.stopper(self.sendData)
self.stopper = None self.stopper = None
@@ -129,6 +128,10 @@ class ApiHandler(RequestHandler):
post = get post = get
def taskFinished(self, result, route): def taskFinished(self, result, route):
IOLoop.current().add_callback(self.sendData, result, route)
self.unlock()
def sendData(self, result, route):
if not self.request.connection.stream.closed(): if not self.request.connection.stream.closed():
try: try:
@@ -136,14 +139,12 @@ class ApiHandler(RequestHandler):
jsonp_callback = self.get_argument('callback_func', default = None) jsonp_callback = self.get_argument('callback_func', default = None)
if jsonp_callback: if jsonp_callback:
self.write(str(jsonp_callback) + '(' + json.dumps(result) + ')') self.set_header('Content-Type', 'text/javascript')
self.set_header("Content-Type", "text/javascript") self.finish(str(jsonp_callback) + '(' + json.dumps(result) + ')')
self.finish()
elif isinstance(result, tuple) and result[0] == 'redirect': elif isinstance(result, tuple) and result[0] == 'redirect':
self.redirect(result[1]) self.redirect(result[1])
else: else:
self.write(result) self.finish(result)
self.finish()
except UnicodeDecodeError: except UnicodeDecodeError:
log.error('Failed proper encode: %s', traceback.format_exc()) log.error('Failed proper encode: %s', traceback.format_exc())
except: except:
@@ -151,8 +152,6 @@ class ApiHandler(RequestHandler):
try: self.finish({'success': False, 'error': 'Failed returning results'}) try: self.finish({'success': False, 'error': 'Failed returning results'})
except: pass except: pass
self.unlock()
def unlock(self): def unlock(self):
try: api_locks[self.route].release() try: api_locks[self.route].release()
except: pass except: pass
+1 -2
View File
@@ -44,8 +44,7 @@ def toUnicode(original, *args):
raise raise
except: except:
log.error('Unable to decode value "%s..." : %s ', (repr(original)[:20], traceback.format_exc())) log.error('Unable to decode value "%s..." : %s ', (repr(original)[:20], traceback.format_exc()))
ascii_text = str(original).encode('string_escape') return toSafeString(original)
return toUnicode(ascii_text)
def ss(original, *args): def ss(original, *args):
@@ -1,7 +1,7 @@
import traceback import traceback
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from couchpotato.core.helpers.encoding import tryUrlencode from couchpotato.core.helpers.encoding import tryUrlencode, toUnicode
from couchpotato.core.helpers.variable import tryInt from couchpotato.core.helpers.variable import tryInt
from couchpotato.core.logger import CPLog from couchpotato.core.logger import CPLog
from couchpotato.core.media._base.providers.torrent.base import TorrentProvider from couchpotato.core.media._base.providers.torrent.base import TorrentProvider
@@ -56,11 +56,12 @@ class Base(TorrentProvider):
full_id = link['href'].replace('details.php?id=', '') full_id = link['href'].replace('details.php?id=', '')
torrent_id = full_id[:6] torrent_id = full_id[:6]
name = toUnicode(link.contents[0])
results.append({ results.append({
'id': torrent_id, 'id': torrent_id,
'name': link.contents[0], 'name': name,
'url': self.urls['download'] % (torrent_id, link.contents[0]), 'url': self.urls['download'] % (torrent_id, name),
'detail_url': self.urls['detail'] % torrent_id, 'detail_url': self.urls['detail'] % torrent_id,
'size': self.parseSize(cells[6].contents[0] + cells[6].contents[2]), 'size': self.parseSize(cells[6].contents[0] + cells[6].contents[2]),
'seeders': tryInt(cells[8].find('span').contents[0]), 'seeders': tryInt(cells[8].find('span').contents[0]),
+2 -1
View File
@@ -14,6 +14,7 @@ from couchpotato.core.logger import CPLog
from couchpotato.core.notifications.base import Notification from couchpotato.core.notifications.base import Notification
from .index import NotificationIndex, NotificationUnreadIndex from .index import NotificationIndex, NotificationUnreadIndex
from couchpotato.environment import Env from couchpotato.environment import Env
from tornado.ioloop import IOLoop
log = CPLog(__name__) log = CPLog(__name__)
@@ -190,7 +191,7 @@ class CoreNotifier(Notification):
while len(self.listeners) > 0 and not self.shuttingDown(): while len(self.listeners) > 0 and not self.shuttingDown():
try: try:
listener, last_id = self.listeners.pop() listener, last_id = self.listeners.pop()
listener({ IOLoop.current().add_callback(listener, {
'success': True, 'success': True,
'result': [notification], 'result': [notification],
}) })