Ejemplo n.º 1
0
    def setup_actor(self, name, pusername):
        """Create a new actor in this backend."""
        p = ap.Person(
            name=name,
            preferredUsername=pusername,
            summary="Hello",
            id=f"https://lol.com/{pusername}",
            inbox=f"https://lol.com/{pusername}/inbox",
            followers=f"https://lol.com/{pusername}/followers",
            following=f"https://lol.com/{pusername}/following",
        )

        self.USERS[p.preferredUsername] = p
        self.DB[p.id] = {"inbox": [], "outbox": []}
        self.INBOX_IDX[p.id] = {}
        self.OUTBOX_IDX[p.id] = {}
        self.FOLLOWERS[p.id] = []
        self.FOLLOWING[p.id] = []
        self.FETCH_MOCK[p.id] = p.to_dict()
        self._METHOD_CALLS[p.id] = []
        return p
Ejemplo n.º 2
0
from core.meta import not_deleted

# _Response = Union[flask.Response, werkzeug.wrappers.Response, str, Any]
_Response = Any

p = PousseTaches(
    os.getenv("MICROBLOGPUB_POUSSETACHES_HOST", "http://localhost:7991"),
    os.getenv("MICROBLOGPUB_INTERNAL_HOST", "http://localhost:5000"),
)

csrf = CSRFProtect()

back = activitypub.MicroblogPubBackend()
ap.use_backend(back)

MY_PERSON = ap.Person(**ME)


@lru_cache(512)
def build_resp(resp):
    """Encode the response to gzip if supported by the client."""
    headers = {"Cache-Control": "max-age=0, private, must-revalidate"}
    accept_encoding = request.headers.get("Accept-Encoding", "")
    if "gzip" in accept_encoding.lower():
        return (
            gzip.compress(resp.encode(), compresslevel=6),
            {
                **headers, "Vary": "Accept-Encoding",
                "Content-Encoding": "gzip"
            },
        )