Skip to content

PasteRsSharer

Base classes

Name Children Inherits
TextSharer
anyenv.text_sharing.base
Base class for text sharing services.

⋔ Inheritance diagram

graph TD
  3539877965["paste_rs.PasteRsSharer"]
  2782231920["base.TextSharer"]
  925645236["abc.ABC"]
  2751680898["builtins.object"]
  2782231920 --> 3539877965
  925645236 --> 2782231920
  2751680898 --> 925645236

🛈 DocStrings

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)

:fa-brands-github: Show source on GitHub