1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-11-18 07:15:13 -05:00

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
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):
args = None
path = self.request.uri.split('?')[0]
path = self.request.uri.replace(sickbeard.WEB_ROOT,'').split('?')[0]
method = path.strip('/').split('/')[-1]
if path.startswith('/api'):
@ -179,8 +166,10 @@ class IndexHandler(RequestHandler):
if klass and not method.startswith('_'):
# Sanitize argument lists:
if self.request.arguments:
args = self.delist_arguments(self.request.arguments)
args = self.request.arguments
for arg, value in args.items():
if len(value) == 1:
args[arg] = value[0]
# Regular method handler for classes
func = getattr(klass, method, None)
@ -193,29 +182,38 @@ class IndexHandler(RequestHandler):
func = getattr(klass, 'index', None)
if func:
if args:
return func(**args)
else:
return func()
raise HTTPError(404)
def redirect(self, url, permanent=False, status=None):
if not self._transforms:
self._transforms = []
super(IndexHandler, self).redirect(url, permanent, status)
super(IndexHandler, self).redirect(sickbeard.WEB_ROOT + url, permanent, status)
@asynchronous
@gen.engine
def get(self, *args, **kwargs):
try:
self.finish(self._dispatch())
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)
@asynchronous
@gen.engine
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):
""" Keep web crawlers out """
@ -1465,8 +1463,6 @@ class ConfigGeneral(IndexHandler):
else:
ui.notifications.message('Configuration Saved', ek.ek(os.path.join, sickbeard.CONFIG_FILE))
self.redirect("/home/")
class ConfigSearch(IndexHandler):
def index(self, *args, **kwargs):

View File

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

View File

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