Changeset 2438

Show
Ignore:
Timestamp:
06/01/09 09:45:19 (10 months ago)
Author:
nick
Message:

Removed dependancy for fpconst for pure python

Location:
pyamf/branches/remove-fpconst-564/pyamf
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • pyamf/branches/remove-fpconst-564/pyamf/tests/util.py

    r2432 r2438  
    1313import pyamf 
    1414from pyamf.util import BufferedByteStream, is_float_broken 
     15 
     16PosInf = 1e300000 
     17NegInf = -1e300000 
     18NaN = PosInf / PosInf 
    1519 
    1620 
     
    111115 
    112116def isNaN(val): 
    113     if is_float_broken(): 
    114         import fpconst 
    115  
    116         return fpconst.isNaN(val) 
    117     else: 
    118         return str(float(val)) == str(1e300000/1e300000) 
     117    return str(float(val)) == str(NaN) 
    119118 
    120119 
    121120def isPosInf(val): 
    122     if is_float_broken(): 
    123         import fpconst 
    124  
    125         return fpconst.isPosInf(val) 
    126     else: 
    127         return val == 1e300000 
     121    return str(float(val)) == str(PosInf) 
    128122 
    129123 
    130124def isNegInf(val): 
    131     if is_float_broken(): 
    132         import fpconst 
    133  
    134         return fpconst.isNegInf(val) 
    135     else: 
    136         return val == -1e300000 
     125    return str(float(val)) == str(NegInf) 
    137126 
    138127 
  • pyamf/branches/remove-fpconst-564/pyamf/util/__init__.py

    r2432 r2438  
    2121except ImportError: 
    2222    from StringIO import StringIO 
     23 
    2324 
    2425xml_types = None 
     
    4243int_types = tuple(int_types) 
    4344str_types = tuple(str_types) 
     45 
     46PosInf = 1e300000 
     47NegInf = -1e300000 
     48# we do this instead of float('nan') because windows throws a wobbler. 
     49NaN = PosInf / PosInf 
    4450 
    4551 
     
    911917    @rtype: C{bool} 
    912918    """ 
    913     # we do this instead of float('nan') because windows throws a wobbler. 
    914     nan = 1e300000/1e300000 
    915  
    916     return str(nan) != str(struct.unpack("!d", '\xff\xf8\x00\x00\x00\x00\x00\x00')[0]) 
     919    global NaN 
     920 
     921    return str(NaN) != str(struct.unpack("!d", '\xff\xf8\x00\x00\x00\x00\x00\x00')[0]) 
     922 
     923 
     924def isNaN(val): 
     925    return str(float(val)) == str(NaN) 
     926 
     927 
     928def isPosInf(val): 
     929    return str(float(val)) == str(PosInf) 
     930 
     931 
     932def isNegInf(val): 
     933    return str(float(val)) == str(NegInf) 
    917934 
    918935 
     
    927944 
    928945if is_float_broken(): 
    929     import fpconst 
    930  
    931946    def read_double_workaround(self): 
     947        global PosInf, NegInf, NaN 
     948 
    932949        bytes = self.read(8) 
    933950 
    934951        if self._is_big_endian(): 
    935952            if bytes == '\xff\xf8\x00\x00\x00\x00\x00\x00': 
    936                 return fpconst.NaN 
     953                return NaN 
    937954 
    938955            if bytes == '\xff\xf0\x00\x00\x00\x00\x00\x00': 
    939                 return fpconst.NegInf 
     956                return NegInf 
    940957 
    941958            if bytes == '\x7f\xf0\x00\x00\x00\x00\x00\x00': 
    942                 return fpconst.PosInf 
     959                return PosInf 
    943960        else: 
    944961            if bytes == '\x00\x00\x00\x00\x00\x00\xf8\xff': 
    945                 return fpconst.NaN 
     962                return NaN 
    946963 
    947964            if bytes == '\x00\x00\x00\x00\x00\x00\xf0\xff': 
    948                 return fpconst.NegInf 
     965                return NegInf 
    949966 
    950967            if bytes == '\x00\x00\x00\x00\x00\x00\xf0\x7f': 
    951                 return fpconst.PosInf 
     968                return PosInf 
    952969 
    953970        return struct.unpack("%sd" % self.endian, bytes)[0] 
     
    959976            raise TypeError('expected a float (got:%r)' % (type(d),)) 
    960977 
    961         if fpconst.isNaN(d): 
     978        if isNaN(d): 
    962979            if self._is_big_endian(): 
    963980                self.write('\xff\xf8\x00\x00\x00\x00\x00\x00') 
    964981            else: 
    965982                self.write('\x00\x00\x00\x00\x00\x00\xf8\xff') 
    966         elif fpconst.isNegInf(d): 
     983        elif isNegInf(d): 
    967984            if self._is_big_endian(): 
    968985                self.write('\xff\xf0\x00\x00\x00\x00\x00\x00') 
    969986            else: 
    970987                self.write('\x00\x00\x00\x00\x00\x00\xf0\xff') 
    971         elif fpconst.isPosInf(d): 
     988        elif isPosInf(d): 
    972989            if self._is_big_endian(): 
    973990                self.write('\x7f\xf0\x00\x00\x00\x00\x00\x00') 
     
    980997    DataTypeMixIn.write_double = write_double_workaround 
    981998    write_double_workaround.old_func = x 
     999 
    9821000 
    9831001try: