Coverage for pygeodesy/basics.py : 96%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
''' _TypesError, _ValueError joined_, _UNDERSCORE_, _utf_8_, \ _version_, _0_0
except ImportError: # PYCHOK no cover try: _Ints = int, long # int objects (C{tuple}) except NameError: # Python 3+ _Ints = int, # int objects (C{tuple})
except ImportError: # PYCHOK no cover try: _Scalars = int, long, float # scalar objects (C{tuple}) except NameError: _Scalars = int, float # scalar objects (C{tuple})
# and isinstance(range(1), _Sequence): else: raise ImportError # _AssertionError except ImportError: # PYCHOK no cover _Sequence = tuple # immutable for .points._Basequence _Seqs = list, _Sequence # , range for function len2 below
'''(INTERNAL) Set applicable C{bool} properties/attributes. ''' t = n, v, inst.__class__.__name__ # XXX .classname raise Error('not applicable: %s=%r for %s' % t)
'''Clip a string to the given length limit.
@arg bstr: String (C{bytes} or C{str}). @kwarg limit: Length limit (C{int}). @kwarg white: Optionally, replace all whitespace (C{str}).
@return: The clipped or unclipped B{C{bstr}}. '''
'''Split a string in 2 halfs.
@arg str2: String to split (C{str}).
@return: 2-Tuple (_1st, _2nd) half (C{str}).
@raise ValueError: Zero or odd C{len}(B{C{str2}}). ''' raise _ValueError(str2=str2, txt='odd')
if _FOR_DOCS: # XXX avoid epidoc Python 2.7 error def isclass(obj): '''Return C{True} if B{C{obj}} is a C{class}.
@see: Python's C{inspect.isclass}. ''' return _isclass(obj) else:
'''Check for C{Inf} and C{NaN} values.
@arg obj: Value (C{scalar}).
@return: C{False} if B{C{obj}} is C{INF} or C{NAN}, C{True} otherwise.
@raise TypeError: Non-scalar B{C{obj}}. ''' raise _IsnotError(isscalar.__name__, obj=obj)
'''Return C{True} if B{C{obj}} is a valid Python identifier. ''' and not obj[:1].isdigit()) else False
'''Check for C{int} type or an integer C{float} value.
@arg obj: The object (any C{type}). @kwarg both: Optionally, check C{float} type and value (C{bool}).
@return: C{True} if B{C{obj}} is C{int} or an integer C{float}, C{False} otherwise. ''' except AttributeError: # PYCHOK no cover return False # XXX float(int(obj)) == obj?
except ImportError:
def iskeyword(unused): '''Not Implemented. Return C{False}, always. ''' return False
'''Check for L{NEG0}, negative 0.0.
@arg obj: Value (C{scalar}).
@return: C{True} if B{C{obj}} is C{NEG0} or -0.0, C{False} otherwise. ''' # and str(obj).rstrip(_0_) == '-0.'
'''Check for scalar types.
@arg obj: The object (any C{type}).
@return: C{True} if B{C{obj}} is C{scalar}, C{False} otherwise. '''
'''Check for sequence types.
@arg obj: The object (any C{type}). @arg excluded: Optional exclusions (C{type}).
@note: Excluding C{tuple} implies excluding C{namedtuple}.
@return: C{True} if B{C{obj}} is a sequence, C{False} otherwise. ''' isinstance(obj, _Seqs)
'''Check for string types.
@arg obj: The object (any C{type}).
@return: C{True} if B{C{obj}} is C{str}, C{False} otherwise. '''
'''Check whether a class is a sub-class of a super class.
@arg Sub: The sub-class (C{class}). @arg Super: The super class (C{class}).
@return: C{True} if B{C{Sub}} is a sub-class of B{C{Super}}, C{False} otherwise (C{bool}). '''
'''Make built-in function L{len} work for generators, iterators, etc. since those can only be started exactly once.
@arg items: Generator, iterator, list, range, tuple, etc.
@return: 2-Tuple C{(n, items)} of the number of items (C{int}) and the items (C{list} or C{tuple}). '''
'''Apply each argument to a single-argument function and return a C{tuple} of results.
@arg func: Function to apply (C{callable}). @arg xs: Arguments to apply (C{any positional}).
@return: Function results (C{tuple}). '''
'''Apply arguments to a function and return a C{tuple} of results.
Unlike Python 2's built-in L{map}, Python 3+ L{map} returns a L{map} object, an iterator-like object which generates the results only once. Converting the L{map} object to a tuple maintains Python 2 behavior.
@arg func: Function to apply (C{callable}). @arg xs: Arguments to apply (C{list, tuple, ...}).
@return: Function results (C{tuple}). '''
'''Decorator for a property with documentation.
@arg doc: The property documentation (C{str}).
@example:
>>> @property_doc_("documentation text.") >>> def name(self): >>> ... >>> >>> @name.setter >>> def name(self, value): >>> ... ''' # See Luciano Ramalho, "Fluent Python", page 212ff, O'Reilly, 2016, # "Parameterized Decorators", especially Example 7-23. Also, see # <https://Python-3-Patterns-Idioms-Test.ReadTheDocs.io/en/latest/PythonDecorators.html>
'''(INTERNAL) Return C{method} as documented C{property.getter}. '''
# No __doc__ on purpose
'''New immutable, read-only L{property_RO} to be used as C{decorator}.
@arg method: The callable being decorated as C{property.getter}.
@note: Like standard Python C{property} without a C{property.setter} and with a more descriptive error message when set. ''' self.__doc__ = method.__doc__
# U{Descriptor HowTo Guide<https://docs.Python.org/3/howto/descriptor.html>} '''Throws an C{AttributeError}, always. ''' raise _AttributeError('%s property: %r.%s = %r' % t)
# def property_RO(method): # OBSOLETE # '''An immutable property (C{Read Only}). # # @arg method: The callable to be decorated as C{property.getter}. # # @note: Like standard Python C{property} without a C{property.setter}, # but with a more descriptive error message when set. # ''' # def Read_Only(inst, value): # '''Throws an C{AttributeError}, always. # ''' # t = Read_Only.__name__, inst, method.__name__, value # raise AttributeError('%s property: %r.%s = %r' % t) # # return property(method, Read_Only, None, method.__doc__ or 'N/A')
'''Convert C{unicode} or C{bytes} to C{str}. '''
'''(INTERNAL) Copy attribute values from B{C{other}} to B{C{insto}}.
@arg insto: Object to copy attribute values to (any C{type}). @arg other: Object to copy attribute values from (any C{type}). @arg attrs: One or more attribute names (C{str}s).
@return: Object B{C{insto}}, updated.
@raise AttributeError: An B{C{attrs}} doesn't exist or is not settable. ''' raise _AttributeError('.%s' % (a,), o)
'''(INTERNAL) Copy an object, shallow or deep.
@arg inst: The object to copy (any C{type}). @kwarg deep: If C{True} make a deep, otherwise a shallow copy (C{bool}).
@return: The copy of B{C{inst}}. '''
'''(INTERNAL) Check C{Types} of all C{name=value} pairs.
@arg Types: One or more classes or types (C{class}). @kwarg name_value_pairs: One or more B{C{name=value}} pairs with the C{value} to be checked.
@raise TypeError: At least one of the B{C{name_value_pairs}} is not any of the B{C{Types}}. ''' raise _TypesError(n, v, *Types)
'''(INTERNAL) Override C{dflts} with C{kwds}. '''
'''(INTERNAL) Import C{numpy} and check required version '''
'''(INTERNAL) Import C{scipy} and check required version '''
'''(INTERNAL) Check super C{Class} of all C{name=value} pairs.
@arg Class: A class or type (C{class}). @kwarg name_value_pairs: One or more B{C{name=value}} pairs with the C{value} to be checked.
@raise TypeError: At least one of the B{C{name_value_pairs}} is not a sub-class of B{C{Class}}. ''' raise _TypesError(n, v, Class)
'''(INTERNAL) Check the C{package} version vs B{C{required}}. ''' _DOT_.join(map2(str, t)), 'below', _DOT_.join(map2(str, required)), 'required', 'by', mn(where, True)) raise ImportError(t)
'''(INTERNAL) Zip C{lefts} and C{rights} into a C{str}. '''
# **) MIT License # # Copyright (C) 2016-2020 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |