paste_service

MAX_PASTE_SIZE = 524288[source]

The maximum allows size of a paste, in bytes.

class PasteFile(**data)[source]

Bases: BaseModel

A file to be pasted to the paste service.

Parameters:
  • content (str) – The content of the file.

  • name (str) – The name of the file to upload. Defaults to ""

  • lexer (str) – The lexer to use when applying text formatting. Defaults to "python"

__class_vars__: ClassVar[set[str]] = {}

The names of the class variables defined on the model.

__private_attributes__: ClassVar[Dict[str, ModelPrivateAttr]] = {}

Metadata about the private attributes of the model.

__pydantic_complete__: ClassVar[bool] = True

Whether model building is completed, or if there are still undefined fields.

__pydantic_computed_fields__: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding [ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects.

__pydantic_core_schema__: ClassVar[CoreSchema] = {'cls': <class 'pydis_core.utils.paste_service.PasteFile'>, 'config': {'title': 'PasteFile'}, 'custom_init': False, 'metadata': {'pydantic_js_functions': [<bound method BaseModel.__get_pydantic_json_schema__ of <class 'pydis_core.utils.paste_service.PasteFile'>>]}, 'ref': 'pydis_core.utils.paste_service.PasteFile:94663045380944', 'root_model': False, 'schema': {'computed_fields': [], 'fields': {'content': {'metadata': {}, 'schema': {'type': 'str'}, 'type': 'model-field'}, 'lexer': {'metadata': {}, 'schema': {'default': 'python', 'schema': {'type': 'str'}, 'type': 'default'}, 'type': 'model-field'}, 'name': {'metadata': {}, 'schema': {'default': '', 'schema': {'type': 'str'}, 'type': 'default'}, 'type': 'model-field'}}, 'model_name': 'PasteFile', 'type': 'model-fields'}, 'type': 'model'}

The core schema of the model.

__pydantic_custom_init__: ClassVar[bool] = False

Whether the model has a custom __init__ method.

__pydantic_decorators__: ClassVar[_decorators.DecoratorInfos] = DecoratorInfos(validators={}, field_validators={}, root_validators={}, field_serializers={}, model_serializers={}, model_validators={}, computed_fields={})

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_extra__: dict[str, Any] | None

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields__: ClassVar[Dict[str, FieldInfo]] = {'content': FieldInfo(annotation=str, required=True), 'lexer': FieldInfo(annotation=str, required=False, default='python'), 'name': FieldInfo(annotation=str, required=False, default='')}

A dictionary of field names and their corresponding [FieldInfo][pydantic.fields.FieldInfo] objects. This replaces Model.__fields__ from Pydantic V1.

__pydantic_fields_set__: set[str]

The names of fields explicitly set during instantiation.

__pydantic_generic_metadata__: ClassVar[_generics.PydanticGenericMetadata] = {'args': (), 'origin': None, 'parameters': ()}

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__: ClassVar[Dict[str, Any] | None] = None

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__: ClassVar[None | Literal['model_post_init']] = None

The name of the post-init method for the model, if defined.

__pydantic_private__: dict[str, Any] | None

Values of private attributes set on the model instance.

__pydantic_serializer__: ClassVar[SchemaSerializer] = SchemaSerializer(serializer=Model(     ModelSerializer {         class: Py(             0x0000561875317b50,         ),         serializer: Fields(             GeneralFieldsSerializer {                 fields: {                     "content": SerField {                         key_py: Py(                             0x00007fbf0c5679f0,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             Str(                                 StrSerializer,                             ),                         ),                         required: true,                     },                     "name": SerField {                         key_py: Py(                             0x00007fbf0d356ea0,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             WithDefault(                                 WithDefaultSerializer {                                     default: Default(                                         Py(                                             0x00007fbf0d3530c0,                                         ),                                     ),                                     serializer: Str(                                         StrSerializer,                                     ),                                 },                             ),                         ),                         required: true,                     },                     "lexer": SerField {                         key_py: Py(                             0x00007fbf0c289270,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             WithDefault(                                 WithDefaultSerializer {                                     default: Default(                                         Py(                                             0x00007fbf0bff53f0,                                         ),                                     ),                                     serializer: Str(                                         StrSerializer,                                     ),                                 },                             ),                         ),                         required: true,                     },                 },                 computed_fields: Some(                     ComputedFields(                         [],                     ),                 ),                 mode: SimpleDict,                 extra_serializer: None,                 filter: SchemaFilter {                     include: None,                     exclude: None,                 },                 required_fields: 3,             },         ),         has_extra: false,         root_model: false,         name: "PasteFile",     }, ), definitions=[])

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__: ClassVar[SchemaValidator | PluggableSchemaValidator] = SchemaValidator(title="PasteFile", validator=Model(     ModelValidator {         revalidate: Never,         validator: ModelFields(             ModelFieldsValidator {                 fields: [                     Field {                         name: "content",                         lookup_key: Simple {                             key: "content",                             py_key: Py(                                 0x00007fbf0134cef0,                             ),                             path: LookupPath(                                 [                                     S(                                         "content",                                         Py(                                             0x00007fbf0134ceb0,                                         ),                                     ),                                 ],                             ),                         },                         name_py: Py(                             0x00007fbf0c5679f0,                         ),                         validator: Str(                             StrValidator {                                 strict: false,                                 coerce_numbers_to_str: false,                             },                         ),                         frozen: false,                     },                     Field {                         name: "name",                         lookup_key: Simple {                             key: "name",                             py_key: Py(                                 0x00007fbf0134cf70,                             ),                             path: LookupPath(                                 [                                     S(                                         "name",                                         Py(                                             0x00007fbf0134cf30,                                         ),                                     ),                                 ],                             ),                         },                         name_py: Py(                             0x00007fbf0d356ea0,                         ),                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x00007fbf0d3530c0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Str(                                     StrValidator {                                         strict: false,                                         coerce_numbers_to_str: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[str]",                                 undefined: Py(                                     0x00007fbf0b1fa570,                                 ),                             },                         ),                         frozen: false,                     },                     Field {                         name: "lexer",                         lookup_key: Simple {                             key: "lexer",                             py_key: Py(                                 0x00007fbf0134cfb0,                             ),                             path: LookupPath(                                 [                                     S(                                         "lexer",                                         Py(                                             0x00007fbf0134cff0,                                         ),                                     ),                                 ],                             ),                         },                         name_py: Py(                             0x00007fbf0c289270,                         ),                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x00007fbf0bff53f0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Str(                                     StrValidator {                                         strict: false,                                         coerce_numbers_to_str: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[str]",                                 undefined: Py(                                     0x00007fbf0b1fa570,                                 ),                             },                         ),                         frozen: false,                     },                 ],                 model_name: "PasteFile",                 extra_behavior: Ignore,                 extras_validator: None,                 strict: false,                 from_attributes: false,                 loc_by_alias: true,             },         ),         class: Py(             0x0000561875317b50,         ),         generic_origin: None,         post_init: None,         frozen: false,         custom_init: false,         root_model: false,         undefined: Py(             0x00007fbf0b1fa570,         ),         name: "PasteFile",     }, ), definitions=[], cache_strings=True)

The pydantic-core SchemaValidator used to validate instances of the model.

__signature__: ClassVar[Signature] = <Signature (*, content: str, name: str = '', lexer: str = 'python') -> None>

The synthesized __init__ [Signature][inspect.Signature] of the model.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class PasteResponse(**data)[source]

Bases: BaseModel

A successful response from the paste service.

Parameters:
  • link (str) – The URL to the saved paste.

  • removal (str) – The URL to delete the saved paste.

__class_vars__: ClassVar[set[str]] = {}

The names of the class variables defined on the model.

__private_attributes__: ClassVar[Dict[str, ModelPrivateAttr]] = {}

Metadata about the private attributes of the model.

__pydantic_complete__: ClassVar[bool] = True

Whether model building is completed, or if there are still undefined fields.

__pydantic_computed_fields__: ClassVar[Dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding [ComputedFieldInfo][pydantic.fields.ComputedFieldInfo] objects.

__pydantic_core_schema__: ClassVar[CoreSchema] = {'cls': <class 'pydis_core.utils.paste_service.PasteResponse'>, 'config': {'title': 'PasteResponse'}, 'custom_init': False, 'metadata': {'pydantic_js_functions': [<bound method BaseModel.__get_pydantic_json_schema__ of <class 'pydis_core.utils.paste_service.PasteResponse'>>]}, 'ref': 'pydis_core.utils.paste_service.PasteResponse:94663045373136', 'root_model': False, 'schema': {'computed_fields': [], 'fields': {'link': {'metadata': {}, 'schema': {'type': 'str'}, 'type': 'model-field'}, 'removal': {'metadata': {}, 'schema': {'type': 'str'}, 'type': 'model-field'}}, 'model_name': 'PasteResponse', 'type': 'model-fields'}, 'type': 'model'}

The core schema of the model.

__pydantic_custom_init__: ClassVar[bool] = False

Whether the model has a custom __init__ method.

__pydantic_decorators__: ClassVar[_decorators.DecoratorInfos] = DecoratorInfos(validators={}, field_validators={}, root_validators={}, field_serializers={}, model_serializers={}, model_validators={}, computed_fields={})

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

__pydantic_extra__: dict[str, Any] | None

A dictionary containing extra values, if [extra][pydantic.config.ConfigDict.extra] is set to ‘allow’.

__pydantic_fields__: ClassVar[Dict[str, FieldInfo]] = {'link': FieldInfo(annotation=str, required=True), 'removal': FieldInfo(annotation=str, required=True)}

A dictionary of field names and their corresponding [FieldInfo][pydantic.fields.FieldInfo] objects. This replaces Model.__fields__ from Pydantic V1.

__pydantic_fields_set__: set[str]

The names of fields explicitly set during instantiation.

__pydantic_generic_metadata__: ClassVar[_generics.PydanticGenericMetadata] = {'args': (), 'origin': None, 'parameters': ()}

Metadata for generic models; contains data used for a similar purpose to __args__, __origin__, __parameters__ in typing-module generics. May eventually be replaced by these.

__pydantic_parent_namespace__: ClassVar[Dict[str, Any] | None] = None

Parent namespace of the model, used for automatic rebuilding of models.

__pydantic_post_init__: ClassVar[None | Literal['model_post_init']] = None

The name of the post-init method for the model, if defined.

__pydantic_private__: dict[str, Any] | None

Values of private attributes set on the model instance.

__pydantic_serializer__: ClassVar[SchemaSerializer] = SchemaSerializer(serializer=Model(     ModelSerializer {         class: Py(             0x0000561875315cd0,         ),         serializer: Fields(             GeneralFieldsSerializer {                 fields: {                     "removal": SerField {                         key_py: Py(                             0x00007fbf01e2c9f0,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             Str(                                 StrSerializer,                             ),                         ),                         required: true,                     },                     "link": SerField {                         key_py: Py(                             0x00007fbf0d2ac2a0,                         ),                         alias: None,                         alias_py: None,                         serializer: Some(                             Str(                                 StrSerializer,                             ),                         ),                         required: true,                     },                 },                 computed_fields: Some(                     ComputedFields(                         [],                     ),                 ),                 mode: SimpleDict,                 extra_serializer: None,                 filter: SchemaFilter {                     include: None,                     exclude: None,                 },                 required_fields: 2,             },         ),         has_extra: false,         root_model: false,         name: "PasteResponse",     }, ), definitions=[])

The pydantic-core SchemaSerializer used to dump instances of the model.

__pydantic_validator__: ClassVar[SchemaValidator | PluggableSchemaValidator] = SchemaValidator(title="PasteResponse", validator=Model(     ModelValidator {         revalidate: Never,         validator: ModelFields(             ModelFieldsValidator {                 fields: [                     Field {                         name: "link",                         lookup_key: Simple {                             key: "link",                             py_key: Py(                                 0x00007fbf0136bcb0,                             ),                             path: LookupPath(                                 [                                     S(                                         "link",                                         Py(                                             0x00007fbf0136bc70,                                         ),                                     ),                                 ],                             ),                         },                         name_py: Py(                             0x00007fbf0d2ac2a0,                         ),                         validator: Str(                             StrValidator {                                 strict: false,                                 coerce_numbers_to_str: false,                             },                         ),                         frozen: false,                     },                     Field {                         name: "removal",                         lookup_key: Simple {                             key: "removal",                             py_key: Py(                                 0x00007fbf0136bd30,                             ),                             path: LookupPath(                                 [                                     S(                                         "removal",                                         Py(                                             0x00007fbf0136bcf0,                                         ),                                     ),                                 ],                             ),                         },                         name_py: Py(                             0x00007fbf01e2c9f0,                         ),                         validator: Str(                             StrValidator {                                 strict: false,                                 coerce_numbers_to_str: false,                             },                         ),                         frozen: false,                     },                 ],                 model_name: "PasteResponse",                 extra_behavior: Ignore,                 extras_validator: None,                 strict: false,                 from_attributes: false,                 loc_by_alias: true,             },         ),         class: Py(             0x0000561875315cd0,         ),         generic_origin: None,         post_init: None,         frozen: false,         custom_init: false,         root_model: false,         undefined: Py(             0x00007fbf0b1fa570,         ),         name: "PasteResponse",     }, ), definitions=[], cache_strings=True)

The pydantic-core SchemaValidator used to validate instances of the model.

__signature__: ClassVar[Signature] = <Signature (*, link: str, removal: str) -> None>

The synthesized __init__ [Signature][inspect.Signature] of the model.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

exception PasteTooLongError[source]

Bases: Exception

Raised when content is too large to upload to the paste service.

exception PasteUnsupportedLexerError[source]

Bases: Exception

Raised when an unsupported lexer is used.

exception PasteUploadError[source]

Bases: Exception

Raised when an error is encountered uploading to the paste service.

async send_to_paste_service(*, files, http_session, paste_url='https://paste.pythondiscord.com', max_size=524288)[source]

Upload some contents to the paste service.

Parameters:
  • files (list[PasteFile]) – The files to be uploaded to the paste service.

  • http_session (aiohttp.ClientSession) – The session to use when POSTing the content to the paste service.

  • paste_url (str) – The base url to the paste service.

  • max_size (int) – The max number of bytes to be allowed. Anything larger than MAX_PASTE_SIZE will be rejected.

Raises:
Return type:

PasteResponse

Returns:

A pydantic model containing both the URL of the paste, and a URL to remove the paste.