Ejemplo n.º 1
0
 async def upload_file(self, path: Path) -> Path:
     fobj = BytesIO()
     with ZipFile(fobj, "w", ZIP_DEFLATED) as zf:
         zf.write(path, path.name)
     content = base64.b64encode(fobj.getvalue()).decode("utf-8")
     status, data = await self.request(url="/file",
                                       method="POST",
                                       data={"file": content})
     check_response_error(status, data)
     value = unwrap(data.get("value", None))
     log.info("upload-file", path=path, resolved_path=value)
     return Path(value)
Ejemplo n.º 2
0
def unwrap(value):
    if isinstance(value, dict) and ("ELEMENT" in value
                                    or constants.WEB_ELEMENT in value):
        wrapped_id = value.get("ELEMENT", None)
        if wrapped_id:
            return value["ELEMENT"]
        else:
            return value[constants.WEB_ELEMENT]

    elif isinstance(value, list):
        return list(unwrap(item) for item in value)
    else:
        return value