當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。