當前位置: 首頁>>代碼示例>>Python>>正文


Python types.LambdaType方法代碼示例

本文整理匯總了Python中types.LambdaType方法的典型用法代碼示例。如果您正苦於以下問題:Python types.LambdaType方法的具體用法?Python types.LambdaType怎麽用?Python types.LambdaType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在types的用法示例。


在下文中一共展示了types.LambdaType方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _get_calculated_size

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def _get_calculated_size(self, size, data):
        """
        Get's the final size of the field and runs the lambda functions
        recursively until a final size is derived. If size is None then it
        will just return the length of the data as it is assumed it is the
        final field (None should only be set on size for the final field).

        :param size: The size to calculate/expand
        :param data: The data that the size is being calculated for
        :return: The final size
        """
        # if the size is derived from a lambda function, run it now; otherwise
        # return the value we passed in or the length of the data if the size
        # is None (last field value)
        if size is None:
            return len(data)
        elif isinstance(size, types.LambdaType):
            expanded_size = size(self.structure)
            return self._get_calculated_size(expanded_size, data)
        else:
            return size 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:23,代碼來源:structure.py

示例2: _parse_value

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def _parse_value(self, value):
        if value is None:
            int_value = 0
        elif isinstance(value, types.LambdaType):
            int_value = value
        elif isinstance(value, bytes):
            format = self._get_struct_format(self.size, self.unsigned)
            struct_string = "%s%s"\
                            % ("<" if self.little_endian else ">", format)
            int_value = struct.unpack(struct_string, value)[0]
        elif isinstance(value, integer_types):
            int_value = value
        else:
            raise TypeError("Cannot parse value for field %s of type %s to "
                            "an int" % (self.name, type(value).__name__))
        return int_value 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:18,代碼來源:structure.py

示例3: __init__

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def __init__(self, submit_config: submit.SubmitConfig, config_module: types.ModuleType = None, max_epoch: Any = None):
        self.submit_config = submit_config
        self.should_stop_flag = False
        self.has_closed = False
        self.start_time = time.time()
        self.last_update_time = time.time()
        self.last_update_interval = 0.0
        self.max_epoch = max_epoch

        # pretty print the all the relevant content of the config module to a text file
        if config_module is not None:
            with open(os.path.join(submit_config.run_dir, "config.txt"), "w") as f:
                filtered_dict = {k: v for k, v in config_module.__dict__.items() if not k.startswith("_") and not isinstance(v, (types.ModuleType, types.FunctionType, types.LambdaType, submit.SubmitConfig, type))}
                pprint.pprint(filtered_dict, stream=f, indent=4, width=200, compact=False)

        # write out details about the run to a text file
        self.run_txt_data = {"task_name": submit_config.task_name, "host_name": submit_config.host_name, "start_time": datetime.datetime.now().isoformat(sep=" ")}
        with open(os.path.join(submit_config.run_dir, "run.txt"), "w") as f:
            pprint.pprint(self.run_txt_data, stream=f, indent=4, width=200, compact=False) 
開發者ID:produvia,項目名稱:ai-platform,代碼行數:21,代碼來源:run_context.py

示例4: __init__

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def __init__(self,
                 interpreter,  # type: NaturalLanguageInterpreter
                 policy_ensemble,  # type: PolicyEnsemble
                 domain,  # type: Domain
                 tracker_store,  # type: TrackerStore
                 max_number_of_predictions=10,  # type: int
                 message_preprocessor=None,  # type: Optional[LambdaType]
                 on_circuit_break=None  # type: Optional[LambdaType]
                 ):
        self.interpreter = interpreter
        self.policy_ensemble = policy_ensemble
        self.domain = domain
        self.tracker_store = tracker_store
        self.max_number_of_predictions = max_number_of_predictions
        self.message_preprocessor = message_preprocessor
        self.on_circuit_break = on_circuit_break 
開發者ID:Rowl1ng,項目名稱:rasa_wechat,代碼行數:18,代碼來源:processor.py

示例5: get_field_type

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def get_field_type(self,field,name = None):
        m = {
            IntegerField : Integer,
            FloatField : Float,
            CharField : lambda field: String(length = field.length),
            EnumField : lambda field: Enum(*field.enums,name = name,native_enum = field.native_enum),
            TextField : Text,
            BooleanField: Boolean,
            BinaryField: LargeBinary,
            DateField: Date,
            DateTimeField: DateTime
        }
        for cls,t in m.items():
            if isinstance(field,cls):
                if isinstance(t,LambdaType):
                    return t(field)
                return t
        raise AttributeError("Invalid field type: %s" % field) 
開發者ID:adewes,項目名稱:blitzdb,代碼行數:20,代碼來源:backend.py

示例6: get_config

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def get_config(self):
        if isinstance(self.function, python_types.LambdaType):
            function = func_dump(self.function)
            function_type = 'lambda'
        else:
            function = self.function.__name__
            function_type = 'function'

        if isinstance(self._output_shape, python_types.LambdaType):
            output_shape = func_dump(self._output_shape)
            output_shape_type = 'lambda'
        elif callable(self._output_shape):
            output_shape = self._output_shape.__name__
            output_shape_type = 'function'
        else:
            output_shape = self._output_shape
            output_shape_type = 'raw'

        config = {'function': function,
                  'function_type': function_type,
                  'output_shape': output_shape,
                  'output_shape_type': output_shape_type,
                  'arguments': self.arguments}
        base_config = super(Lambda, self).get_config()
        return dict(list(base_config.items()) + list(config.items())) 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:27,代碼來源:core.py

