Python marshmallow.fields.UUID Examples
The following are 5
code examples of marshmallow.fields.UUID().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
marshmallow.fields
, or try the search function
.
Example #1
Source File: convert.py From lux with BSD 3-Clause "New" or "Revised" License | 6 votes |
def _add_column_kwargs(self, kwargs, column): """Add keyword arguments to kwargs (in-place) based on the passed in `Column <sqlalchemy.schema.Column>`. """ if column.nullable: kwargs['allow_none'] = True kwargs['required'] = not column.nullable and not _has_default(column) if hasattr(column.type, 'enums'): kwargs['validate'].append(validate.OneOf(choices=column.type.enums)) # Add a length validator if a max length is set on the column # Skip UUID columns # (see https://github.com/marshmallow-code/marshmallow-sqlalchemy/issues/54) if hasattr(column.type, 'length'): try: python_type = column.type.python_type except (AttributeError, NotImplementedError): python_type = None if not python_type or not issubclass(python_type, uuid.UUID): kwargs['validate'].append(validate.Length(max=column.type.length)) if hasattr(column.type, 'scale'): kwargs['places'] = getattr(column.type, 'scale', None)
Example #2
Source File: test_class_schema.py From marshmallow_dataclass with MIT License | 6 votes |
def test_use_type_mapping_from_base_schema(self): class CustomType: pass class CustomField(Field): pass class CustomListField(ListField): pass class BaseSchema(Schema): TYPE_MAPPING = {CustomType: CustomField, typing.List: CustomListField} @dataclasses.dataclass class WithCustomField: custom: CustomType custom_list: typing.List[float] uuid: UUID n: int schema = class_schema(WithCustomField, base_schema=BaseSchema)() self.assertIsInstance(schema.fields["custom"], CustomField) self.assertIsInstance(schema.fields["custom_list"], CustomListField) self.assertIsInstance(schema.fields["uuid"], UUIDField) self.assertIsInstance(schema.fields["n"], Integer)
Example #3
Source File: test_scheme_from_target.py From marshmallow-annotations with MIT License | 5 votes |
def test_autogenerates_fields(registry_): class SomeTypeThingScheme(AnnotationSchema): class Meta: registry = registry_ target = SomeTypeThing registry = registry_ scheme_fields = SomeTypeThingScheme._declared_fields assert isinstance(scheme_fields["id"], fields.UUID) assert isinstance(scheme_fields["name"], fields.String) assert not scheme_fields["name"].required assert scheme_fields["name"].allow_none
Example #4
Source File: instrument.py From pyrh with MIT License | 5 votes |
def instrument( self, symbol: Optional[str] = None, id_: Optional[str] = None ) -> Instrument: """Get a single instrument using a provided query parameter. Note: The input parameters are mutually exclusive. Additionally, if you query a hidden symbol it will return emtpy. The only way to view hidden symbols is to use the instruments endpoint. Args: symbol: A ticker symbol id_: A UUID that represents an instrument Returns: A single instance of an `Instrument` Raises: PyrhValueError: Neither of the input kwargs are passed in. """ if any(opt is not None for opt in [symbol, id_]): return cast( Instrument, self.get( urls.instruments(symbol=symbol, id_=id_), schema=InstrumentSchema() ), ) else: raise PyrhValueError("No valid options were provided.")
Example #5
Source File: failurereason.py From zeus with Apache License 2.0 | 5 votes |
def process_aggregates(self, data, **kwargs): return { "reason": data.reason, "runs": [ {"id": UUID(e[0]), "job_id": UUID(e[1]) if e[1] else None} for e in sorted( data.runs, key=lambda e: UUID(e[1]) if e[1] else 0, reverse=True ) ], }