Xmlb.Machine

g GObject.Object GObject.Object Xmlb.Machine Xmlb.Machine GObject.Object->Xmlb.Machine

Subclasses:

None

Methods

Inherited:

GObject.Object (37)

Structs:

GObject.ObjectClass (5)

class

new ()

add_method (name, n_opcodes, method_cb, *user_data)

add_opcode_fixup (opcodes_sig, fixup_cb, *user_data)

add_operator (str, name)

add_text_handler (handler_cb, *user_data)

get_stack_size ()

opcode_func_init (func_name)

parse (text, text_len)

parse_full (text, text_len, flags)

run (opcodes, exec_data)

run_with_bindings (opcodes, bindings, exec_data)

set_debug_flags (flags)

set_stack_size (stack_size)

stack_pop (stack)

stack_push (stack)

stack_push_integer (stack, val)

stack_push_text (stack, str)

stack_push_text_static (stack, str)

stack_push_text_steal (stack, str)

Virtual Methods

Inherited:

GObject.Object (7)

Properties

None

Signals

Inherited:

GObject.Object (1)

Fields

Inherited:

GObject.Object (1)

Name

Type

Access

Description

parent_instance

GObject.Object

r

Class Details

class Xmlb.Machine(**kwargs)
Bases:

GObject.Object

Abstract:

No

Structure:

Xmlb.MachineClass

classmethod new()
Returns:

a new Xmlb.Machine

Return type:

Xmlb.Machine

Creates a new virtual machine.

New in version 0.1.1.

add_method(name, n_opcodes, method_cb, *user_data)
Parameters:
  • name (str) – function name, e.g. contains

  • n_opcodes (int) – minimum number of opcodes required on the stack

  • method_cb (Xmlb.MachineMethodFunc) – function to call

  • user_data (object or None) – user pointer to pass to method_cb, or None

Adds a new function to the virtual machine. Registered functions can then be used as methods.

The method_cb must not modify the stack it’s passed unless it’s going to succeed. In particular, if a method call is not optimisable, it must not modify the stack it’s passed.

You need to add a custom function using Xmlb.Machine.add_method() before using methods that may reference it, for example Xmlb.Machine.add_opcode_fixup().

New in version 0.1.1.

add_opcode_fixup(opcodes_sig, fixup_cb, *user_data)
Parameters:

Adds an opcode fixup. Fixups can be used to optimize the stack of opcodes or to add support for a nonstandard feature, for instance supporting missing attributes to functions.

New in version 0.1.1.

add_operator(str, name)
Parameters:
  • str (str) – operator string, e.g. ==

  • name (str) – function name, e.g. contains

Adds a new operator to the virtual machine. Operators can then be used instead of explicit methods like eq().

You need to add a custom operator using Xmlb.Machine.add_operator() before using Xmlb.Machine.parse(). Common operators like <= and = are built-in and do not have to be added manually.

New in version 0.1.1.

add_text_handler(handler_cb, *user_data)
Parameters:

Adds a text handler. This allows the virtual machine to support nonstandard encoding or shorthand mnemonics for standard functions.

New in version 0.1.1.

get_stack_size()
Returns:

integer

Return type:

int

Gets the maximum stack size used for the machine.

New in version 0.1.3.

opcode_func_init(func_name)
Parameters:

func_name (str) – function name, e.g. eq

Returns:

True if the function was found and the opcode initialised, False otherwise

opcode:

a stack allocated Xmlb.Opcode to initialise

Return type:

(bool, opcode: Xmlb.Opcode)

Initialises a stack allocated Xmlb.Opcode for a registered function. Some standard functions are registered by default, for instance eq or ge. Other functions have to be added using Xmlb.Machine.add_method().

New in version 0.2.0.

parse(text, text_len)
Parameters:
  • text (str) – predicate to parse, e.g. contains(text(),'xyx')

  • text_len (int) – length of text, or -1 if text is NUL terminated

Raises:

GLib.Error

Returns:

opcodes, or None on error

Return type:

Xmlb.Stack

