当前位置: 首页>>代码示例>>Python>>正文


Python fields.UUID属性代码示例

本文整理汇总了Python中marshmallow.fields.UUID属性的典型用法代码示例。如果您正苦于以下问题:Python fields.UUID属性的具体用法?Python fields.UUID怎么用?Python fields.UUID使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在marshmallow.fields的用法示例。


在下文中一共展示了fields.UUID属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _add_column_kwargs

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import UUID [as 别名]
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) 
开发者ID:quantmind,项目名称:lux,代码行数:26,代码来源:convert.py

示例2: test_use_type_mapping_from_base_schema

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import UUID [as 别名]
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) 
开发者ID:lovasoa,项目名称:marshmallow_dataclass,代码行数:27,代码来源:test_class_schema.py

示例3: test_autogenerates_fields

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import UUID [as 别名]
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 
开发者ID:justanr,项目名称:marshmallow-annotations,代码行数:15,代码来源:test_scheme_from_target.py

示例4: instrument

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import UUID [as 别名]
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.") 
开发者ID:robinhood-unofficial,项目名称:pyrh,代码行数:32,代码来源:instrument.py

示例5: process_aggregates

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import UUID [as 别名]
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
                )
            ],
        } 
开发者ID:getsentry,项目名称:zeus,代码行数:12,代码来源:failurereason.py


注:本文中的marshmallow.fields.UUID属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。