def handle(self, event, context): super().handle(event, context) try: token = event[ 'token'] if 'token' in event else self.badge_service.create_token( ) __, badge_codes = self.badge_service.get_badges_from_token(token) response = self.discography_service.get_discography(badge_codes, no_cache=False) return DiscographyHandler.Result( 'Discography successfully fetched', badge_codes, token, response) except ValueError as e: self.LOG.warning(e.with_traceback) token = self.badge_service.create_token() discography = self.discography_service.get_discography( [], no_cache=False) raise HandlerBase.InvalidTokenError( badToken=event['token'], goodToken=self.badge_service.create_token(), badges=[], discography=discography) except Exception as e: self.LOG.exception("DiscographyHandler.handle") raise HandlerBase.InternalError()
def handle(self, event, context): super().handle(event, context) try: if 'token' not in event: return BadgesHandler.Result('New, empty token created', [], self.badge_service.create_token()) elif 'key' not in event: __, badgeCodes = self.badge_service.get_badges_from_token( event['token']) return BadgesHandler.Result(f'Token {event["token"]} is valid', badgeCodes, event['token']) else: badges, token, addedCode = self.badge_service.add_badge_to_token( event['token'], event['key']) return BadgesHandler.Result('Badge added to token', badges, token, addedCode) except ValueError as e: self.LOG.warning(e.with_traceback) raise HandlerBase.InvalidTokenError( badToken=event['token'], goodToken=self.badge_service.create_token(), badges=[]) except KeyError as e: self.LOG.warning(e.with_traceback) __, badgeCodes = self.badge_service.get_badges_from_token( event['token']) raise HandlerBase.InvalidKeyError(badKey=event['key'], token=event['token'], badges=badgeCodes) except Exception as e: self.LOG.exception("BadgesHandler.handle") raise HandlerBase.InternalError()
def __init__(self, sock, server,porxy = True,remote_host=None,remote_port=None): u""" porxy 是否是代理服务器模式,代理服务器模式会强制关闭不支持的协议。 删除未知的 Connection 指定的 http 头,删除未知的 upgrade 头。 非代理服务器模式(socks5拦截模式)碰到未知的 upgrade 头会回退到socks5代理模式。 remote_host 目标主机 remote_port 目标端口 """ HandlerBase.__init__(self,sock,server) self.porxy = porxy self.remote_host = remote_host self.remote_port = remote_port
def __init__(self, sock, server, porxy=True, remote_host=None, remote_port=None): u""" porxy 是否是代理服务器模式,代理服务器模式会强制关闭不支持的协议。 删除未知的 Connection 指定的 http 头,删除未知的 upgrade 头。 非代理服务器模式(socks5拦截模式)碰到未知的 upgrade 头会回退到socks5代理模式。 remote_host 目标主机 remote_port 目标端口 """ HandlerBase.__init__(self, sock, server) self.porxy = porxy self.remote_host = remote_host self.remote_port = remote_port
def handle(self, event, context): super().handle(event, context) try: if self.is_refresh_trigger_event(event): self.discography_service.refresh_cache() return RefreshCacheHandler.Result('Discography cache refreshed') else: self.discography_service.trigger_cache_refresh() return RefreshCacheHandler.Result('Discography cache refresh triggered') except Exception: self.LOG.exception("handlers.handle_refresh_discography_cache") raise HandlerBase.InternalError()
def __init__(self, sock,server): HandlerBase.__init__(self,sock,server)