コード例 #1
0
ファイル: units.py プロジェクト: rbpdqdat/PyGeodesy
    def __new__(cls,
                arg=None,
                name=_northing_,
                Error=UnitError,
                falsed=False,
                osgr=False,
                **name_arg):
        '''New named C{Northing} instance.

           @arg cls: This class (C{Northing} or sub-class).
           @kwarg arg: The value (any C{type} convertable to C{float}).
           @kwarg name: Optional instance name (C{str}).
           @kwarg Error: Optional error to raise, overriding the default
                         L{UnitError}.
           @kwarg falsed: The B{C{arg}} value includes false origin (C{bool}).
           @kwarg osgr: Check B{C{arg}} as an OSGR northing (C{bool}).
           @kwarg name_arg: Optional C{name=arg} keyword argument,
                            inlieu of B{C{name}} and B{C{arg}}.

           @returns: A C{Northing} instance.

           @raise Error: Invalid B{C{arg}} or negative, falsed B{C{arg}}.
        '''
        if name_arg:
            name, arg = _xkwds_popitem(name_arg)
        self = Float.__new__(cls, arg=arg, name=name, Error=Error)
        if osgr and (self < 0 or self > 1300e3):  # like Veness
            raise _Error(cls, arg, name=name, Error=Error)
        elif falsed and self < 0:
            raise _Error(cls,
                         arg,
                         name=name,
                         Error=Error,
                         txt='negative, falsed')
        return self
コード例 #2
0
ファイル: units.py プロジェクト: rbpdqdat/PyGeodesy
    def __new__(cls, arg=None, name=NN, Error=UnitError, **name_arg):
        '''New named C{str} instance.

           @kwarg cls: This class (C{Str} or sub-class).
           @kwarg arg: The value (any C{type} convertable to C{str}).
           @kwarg name: Optional instance name (C{str}).
           @kwarg Error: Optional error to raise, overriding
                         the default (C{ValueError}).
           @kwarg name_arg: Optional C{name=arg} keyword argument,
                            inlieu of B{C{name}} and B{C{arg}}.

           @returns: A L{Str} instance.

           @raise Error: Invalid B{C{arg}}.
        '''
        if name_arg:
            name, arg = _xkwds_popitem(name_arg)
        try:
            self = str.__new__(cls, arg)
            if name:
                _NamedUnit.name.fset(self, name)  # see _Named.name
            return self

        except (TypeError, ValueError) as x:  # XXX not ... as x:
            raise _Error(cls, arg, name=name, Error=Error, txt=str(x))
コード例 #3
0
ファイル: units.py プロジェクト: rbpdqdat/PyGeodesy
    def __new__(cls, arg=None, name=NN, Error=UnitError, **name_arg):
        '''New named C{bool} instance.

           @kwarg cls: This class (C{Bool} or sub-class).
           @kwarg arg: The value (any C{type} convertable to C{bool}).
           @kwarg name: Optional instance name (C{str}).
           @kwarg Error: Optional error to raise, overriding the
                         default L{UnitError}.
           @kwarg name_arg: Optional C{name=arg} keyword argument,
                            inlieu of B{C{name}} and B{C{arg}}.

           @returns: A L{Bool}, a C{bool}-like instance.

           @raise Error: Invalid B{C{arg}}.
        '''
        if name_arg:
            name, arg = _xkwds_popitem(name_arg)
        try:
            b = bool(arg)
        except (TypeError, ValueError) as x:  # XXX not ... as x:
            raise _Error(cls, arg, name=name, Error=Error, txt=str(x))

        self = Int.__new__(cls, b, name=name, Error=Error)
        self._bool_True_or_False = b
        return self
コード例 #4
0
ファイル: units.py プロジェクト: rbpdqdat/PyGeodesy
    def __new__(cls,
                arg=None,
                name=NN,
                Error=UnitError,
                low=0,
                high=None,
                **name_arg):
        '''New named C{int} instance with limits.

           @kwarg cls: This class (C{Int_} or sub-class).
           @arg arg: The value (any C{type} convertable to C{int}).
           @kwarg name: Optional instance name (C{str}).
           @kwarg Error: Optional error to raise, overriding the default
                         C{UnitError}.
           @kwarg low: Optional lower B{C{arg}} limit (C{float} or C{None}).
           @kwarg high: Optional upper B{C{arg}} limit (C{float} or C{None}).
           @kwarg name_arg: Optional C{name=arg} keyword argument,
                            inlieu of B{C{name}} and B{C{arg}}.

           @returns: An L{Int_} instance.

           @raise Error: Invalid B{C{arg}} or B{C{arg}} below B{C{low}} or
                         above B{C{high}}.
        '''
        if name_arg:
            name, arg = _xkwds_popitem(name_arg)
        self = Int.__new__(cls, arg=arg, name=name, Error=Error)
        if (low is not None) and self < low:
            txt = Fmt.limit(below=low)
        elif (high is not None) and self > high:
            txt = Fmt.limit(above=high)
        else:
            return self
        raise _Error(cls, arg, name=name, Error=Error, txt=txt)
コード例 #5
0
ファイル: vector3d.py プロジェクト: rbpdqdat/PyGeodesy
def _otherV3d(sphere=True, **name_v):
    # check B{C{name#}} vector instance, return Vector3d
    name, v = _xkwds_popitem(name_v)
    try:
        return Vector3d(v.x, v.y, v.z if sphere else _0_0, name=name)
    except AttributeError:  # no _x_ or _y_ attr
        pass
    raise _xotherError(Vector3d(0, 0, 0), v, name=name, up=2)
