def test_params_python3_strings( self ): try: glGetUniformBlockIndex( 0, unicode("Moo") ) except ArgumentError as err: assert OpenGL.ERROR_ON_COPY, """Shouldn't have raised error on copy for unicode""" except TypeError as err: raise except GLError as err: # expected error, as we don't have a shader there... pass
def test_params_python3_strings(self): try: glGetUniformBlockIndex(0, unicode("Moo")) except ArgumentError as err: assert OpenGL.ERROR_ON_COPY, """Shouldn't have raised error on copy for unicode""" except TypeError as err: raise except GLError as err: # expected error, as we don't have a shader there... pass
def coerce( self, value ): """Coerce the given value to our type Allowable types: simple string -> unchanged unicode string -> utf-8 encoded sequence of length == 1 where first element is a string -> returns first element sequence of length > 1 where all elements are strings -> returns string.join( value, '') """ if isinstance( value, bytes ): return value.decode( 'utf-8') elif isinstance( value, field.SEQUENCE_TYPES): if value and len(value) == 1: value = value[0] elif not value: value = u"" else: value = u"".join( value ) if not isinstance( value, unicode ): value = unicode(value) return value
self.glyphs[character] = glyph self.glyphNames[glyphName] = glyph return glyph def __repr__(self): """Provide a representation of the Font""" return """%s( %r, %r )""" % ( self.__class__.__name__, self.filename, self.encoding, ) if __name__ == "__main__": import os, glob, traceback testText = [unicode(chr(x), 'latin-1') for x in range(32, 256)] def scan(directory=os.path.join(os.environ['windir'], 'fonts')): files = glob.glob(os.path.join(directory, "*.ttf")) errors = [] for file in files: error = (file, []) print('\nFile', file) try: font = Font(file, ) except Exception as err: traceback.print_exc() error[1].append((file, "Couldn't load")) else: for character in testText: try:
def as_unicode(u): if isinstance(u, bytes): return unicode(u, 'utf-8') return u