我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用builtins.property()。
def produce_module_arguments_from_json_schema(json_doc, skip_attrs): module_arguments = list() for property in json_doc: # Skip readonly attributes if property['readonly'] is True: continue # Skip attributes in skip_attrs if property['name'] in skip_attrs: continue key = property['name'] entry = {} entry['key'] = key entry['transforms'] = [] # Convert json type to ansible module argument type declaration entry['type'] = property['type'] # Add choices if applicable if 'choices' in property: choice_set = frozenset([choice.lower() for choice in property['choices']]) if choice_set == frozenset(['yes', 'no']): # Overwrite type to bool entry['type'] = 'bool' entry['transforms'] = ['bool_yes_no'] elif choice_set == frozenset(['on', 'off']): # Overwrite type to bool entry['type'] = 'bool' entry['transforms'] = ['bool_on_off'] elif choice_set == frozenset(['enabled', 'disabled']): entry['choices'] = ['enabled', 'disabled'] else: entry['choices'] = property['choices'] # Add to ansible modules argument module_arguments.append(entry) return module_arguments
def produce_readwrite_attrs_list(json_doc): readonly_list = list() for property in json_doc: # Add only readonly attributes if property['readonly'] is False: readonly_list.append(property['name']) return readonly_list
def produce_readonly_attrs_list(json_doc): readonly_list = list() for property in json_doc: # Add only readonly attributes if property['readonly'] is True: readonly_list.append(property['name']) return readonly_list
def produce_immutables_list(json_doc): immutables_list = [] for property in json_doc: # Add only readonly attributes if 'mutable' in property and not property['mutable'] and not property['readonly']: immutables_list.append(property['name']) return immutables_list
def __init__(self, type, default=None, name='', hint=0, usage=lib.GODOT_PROPERTY_USAGE_DEFAULT, hint_string='', rpc=lib.GODOT_METHOD_RPC_MODE_DISABLED): self.property = None self.type = type self.default = default self.name = name self.hint = hint self.usage = usage self.hint_string = hint_string if isinstance(rpc, RPCMode): self.rpc = rpc.mod else: self.rpc = rpc
def __call__(self, decorated): # This object is used as a decorator if not callable(decorated) and not isinstance(decorated, builtins.property): raise RuntimeError("@export should decorate function or property.") # It's possible decorated has already been passed through a rpc decorator rpc = getattr(decorated, '__rpc', None) if rpc: self.rpc = rpc self.property = decorated return self
def setter(self, setfunc): if not self.property: raise RuntimeError("Cannot use setter attribute before defining the getter !") self.property = self.property.setter(setfunc) return self