resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d Resolves a dotted attribute name to an object. Raises an AttributeError if any attribute in the chain starts with a '_'. If the optional allow_dotted_names argument is false, dots are not supported and this function operates similar
(obj, attr, allow_dotted_names=True)
| 122 | fcntl = None |
| 123 | |
| 124 | def resolve_dotted_attribute(obj, attr, allow_dotted_names=True): |
| 125 | """resolve_dotted_attribute(a, 'b.c.d') => a.b.c.d |
| 126 | |
| 127 | Resolves a dotted attribute name to an object. Raises |
| 128 | an AttributeError if any attribute in the chain starts with a '_'. |
| 129 | |
| 130 | If the optional allow_dotted_names argument is false, dots are not |
| 131 | supported and this function operates similar to getattr(obj, attr). |
| 132 | """ |
| 133 | |
| 134 | if allow_dotted_names: |
| 135 | attrs = attr.split('.') |
| 136 | else: |
| 137 | attrs = [attr] |
| 138 | |
| 139 | for i in attrs: |
| 140 | if i.startswith('_'): |
| 141 | raise AttributeError( |
| 142 | 'attempt to access private attribute "%s"' % i |
| 143 | ) |
| 144 | else: |
| 145 | obj = getattr(obj,i) |
| 146 | return obj |
| 147 | |
| 148 | def list_public_methods(obj): |
| 149 | """Returns a list of attribute strings, found in the specified |
no test coverage detected
searching dependent graphs…