Skip to content

paste_rs

Class info

Classes

Name Children Inherits
PasteRsSharer
anyenv.text_sharing.paste_rs
Share text via paste.rs.

    🛈 DocStrings

    paste.rs text sharing provider.

    PasteRsSharer

    Bases: TextSharer

    Share text via paste.rs.

    Source code in src/anyenv/text_sharing/paste_rs.py
    class PasteRsSharer(TextSharer):
        """Share text via paste.rs."""
    
        @property
        def name(self) -> str:
            """Name of the sharing service."""
            return "paste.rs"
    
        async def share(
            self,
            content: str,
            *,
            title: str | None = None,
            syntax: str | None = None,
            visibility: Visibility = "unlisted",
            expires_in: int | None = None,
        ) -> ShareResult:
            """Share content on paste.rs.
    
            Args:
                content: The text content to share
                title: Ignored (paste.rs doesn't support titles)
                syntax: Used as file extension for syntax highlighting
                visibility: Ignored (all pastes are unlisted)
                expires_in: Ignored (paste.rs doesn't support expiration)
            """
            import anyenv
    
            headers = {"Content-Type": "text/plain; charset=utf-8"}
            data = content.encode()
            response = await anyenv.request("POST", "https://paste.rs/", data=data, headers=headers)
            url = response.text.strip()
            ext = syntax or "txt"
            return ShareResult(url=f"{url}.{ext}", raw_url=url)
    

    name property

    name: str
    

    Name of the sharing service.

    share async

    share(
        content: str,
        *,
        title: str | None = None,
        syntax: str | None = None,
        visibility: Visibility = "unlisted",
        expires_in: int | None = None,
    ) -> ShareResult
    

    Share content on paste.rs.

    Parameters:

    Name Type Description Default
    content str

    The text content to share

    required
    title str | None

    Ignored (paste.rs doesn't support titles)

    None
    syntax str | None

    Used as file extension for syntax highlighting

    None
    visibility Visibility

    Ignored (all pastes are unlisted)

    'unlisted'
    expires_in int | None

    Ignored (paste.rs doesn't support expiration)

    None
    Source code in src/anyenv/text_sharing/paste_rs.py
    async def share(
        self,
        content: str,
        *,
        title: str | None = None,
        syntax: str | None = None,
        visibility: Visibility = "unlisted",
        expires_in: int | None = None,
    ) -> ShareResult:
        """Share content on paste.rs.
    
        Args:
            content: The text content to share
            title: Ignored (paste.rs doesn't support titles)
            syntax: Used as file extension for syntax highlighting
            visibility: Ignored (all pastes are unlisted)
            expires_in: Ignored (paste.rs doesn't support expiration)
        """
        import anyenv
    
        headers = {"Content-Type": "text/plain; charset=utf-8"}
        data = content.encode()
        response = await anyenv.request("POST", "https://paste.rs/", data=data, headers=headers)
        url = response.text.strip()
        ext = syntax or "txt"
        return ShareResult(url=f"{url}.{ext}", raw_url=url)