示例#1
0
def consume_event(response: http.client.HTTPResponse) -> Tuple[str, Any]:
    _, event = consume_line(response)
    _, raw_data = consume_line(response)

    # Swallow the intermediate line
    response.readline()

    return event, json.loads(raw_data)
示例#2
0
    def _check_for_redirect(self, url: str, req: http.client.HTTPResponse):
        response_url = req.geturl()
        if url != response_url:
            new_owner, new_name = (urllib.parse.urlsplit(
                response_url).path.strip("/").split("/")[:2])

            new_repo = RepoGitHub(owner=new_owner,
                                  repo=new_name,
                                  branch=self.branch)
            self.redirect = new_repo
示例#3
0
    def _check_for_redirect(self, url: str, req: http.client.HTTPResponse):
        response_url = req.geturl()
        if url != response_url:
            new_owner, new_name = (urllib.parse.urlsplit(
                response_url).path.strip("/").split("/")[:2])
            end_line = "\n" if self.alias is None else f" as {self.alias}\n"
            plugin_line = "{owner}/{name}" + end_line

            old_plugin = plugin_line.format(owner=self.owner, name=self.name)
            new_plugin = plugin_line.format(owner=new_owner, name=new_name)
            self.redirect[old_plugin] = new_plugin
示例#4
0
 def _response_parse(self, res: http.client.HTTPResponse) -> dict:
     body = res.read().decode("utf-8")
     if body is "" or body is None:
         return {}
     regex = r"(\"[^\":,]+?_id\"):([0-9]+)"
     matches = re.findall(regex, body)
     for m in matches:
         body = body.replace(m[0] + ":" + m[1], m[0] + ":\"" + m[1] + "\"")
     body = json.loads(body)
     status = body.get("status", None)
     if status is None:
         status = body.get("error", None)
     if status == "success":
         return body
     elif status == "error":
         ex = APIException()
         ex.state = res.status
         ex.hdrs = res.getheaders()
         ex.fp = res.fp
         ex.filename = res.url
         ex.msg = body["errors"]
         ex.code = body["errorCode"]
         raise ex
示例#5
0
def consume_line(response: http.client.HTTPResponse) -> Tuple[str, str]:
    name, _, data = response.readline().decode('utf-8').rstrip('\n').partition(':')
    return name.strip(), data.strip()