コード例 #1
0
    async def check(self, aio_client: aiohttp.ClientSession,
                    usernames: AbstractSet[str]) -> ni_abc.Status:
        base_url = "http://bugs.python.org/user?@template=clacheck&github_names="
        url = base_url + ','.join(usernames)
        self.server.log("Checking CLA status: " + url)
        async with aio_client.get(url) as response:
            if response.status >= 300:
                msg = f'unexpected response for {response.url!r}: {response.status}'
                raise client.HTTPException(msg)
            # Explicitly decode JSON as b.p.o doesn't set the content-type as
            # `application/json`.
            results = json.loads(await response.text())
        self.server.log("Raw CLA status: " + str(results))
        status_results = [results[k] for k in results.keys() if k in usernames]
        self.server.log("Filtered CLA status: " + str(status_results))
        if len(status_results) != len(usernames):
            raise ValueError("# of usernames don't match # of results "
                             "({} != {})".format(len(usernames), len(status_results)))
        elif any(x not in (True, False, None) for x in status_results):
            raise TypeError("unexpected value in " + str(status_results))

        if all(status_results):
            return ni_abc.Status.signed
        elif any(value is None for value in status_results):
            return ni_abc.Status.username_not_found
        else:
            return ni_abc.Status.not_signed
コード例 #2
0
 def _resolveError(self, response):
     status = response["status"]
     if response["data"]:
         message = '{}: {}'.format(response["reason"], response["data"])
     else:
         message = response["reason"]
     if status in [400, 401, 402, 403, 406, 500]:
         self.Error({"status": status, "message": message})
     else:
         raise httplib.HTTPException(status, message)
コード例 #3
0
 def parse(fp: IOBase):
     """Parses only RFC2822 headers from a file pointer.
     """
     headers = Headers()
     while True:
         line = fp.readline(_MAXLINE + 1)
         if len(line) > _MAXLINE:
             raise client.LineTooLong("header line")
         headers.add_header_line(line)
         if len(headers) > _MAXHEADERS:
             raise client.HTTPException("got more than %d headers" %
                                        _MAXHEADERS)
         if line in (b'\r\n', b'\n', b''):
             break
     return headers
コード例 #4
0
 async def check(self, usernames):
     base_url = "http://bugs.python.org/user?@template=clacheck&github_names="
     url = base_url + ','.join(usernames)
     async with abc.session().get(url) as response:
         if response.status >= 300:
             msg = 'unexpected response for {!r}: {}'.format(
                 response.url, response.status)
             raise client.HTTPException(msg)
         # Explicitly decode JSON as b.p.o doesn't set the content-type as
         # `application/json`.
         results = json.loads(await response.text())
     if all(results.values()):
         return abc.Status.signed
     elif any(value is None for value in results.values()):
         return abc.Status.username_not_found
     else:
         return abc.Status.not_signed
コード例 #5
0
ファイル: pywsgi.py プロジェクト: kakarrot2009/gevent
 def headers_factory(_, fp, *args):
     headers = 0
     feedparser = FeedParser(OldMessage)
     try:
         while True:
             line = fp.readline(client._MAXLINE + 1)
             if len(line) > client._MAXLINE:
                 ret = OldMessage()
                 ret.status = 'Line too long'
                 return ret
             headers += 1
             if headers > client._MAXHEADERS:
                 raise client.HTTPException("got more than %d headers" %
                                            client._MAXHEADERS)
             feedparser.feed(line.decode('iso-8859-1'))
             if line in (b'\r\n', b'\n', b''):
                 return feedparser.close()
     finally:
         # break the recursive reference chain
         feedparser.__dict__.clear()
コード例 #6
0
 def apirequest(cls, url, apikey=None, **params):
     """Create query to the BTC-E API (decoded response).
     @raise APIError, httplib.HTTPException: BTC-E and CloudFlare errors
     @param url: Public/Trade API plain URL without parameters
     @param apikey: Trade API Key {'Key': 'KEY', 'Secret': 'SECRET'}
     @param **params: Public/Trade API method and/or parameters
     @return: BTC-E API response (decoded data) <type 'dict'>"""
     data = cls.jsonrequest(url, apikey, **params)
     try:
         data = jsonloads(data, parse_float=Decimal, parse_int=Decimal)
     except ValueError:
         if cls._resp.status != httplib.OK:
             # CloudFlare HTTP errors
             raise httplib.HTTPException("{} {}".format(
                 cls._resp.status, cls._resp.reason))
         else:
             # BTC-E API unknown errors
             raise APIError(str(data) or "Unknown Error")
     else:
         if 'error' in data:
             # BTC-E API standard errors
             logging.info(params)
             raise APIError(str(data['error']))
     return data
コード例 #7
0
 def check_response(response: web.Response) -> None:
     if response.status >= 300:
         msg = 'unexpected response for {!r}: {}'.format(
             response.url, response.status)
         raise client.HTTPException(msg)
コード例 #8
0
 def _resolveError(self, status, message=None):
     if status == 400 or status == 401 or status == 402 or \
                     status == 403 or status == 406 or status == 500:
         self.Error({"status": status, "message": message})
     else:
         raise httplib.HTTPException(status, message)
コード例 #9
0
 def getresponse(self):
     raise http_client.HTTPException()
コード例 #10
0
 def request(self, *args, **kwargs):
     self.__class__.retries += 1
     raise http_client.HTTPException()
コード例 #11
0
 def __init__(self, *args, **kwargs):
     self.__class__.retries += 1
     raise http_client.HTTPException()