Coverage for pygeodesy/streprs.py : 99%

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 -*-
'''
_H_, _item_ps, _N_, _PERCENT_, _scalar_, \ _SPACE_, _STAR_, _UNDERSCORE_, _0_
# formats %G and %.g drop all trailing zeros and the # decimal point making the float appear as an int
'''(INTERNAL) Helper for C{fstr}, C{pairs}, C{reprs} and C{strs} ''' else: raise _ValueError(fmt=fmt, txt='not %r' % (t,))
# corner case testLcc lon0=-96.0 t.rstrip(_0_).endswith(_DOT_)): else: raise _IsnotError(_scalar_, floats=o)
'''Make a valid name of alphanumeric and OKd characters.
@arg name: The original name (C{str}). @kwarg OKd: Other acceptable characters (C{str}). @kwarg sub: Substitute for invalid charactes (C{str}).
@return: The modified name (C{str}).
@note: Leading and trailing whitespace characters are removed and intermediate whitespace characters are coalesced and substituted. '''
'''Get instance attributes as I{name=value} strings, with C{float}s handled like L{fstr}.
@arg inst: The instance (any C{type}). @arg names: The attribute names (C{str}s). @kwarg kwds: Keyword argument for function L{pairs}, except B{C{Nones=True}} to in-/exclude missing or attributes with a C{None} I{value}.
@return: A C{tuple(sep.join(t) for t in zip(names, reprs(values, ...)))} of C{str}s. '''
'''Return easting, northing string representations.
@arg easting: Easting from false easting (C{meter}). @arg northing: Northing from from false northing (C{meter}). @arg prec: Precision in number of digits (C{int}, [1..5]). @arg extras: Optional leading items (C{str}s).
@return: B{C{extras}} + 2-Tuple C{(eastingStr, northingStr)}.
@raise ValueError: Invalid B{C{prec}}. ''' raise _ValueError(prec=prec) '%0*d' % (w, int(northing * p)))
'''Convert one or more floats to string, optionally stripped of trailing zero decimals.
@arg floats: Single or a list, sequence, tuple, etc. (C{scalar}s). @kwarg prec: The C{float} precision, number of decimal digits (0..9). Trailing zero decimals are stripped if B{C{prec}} is positive, but kept for negative B{C{prec}} values. @kwarg fmt: Optional, C{float} format (C{str}). @kwarg ints: Optionally, remove the decimal dot for C{int} values (C{bool}). @kwarg sep: Separator joining the B{C{floats}} (C{str}). @kwarg strepr: Optional callable to format non-C{floats} (typically C{repr}, C{str}) or C{None} to raise a TypeError.
@return: The C{sep.join(strs(floats, ...)} joined (C{str}) or single C{strs((floats,), ...)} (C{str}) if B{C{floats}} is C{scalar}. '''
'''(INTERNAL) For C{Css.} and C{Lcc.} C{toRepr} and C{toStr}. ''' fstr(inst.northing, prec=prec))
'''Strip trailing zero decimals from a C{float} string.
@arg efstr: Float with or without exponent (C{str}). @kwarg ap1z: Append the decimal point and one zero decimal if the B{C{efstr}} is all digits (C{bool}).
@return: Float (C{str}). '''
# %.G and %.g formats drop the decimal # point and all trailing zeros, ... else: # ... insert one dot and zero
'''Return a string for the height value.
@arg height: Height value (C{float}). @kwarg prec: The C{float} precision, number of decimal digits (0..9). Trailing zero decimals are stripped if B{C{prec}} is positive, but kept for negative B{C{prec}} values. @kwarg fmt: Optional, C{float} format (C{str}). @kwarg ints: Optionally, remove the decimal dot for C{int} values (C{bool}). @kwarg m: Optional unit of the height (C{str}). '''
'''Return the string representation of an instantiation.
@arg inst: The instance (any C{type}). @arg args: Optional positional arguments. @kwarg kwds: Optional keyword arguments.
@return: Representation (C{str}). '''
'''Convert items to I{name=value} strings, with C{float}s handled like L{fstr}.
@arg items: Name-value pairs (C{dict} or 2-{tuple}s of any C{type}s). @kwarg prec: The C{float} precision, number of decimal digits (0..9). Trailing zero decimals are stripped if B{C{prec}} is positive, but kept for negative B{C{prec}} values. @kwarg fmt: Optional, C{float} format (C{str}). @kwarg ints: Optionally, remove the decimal dot fir C{int} values (C{bool}). @kwarg sep: Separator joining I{names} and I{values} (C{str}).
@return: A C{tuple(sep.join(t) for t in zip(names, reprs(values,...)))} of C{str}s. ''' # can't unzip empty items tuple, list, etc. except (TypeError, ValueError): raise _IsnotError(dict.__name__, '2-tuples', items=items)
'''Convert objects to C{repr} strings, with C{float}s handled like L{fstr}.
@arg objs: List, sequence, tuple, etc. (any C{type}s). @kwarg prec: The C{float} precision, number of decimal digits (0..9). Trailing zero decimals are stripped if B{C{prec}} is positive, but kept for negative B{C{prec}} values. @kwarg fmt: Optional, C{float} format (C{str}). @kwarg ints: Optionally, remove the decimal dot fir C{int} values (C{bool}).
@return: A C{tuple(map(fstr|repr, objs))} of C{str}s. '''
'''Convert objects to C{str} strings, with C{float}s handled like L{fstr}.
@arg objs: List, sequence, tuple, etc. (any C{type}s). @kwarg prec: The C{float} precision, number of decimal digits (0..9). Trailing zero decimals are stripped if B{C{prec}} is positive, but kept for negative B{C{prec}} values. @kwarg fmt: Optional, C{float} format (C{str}). @kwarg ints: Optionally, remove the decimal dot fir C{int} values (C{bool}).
@return: A C{tuple(map(fstr|str, objs))} of C{str}s. '''
'''Return the string representation of an invokation.
@arg name: Function, method or class name (C{str}). @arg args: Optional positional arguments. @kwarg kwds: Optional keyword arguments.
@return: Representation (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. |