Esempio n. 1
0
 def get_default_function_ns(self):
     uri = ffi.new('char**')
     _handle_error(
         self._context.set_default_element_and_type_ns(self._context, uri))
     if uri[0] == ffi.NULL:
         return None
     return ffi.string(uri[0]).decode('utf8')
Esempio n. 2
0
 def get_ns_by_prefix(self, prefix):
     uri = ffi.new('char**', ffi.NULL)
     _handle_error(
         self._context.get_ns_by_prefix(self._context,
                                        prefix.encode('utf8'), uri))
     if uri[0] == ffi.NULL:
         raise XQueryStaticError
     return ffi.string(uri[0]).decode('utf8')
Esempio n. 3
0
def error_handle_callback(handler, err, error_uri, error_localname,
                          description, error_object):
    """Handle XQuery errors and create a corresponding Python exception"""
    error_uri_str = ffi.string(error_uri).decode('utf8')
    error_localname_str = ffi.string(error_localname).decode('utf8')
    description_str = ffi.string(description).decode('utf8')
    info = "\n".join((error_uri_str, error_localname_str, description_str))
    if err == lib.XQC_STATIC_ERROR:
        exc = XQueryStaticError
    elif err == lib.XQC_TYPE_ERROR:
        exc = XQueryTypeError
    elif err == lib.XQC_DYNAMIC_ERROR:
        exc = XQueryDynamicError
    elif err == lib.XQC_SERIALIZATION_ERROR:
        exc = XQuerySerializationError
    else:
        exc = Exception
    # TODO should make this thread safe
    global _last_exception
    _last_exception = exc(info)
Esempio n. 4
0
 def node_name(self):
     uri = ffi.new('char**')
     s = ffi.new('char**')
     _handle_error(self._seq.node_name(self._seq, uri, s))
     return (ffi.string(uri[0]).decode('utf8'),
             ffi.string(s[0]).decode('utf8'))
Esempio n. 5
0
 def string_value(self):
     s = ffi.new('char**')
     _handle_error(self._seq.string_value(self._seq, s))
     return ffi.string(s[0]).decode('utf8')
Esempio n. 6
0
 def get_base_uri(self):
     s = ffi.new('char**')
     self._context.get_base_uri(self._context, s)
     return ffi.string(s[0]).decode('utf8')
Esempio n. 7
0
 def get_default_element_and_type_ns(self):
     uri = ffi.new('char**')
     _handle_error(
         self._context.get_default_element_and_type_ns(self._context, uri))
     return ffi.string(uri[0]).decode('utf8')