def _all_listing(alls, localls, libs=False, _file_=_NN_, argv0='#'): '''(INTERNAL) Print sorted __all__ names and values. ''' def _all_in(alls, inns, m, n): t = tuple(a for a in alls if a not in inns) if t: t = _COMMASPACE_.join(t) raise NameError('missing %s: %s' % (_DOT_(m, n), t)) f = _file_ or localls.get('__file__', _NN_) m, n = _dirbasename2(f) printf('%s = %s(', _DOT_(m, '__all__'), alls.__class__.__name__, argv0=argv0, nl=1) lazy = _ALL_LAZY.get(n, ()) if lazy: _all_in(alls, lazy, 'lazily', n) _all_in(lazy, alls, m, '__all__') _all_in(lazy, localls, m, 'locals()') d = i = 0 p = _NN_ for n in sorted(alls, key=str.lower): v = localls[n] r = repr(v) if isinstance(v, _Ints): r = '%s or 0x%X' % (r, v) v, s = _int2(v) if s > 2: r = '%s or %d << %s' % (r, v, s) elif r.startswith('<class '): r = r.replace("'", _NN_) elif r.startswith('<function '): r = r[:10] + _DOT_(v.__module__, r[10:]) r = r.replace('__main__', _NN_) # .replace('__main__', m) if n == p: d += 1 r += ' DUPLICATE' else: p = n if r.startswith(_DOT_(n, _NN_)): # increase indentation to align enums, constants, etc. r = r.replace(_SPACE_ * len(n), _SPACE_ * (len(n) + len(m) + 2)) else: r = '%s is %s' % (n, r) printf(' %s,', _DOT_(m, r), argv0=argv0) i += 1 if d: d = _NN_(_SPACE_, d, ' DUPLICATE', 's' if d > 1 else _NN_) else: d = _NN_ printf(')[%d]%s', i, d, argv0=argv0) _all_versions(libs=libs, _file_=f, _version_=localls.get('__version__', _NN_), argv0=argv0) # PYCHOK kwargs
def _all_versionstr(libs=False, _file_=_NN_, _version_=_NN_): '''(INTERNAL) PyCocao, Python, macOS, etc. versions as C{str}. ''' from pycocoa import oslibs, _pycocoa, version as _version t = (('version', _version_ or _version), # PYCHOK shadow ('.isLazy', str(isLazy)), ('Python', _Python_, _platform.architecture()[0], machine()), ('macOS', _macOSver())) if libs: t += ('oslibs', str(sorted(oslibs.get_libs().keys())).replace("'", _NN_)), m, _ = _dirbasename2(_file_ or _pycocoa) return _DOT_(m, _COMMASPACE_.join(_SPACE_.join(v) for v in t))
def _varstr(constants, strepr=None): '''(INTERNAL) Return all C{@var Class.<name>: <doc>} lines as C{str}. ''' def _doc1(c, n, f): # get class c's 1st __doc__ line or value from f(c) d = f(c) if callable(f) else ( getattr(c, '__doc__') or _NN_) # PYCHOK getattr t = d.split(_NL_)[0].strip().rstrip(_DOT_) return '@var %s: %s.' % (n, t) C = constants.__class__ N = C.__name__.lstrip(_UNDER_) v = [_NN_, _doc1(C, N, None)] for n, _ in constants.items(): v.append(_doc1(getattr(C, n), _DOT_(N, n), strepr)) return _NL_.join(v)
def _strepr(self, fmt): c = self.__class__.__name__.lstrip(_UNDER_) j = _NN_(',', _NL_, _SPACE_ * len(c), _DOT_) t = j.join(fmt(*t) for t in sortuples(self.items())) return _DOT_(c, t)
def __setattr__(self, name, value): if not hasattr(self, name): raise NameError('no such %s' % (_DOT_(self.__class__.__name__, name),)) super(_MutableConstants, self).__setattr__(name, value)
def Read_Only(self, ignored): '''Throws an C{AttributeError}, always. ''' raise AttributeError('Read_Only property: %s = %r' % (_DOT_(self, method.__name__), ignored))
def _all_in(alls, inns, m, n): t = tuple(a for a in alls if a not in inns) if t: t = _COMMASPACE_.join(t) raise NameError('missing %s: %s' % (_DOT_(m, n), t))
def __setattr__(self, name, value): raise TypeError('%s = %r' % (_DOT_(self.__class__.__name__, name), value))
from pycocoa.utils import _all_listing, _Globals, printf _Globals.argv0 = _NN_ for i, p in enumerate(get_printers()): printf('%2s %s: ID %r, makemodel %r, URI %r', i + 1, p, p.ID, p.makemodel, p.deviceURI) d = get_printer() if d: printf('default (%s) printer: %s...', d.isDefault, d, nl=1) for a in ('name', 'ID', 'makemodel', 'isColor', 'location', 'psCapable', 'psLevel', 'isRemote', 'deviceURI', 'deviceDescription', 'description', 'PPD', 'resolution'): printf(' %s: %r', _DOT_(d, a), getattr(d, a)) printf(_NN_) for i, p in enumerate(get_papers(d)): t = tuple(map(zfstr, (p.width, p.height) + p.size2inch)) printf('%2s %s: ID %r, %sx%s (%sX%s)', i + 1, p, p.ID, *t) p = Paper('A4') printf('paper: %s...', p, nl=1) for a in ('name', 'ID', 'height', 'width', 'size2inch', 'size2mm', 'PPD', 'printer'): printf(' %s: %r', _DOT_(p, a), getattr(p, a)) printf(' %s: %r', _DOT_(p, 'localname'), p.localname(), nt=1) _all_listing(__all__, locals())
def pop(self, key, **unused): raise TypeError('%s(%r)' % (_DOT_(self, self.pop.__name__), key))
def clear(self): raise TypeError('%s()' % (_DOT_(self, 'clear'), ))