(self, from_type, to_type)
Get a converter function; raise ValueError if not allowed
Get a converter function; raise ValueError if not allowed
Get a converter function ; raise ValueError if not allowed
def get_converter(self, from_type, to_type):
        """Get a converter function; raise ValueError if not allowed"""
        if to_type is None or from_type == to_type:
            return lambda _x: _x
        converter = {
            (bytes, text_type): partial(self.codepage.bytes_to_unicode, preserve=cp.CONTROL),
            (text_type, bytes): self.codepage.unicode_to_bytes,
            (int, bool): bool,
            (float, bool): bool,
            (bool, int): lambda _bool: (-1 if _bool else 0),
            (int, float): float,
            (float, int): lambda _flt: int(math.floor(_flt)),
            (bool, float): lambda _bool: (-1. if _bool else 0.),
        }
        try:
            return converter[(from_type, to_type)]
        except KeyError:
            raise ValueError("BASIC can't convert %s to %s." % (from_type, to_type))
def get_converter ( self , from_type , to_type ) : if to_type is None or from_type == to_type : return lambda _x : _x converter = { ( bytes , text_type ) : partial ( self . codepage . bytes_to_unicode , preserve = cp . CONTROL ) , ( text_type , bytes ) : self . codepage . unicode_to_bytes , ( int , bool ) : bool , ( float , bool ) : bool , ( bool , int ) : lambda _bool : ( - 1 if _bool else 0 ) , ( int , float ) : float , ( float , int ) : lambda _flt : int ( math . floor ( _flt ) ) , ( bool , float ) : lambda _bool : ( - 1. if _bool else 0. ) , } try : return converter [ ( from_type , to_type ) ] except KeyError : raise ValueError ( "BASIC can't convert %s to %s." % ( from_type , to_type ) )