Parses an XPath predicate. Not all of XPath 1.0 or XPath 1.0 is supported, and new functions and mnemonics can be added using Xmlb.Machine.add_method() and Xmlb.Machine.add_text_handler().

New in version 0.1.1.

parse_full(text, text_len, flags)
Parameters:
Raises:

GLib.Error

Returns:

opcodes, or None on error

Return type:

Xmlb.Stack

Parses an XPath predicate. Not all of XPath 1.0 or XPath 1.0 is supported, and new functions and mnemonics can be added using Xmlb.Machine.add_method() and Xmlb.Machine.add_text_handler().

New in version 0.1.4.

run(opcodes, exec_data)
Parameters:
Raises:

GLib.Error

Returns:

a new Xmlb.Opcode, or None

result:

return status after running opcodes

Return type:

(bool, result: bool)

Runs a set of opcodes on the virtual machine.

It is safe to call this function from a different thread to the one that created the Xmlb.Machine.

New in version 0.1.1.

Deprecated since version 0.3.0: Use Xmlb.Machine.run_with_bindings() instead.

run_with_bindings(opcodes, bindings, exec_data)
Parameters:
Raises:

GLib.Error

Returns:

a new Xmlb.Opcode, or None

result:

return status after running opcodes

Return type:

(bool, result: bool)

Runs a set of opcodes on the virtual machine, using the bound values given in bindings to substitute for bound opcodes.

It is safe to call this function from a different thread to the one that created the Xmlb.Machine.

New in version 0.3.0.

set_debug_flags(flags)
Parameters:

flags (Xmlb.MachineDebugFlags) – Xmlb.MachineDebugFlags, e.g. Xmlb.MachineDebugFlags.SHOW_STACK

Sets the debug level of the virtual machine.

New in version 0.1.1.

set_stack_size(stack_size)
Parameters:

stack_size (int) – integer

Sets the maximum stack size used for the machine.

The stack size will be affective for new jobs started with Xmlb.Machine.run() and Xmlb.Machine.parse().

New in version 0.1.3.

stack_pop(stack)
Parameters:

stack (Xmlb.Stack) – a Xmlb.Stack

Raises:

GLib.Error

Returns:

True if popping succeeded, False if the stack was empty already

opcode_out:

return location for the popped Xmlb.Opcode

Return type:

(bool, opcode_out: Xmlb.Opcode)

Pops an opcode from the stack.

New in version 0.2.0.

stack_push(stack)
Parameters:

stack (Xmlb.Stack) – a Xmlb.Stack

Raises:

GLib.Error

Returns:

True if a new empty opcode was returned, or False if the stack has reached its maximum size

opcode_out:

return location for the new Xmlb.Opcode

Return type:

(bool, opcode_out: Xmlb.Opcode or None)

Pushes a new empty opcode onto the end of the stack. A pointer to the opcode is returned in opcode_out so that the caller can initialise it.

If the stack reaches its maximum size, Gio.IOErrorEnum.NO_SPACE will be returned.

New in version 0.2.0.

stack_push_integer(stack, val)
Parameters:
Raises:

GLib.Error

Returns:

True on success, False otherwise

Return type:

bool

Adds an integer literal to the stack.

Errors are as for Xmlb.Machine.stack_push().

New in version 0.2.0.

stack_push_text(stack, str)
Parameters:
Raises:

GLib.Error

Returns:

True on success, False otherwise

Return type:

bool

Adds a text literal to the stack, copying str.

Errors are as for Xmlb.Machine.stack_push().

New in version 0.2.0.

stack_push_text_static(stack, str)
Parameters:
Raises:

GLib.Error

Returns:

True on success, False otherwise

Return type:

bool

Adds static text literal to the stack.

Errors are as for Xmlb.Machine.stack_push().

New in version 0.2.0.

stack_push_text_steal(stack, str)
Parameters:
Raises:

GLib.Error

Returns:

True on success, False otherwise

Return type:

bool

Adds a stolen text literal to the stack.

Errors are as for Xmlb.Machine.stack_push().

New in version 0.2.0.