paste_service¶
- class PasteFile(**data)[source]¶
Bases:
BaseModel
A file to be pasted to the paste service.
- Parameters:
- __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:94903252981328', '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( 0x0000565062ae9650, ), serializer: Fields( GeneralFieldsSerializer { fields: { "content": SerField { key_py: Py( 0x00007f9bab3679f0, ), alias: None, alias_py: None, serializer: Some( Str( StrSerializer, ), ), required: true, }, "name": SerField { key_py: Py( 0x00007f9bac156ea0, ), alias: None, alias_py: None, serializer: Some( WithDefault( WithDefaultSerializer { default: Default( Py( 0x00007f9bac1530c0, ), ), serializer: Str( StrSerializer, ), }, ), ), required: true, }, "lexer": SerField { key_py: Py( 0x00007f9bab09d330, ), alias: None, alias_py: None, serializer: Some( WithDefault( WithDefaultSerializer { default: Default( Py( 0x00007f9baae09470, ), ), 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( 0x00007f9ba4814a70, ), path: LookupPath( [ S( "content", Py( 0x00007f9ba4814a30, ), ), ], ), }, name_py: Py( 0x00007f9bab3679f0, ), validator: Str( StrValidator { strict: false, coerce_numbers_to_str: false, }, ), frozen: false, }, Field { name: "name", lookup_key: Simple { key: "name", py_key: Py( 0x00007f9ba4814af0, ), path: LookupPath( [ S( "name", Py( 0x00007f9ba4814ab0, ), ), ], ), }, name_py: Py( 0x00007f9bac156ea0, ), validator: WithDefault( WithDefaultValidator { default: Default( Py( 0x00007f9bac1530c0, ), ), on_error: Raise, validator: Str( StrValidator { strict: false, coerce_numbers_to_str: false, }, ), validate_default: false, copy_default: false, name: "default[str]", undefined: Py( 0x00007f9baa04a570, ), }, ), frozen: false, }, Field { name: "lexer", lookup_key: Simple { key: "lexer", py_key: Py( 0x00007f9ba4814b30, ), path: LookupPath( [ S( "lexer", Py( 0x00007f9ba4814b70, ), ), ], ), }, name_py: Py( 0x00007f9bab09d330, ), validator: WithDefault( WithDefaultValidator { default: Default( Py( 0x00007f9baae09470, ), ), on_error: Raise, validator: Str( StrValidator { strict: false, coerce_numbers_to_str: false, }, ), validate_default: false, copy_default: false, name: "default[str]", undefined: Py( 0x00007f9baa04a570, ), }, ), frozen: false, }, ], model_name: "PasteFile", extra_behavior: Ignore, extras_validator: None, strict: false, from_attributes: false, loc_by_alias: true, }, ), class: Py( 0x0000565062ae9650, ), generic_origin: None, post_init: None, frozen: false, custom_init: false, root_model: false, undefined: Py( 0x00007f9baa04a570, ), 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:
- __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:94903253382032', '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( 0x0000565062b4b390, ), serializer: Fields( GeneralFieldsSerializer { fields: { "link": SerField { key_py: Py( 0x00007f9bac0ac2a0, ), alias: None, alias_py: None, serializer: Some( Str( StrSerializer, ), ), required: true, }, "removal": SerField { key_py: Py( 0x00007f9ba52cc870, ), 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( 0x00007f9ba4827770, ), path: LookupPath( [ S( "link", Py( 0x00007f9ba4827730, ), ), ], ), }, name_py: Py( 0x00007f9bac0ac2a0, ), validator: Str( StrValidator { strict: false, coerce_numbers_to_str: false, }, ), frozen: false, }, Field { name: "removal", lookup_key: Simple { key: "removal", py_key: Py( 0x00007f9ba48277f0, ), path: LookupPath( [ S( "removal", Py( 0x00007f9ba48277b0, ), ), ], ), }, name_py: Py( 0x00007f9ba52cc870, ), 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( 0x0000565062b4b390, ), generic_origin: None, post_init: None, frozen: false, custom_init: false, root_model: false, undefined: Py( 0x00007f9baa04a570, ), 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 thanMAX_PASTE_SIZE
will be rejected.
- Raises:
ValueError –
max_length
greater than the maximum allowed by the paste service.PasteTooLongError –
contents
too long to upload.PasteUploadError – Uploading failed.
- Return type:
- Returns:
A pydantic model containing both the URL of the paste, and a URL to remove the paste.