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


Python cattr.unstructure方法代码示例

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


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

示例1: _serialize_operator_extra_links

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def _serialize_operator_extra_links(
        cls,
        operator_extra_links: Iterable[BaseOperatorLink]
    ):
        """
        Serialize Operator Links. Store the import path of the OperatorLink and the arguments
        passed to it. Example
        ``[{'airflow.providers.google.cloud.operators.bigquery.BigQueryConsoleLink': {}}]``

        :param operator_extra_links: Operator Link
        :return: Serialized Operator Link
        """
        serialize_operator_extra_links = []
        for operator_extra_link in operator_extra_links:
            op_link_arguments = cattr.unstructure(operator_extra_link)
            if not isinstance(op_link_arguments, dict):
                op_link_arguments = {}
            serialize_operator_extra_links.append(
                {
                    "{}.{}".format(operator_extra_link.__class__.__module__,
                                   operator_extra_link.__class__.__name__): op_link_arguments
                }
            )

        return serialize_operator_extra_links 
开发者ID:apache,项目名称:airflow,代码行数:27,代码来源:serialized_objects.py

示例2: main

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def main() -> None:
    args = parse_args()
    print(
        f"Converting {args.trainer_config_path} and saving to {args.output_config_path}."
    )

    old_config = load_config(args.trainer_config_path)
    behavior_config_dict = convert_behaviors(old_config)
    full_config = {"behaviors": behavior_config_dict}

    # Convert curriculum and sampler. note that we don't validate these; if it was correct
    # before it should be correct now.
    if args.curriculum is not None:
        curriculum_config_dict = load_config(args.curriculum)
        full_config["curriculum"] = curriculum_config_dict

    if args.sampler is not None:
        sampler_config_dict = load_config(args.sampler)
        full_config["parameter_randomization"] = sampler_config_dict

    # Convert config to dict
    unstructed_config = cattr.unstructure(full_config)
    unstructed_config = remove_nones(unstructed_config)
    write_to_yaml_file(unstructed_config, args.output_config_path) 
开发者ID:StepNeverStop,项目名称:RLs,代码行数:26,代码来源:upgrade_config.py

示例3: unstructure_hook

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def unstructure_hook(api_model):
    """cattr unstructure hook

    Map reserved_ words in models to correct json field names.
    Also handle stripping None fields from dict while setting
    EXPLICIT_NULL fields to None so that we only send null
    in the json for fields the caller set EXPLICIT_NULL on.
    """
    data = cattr.global_converter.unstructure_attrs_asdict(api_model)
    for key, value in data.copy().items():
        if value is None:
            del data[key]
        elif value == model.EXPLICIT_NULL:
            data[key] = None
    for reserved in keyword.kwlist:
        if f"{reserved}_" in data:
            data[reserved] = data.pop(f"{reserved}_")
    return data 
开发者ID:looker-open-source,项目名称:sdk-codegen,代码行数:20,代码来源:serialize.py

示例4: _send_first_wht_confirmation

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def _send_first_wht_confirmation(self, event: EventData) -> None:
        """Send first confirmation of a warehouse task."""
        if isinstance(self.active_wht, WarehouseTask):
            confirmation = ConfirmWarehouseTask(
                lgnum=self.active_wht.lgnum, tanum=self.active_wht.tanum,
                rsrc=self.robot_config.rsrc, who=self.active_wht.who,
                confirmationnumber=ConfirmWarehouseTask.FIRST_CONF,
                confirmationtype=ConfirmWarehouseTask.CONF_SUCCESS)

            self.order_controller.confirm_wht(unstructure(confirmation))

            _LOGGER.info(
                'First confirmation for warehouse task %s of warehouse order %s sent to order '
                'manager', self.active_wht.tanum, self.active_wht.who)

            # Delete source information from warehouse task of active warehouse order
            if isinstance(self.active_who, WarehouseOrder):
                for i, wht in enumerate(self.active_who.warehousetasks):
                    if wht.tanum == self.active_wht.tanum:
                        self.active_who.warehousetasks[i].vltyp = ''
                        self.active_who.warehousetasks[i].vlber = ''
                        self.active_who.warehousetasks[i].vlpla = ''
        else:
            raise TypeError('No warehouse task assigned to self.active_wht') 
开发者ID:SAP,项目名称:ewm-cloud-robotics,代码行数:26,代码来源:statemachine.py

示例5: _send_second_wht_confirmation

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def _send_second_wht_confirmation(self, event: EventData) -> None:
        """Send second confirmation of a warehouse task."""
        if isinstance(self.active_wht, WarehouseTask):
            confirmation = ConfirmWarehouseTask(
                lgnum=self.active_wht.lgnum, tanum=self.active_wht.tanum,
                rsrc=self.robot_config.rsrc, who=self.active_wht.who,
                confirmationnumber=ConfirmWarehouseTask.SECOND_CONF,
                confirmationtype=ConfirmWarehouseTask.CONF_SUCCESS)

            self.order_controller.confirm_wht(unstructure(confirmation))

            _LOGGER.info(
                'Second confirmation for warehouse task %s of warehouse order %s sent to order '
                'manager', self.active_wht.tanum, self.active_wht.who)
        else:
            raise TypeError('No warehouse task assigned to self.active_wht') 
开发者ID:SAP,项目名称:ewm-cloud-robotics,代码行数:18,代码来源:statemachine.py