コード例 #6
0
ファイル: named.py プロジェクト: rbpdqdat/PyGeodesy
def _xother3(inst, other, name=_other_, up=1, **name_other):
    '''(INTERNAL) Get C{name} and C{up} for a named C{other}.
    '''
    if name_other:  # and not other and len(name_other) == 1
        name, other = _xkwds_popitem(name_other)
    elif other and len(other) == 1:
        other = other[0]
    else:
        raise _AssertionError(name, other, txt=classname(inst, prefixed=True))
    return other, name, up
コード例 #7
0
ファイル: units.py プロジェクト: rbpdqdat/PyGeodesy
 def __new__(cls,
             arg=None,
             name=_lat_,
             Error=UnitError,
             clip=90,
             **name_arg):
     '''See L{Degrees} and L{Radians}.
     '''
     if name_arg:
         name, arg = _xkwds_popitem(name_arg)
     d = Phi.__new__(cls, arg=arg, name=name, Error=Error, clip=clip)
     return Radians.__new__(cls, arg=radians(d), name=name, Error=Error)
コード例 #8
0
ファイル: units.py プロジェクト: rbpdqdat/PyGeodesy
 def __new__(cls,
             arg=None,
             name=_epoch_,
             Error=TRFError,
             low=1900,
             high=9999,
             **name_arg):
     '''See L{Float_}.
     '''
     if name_arg:
         name, arg = _xkwds_popitem(name_arg)
     return arg if isinstance(arg, Epoch) else \
            Float_.__new__(cls, arg=arg, name=name, Error=Error, low=low, high=high)
コード例 #9
0
ファイル: units.py プロジェクト: rbpdqdat/PyGeodesy
 def __new__(cls,
             arg=None,
             name=_bearing_,
             Error=UnitError,
             clip=0,
             **name_arg):
     '''See L{Degrees}.
     '''
     if name_arg:
         name, arg = _xkwds_popitem(name_arg)
     d = Degrees.__new__(cls,
                         arg=arg,
                         name=name,
                         Error=Error,
                         suffix=_N_,
                         clip=clip)
     b = d % 360
     return d if b == d else Degrees.__new__(
         cls, arg=b, name=name, Error=Error)
コード例 #10
0
ファイル: units.py プロジェクト: rbpdqdat/PyGeodesy
    def __new__(cls,
                arg=None,
                name=_degrees_,
                Error=UnitError,
                suffix=_NSEW_,
                low=None,
                high=None,
                **name_arg):
        '''New named C{Degrees} instance.

           @arg cls: This class (C{Degrees_} or sub-class).
           @kwarg arg: The value (any C{type} convertable to C{float} or
                       parsable by L{parseDMS}).
           @kwarg name: Optional instance name (C{str}).
           @kwarg Error: Optional error to raise, overriding the default
                         L{UnitError}.
           @kwarg suffix: Optional, valid compass direction suffixes (C{NSEW}).
           @kwarg low: Optional lower B{C{arg}} limit (C{float} or C{None}).
           @kwarg high: Optional upper B{C{arg}} limit (C{float} or C{None}).
           @kwarg name_arg: Optional C{name=arg} keyword argument,
                            inlieu of B{C{name}} and B{C{arg}}.

           @returns: A C{Degrees} instance.

           @raise Error: Invalid B{C{arg}} or B{C{abs(deg)}} below B{C{low}}
                         or above B{C{high}}.
        '''
        if name_arg:
            name, arg = _xkwds_popitem(name_arg)
        self = Degrees.__new__(cls,
                               arg=arg,
                               name=name,
                               Error=Error,
                               suffix=suffix,
                               clip=0)
        if (low is not None) and self < low:
            txt = Fmt.limit(below=low)
        elif (high is not None) and self > high:
            txt = Fmt.limit(above=high)
        else:
            return self
        raise _Error(cls, arg, name=name, Error=Error, txt=txt)
コード例 #11
0
ファイル: units.py プロジェクト: rbpdqdat/PyGeodesy
    def __new__(cls,
                arg=None,
                name=_radians_,
                Error=UnitError,
                suffix=_NSEW_,
                clip=0,
                **name_arg):
        '''New named C{Radians} instance.

           @arg cls: This class (C{Radians} or sub-class).
           @kwarg arg: The value (any C{type} convertable to C{float} or
                       parsable by L{parseRad}).
           @kwarg name: Optional instance name (C{str}).
           @kwarg Error: Optional error to raise, overriding the default
                         L{UnitError}.
           @kwarg suffix: Optional, valid compass direction suffixes (C{NSEW}).
           @kwarg clip: Optional B{C{arg}} range B{C{-clip..+clip}}
                        (C{radians} or C{0} or C{None} for unclipped).
           @kwarg name_arg: Optional C{name=arg} keyword argument,
                            inlieu of B{C{name}} and B{C{arg}}.

           @returns: A C{Radians} instance.

           @raise Error: Invalid B{C{arg}} or B{C{abs(deg)}} outside the
                         B{C{clip}} range and L{rangerrors} set to C{True}.
        '''
        if name_arg:
            name, arg = _xkwds_popitem(name_arg)
        try:
            return Float.__new__(cls,
                                 parseRad(arg, suffix=suffix, clip=clip),
                                 name=name,
                                 Error=Error)
        except RangeError as x:
            t, E = str(x), type(x)
        except (TypeError, ValueError) as x:
            t, E = str(x), Error
        raise _Error(cls, arg, name=name, Error=E, txt=t)