pycocoa.getters

Package pycocoa :: Module getters |
[frames] | no frames]

# Module getters

`get_...` functions to obtain ObjC classes, methods, protocols, etc.

Version: 25.03.23

Functions
get_c_func_t(encoding, codes=None) Get the `ctypes` function type for a given function signature. |
get_class(name) Get a registered ObjC class by name. |
get_classes(*prefixes) Yield all loaded ObjC classes with a name starting with one of the given prefixes. |
get_classname(clas, dflt=missing) Get the name of an ObjC class. |
get_classnameof(objc, dflt=missing) Get the name of the ObjC class of an object. |
get_classof(objc) Get the ObjC class of an object. |
get_ivar(objc, name, ctype=None) Get the value of an instance variable (ivar). |
get_ivars(clas, *prefixes) Yield all instance variables (ivar) of an ObjC class with a name starting with one of the given prefixes. |
get_inheritance(clas) Yield the inheritance of an ObjC class. |
get_metaclass(name) Get a registered ObjC metaclass by name. |
get_method(clas, name) Get a method of an ObjC class by name. |
get_methods(clas, *prefixes) Yield all methods of an ObjC class with a name starting with one of the given prefixes. |
get_properties(clas_or_proto, *prefixes) Yield all properties of an ObjC class or protocol with a name starting with one of the given prefixes. |
get_protocol(name) Get a registered ObjC protocol by name. |
get_protocols(clas, *prefixes) Yield all protocols of an ObjC class with a name starting with one of the given prefixes. |
get_selector(name_) Get an ObjC selector by name. |
get_selectornameof(sel) Get the name of an ObjC selector. |
get_selectorname_permutations(name_, leading=False) Yield all permutations of a Python-style selector name. |
get_superclass(clas) Get the ObjC super-class of an ObjC class. |
get_superclassof(objc) Get the ObjC super-class of an object. |
get_superclassnameof(objc, dflt=missing) Get the name of the ObjC super-class of an object. |

Variables
| __all__ = `_ALL_LAZY.getters`

Function Details

### get_c_func_t(encoding, codes=None) |
Get the `ctypes` function type for a given function signature. Parameters: `encoding` - Type encoding of the signature (`str` or `bytes`). `codes` - The individual type codes (`type encoding`[]) Note: The signature encoding is a `str` or `bytes`, not unicode and codes is a list of the individual type encodings, limited to basic type encodings and pointers to basic type encodings. Does not handle `array`s, `bitfield`s, arbitrary `struct`s and `union`s. If keyword codes is not supplied, it will be created from the signature by split_encoding, not split_emcoding2.

### get_class(name) |
Get a registered ObjC class by name. Parameters: `name` - The class name (`str`). Returns: The class (Class_t) if found, `None` otherwise.

### get_classes(*prefixes) |
Yield all loaded ObjC classes with a name starting with one of the given prefixes. Parameters: `prefixes` - No, one or more class names to match (`str`-s). Returns: For each class yield a 2-tuple (name, class) where name is the class name and class is the ObjC Class_t object.

### get_classname(clas, dflt=missing) |
Get the name of an ObjC class. Parameters: `clas` - The class (Class_t). Returns: The class name (`str`). Raises: `SegfaultError` - See function segfaulty. `ValueError` - Invalid clas, iff no dflt provided.

### get_classnameof(objc, dflt=missing) |
Get the name of the ObjC class of an object. Parameters: `objc` - The object (`Object` or Id_t). Returns: The object's class name (`str`). Raises: `SegfaultError` - See function segfaulty. `ValueError` - Invalid objc, iff no dflt provided.

### get_classof(objc) |
Get the ObjC class of an object. Parameters: `objc` - The object (`Object` or Id_t). Returns: The object's class (Class_t) if found, `None` otherwise.

### get_ivar(objc, name, ctype=None) |
Get the value of an instance variable (ivar). Parameters: `objc` - The object (`Object` or Id_t). `name` - The instance variable name (`str`). `ctype` - The instance variable type (`ctypes`), Returns: The ivar value (`any`) if found, `None` otherwise.

