def __new__(cls, value):
        '''Ensure we only have a only one instance for any string,
         and that we encode ascii as 1-byte-per character when possible'''
        
        encodedValue = None
        
        for encoding in ('ascii', 'utf_16_be'):
            try:
               encodedValue = value.encode(encoding)
            except: pass
            if encodedValue is not None:
                if encodedValue not in cls.__instances:
                    cls.__instances[encodedValue] = super(StringWrapper, cls).__new__(cls)
                    cls.__instances[encodedValue].encodedValue = encodedValue
                    cls.__instances[encodedValue].encoding = encoding
                return cls.__instances[encodedValue]
        
        raise ValueError('Unable to get ascii or utf_16_be encoding for %s' % repr(value))
def __new__ ( cls , value ) : encodedValue = None for encoding in ( 'ascii' , 'utf_16_be' ) : try : encodedValue = value . encode ( encoding ) except : pass if encodedValue is not None : if encodedValue not in cls . __instances : cls . __instances [ encodedValue ] = super ( StringWrapper , cls ) . __new__ ( cls ) cls . __instances [ encodedValue ] . encodedValue = encodedValue cls . __instances [ encodedValue ] . encoding = encoding return cls . __instances [ encodedValue ] raise ValueError ( 'Unable to get ascii or utf_16_be encoding for %s' % repr ( value ) )
Ensure we only have a only one instance for any string,
         and that we encode ascii as 1-byte-per character when possible