示例7: __init__

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def __init__(self,
                 interpreter: NaturalLanguageInterpreter,
                 policy_ensemble: PolicyEnsemble,
                 domain: Domain,
                 tracker_store: TrackerStore,
                 generator: NaturalLanguageGenerator,
                 action_endpoint: Optional[EndpointConfig] = None,
                 max_number_of_predictions: int = 10,
                 message_preprocessor: Optional[LambdaType] = None,
                 on_circuit_break: Optional[LambdaType] = None,
                 ):
        self.interpreter = interpreter
        self.nlg = generator
        self.policy_ensemble = policy_ensemble
        self.domain = domain
        self.tracker_store = tracker_store
        self.max_number_of_predictions = max_number_of_predictions
        self.message_preprocessor = message_preprocessor
        self.on_circuit_break = on_circuit_break
        self.action_endpoint = action_endpoint 
開發者ID:RasaHQ,項目名稱:rasa_core,代碼行數:22,代碼來源:processor.py

示例8: new_looper

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def new_looper(a, arg=None):
    """Helper function for nest()
    determines what sort of looper to make given a's type"""
    if isinstance(a,types.TupleType):
        if len(a) == 2:
            return RangeLooper(a[0],a[1])
        elif len(a) == 3:
            return RangeLooper(a[0],a[1],a[2])
    elif isinstance(a, types.BooleanType):
        return BooleanLooper(a)
    elif isinstance(a,types.IntType) or isinstance(a, types.LongType):
        return RangeLooper(a)
    elif isinstance(a, types.StringType) or isinstance(a, types.ListType):
        return ListLooper(a)
    elif isinstance(a, Looper):
        return a
    elif isinstance(a, types.LambdaType):
        return CalcField(a, arg) 
開發者ID:ActiveState,項目名稱:code,代碼行數:20,代碼來源:recipe-473818.py

示例9: test_set_lambda

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def test_set_lambda(self):
        structure = self.StructureTest()
        field = structure['field']
        field.name = "field"
        field.structure = self.StructureTest
        field.set_value(lambda s: 4567)
        expected = 4567
        actual = field.get_value()
        assert isinstance(field.value, types.LambdaType)
        assert actual == expected
        assert len(field) == 4 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:13,代碼來源:test_structure.py

示例10: test_set_lambda_as_bytes

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def test_set_lambda_as_bytes(self):
        structure = self.StructureTest()
        field = structure['field']
        field.name = "field"
        field.structure = self.StructureTest
        field.set_value(lambda s: b"\x10\x11\x12\x13")
        expected = [b"\x10\x11", b"\x12\x13"]
        actual = field.get_value()
        assert isinstance(field.value, types.LambdaType)
        assert actual == expected
        assert len(field) == 4 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:13,代碼來源:test_structure.py

示例11: test_set_lambda_as_list

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def test_set_lambda_as_list(self):
        structure = self.StructureTest()
        field = structure['field']
        field.name = "field"
        field.structure = self.StructureTest
        field.set_value(lambda s: [b"\x10\x11", b"\x12\x13"])
        expected = [b"\x10\x11", b"\x12\x13"]
        actual = field.get_value()
        assert isinstance(field.value, types.LambdaType)
        assert actual == expected
        assert len(field) == 4 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:13,代碼來源:test_structure.py

示例12: __init__

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def __init__(self, little_endian=True, default=None, size=None):
        """
        The base class of a Field object. This contains the framework that a
        field SHOULD implement in regards to packing and unpacking a value.
        There should be little need to call this particular object as it is
        designed to be a base class for *Type classes.

        :param little_endian: When converting an int/uuid to bytes, the byte
            order to pack as, False means it will be big endian
        :param default: The default value of the field, this can be any
            supported value such as as well as a lambda function or None
            (default).
        :param size: The size of the field, this can be an int, lambda function
            or None (for variable length end field) unless overridden in Class
            definition.
        """
        field_type = self.__class__.__name__
        self.little_endian = little_endian

        if not (size is None or isinstance(size, integer_types) or
                isinstance(size, types.LambdaType)):
            raise InvalidFieldDefinition("%s size for field must be an int or "
                                         "None for a variable length"
                                         % field_type)
        self.size = size
        self.default = default
        self.value = None 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:29,代碼來源:structure.py

示例13: _get_struct_format

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def _get_struct_format(self, size, unsigned=True):
        """
        Get's the format specified for use in struct. This is only designed
        for 1, 2, 4, or 8 byte values and will throw an exception if it is
        anything else.

        :param size: The size as an int
        :return: The struct format specifier for the size specified
        """
        if isinstance(size, types.LambdaType):
            size = size(self.structure)

        struct_format = {
            1: 'B',
            2: 'H',
            4: 'L',
            8: 'Q'
        }
        if size not in struct_format.keys():
            raise InvalidFieldDefinition("Cannot struct format of size %s"
                                         % size)
        format_char = struct_format[size]
        if not unsigned:
            format_char = format_char.lower()

        return format_char 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:28,代碼來源:structure.py

示例14: _create_list_from_bytes

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def _create_list_from_bytes(self, list_count, list_type, value):
        # calculate the list_count and rerun method if a lambda
        if isinstance(list_count, types.LambdaType):
            list_count = list_count(self.structure)
            return self._create_list_from_bytes(list_count, list_type, value)

        list_value = []
        for idx in range(0, list_count):
            new_field = copy.deepcopy(list_type)
            value = new_field.unpack(value)
            list_value.append(new_field)
        return list_value 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:14,代碼來源:structure.py

示例15: __init__

# 需要導入模塊: import types [as 別名]
# 或者: from types import LambdaType [as 別名]
def __init__(self, lambd):
        assert isinstance(lambd, types.LambdaType)
        self.lambd = lambd 
開發者ID:miraiaroha,項目名稱:ACAN,代碼行數:5,代碼來源:transforms.py


注:本文中的types.LambdaType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。