Merge remote-tracking branch 'origin/dev'

This commit is contained in:
echel0n 2014-06-17 23:57:39 -07:00
commit 574e300162
3 changed files with 31 additions and 36 deletions

View file

@ -143,22 +143,9 @@ class IndexHandler(RequestHandler):
sickbeard.REMOTE_IP = self.request.remote_ip sickbeard.REMOTE_IP = self.request.remote_ip
req_headers = self.request.headers req_headers = self.request.headers
def delist_arguments(self, args):
"""
Takes a dictionary, 'args' and de-lists any single-item lists then
returns the resulting dictionary.
In other words, {'foo': ['bar']} would become {'foo': 'bar'}
"""
for arg, value in args.items():
if len(value) == 1:
args[arg] = value[0]
return args
def _dispatch(self): def _dispatch(self):
args = None path = self.request.uri.replace(sickbeard.WEB_ROOT,'').split('?')[0]
path = self.request.uri.split('?')[0]
method = path.strip('/').split('/')[-1] method = path.strip('/').split('/')[-1]
if path.startswith('/api'): if path.startswith('/api'):
@ -179,8 +166,10 @@ class IndexHandler(RequestHandler):
if klass and not method.startswith('_'): if klass and not method.startswith('_'):
# Sanitize argument lists: # Sanitize argument lists:
if self.request.arguments: args = self.request.arguments
args = self.delist_arguments(self.request.arguments) for arg, value in args.items():
if len(value) == 1:
args[arg] = value[0]
# Regular method handler for classes # Regular method handler for classes
func = getattr(klass, method, None) func = getattr(klass, method, None)
@ -193,30 +182,39 @@ class IndexHandler(RequestHandler):
func = getattr(klass, 'index', None) func = getattr(klass, 'index', None)
if func: if func:
if args: return func(**args)
return func(**args)
else:
return func()
raise HTTPError(404) raise HTTPError(404)
def redirect(self, url, permanent=False, status=None): def redirect(self, url, permanent=False, status=None):
if not self._transforms: self._transforms = []
self._transforms = [] super(IndexHandler, self).redirect(sickbeard.WEB_ROOT + url, permanent, status)
super(IndexHandler, self).redirect(url, permanent, status)
@asynchronous @asynchronous
@gen.engine
def get(self, *args, **kwargs): def get(self, *args, **kwargs):
try: try:
self.finish(self._dispatch()) response = yield gen.Task(self.getresponse, self._dispatch)
self.finish(response)
except Exception as e: except Exception as e:
logger.log(ex(e), logger.ERROR) logger.log(ex(e), logger.ERROR)
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG) logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
@asynchronous
@gen.engine
def post(self, *args, **kwargs): def post(self, *args, **kwargs):
return self._dispatch() try:
response = yield gen.Task(self.getresponse, self._dispatch)
self.finish(response)
except Exception as e:
logger.log(ex(e), logger.ERROR)
logger.log(u"Traceback: " + traceback.format_exc(), logger.DEBUG)
def getresponse(self, func, callback):
response = func()
callback(response)
def robots_txt(self, *args, **kwargs): def robots_txt(self, *args, **kwargs):
""" Keep web crawlers out """ """ Keep web crawlers out """
self.set_header('Content-Type', 'text/plain') self.set_header('Content-Type', 'text/plain')
@ -1465,8 +1463,6 @@ class ConfigGeneral(IndexHandler):
else: else:
ui.notifications.message('Configuration Saved', ek.ek(os.path.join, sickbeard.CONFIG_FILE)) ui.notifications.message('Configuration Saved', ek.ek(os.path.join, sickbeard.CONFIG_FILE))
self.redirect("/home/")
class ConfigSearch(IndexHandler): class ConfigSearch(IndexHandler):
def index(self, *args, **kwargs): def index(self, *args, **kwargs):

View file

@ -12,7 +12,6 @@ from tornado.ioloop import IOLoop
server = None server = None
class MultiStaticFileHandler(StaticFileHandler): class MultiStaticFileHandler(StaticFileHandler):
def initialize(self, paths, default_filename=None): def initialize(self, paths, default_filename=None):
self.paths = paths self.paths = paths
@ -101,21 +100,20 @@ def initWebServer(options={}):
app = Application([], app = Application([],
debug=sickbeard.DEBUG, debug=sickbeard.DEBUG,
gzip=True, gzip=True,
xheaders=True,
cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=' cookie_secret='61oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo='
) )
# Index Handler # Index Handler
app.add_handlers(".*$", [ app.add_handlers(".*$", [
(r"/", RedirectHandler, {'url': '/home/'}), (r"/", RedirectHandler, {'url': '%s/home/' % options['web_root']}),
(r'/api/(.*)(/?)', webapi.Api), (r'%s/api/(.*)(/?)' % options['web_root'], webapi.Api),
(r'%s(.*)(/?)' % options['web_root'], webserve.IndexHandler) (r'%s/(.*)(/?)' % options['web_root'], webserve.IndexHandler)
]) ])
# Static Path Handler # Static Path Handler
app.add_handlers(".*$", [ app.add_handlers(".*$", [
(r'/(favicon\.ico)', MultiStaticFileHandler, (r'%s/(favicon\.ico)' % options['web_root'], MultiStaticFileHandler,
{'paths': '%s/%s' % (options['web_root'], 'images/ico/favicon.ico')}), {'paths': [os.path.join(options['data_root'], 'images/ico/favicon.ico')]}),
(r'%s/%s/(.*)(/?)' % (options['web_root'], 'images'), MultiStaticFileHandler, (r'%s/%s/(.*)(/?)' % (options['web_root'], 'images'), MultiStaticFileHandler,
{'paths': [os.path.join(options['data_root'], 'images'), {'paths': [os.path.join(options['data_root'], 'images'),
os.path.join(sickbeard.CACHE_DIR, 'images'), os.path.join(sickbeard.CACHE_DIR, 'images'),

View file

@ -630,6 +630,7 @@ class RequestHandler(object):
self.set_status(status) self.set_status(status)
self.set_header("Location", urlparse.urljoin(utf8(self.request.uri), self.set_header("Location", urlparse.urljoin(utf8(self.request.uri),
utf8(url))) utf8(url)))
self.finish() self.finish()
def write(self, chunk): def write(self, chunk):