diff options
author | René 'Necoro' Neumann <necoro@necoro.net> | 2010-04-14 04:42:56 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.net> | 2010-04-14 04:42:56 +0200 |
commit | efd5aa7d6e66cc1ab201d5fc5933787a7c8690b5 (patch) | |
tree | 7683480524e6679e62f7c640eb8127bfbf5d3480 /portato/eix/parser.pyx | |
parent | 9c277a984863d4a5e509efb19db65c684b242ce0 (diff) | |
download | portato-efd5aa7d6e66cc1ab201d5fc5933787a7c8690b5.tar.gz portato-efd5aa7d6e66cc1ab201d5fc5933787a7c8690b5.tar.bz2 portato-efd5aa7d6e66cc1ab201d5fc5933787a7c8690b5.zip |
Fixed the unicode support and stuff ... and also made eix faster :)
Diffstat (limited to 'portato/eix/parser.pyx')
-rw-r--r-- | portato/eix/parser.pyx | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/portato/eix/parser.pyx b/portato/eix/parser.pyx index 6363b37..4315191 100644 --- a/portato/eix/parser.pyx +++ b/portato/eix/parser.pyx @@ -33,6 +33,8 @@ cdef extern from "stdio.h": cdef extern from "Python.h": FILE* PyFile_AsFile(object) +cimport python_unicode + ctypedef unsigned char UChar ctypedef long long LLong @@ -54,7 +56,15 @@ cdef int _get_byte (FILE* file) except -1: # Base Types # -cdef LLong _number (object pfile): +cpdef LLong number (object pfile): + """ + Returns a number. + + :param file: The file to read from + :type file: file + :rtype: int + """ + cdef UChar n cdef LLong value cdef int i @@ -84,18 +94,7 @@ cdef LLong _number (object pfile): return value -def number (file): - """ - Returns a number. - - :param file: The file to read from - :type file: file - :rtype: int - """ - - return _number(file) - -def vector (file, get_type, nelems = None): +cpdef object vector (object file, object get_type, object nelems = None): """ Returns a vector of elements. @@ -118,13 +117,13 @@ def vector (file, get_type, nelems = None): cdef LLong i if nelems is None: - n = _number(file) + n = number(file) else: n = nelems return [get_type(file) for i in range(n)] -def string (file): +cpdef object string (object file, char u = 0): """ Returns a string. @@ -132,13 +131,16 @@ def string (file): :type file: file :rtype: str """ - nelems = _number(file) + cdef LLong nelems = number(file) s = file.read(nelems) if len(s) != nelems: raise EndOfFileException, file.name + if u: + return python_unicode.PyUnicode_DecodeUTF8(s, nelems, 'replace') + return s # @@ -220,8 +222,8 @@ cdef class header: :param file: The file to read from :type file: file """ - self.version = _number(file) - self.ncats = _number(file) + self.version = number(file) + self.ncats = number(file) self.overlays = vector(file, overlay) self.provide = vector(file, string) self.licenses = vector(file, string) @@ -274,12 +276,12 @@ cdef class package: cdef FILE* cfile = PyFile_AsFile(file) cdef long after_offset - self._offset = _number(file) + self._offset = number(file) after_offset = ftell(cfile) self.name = string(file) - self.description = unicode(string(file)) + self.description = string(file,1) # skip the rest, as it is currently unneeded #self.provide = vector(file, number) |