### get_ivars(clas, *prefixes) |
Yield all instance variables (ivar) of an ObjC class with a name starting with one of the given prefixes. Parameters: `clas` - The class (Class_t). `prefixes` - No, one or more ivar names to match (`str`-s). Returns: For each ivar yield a 4-tuple (name, encoding, ctype, ivar) where name is the ivar name, encoding is the ivar's type encoding, ctype is the ivar's `ctypes` type and ivar is the Ivar_t object.

### get_inheritance(clas) |
Yield the inheritance of an ObjC class. Parameters: `clas` - Class (Class_t). Returns: The parent classes (Class_t), in bottom-up order.

### get_metaclass(name) |
Get a registered ObjC metaclass by name. Parameters: `name` - The metaclass (`str`). Returns: The metaclass (Class_t) if found, `None` otherwise.

### get_method(clas, name) |
Get a method of an ObjC class by name. Parameters: `clas` - Class (Class_t). `name` - Method name (`str`). Returns: The method (Method_t) if found, `None` otherwise.

### get_methods(clas, *prefixes) |
Yield all methods of an ObjC class with a name starting with one of the given prefixes. Parameters: `clas` - The class (Class_t). `prefixes` - No, one or more method names to match (`str`-s). Returns: For each method yield a 4-tuple (name, encoding, resargtypes, method), where name is the method name, encoding is the type encoding of the method signature including the return type, resargtypes the `ctypes` signature, a `list`list of the argtypes preceeded by the restype and method the Method_t object.

### get_properties(clas_or_proto, *prefixes) |
Yield all properties of an ObjC class or protocol with a name starting with one of the given prefixes. Parameters: `clas_or_proto` - The class or protocol (Class_t or Protocol_t). `prefixes` - No, one or more property names to match (`str`-s). Returns: For each property, yield a 3-tuple (name, attributes, setter, property) where attributes is a comma-separated list of the property attibutes, setter is the name of the property setter method, provided the property is writable and property is the `Property` object. For read-only properties, the setter is an empty name `""`. Note: ObjC Property Attributes: T<type>"name" = Type & = Retain last value (retain) C = Copy D = Dynamic (@dynamic) G<name> = Getter selector name N = Non-atomic (nonatomic) P = To be garbage collected R = Read-only (readonly) S<name> = Setter selector name t<encoding> = Old-style type encoding W = Weak reference (__weak) See Also: Property Attributes.

### get_protocol(name) |
Get a registered ObjC protocol by name. Parameters: `name` - The protocol name (`str`). Returns: The protocol (Protocol_t) if found, `None` otherwise.

### get_protocols(clas, *prefixes) |
Yield all protocols of an ObjC class with a name starting with one of the given prefixes. Parameters: `clas` - The class (Class_t). `prefixes` - No, one or more protocol names to match (`str`-s). Returns: For each protocol, yield a 2-tuple (name, protocol) where name is the protocol name and protocol the Protocol_t object.

### get_selector(name_) |
Get an ObjC selector by name. Parameters: `name_` - The selector name (`str`). Returns: The selector (SEL_t) if found, `None` otherwise.

### get_selectornameof(sel) |
Get the name of an ObjC selector. Parameters: `sel` - The selector (SEL_t). Returns: The selector name (`str`) if found, `""` otherwise.

### get_selectorname_permutations(name_, leading=False) |
Yield all permutations of a Python-style selector name. Parameters: `name_` - The selector name with underscores (`str`). `leading` - In-/exclude leading underscores in name_ permutations (`bool`), default `False` meaning exclude. Returns: The selector name (`str`) for each underscore and colon permutation. Note: Only the underscores in name_ are permuted, any colons in name_ remain unchanged.

### get_superclass(clas) |
Get the ObjC super-class of an ObjC class. Parameters: `clas` - The class (Class_t). Returns: The super-class (Class_t), `None` otherwise.

### get_superclassof(objc) |
Get the ObjC super-class of an object. Parameters: `objc` - The object (`Object` or Id_t). Returns: The super-class (Class_t), `None` otherwise.

### get_superclassnameof(objc, dflt=missing) |
Get the name of the ObjC super-class of an object. Parameters: `objc` - The object (`Object` or Id_t). Returns: The object'ssuper-class name (`str`). Raises: `ValueError` - Invalid objc, iff no dflt provided.