# Path: constants/exceptions.py
# class invalidArgumentsException(Exception):
# class loginFailedException(Exception):
# class userBannedException(Exception):
# class userLockedException(Exception):
# class noBanchoSessionException(Exception):
# class osuApiFailException(Exception):
# class fileNotFoundException(Exception):
# class invalidBeatmapException(Exception):
# class unsupportedGameModeException(Exception):
# class beatmapTooLongException(Exception):
# class need2FAException(Exception):
# class noAPIDataError(Exception):
# class scoreNotFoundError(Exception):
# class ppCalcException(Exception):
# 	def __init__(self, handler):
# 	def __init__(self, handler, who):
# 	def __init__(self, handler, who):
# 	def __init__(self, handler, who):
# 	def __init__(self, handler, who, ip):
# 	def __init__(self, handler):
# 	def __init__(self, handler, f):
# 	def __init__(self, handler):
# 	def __init__(self, handler, who, ip):
# 	def __init__(self, exception):


import tornado.gen
import tornado.web
from common.sentry import sentry
from common.web import requestsManager
from common.web import cheesegull
from constants import exceptions
from common.log import logUtils as log

class handler(requestsManager.asyncRequestHandler):
	"""
	Handler for /web/osu-search.php
	"""
	MODULE_NAME = "osu_direct_search"

	@tornado.web.asynchronous
	@tornado.gen.engine
	@sentry.captureTornado
	def asyncGet(self):
		output = ""
		try:
			try:
				# Get arguments
				gameMode = self.get_argument("m", None)
				if gameMode is not None:
					gameMode = int(gameMode)
				if gameMode < 0 or gameMode > 3:
					gameMode = None

				rankedStatus = self.get_argument("r", None)
				if rankedStatus is not None:
					rankedStatus = int(rankedStatus)

				query = self.get_argument("q", "")
				page = int(self.get_argument("p", "0"))
				if query.lower() in ["newest", "top rated", "most played"]:
					query = ""
			except ValueError:

# Path: constants/exceptions.py
# class invalidArgumentsException(Exception):
# class loginFailedException(Exception):
# class userBannedException(Exception):
# class userLockedException(Exception):
# class noBanchoSessionException(Exception):
# class osuApiFailException(Exception):
# class fileNotFoundException(Exception):
# class invalidBeatmapException(Exception):
# class unsupportedGameModeException(Exception):
# class beatmapTooLongException(Exception):
# class need2FAException(Exception):
# class noAPIDataError(Exception):
# class scoreNotFoundError(Exception):
# class ppCalcException(Exception):
# 	def __init__(self, handler):
# 	def __init__(self, handler, who):
# 	def __init__(self, handler, who):
# 	def __init__(self, handler, who):
# 	def __init__(self, handler, who, ip):
# 	def __init__(self, handler):
# 	def __init__(self, handler, f):
# 	def __init__(self, handler):
# 	def __init__(self, handler, who, ip):
# 	def __init__(self, exception):


# Path: handlers/osuSearchHandler.py
import tornado.gen
import tornado.web
from common.sentry import sentry
from common.web import requestsManager
from common.web import cheesegull
from constants import exceptions
from common.log import logUtils as log


class handler(requestsManager.asyncRequestHandler):
	"""
	Handler for /web/osu-search.php
	"""
	MODULE_NAME = "osu_direct_search"

	@tornado.web.asynchronous
	@tornado.gen.engine
	@sentry.captureTornado
	def asyncGet(self):
		output = ""
		try:
			try:
				# Get arguments
				gameMode = self.get_argument("m", None)
				if gameMode is not None:
					gameMode = int(gameMode)
				if gameMode < 0 or gameMode > 3:
					gameMode = None

				rankedStatus = self.get_argument("r", None)
				if rankedStatus is not None:
					rankedStatus = int(rankedStatus)

				query = self.get_argument("q", "")
				page = int(self.get_argument("p", "0"))
				if query.lower() in ["newest", "top rated", "most played"]:
					query = ""
			except ValueError:

				raise exceptions.invalidArgumentsException(self.MODULE_NAME)