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


Python DictUtils.cleanDictKeys方法代码示例

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


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

示例1: fromMessage

# 需要导入模块: from pyaid.dict.DictUtils import DictUtils [as 别名]
# 或者: from pyaid.dict.DictUtils.DictUtils import cleanDictKeys [as 别名]
    def fromMessage(cls, message):
        if not message:
            return None

        try:
            if NimbleEnvironment.ENABLE_COMPRESSION:
                message = zlib.decompress(message)
            data = json.loads(message.replace(NimbleData._NEWLINE_ESCAPE, '\n').strip())
        except Exception as err:
            print('Corrupt Nimble Data:')
            print(str(message))
            print(err)
            return None

        data      = DictUtils.cleanDictKeys(data)
        className = data['class']
        if className == cls.__name__:
            return NimbleData(**data)

        module = ''
        try:
            module  = '.'.join(cls.__module__.split('.')[:-1]) + '.' + className
            res     = __import__(module, globals(), locals(), [className])
            Source  = getattr(res, className)
            return Source(**data)
        except Exception as err:
            print('Invalid Nimble data:')
            print('ERROR: ', err)
            print('MESSAGE:', message)
            print('DATA:', data)
            print('CLASS:', className)
            print('MODULE:', module)

        return None
开发者ID:sernst,项目名称:Nimble,代码行数:36,代码来源:NimbleData.py

示例2: _instantiateClass

# 需要导入模块: from pyaid.dict.DictUtils import DictUtils [as 别名]
# 或者: from pyaid.dict.DictUtils.DictUtils import cleanDictKeys [as 别名]
    def _instantiateClass(self, Target, command):
        k       = 'constructorArgs'
        conArgs = command[k] if k in command else None

        k         = 'constructorKwargs'
        conKwargs = command[k] if k in command else None

        if conArgs and conKwargs:
            targetObject = Target(*conArgs, **DictUtils.cleanDictKeys(conKwargs))
        elif conArgs:
            targetObject = Target(*conArgs)
        elif conKwargs:
            targetObject = Target(**DictUtils.cleanDictKeys(conKwargs))
        else:
            targetObject = Target()

        return targetObject
开发者ID:Gorfaal,项目名称:Nimble,代码行数:19,代码来源:MayaRouter.py

示例3: _executeCommand

# 需要导入模块: from pyaid.dict.DictUtils import DictUtils [as 别名]
# 或者: from pyaid.dict.DictUtils.DictUtils import cleanDictKeys [as 别名]
    def _executeCommand(cls, payload):
        cmd = payload['command']
        if cmd is None or (StringUtils.isStringType(cmd) and not cmd in globals()):
            return NimbleResponseData(
                    kind=DataKindEnum.COMMAND,
                    response=NimbleResponseData.FAILED_RESPONSE,
                    error=DataErrorEnum.INVALID_COMMAND )

        if StringUtils.isStringType(cmd):
            targetObject = globals().get(cmd)
        else:
            if isinstance(cmd, dict):
                module = str(cmd['module'])
                target = str(cmd['target'])
                method = str(cmd['method']) if 'method' in cmd else None
            else:
                target = str(cmd[0])
                module = str(cmd[1]) if len(cmd) > 0 else None
                method = str(cmd[2]) if len(cmd) > 1 else None

            try:
                res    = __import__(module, globals(), locals(), [target])
                Target = getattr(res, target)
                if method:
                    m = getattr(Target, method)
                    if m is None:
                        raise Exception(
                            '%s not found on %s. Unable to execute command.' % \
                            (str(method), str(target) ))
            except Exception as err:
                return NimbleResponseData(
                    kind=DataKindEnum.COMMAND,
                    response=NimbleResponseData.FAILED_RESPONSE,
                    error=cls._getDetailedError(
                        'Failed to import remote command module', err) )

            if method:
                targetObject = getattr(Target, method)
                if inspect.ismethod(targetObject) and targetObject.__self__ is None:
                    targetObject = getattr(cls._instantiateClass(Target, cmd), method)
            elif inspect.isclass(Target):
                targetObject = cls._instantiateClass(Target, cmd)
            else:
                targetObject = Target

        try:
            result = targetObject(
                *payload['args'],
                **DictUtils.cleanDictKeys(payload['kwargs']) )
            return cls.createReply(DataKindEnum.COMMAND, result)
        except Exception as err:
            return NimbleResponseData(
                kind=DataKindEnum.COMMAND,
                response=NimbleResponseData.FAILED_RESPONSE,
                error=cls._getDetailedError('Failed to execute command', err) )
开发者ID:sernst,项目名称:Nimble,代码行数:57,代码来源:MayaRouter.py

示例4: _executeMayaCommand

# 需要导入模块: from pyaid.dict.DictUtils import DictUtils [as 别名]
# 或者: from pyaid.dict.DictUtils.DictUtils import cleanDictKeys [as 别名]
    def _executeMayaCommand(cls, payload, createReply=True):
        cmd = getattr(mc, str(payload["command"]), None)
        if cmd is None:
            return NimbleResponseData(
                kind=DataKindEnum.MAYA_COMMAND,
                error=DataErrorEnum.UNRECOGNIZED_MAYA_COMMAND,
                response=NimbleResponseData.FAILED_RESPONSE,
            )

        try:
            result = cmd(*payload["args"], **DictUtils.cleanDictKeys(payload["kwargs"]))
            if createReply:
                return cls.createReply(DataKindEnum.MAYA_COMMAND, result)
            else:
                return result
        except Exception as err:
            return NimbleResponseData(
                kind=DataKindEnum.MAYA_COMMAND, error=str(err), response=NimbleResponseData.FAILED_RESPONSE
            )
开发者ID:leonsooi,项目名称:Nimble,代码行数:21,代码来源:MayaRouter.py

示例5: _executeMayaCommand

# 需要导入模块: from pyaid.dict.DictUtils import DictUtils [as 别名]
# 或者: from pyaid.dict.DictUtils.DictUtils import cleanDictKeys [as 别名]
    def _executeMayaCommand(cls, payload, createReply =True):
        cmd = getattr(mc, str(payload['command']), None)
        if cmd is None:
            return NimbleResponseData(
                kind=DataKindEnum.MAYA_COMMAND,
                error=DataErrorEnum.UNRECOGNIZED_MAYA_COMMAND,
                response=NimbleResponseData.FAILED_RESPONSE )

        args = None
        kwargs = None
        try:
            kwargs = DictUtils.cleanDictKeys(payload['kwargs'], True)
            args = payload['args']

            try:
                result = cmd(*args, **kwargs)
            except Exception:
                # Attempts to remove an empty key if one is somehow created
                if '' in kwargs:
                    del kwargs['']
                else:
                    raise
                result = cmd(*args, **kwargs)

            if createReply:
                return cls.createReply(DataKindEnum.MAYA_COMMAND, result)
            else:
                return result
        except Exception as err:
            print('ERROR:', cmd, args, kwargs)
            message = '\n'.join([
                'Failed to execute maya command with payload:',
                'CMD {}'.format(cmd),
                'PAYLOAD: {}'.format(DictUtils.prettyPrint(payload)),
                'ARGS: {}'.format(args),
                'KWARGS: {}'.format(DictUtils.prettyPrint(kwargs)) ])

            return NimbleResponseData(
                kind=DataKindEnum.MAYA_COMMAND,
                error=cls._getDetailedError(message, err),
                response=NimbleResponseData.FAILED_RESPONSE )
开发者ID:sernst,项目名称:Nimble,代码行数:43,代码来源:MayaRouter.py


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