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:94212475815296', '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_extra_info__: ClassVar[PydanticExtraInfo | None] = None

A wrapper around the __pydantic_extra__ annotation, if explicitly annotated on a model.

This is a private attribute, not meant to be used outside Pydantic.

__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': ()}

A dictionary containing metadata about generic Pydantic models.

The origin and args items map to the [__origin__][genericalias.__origin__] and [__args__][genericalias.__args__] attributes of [generic aliases][types-genericalias], and the parameter item maps to the __parameter__ attribute of generic classes.

__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=PolymorphismTrampoline(     PolymorphismTrampoline {         class: Py(             0x000055af8d278580,         ),         serializer: PolymorphismTrampoline(             PolymorphismTrampoline {                 class: Py(                     0x000055af8d278580,                 ),                 serializer: Model(                     ModelSerializer {                         class: Py(                             0x000055af8d278580,                         ),                         serializer: Fields(                             GeneralFieldsSerializer {                                 fields: {                                     "name": SerField {                                         key: "name",                                         alias: None,                                         serializer: Some(                                             WithDefault(                                                 WithDefaultSerializer {                                                     default: Default(                                                         Py(                                                             0x00007f46f36225d0,                                                         ),                                                     ),                                                     serializer: Str(                                                         StrSerializer,                                                     ),                                                 },                                             ),                                         ),                                         required: true,                                         serialize_by_alias: None,                                         serialization_exclude_if: None,                                     },                                     "lexer": SerField {                                         key: "lexer",                                         alias: None,                                         serializer: Some(                                             WithDefault(                                                 WithDefaultSerializer {                                                     default: Default(                                                         Py(                                                             0x00007f46f2f978d0,                                                         ),                                                     ),                                                     serializer: Str(                                                         StrSerializer,                                                     ),                                                 },                                             ),                                         ),                                         required: true,                                         serialize_by_alias: None,                                         serialization_exclude_if: None,                                     },                                     "content": SerField {                                         key: "content",                                         alias: None,                                         serializer: Some(                                             Str(                                                 StrSerializer,                                             ),                                         ),                                         required: true,                                         serialize_by_alias: None,                                         serialization_exclude_if: None,                                     },                                 },                                 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",                     },                 ),                 enabled_from_config: false,             },         ),         enabled_from_config: false,     }, ), definitions=[])

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

__pydantic_setattr_handlers__: ClassVar[Dict[str, Callable[[BaseModel, str, Any], None]]] = {}

__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__

__pydantic_validator__: ClassVar[SchemaValidator | PluggableSchemaValidator] = SchemaValidator(title="PasteFile", validator=Model(     ModelValidator {         revalidate: Never,         validator: ModelFields(             ModelFieldsValidator {                 fields: [                     Field {                         name: "content",                         lookup_path_collection: LookupPathCollection {                             by_name: LookupPath {                                 first_item: PathItemString(                                     "content",                                 ),                                 rest: [],                             },                             by_alias: [],                         },                         validator: Str(                             StrValidator {                                 strict: false,                                 coerce_numbers_to_str: false,                             },                         ),                         frozen: false,                     },                     Field {                         name: "name",                         lookup_path_collection: LookupPathCollection {                             by_name: LookupPath {                                 first_item: PathItemString(                                     "name",                                 ),                                 rest: [],                             },                             by_alias: [],                         },                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x00007f46f36225d0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Str(                                     StrValidator {                                         strict: false,                                         coerce_numbers_to_str: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[str]",                                 undefined: Py(                                     0x00007f46f1540c50,                                 ),                             },                         ),                         frozen: false,                     },                     Field {                         name: "lexer",                         lookup_path_collection: LookupPathCollection {                             by_name: LookupPath {                                 first_item: PathItemString(                                     "lexer",                                 ),                                 rest: [],                             },                             by_alias: [],                         },                         validator: WithDefault(                             WithDefaultValidator {                                 default: Default(                                     Py(                                         0x00007f46f2f978d0,                                     ),                                 ),                                 on_error: Raise,                                 validator: Str(                                     StrValidator {                                         strict: false,                                         coerce_numbers_to_str: false,                                     },                                 ),                                 validate_default: false,                                 copy_default: false,                                 name: "default[str]",                                 undefined: Py(                                     0x00007f46f1540c50,                                 ),                             },                         ),                         frozen: false,                     },                 ],                 model_name: "PasteFile",                 extra_behavior: Ignore,                 extras_validator: None,                 extras_keys_validator: None,                 strict: false,                 from_attributes: false,                 loc_by_alias: true,                 lookup: LookupTree {                     inner: {                         PathItemString(                             "name",                         ): LookupTreeNode {                             fields: [                                 LookupFieldInfo {                                     field_index: 1,                                     lookup_priority: LookupFieldPriority {                                         lookup_type: Both,                                         alias_index: 0,                                     },                                 },                             ],                             map: {},                             list: {},                         },                         PathItemString(                             "lexer",                         ): LookupTreeNode {                             fields: [                                 LookupFieldInfo {                                     field_index: 2,                                     lookup_priority: LookupFieldPriority {                                         lookup_type: Both,                                         alias_index: 0,                                     },                                 },                             ],                             map: {},                             list: {},                         },                         PathItemString(                             "content",                         ): LookupTreeNode {                             fields: [                                 LookupFieldInfo {                                     field_index: 0,                                     lookup_priority: LookupFieldPriority {                                         lookup_type: Both,                                         alias_index: 0,                                     },                                 },                             ],                             map: {},                             list: {},                         },                     },                 },                 validate_by_alias: None,                 validate_by_name: None,             },         ),         class: Py(             0x000055af8d278580,         ),         generic_origin: None,         post_init: None,         frozen: false,         custom_init: false,         root_model: false,         undefined: Py(             0x00007f46f1540c50,         ),         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:94212477246176', '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_extra_info__: ClassVar[PydanticExtraInfo | None] = None

A wrapper around the __pydantic_extra__ annotation, if explicitly annotated on a model.

This is a private attribute, not meant to be used outside Pydantic.

__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': ()}

A dictionary containing metadata about generic Pydantic models.

The origin and args items map to the [__origin__][genericalias.__origin__] and [__args__][genericalias.__args__] attributes of [generic aliases][types-genericalias], and the parameter item maps to the __parameter__ attribute of generic classes.

__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=PolymorphismTrampoline(     PolymorphismTrampoline {         class: Py(             0x000055af8d3d5ae0,         ),         serializer: PolymorphismTrampoline(             PolymorphismTrampoline {                 class: Py(                     0x000055af8d3d5ae0,                 ),                 serializer: Model(                     ModelSerializer {                         class: Py(                             0x000055af8d3d5ae0,                         ),                         serializer: Fields(                             GeneralFieldsSerializer {                                 fields: {                                     "removal": SerField {                                         key: "removal",                                         alias: None,                                         serializer: Some(                                             Str(                                                 StrSerializer,                                             ),                                         ),                                         required: true,                                         serialize_by_alias: None,                                         serialization_exclude_if: None,                                     },                                     "link": SerField {                                         key: "link",                                         alias: None,                                         serializer: Some(                                             Str(                                                 StrSerializer,                                             ),                                         ),                                         required: true,                                         serialize_by_alias: None,                                         serialization_exclude_if: None,                                     },                                 },                                 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",                     },                 ),                 enabled_from_config: false,             },         ),         enabled_from_config: false,     }, ), definitions=[])

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

__pydantic_setattr_handlers__: ClassVar[Dict[str, Callable[[BaseModel, str, Any], None]]] = {}

__setattr__ handlers. Memoizing the handlers leads to a dramatic performance improvement in __setattr__

__pydantic_validator__: ClassVar[SchemaValidator | PluggableSchemaValidator] = SchemaValidator(title="PasteResponse", validator=Model(     ModelValidator {         revalidate: Never,         validator: ModelFields(             ModelFieldsValidator {                 fields: [                     Field {                         name: "link",                         lookup_path_collection: LookupPathCollection {                             by_name: LookupPath {                                 first_item: PathItemString(                                     "link",                                 ),                                 rest: [],                             },                             by_alias: [],                         },                         validator: Str(                             StrValidator {                                 strict: false,                                 coerce_numbers_to_str: false,                             },                         ),                         frozen: false,                     },                     Field {                         name: "removal",                         lookup_path_collection: LookupPathCollection {                             by_name: LookupPath {                                 first_item: PathItemString(                                     "removal",                                 ),                                 rest: [],                             },                             by_alias: [],                         },                         validator: Str(                             StrValidator {                                 strict: false,                                 coerce_numbers_to_str: false,                             },                         ),                         frozen: false,                     },                 ],                 model_name: "PasteResponse",                 extra_behavior: Ignore,                 extras_validator: None,                 extras_keys_validator: None,                 strict: false,                 from_attributes: false,                 loc_by_alias: true,                 lookup: LookupTree {                     inner: {                         PathItemString(                             "removal",                         ): LookupTreeNode {                             fields: [                                 LookupFieldInfo {                                     field_index: 1,                                     lookup_priority: LookupFieldPriority {                                         lookup_type: Both,                                         alias_index: 0,                                     },                                 },                             ],                             map: {},                             list: {},                         },                         PathItemString(                             "link",                         ): LookupTreeNode {                             fields: [                                 LookupFieldInfo {                                     field_index: 0,                                     lookup_priority: LookupFieldPriority {                                         lookup_type: Both,                                         alias_index: 0,                                     },                                 },                             ],                             map: {},                             list: {},                         },                     },                 },                 validate_by_alias: None,                 validate_by_name: None,             },         ),         class: Py(             0x000055af8d3d5ae0,         ),         generic_origin: None,         post_init: None,         frozen: false,         custom_init: false,         root_model: false,         undefined: Py(             0x00007f46f1540c50,         ),         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.