示例6: _send_first_wht_confirmation_error

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def _send_first_wht_confirmation_error(self, event: EventData) -> None:
        """Send first confirmation error of a warehouse task."""
        if isinstance(self.active_wht, WarehouseTask):
            confirmation = ConfirmWarehouseTask(
                lgnum=self.active_wht.lgnum, tanum=self.active_wht.tanum,
                rsrc=self.robot_config.rsrc, who=self.active_wht.who,
                confirmationnumber=ConfirmWarehouseTask.FIRST_CONF,
                confirmationtype=ConfirmWarehouseTask.CONF_ERROR)

            self.order_controller.confirm_wht(unstructure(confirmation))

            _LOGGER.info(
                'First confirmation error for warehouse task %s of warehouse order %s sent to '
                'order manager', self.active_wht.tanum, self.active_wht.who)
        else:
            raise TypeError('No warehouse task assigned to self.active_wht') 
开发者ID:SAP,项目名称:ewm-cloud-robotics,代码行数:18,代码来源:statemachine.py

示例7: _request_who_confirmation_notification

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def _request_who_confirmation_notification(self, event: EventData) -> None:
        """
        Send a warehouse order completion request to EWM Order Manager.

        It notifies the robot when the warehouse order was completed.
        """
        if isinstance(self.active_who, WarehouseOrder):
            request = RequestFromRobot(
                self.robot_config.conf.lgnum, self.robot_config.rsrc,
                notifywhocompletion=self.active_who.who)

            self.robotrequest_controller.send_robot_request(unstructure(request))

            _LOGGER.info(
                'Requesting warehouse order completion notification for %s from order manager',
                self.active_who.who)
        else:
            raise TypeError('No warehouse order object in self.active_who') 
开发者ID:SAP,项目名称:ewm-cloud-robotics,代码行数:20,代码来源:statemachine.py

示例8: _render_object

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def _render_object(obj: Any, context) -> Any:
    """
    Renders a attr annotated object. Will set non serializable attributes to none
    """
    return structure(json.loads(ENV.from_string(
        json.dumps(unstructure(obj), default=lambda o: None)
    ).render(**context).encode('utf-8')), type(obj)) 
开发者ID:apache,项目名称:airflow,代码行数:9,代码来源:__init__.py

示例9: _to_dataset

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def _to_dataset(obj: Any, source: str) -> Optional[Metadata]:
    """
    Create Metadata from attr annotated object
    """
    if not attr.has(obj):
        return None

    type_name = obj.__module__ + '.' + obj.__class__.__name__
    data = unstructure(obj)

    return Metadata(type_name, source, data) 
开发者ID:apache,项目名称:airflow,代码行数:13,代码来源:__init__.py

示例10: apply_lineage

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def apply_lineage(func):
    """
    Saves the lineage to XCom and if configured to do so sends it
    to the backend.
    """

    @wraps(func)
    def wrapper(self, context, *args, **kwargs):
        self.log.debug("Lineage called with inlets: %s, outlets: %s",
                       self.inlets, self.outlets)
        ret_val = func(self, context, *args, **kwargs)

        outlets = [unstructure(_to_dataset(x, f"{self.dag_id}.{self.task_id}"))
                   for x in self.outlets]
        inlets = [unstructure(_to_dataset(x, None))
                  for x in self.inlets]

        if self.outlets:
            self.xcom_push(context,
                           key=PIPELINE_OUTLETS,
                           value=outlets,
                           execution_date=context['ti'].execution_date)

        if self.inlets:
            self.xcom_push(context,
                           key=PIPELINE_INLETS,
                           value=inlets,
                           execution_date=context['ti'].execution_date)

        return ret_val

    return wrapper 
开发者ID:apache,项目名称:airflow,代码行数:34,代码来源:__init__.py

示例11: defaultdict_to_dict

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def defaultdict_to_dict(d: DefaultDict) -> Dict:
    return {key: cattr.unstructure(val) for key, val in d.items()} 
开发者ID:StepNeverStop,项目名称:RLs,代码行数:4,代码来源:settings.py

示例12: as_dict

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def as_dict(self):
        return cattr.unstructure(self) 
开发者ID:StepNeverStop,项目名称:RLs,代码行数:4,代码来源:settings.py

示例13: to_dict

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def to_dict(self) -> Dict[str, str]:
        return cattr.unstructure(self) 
开发者ID:StepNeverStop,项目名称:RLs,代码行数:4,代码来源:training_status.py

示例14: serialize

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def serialize(api_model: TModelOrSequence) -> bytes:
    """Translate api_model into formdata encoded json bytes
    """
    data = cattr.unstructure(api_model)  # type: ignore
    return json.dumps(data).encode("utf-8")  # type: ignore 
开发者ID:looker-open-source,项目名称:sdk-codegen,代码行数:7,代码来源:serialize.py

示例15: archive

# 需要导入模块: import cattr [as 别名]
# 或者: from cattr import unstructure [as 别名]
def archive(self, content):
        """
        Archive an object
        """

        if hasattr(content, 'name'):
            print("Archiving {0}".format(content.name))

        if content.name not in self._bloom_filter:
            self.archive_file.write(json.dumps(cattr.unstructure(content),
                                               indent=4,
                                               sort_keys=True) + "\n")

            self._bloom_filter.add(content.name)
        return 
开发者ID:weskerfoot,项目名称:DeleteFB,代码行数:17,代码来源:archive.py


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