hutil package¶
Submodules¶
hutil.Qt module¶
Used by autodoc_mock_imports.
hutil.api module¶
-
class
hutil.api.
API
¶ Bases:
object
Methods of this class define the API that is invoked by URLs using the custom URL scheme.
-
exception
Error
¶ Bases:
exceptions.Exception
-
api_functions
= {}¶
-
find_api_function
(function_name, desired_api_version)¶ Look up an API function with the given name, returning None if no such function exists. If a function with the matching API version is found it is returned. Otherwise, the function with the next lowest API version is returned.
-
find_api_function_and_validate_args
(function_name, kwargs, api_version)¶ Make sure the given API function name is valid, and make sure exactly the right keyword arguments are being passed to it.
-
classmethod
register_api_function
(api_version)¶ Return a decorator that marks a method as being part of a particular version of the API.
-
exception
-
exception
hutil.api.
APICallFailed
¶ Bases:
exceptions.Exception
Bases:
exceptions.Exception
-
class
hutil.api.
ClientAPIConnection
(server_url, session_data)¶ -
class
FileArg
(contents, file_name, content_type='application/octet-stream')¶ Bases:
object
This class provides a way for the user to encode a file when passed as a value into encode_multipart_form_data.
-
class
-
class
hutil.api.
ClientSessionData
(session_key)¶ Bases:
object
hutil.cppinline module¶
This module lets you write functions in C++ that are accessible from Python. When necessary, your C++ code is automatically compiled into a library and the library is loaded, but the code won’t be compiled when the library already exists, and the library won’t be reloaded when it’s already loaded.
- NOTE: The Python ctypes module does not support 64-bit Windows in Python 2.5,
- so this module requires Python 2.6 on 64-bit Windows.
- Consider this example:
- myrandomlib = hutil.cppinline.create_library(
- name=”myrandomlib”, includes=”#include <stdlib.h>”, function_sources=[
“”” int myrandom(int num_possible_results) {
return random() % num_possible_results;} “”“])
# Print ten random numbers, each between 0 and 9 inclusive. for i in range(10):
print myrandomlib.myrandom(10)
The call to hutil.cppinline.create_library receives your C++ source code and returns a module-like object (assigned to the variable myrandomlib). You can then call myrandomlib.rand to invoke the corresponding C++ function. If you forget which parameters to pass to rand, you can get the C++ signature with:
>>> myrandomlib.myrandom.signature()
'int rand(int num_posible_results)'
Note that subsequent calls to create_lib with the exact same parameters will not recompile your module, and will not reload it if it’s been loaded in the current session.
If your code contains a compiler error, this module raises a CompilerError exception. You can compile your code with debugging enabled by passing debug=True to create_library.
If you want to check for compiler warnings, call the _compiler_output method of the module-like object. Note that if the library was already compiled when it was loaded, calling _compiler_output will force it to be recompiled.
>>> print myrandomlib._compiler_output()
Making /home/user/houdiniX.Y/inlinecpp/example_string_library_Linux_x86_64_j5c9Dz
T525OU0VdJ5uL0kw.o and /home/user/houdiniX.Y/inlinecpp/example_string_library_Lin
ux_x86_64_j5c9DzT525OU0VdJ5uL0kw.so from /home/user/houdiniX.Y/inlinecpp/example_
string_library_Linux_x86_64_j5c9DzT525OU0VdJ5uL0kw.C
- Your C++ functions may have the following parameter types:
- int float (pass a Python float) double (pass a Python float) const char * (pass a Python str object) bool (Python 2.6 and up only) any other kind of * (pass a valid address e.g. from a numpy or array object)
- Your C++ functions may have one of the following return values:
- void int float double const char * (a null-terminated string that will not be freed) char * (a null-terminated string that will be freed with free()) bool (Python 2.6 and up only) a custom structure type
The shared library file (.so on Linux, .dll on Windows, and .dylib on Mac) is put in your $HOME/.cppinline directory (unless you provide a separate compiler hook). It is named
<name>_<platform>_<processor>_<version_info>_<checksum>.{so|dll|dylib}
where the name is the name you pass to create_library and the checksum is based on the C++ source code. When you change the source code, the shared library name will be different, and this module recompiles the new library and automatically deletes any old libraries. As long as the C++ source code doesn’t change (for example, if it’s embedded inside a digital asset), you can be sure the checksum won’t change and you can distribute the library within your facility as you would with any other HDK library.
-
exception
hutil.cppinline.
CompilerError
¶ Bases:
exceptions.Exception
-
class
hutil.cppinline.
CompilerHook
¶ Bases:
object
This class is the base class for compiler hooks that let you use specific compilers to compile and link C++ code.
-
clean_up_after_compiling
(cpp_file_path, output_shared_library_path, debug, include_dirs, link_dirs, link_libs)¶ Remove any temporary files that were created during the compilation process.
Return a full path to the directory where shared libraries will be placed when initially compiled.
Search for a shared library with the given name, returning its full path or None if it couldn’t be found. This method lets you search for the library in more than the default directory.
-
get_compile_command
(cpp_file_path, output_shared_library_path, debug, include_dirs, link_dirs, link_libs)¶ Return a string containing the command to compile, and optionally also link, the given C++ file.
-
get_link_command
(cpp_file_path, output_shared_library_path, debug, include_dirs, link_dirs, link_libs)¶ Return a string to link the given C++ library, or None if the compile command also performed the linking.
-
-
class
hutil.cppinline.
Config
¶ Bases:
object
Create an instance of this class and pass it to create_library via the config parameter to customize how cppinline works.
In addition to calling the methods of this class, you can change the following attributes:
- compiler_hook
- An instance of a CompilerHook subclass that controls which compiler is used to compile and link C++ code.
- cpp_source_boilerplate_prefix
- Set this to a string that is inserted at the beginning of the C++ code that gets compiled.
- cpp_source_filtering_function
- Set this to a callable object that modifies the source code for each C++ function being wrapped by cppinline. The callable object should receive the original source code and return the modified code. You can set this attribute to None to indicate that no filtering should occur.
- error_trapping_function
- Set this to a callable object that is used to invoke the C++ ctypes function. You can use this function to detect and trap faults/ signals generated by the C++ code. The callable object receives as a parameter a function taking no parameters, and it should return the result of that function. You can set this attribute to None to indicate that no error trapping should occur.
- known_typedefs_dict
- Set this to a dictionary mapping typedef names to C++ type names for type names you pass to register_type_conversion that are actually typedef’d types.
- version_info_string
- Set this to a string that is appended to the shared library name. By using different version strings, you can prevent cppinline from loading libraries that may have already been compiled and linked.
-
register_handle_type
(cpp_type_name, handle_class)¶
-
register_type_conversion
(py_class, cpp_type_name, conversion_function)¶
-
class
hutil.cppinline.
ConverterHandle
(py_object, py_class)¶ Bases:
object
Users of this module can create subclasses of this class and register them using Config.register_handle_type. These classes are used when converting from Python objects to C++ objects, where the C++ object’s lifetime can only be ensured when holding a handle to it.
Subclasses must implement as_pointer() and destroy() methods.
-
class
hutil.cppinline.
GPlusPlusCompilerHook
¶ Bases:
hutil.cppinline.CompilerHook
This default compiler hook uses g++ to compile and link a library.
-
get_compile_command
(cpp_file_path, output_shared_library_path, debug, include_dirs, link_dirs, link_libs)¶ Return a string containing the command to compile, and optionally also link, the given C++ file.
-
get_link_command
(cpp_file_path, output_shared_library_path, debug, include_dirs, link_dirs, link_libs)¶ Return a string to link the given C++ library, or None if the compile command also performed the linking.
-
-
class
hutil.cppinline.
UnconvertedCharP
¶ Bases:
ctypes.c_char_p
-
hutil.cppinline.
create_library
(name, includes='', function_sources=(), debug=False, catch_crashes=None, acquire_hom_lock=False, structs=(), include_dirs=(), link_dirs=(), link_libs=(), config=None)¶ Create a library of C++ functions from C++ source, returning it if it’s already loaded, compiling it only if it hasn’t already been compiled.
- name:
- A unique name used to build the shared object file’s name.
- includes:
- A string containing #include lines to go before your functions. You can also put helper functions in this string that can be called from your functions but are not exposed to Python.
- function_sources:
- A sequence of strings, with each string containing the source code to one of your functions. The string must begin with the signature for your function so it can be parsed out.
- debug:
- If True, the code will be compiled with debug information. If True and you do not specify a value for catch_crashes, Houdini will also attempt to convert crashes in your C++ code into Python RuntimeError exceptions.
- catch_crashes:
- If True, Houdini will attempt to catch crashes in your C++ code and convert them into Python RuntimeError exceptions containing a C++ stack trace. There is no guarantee that Houdini can always recover from crashes in your C++ code, so Houdini may still crash even if this parameter is set to True. Setting this parameter to None (the default) will make it use the same setting as the debug parameter.
- structs:
A sequence of descriptions of C structures that can be used as return values. Each structure description is a pair, where the first element is the name of the structure and the second is a sequence of member descriptions. Each member description is a pair of strings containing the member name and type.
Member types may be one of: - A format characters used by Python’s struct module (e.g. “i” for
integer, “d” for double, “c” for character, etc.).- A format character preceded by a “*”, to indicate an array of those elements. For example, “*i” is an array of integers.
- The name of an earlier type in the sequence of structs.
Note that, instead of a sequence of member descriptions, the second element of a struct description may be a string. In this case, the type will be a typedef. These typedefs are useful to create type names for arrays of values.
For example, the following sequence creates a Point struct with two integer members x and y, and a Data struct containing members named “tolerance” (a double), “single_point” (a Point), and “points” (an array of Points. One of your C++ functions could return a “Data” value that is automatically converted into Python objects.
- (
- (“Point”, (
- (“x”, “i”), (“y”, “i”),
)), (“Data”, (
(“tolerance”, “d”), (“single_point”, “Point”), (“points”, “*Point”),)),
)
- The following sequence creates an IntArray struct:
- ((“IntArray”, “*i”),)
One of your C++ functions could then use IntArray as the return type and return a std::vector<int>.
- include_dirs:
- A sequence of extra directory paths to be used to search for include files. These paths are passed as -I options to the hcustom command when compiling the C++ code.
- link_dirs:
- A sequence of extra directory paths to be used to search for shared or static libraries that the C++ code links against. These paths are passed as -L options to the hcustom command.
- link_libs:
- A sequence of names of extra libraries that the C++ code needs to link against. These library names are passed as -l options to the hcustom command.
- config:
- Either a cppinline.Config object to customize how cppinline works, or None.
hutil.daemon module¶
Daemon process behaviour.
-
class
hutil.daemon.
DaemonContext
(chroot_directory=None, working_directory='/', umask=0, uid=None, gid=None, detach_process=None, files_preserve=None, pidfile=None, stdin=None, stdout=None, stderr=None, signal_map=None)¶ Bases:
object
Context for turning the current program into a daemon process.
A DaemonContext instance represents the behaviour settings and process context for the program when it becomes a daemon. The behaviour and environment is customised by setting options on the instance, before calling the open method.
Each option can be passed as a keyword argument to the DaemonContext constructor, or subsequently altered by assigning to an attribute on the instance at any time prior to calling open. That is, for options named wibble and wubble, the following invocation:
foo = daemon.DaemonContext(wibble=bar, wubble=baz) foo.open()
is equivalent to:
foo = daemon.DaemonContext() foo.wibble = bar foo.wubble = baz foo.open()
The following options are defined.
- files_preserve
Default: None
List of files that should not be closed when starting the daemon. If
None
, all open file descriptors will be closed.Elements of the list are file descriptors (as returned by a file object’s fileno() method) or Python file objects. Each specifies a file that is not to be closed during daemon start.
- chroot_directory
Default: None
Full path to a directory to set as the effective root directory of the process. If
None
, specifies that the root directory is not to be changed.- working_directory
Default: '/'
Full path of the working directory to which the process should change on daemon start.
Since a filesystem cannot be unmounted if a process has its current working directory on that filesystem, this should either be left at default or set to a directory that is a sensible “home directory” for the daemon while it is running.
- umask
Default: 0
File access creation mask (“umask”) to set for the process on daemon start.
Since a process inherits its umask from its parent process, starting the daemon will reset the umask to this value so that files are created by the daemon with access modes as it expects.
- pidfile
Default: None
Context manager for a PID lock file. When the daemon context opens and closes, it enters and exits the pidfile context manager.
- detach_process
Default: None
If
True
, detach the process context when opening the daemon context; ifFalse
, do not detach.If unspecified (
None
) during initialisation of the instance, this will be set toTrue
by default, andFalse
only if detaching the process is determined to be redundant; for example, in the case when the process was started by init, by initd, or by inetd.- signal_map
Default: system-dependent Mapping from operating system signals to callback actions.
The mapping is used when the daemon context opens, and determines the action for each signal’s signal handler:
- A value of
None
will ignore the signal (by setting the signal action tosignal.SIG_IGN
). - A string value will be used as the name of an attribute on the
DaemonContext
instance. The attribute’s value will be used as the action for the signal handler. - Any other value will be used as the action for the signal handler.
The default value depends on which signals are defined on the running system. Each item from the list below whose signal is actually defined in the
signal
module will appear in the default map:signal.SIGCLD
:None
signal.SIGTTIN
:None
signal.SIGTTOU
:None
signal.SIGTSTP
:None
signal.SIGTERM
:'terminate'
- A value of
- uid
Default: os.getuid()
- gid
Default: os.getgid()
The user ID (“UID”) value and group ID (“GID”) value to switch the process to on daemon start.
The default values, the real UID and GID of the process, will relinquish any effective privilege elevation inherited by the process.
- prevent_core
Default: True
If true, prevents the generation of core files, in order to avoid leaking sensitive information from daemons run as root.
- stdin
Default: None
- stdout
Default: None
- stderr
Default: None
Each of stdin, stdout, and stderr is a file-like object which will be used as the new file for the standard I/O stream sys.stdin, sys.stdout, and sys.stderr respectively. The file should therefore be open, with a minimum of mode ‘r’ in the case of stdin, and mode ‘w+’ in the case of stdout and stderr.
If the object has a fileno() method that returns a file descriptor, the corresponding file will be excluded from being closed during daemon start (that is, it will be treated as though it were listed in files_preserve).
If
None
, the corresponding system stream is re-bound to the file named by os.devnull.
-
close
()¶ Exit the daemon process context. :Return:
None
Close the daemon context. This performs the following steps:
- If this instance’s is_open property is false, return immediately. This makes it safe to call close multiple times on an instance.
- If the pidfile attribute is not
None
, exit its context manager. - Mark this instance as closed (for the purpose of future open and close calls).
-
is_open
¶ True
if the instance is currently open.
-
open
()¶ Become a daemon process. :Return:
None
Open the daemon context, turning the current program into a daemon process. This performs the following steps:
If this instance’s is_open property is true, return immediately. This makes it safe to call open multiple times on an instance.
If the prevent_core attribute is true, set the resource limits for the process to prevent any core dump from the process.
If the chroot_directory attribute is not
None
, set the effective root directory of the process to that directory (via os.chroot).This allows running the daemon process inside a “chroot gaol” as a means of limiting the system’s exposure to rogue behaviour by the process. Note that the specified directory needs to already be set up for this purpose.
Set the process UID and GID to the uid and gid attribute values.
Close all open file descriptors. This excludes those listed in the files_preserve attribute, and those that correspond to the stdin, stdout, or stderr attributes.
Change current working directory to the path specified by the working_directory attribute.
Reset the file access creation mask to the value specified by the umask attribute.
If the detach_process option is true, detach the current process into its own process group, and disassociate from any controlling terminal.
Set signal handlers as specified by the signal_map attribute.
If any of the attributes stdin, stdout, stderr are not
None
, bind the system streams sys.stdin, sys.stdout, and/or sys.stderr to the files represented by the corresponding attributes. Where the attribute has a file descriptor, the descriptor is duplicated (instead of re-binding the name).If the pidfile attribute is not
None
, enter its context manager.Mark this instance as open (for the purpose of future open and close calls).
Register the close method to be called during Python’s exit processing.
When the function returns, the running program is a daemon process.
-
static
registerPostOpenCallback
(func)¶
-
static
registerPreOpenCallback
(func)¶
-
terminate
(signal_number, stack_frame)¶ Signal handler for end-process signals. :Return:
None
Signal handler for the
signal.SIGTERM
signal. Performs the following step:- Raise a
SystemExit
exception explaining the signal.
- Raise a
-
exception
hutil.daemon.
DaemonError
¶ Bases:
exceptions.Exception
Base exception class for errors from this module.
-
exception
hutil.daemon.
DaemonOSEnvironmentError
¶ Bases:
hutil.daemon.DaemonError
,exceptions.OSError
Exception raised when daemon OS environment setup receives error.
-
exception
hutil.daemon.
DaemonProcessDetachError
¶ Bases:
hutil.daemon.DaemonError
,exceptions.OSError
Exception raised when process detach fails.
-
hutil.daemon.
change_file_creation_mask
(mask)¶ Change the file creation mask for this process.
-
hutil.daemon.
change_process_owner
(uid, gid)¶ Change the owning UID and GID of this process.
Sets the GID then the UID of the process (in that order, to avoid permission errors) to the specified gid and uid values. Requires appropriate OS privileges for this process.
-
hutil.daemon.
change_root_directory
(directory)¶ Change the root directory of this process.
Sets the current working directory, then the process root directory, to the specified directory. Requires appropriate OS privileges for this process.
-
hutil.daemon.
change_working_directory
(directory)¶ Change the working directory of this process.
-
hutil.daemon.
close_all_open_files
(exclude=set([]))¶ Close all open file descriptors.
Closes every file descriptor (if open) of this process. If specified, exclude is a set of file descriptors to not close.
-
hutil.daemon.
close_file_descriptor_if_open
(fd)¶ Close a file descriptor if already open.
Close the file descriptor fd, suppressing an error in the case the file was not open.
-
hutil.daemon.
detach_process_context
()¶ Detach the process context from parent and session.
Detach from the parent process and session group, allowing the parent to exit while this process continues running.
Reference: “Advanced Programming in the Unix Environment”, section 13.3, by W. Richard Stevens, published 1993 by Addison-Wesley.
-
hutil.daemon.
get_maximum_file_descriptors
()¶ Return the maximum number of open file descriptors for this process.
Return the process hard resource limit of maximum number of open file descriptors. If the limit is “infinity”, a default value of
MAXFD
is returned.
-
hutil.daemon.
is_detach_process_context_required
()¶ Determine whether detaching process context is required.
Return
True
if the process environment indicates the process is already detached:- Process was started by init; or
- Process was started by inetd.
-
hutil.daemon.
is_process_started_by_init
()¶ Determine if the current process is started by init.
The init process has the process ID of 1; if that is our parent process ID, return
True
, otherwiseFalse
.
-
hutil.daemon.
is_process_started_by_superserver
()¶ Determine if the current process is started by the superserver.
The internet superserver creates a network socket, and attaches it to the standard streams of the child process. If that is the case for this process, return
True
, otherwiseFalse
.
-
hutil.daemon.
is_socket
(fd)¶ Determine if the file descriptor is a socket.
Return
False
if querying the socket type of fd raises an error; otherwise returnTrue
.
-
hutil.daemon.
make_default_signal_map
()¶ Make the default signal map for this system.
The signals available differ by system. The map will not contain any signals not defined on the running system.
-
hutil.daemon.
prevent_core_dump
()¶ Prevent this process from generating a core dump.
Sets the soft and hard limits for core dump size to zero. On Unix, this prevents the process from creating core dump altogether.
-
hutil.daemon.
redirect_stream
(system_stream, target_stream)¶ Redirect a system stream to a specified file.
system_stream is a standard system stream such as
sys.stdout
. target_stream is an open file object that should replace the corresponding system stream object.If target_stream is
None
, defaults to opening the operating system’s null device and using its file descriptor.
-
hutil.daemon.
register_atexit_function
(func)¶ Register a function for processing at program exit.
The function func is registered for a call with no arguments at program exit.
-
hutil.daemon.
set_signal_handlers
(signal_handler_map)¶ Set the signal handlers as specified.
The signal_handler_map argument is a map from signal number to signal handler. See the signal module for details.
hutil.debug module¶
Allows you to get a stack trace and inspect variables of a running Python program by sending it a SIGUSR1 signal (non-Windows only).
- For non-dameon programs:
- From the Python program, call hutil.debug.enableUserSignalHandling(). Debug the process by running “kill -USR1 <pid>”.
- For daemon programs:
- From the Python program, call
- hutil.debug.enableUserSignalHandling(as_daemon=True)
- To debug the process, run
- “hython -m htuil.debug <pid>”
-
hutil.debug.
enableUserSignalHandling
(as_daemon=False)¶ All this program to respond to a SIGUSR1 signal by printing a stack trace and launching an interactive Python session.
Note that SIGUSR1 is not available on Windows.
hutil.enum module¶
Provides a simple enumeration class.
- Example usage;
State = hutil.enum.Enumeration(“not_started”, “started”, “done”)
s1 = State.not_started s2 = State.started if s1 != s2:
print “s1 != s2”print s1 # prints “not_started”
- for s in State:
- print s
-
class
hutil.enum.
Enumeration
(*args)¶ Bases:
object
hutil.file module¶
File-related utility functions.
-
hutil.file.
checksum
(file_path)¶ Given a file path, return a checksum of the contents of the file.
-
hutil.file.
convertToWinPath
(path, var_notation='%')¶ Given a path, convert it to a Windows path and return it.
-
hutil.file.
convertToWinVariables
(s)¶ Given a string, replace any variables in the string (i.e. $FOO) with Windows variable notation (i.e. %FOO%).
-
hutil.file.
ensureDirExists
(dir_path)¶
-
hutil.file.
humanReadableSize
(num_bytes)¶ Given a size in bytes, return a string describing that size.
-
hutil.file.
insertFileSuffix
(filename, file_suffix)¶
-
hutil.file.
readFile
(file_name, binary=False)¶ Read in a file and return its contents as a string.
-
hutil.file.
splitVersionSuffix
(filename, version_separator=None)¶ Split the basename and the version suffix from the given filename.
Return a 2-tuple of (basename, version). If there is no version suffix, then (basename, None) is returned. Paths and file extensions are excluded from the basename.
The version suffix is the largest set of digits at the end of the filename (excluding the extension). If version_separator is set to a single character, then the version suffix is the largest set of digits at the end of the filename AND immediately after the character. The version_separator is excluded from the basename.
- Some examples:
- splitVersionSuffix(“myFilename.txt”) => (“myFilename”, None) splitVersionSuffix(“myFilename2.txt”) => (“myFilename”, “2”) splitVersionSuffix(“myFilename_2.txt”) => (“myFilename_”, “2”) splitVersionSuffix(“myFilename_2.txt”, ‘_’) => (“myFilename”, “2”) splitVersionSuffix(“myFilename2.txt”, ‘_’) => (“myFilename2”, None)
-
hutil.file.
writeFile
(file_name, contents, binary=False)¶ Write the given string to a file.
hutil.ipaddress module¶
-
hutil.ipaddress.
doesAddressMatchNetMask
(address, mask)¶ Returns True if the address (xxx.xxx.xxx.xxx) matches the given CIDR netmask (xxx.xxx.xxx.xxx/xx).
-
hutil.ipaddress.
getMyIPAddress
()¶ Get my IP address from an external web server that displays it.
Unfortunately, the only way to get this machine’s externally-visible IP address is to get another machine on the internet to tell it to us.
Return None if the IP address could not be determined.
-
hutil.ipaddress.
getMyLatLong
()¶ Return a tuple of (latitude, longitude) values for our location, based off my IP address.
Return None if the location could not be determined.
-
hutil.ipaddress.
getMyTimezoneOffset
()¶ Return the offset of this timezone from GMT, accounting for whether or not daylight savings time is in effect.
hutil.json module¶
JSON-related utility and wrapper functions.
This module will wrap one of the standard json module, simplejson, or demjson, preferring the standard json. Note that the types of exceptions raised can vary depending on which library is wrapped.
To guarantee utf8-encoded strings instead of unicode strings, use the utf8* versions of the functions.
-
class
hutil.json.
DictAsObject
(*args, **kwargs)¶ Bases:
dict
-
hutil.json.
dumpToFile
(obj, file_path)¶ Save the JSON-encoded representation of an object to a file.
-
hutil.json.
loadFromFile
(file_path)¶ Given a file containing JSON-encoded data, return the decoded object.
-
hutil.json.
object_from_json_data
(obj)¶ Convert a decoded JSON data structure into one with smart dictionaries that support attribute lookups to access dictionary values. For example, if:
- o = object_from_json_data({
“name”: “Joe”, “children”: [
{“name”: “Bob”}, {“name”: “Sally”},]
})
- one could write:
- o[“name”] o[“children”][0][“name”]
- but the output from this function also lets you write:
- o.name o.children[0].name
-
hutil.json.
utf8Dumps
(obj)¶ Like dumps, but ensures that the result is not a unicode object by utf-8 encoding it.
-
hutil.json.
utf8LoadFromFile
(file_path)¶ Like loadFromFile, except the strings in the decoded object are utf8- encoded.
-
hutil.json.
utf8Loads
(string)¶ Like loads, but all strings in the result object are utf8-encoded and not unicode.
hutil.log module¶
Contains a function to create and set up a logger that provides consistent also captures stdout and stderr.
-
hutil.log.
createLogger
(debug, verbose, name, log_file_name)¶ Create and return a logger, and also redirect stdout and stderr to the logger. If debug is True, the logging level is set to logging.DEBUG; otherwise it is set to logging.INFO. If verbose is True, log output is also sent to stdout.
hutil.parsecppsig module¶
This module contains code to parse C++ types and function signatures.
-
class
hutil.parsecppsig.
CPPNativeType
(base_type_name, type_qualifier, is_unsigned, is_const)¶ Bases:
hutil.parsecppsig.CPPType
A class representing a native data type in C++.
-
copy
()¶
-
ctype
()¶
-
msvc_mangled_name
(is_return_type=False)¶
-
name_without_const
()¶
-
-
class
hutil.parsecppsig.
CPPPointerType
(referenced_type, is_const)¶ Bases:
hutil.parsecppsig.CPPType
A class representing a C++ pointer type.
-
copy
()¶
-
ctype
()¶
-
is_pointer
()¶
-
msvc_mangled_name
(is_return_type=False)¶
-
-
class
hutil.parsecppsig.
CPPSignature
(function_name, return_cpp_type, parameters)¶ Bases:
object
-
as_code
()¶
-
msvc_mangled_name
()¶
-
-
class
hutil.parsecppsig.
CPPType
(is_const)¶ Bases:
object
The base class that represents a C++ type.
-
classmethod
is_native_type
(base_type_name)¶
-
is_pointer
()¶
-
classmethod
is_type_keyword
(name)¶
-
is_user_type
()¶
-
name
()¶
-
classmethod
-
class
hutil.parsecppsig.
CPPTypeAndName
(cpp_type, name)¶ Bases:
object
A pair storing a CPPType object and a name. This pair can represent a parameter in a function signature or a member in a struct.
-
as_code
()¶
-
-
class
hutil.parsecppsig.
CPPUserType
(base_type_name, is_const, template_types=(), members=(), extra_ctypes_class_members={})¶ Bases:
hutil.parsecppsig.CPPType
A class representing a user-defined data type in C++ (a class, struct, or typedef). If it represents a class, it may or may not be templated. If it represents a class or struct whose members are known, the number of members will not be zero. If the number of members is not zero, the object doesn’t not represent a typedef.
-
class_definition_code
()¶
-
copy
()¶
-
ctype
()¶
-
is_pointer
()¶
-
is_user_type
()¶
-
msvc_mangled_name
(is_return_type=False)¶
-
name_without_const
()¶
-
-
exception
hutil.parsecppsig.
ParseError
¶ Bases:
exceptions.Exception
-
hutil.parsecppsig.
parse_cpp_signature
(cpp_source, named_types_dict)¶ Given the C++ source code for a function, parse out the function signature and return a CPPSignature object.
-
hutil.parsecppsig.
parse_cpp_type
(cpp_type_name, named_types_dict={})¶
hutil.pbkdf2 module¶
-
class
hutil.pbkdf2.
PBKDF2
(passphrase, salt, iterations=1000, digestmodule=<module 'Crypto.Hash.SHA' from 'C:/PROGRA~1/SIDEEF~1/HOUDIN~1.439/python27/lib/site-packagesCryptoHashSHA.py'>, macmodule=<module 'Crypto.Hash.HMAC' from 'C:/PROGRA~1/SIDEEF~1/HOUDIN~1.439/python27/lib/site-packagesCryptoHashHMAC.py'>)¶ Bases:
object
PBKDF2.py : PKCS#5 v2.0 Password-Based Key Derivation
This implementation takes a passphrase and a salt (and optionally an iteration count, a digest module, and a MAC module) and provides a file-like object from which an arbitrarily-sized key can be read.
If the passphrase and/or salt are unicode objects, they are encoded as UTF-8 before they are processed.
The idea behind PBKDF2 is to derive a cryptographic key from a passphrase and a salt.
PBKDF2 may also be used as a strong salted password hash. The ‘crypt’ function is provided for that purpose.
Remember: Keys generated using PBKDF2 are only as strong as the passphrases they are derived from.
-
close
()¶ Close the stream.
-
static
crypt
(word, salt=None, iterations=None)¶ PBKDF2-based unix crypt(3) replacement.
The number of iterations specified in the salt overrides the ‘iterations’ parameter.
The effective hash length is 192 bits.
-
hexread
(octets)¶ Read the specified number of octets. Return them as hexadecimal.
Note that len(obj.hexread(n)) == 2*n.
-
read
(bytes)¶ Read the specified number of key bytes.
-
-
hutil.pbkdf2.
crypt
(word, salt=None, iterations=None)¶ PBKDF2-based unix crypt(3) replacement.
The number of iterations specified in the salt overrides the ‘iterations’ parameter.
The effective hash length is 192 bits.
hutil.pidfile module¶
This module is to be used in conjunction with the daemon module.
- For example,
- daemon_context = hutil.daemon.DaemonContext(
- uid=nobody_uid, gid=nobody_uid, pidfile=hutil.pidfile.PidFileCheck(“/tmp/your_daemon.pid”))
-
class
hutil.pidfile.
PidFileCheck
(pidfile_name)¶ Bases:
object
hutil.pyrpc module¶
A module to provide transparent Python-to-Python Remote Procedure Calls (RPC). This method is not to be confused with hrpyc, which is built on RPyC.
- From the server, start a thread to listen on socket connections with:
- hpyrpc.start_server()
- From the client, import a module that exists on the server and use it:
- hou = hpyrpc.import_remote_module(“hou”) print(hou.node(“/obj”).name())
-
class
hutil.pyrpc.
BoxedFromProxy
(*args)¶ Bases:
hutil.pyrpc.Boxed
A proxy to an object that exists on the server, boxed up to be sent back to the server.
-
arg_names
= ('object_id',)¶
-
-
class
hutil.pyrpc.
BoxedToClassProxy
(*args)¶ Bases:
hutil.pyrpc.Boxed
A class that exists on the server, boxed up to be sent to the client as a proxy.
-
arg_names
= ('class_object_id',)¶
-
-
class
hutil.pyrpc.
BoxedToObjectProxy
(*args)¶ Bases:
hutil.pyrpc.Boxed
An object that exists on the server, boxed up to be sent to the client as a proxy.
-
arg_names
= ('object_id', 'class_object_id')¶
-
-
class
hutil.pyrpc.
CallMessage
(session, *args)¶ Bases:
hutil.pyrpc.MessageOnObject
Call an object.
-
arg_names
= ('object_id', 'marshalled_args', 'marshalled_kwargs_items')¶
-
handle_ignoring_exceptions
(obj, args, kwargs_items)¶
-
-
class
hutil.pyrpc.
CallMethodMessage
(session, *args)¶ Bases:
hutil.pyrpc.MessageOnObject
Call a method on a object.
This message is only used to invoke the __getattribute__, __setattr__, and __delattr__ methods.
-
arg_names
= ('object_id', 'method_name', 'marshalled_args')¶
-
handle_ignoring_exceptions
(obj, method_name, args)¶
-
-
class
hutil.pyrpc.
CallUnboundMethodMessage
(session, *args)¶ Bases:
hutil.pyrpc.MessageOnObject
Call a method on a object, explicitly passing in the object as the first parameter.
This message is only used to invoke the __getattribute__, __setattr__, and __delattr__ methods.
-
arg_names
= ('object_id', 'method_name', 'marshalled_args')¶
-
handle_ignoring_exceptions
(obj, method_name, args)¶
-
-
exception
hutil.pyrpc.
ConnectionError
¶ Bases:
exceptions.Exception
-
class
hutil.pyrpc.
DataSerializer
¶ Bases:
object
-
builtin_ids_to_names
= {7655664L: '__name__', 7667912L: '__import__', 7667976L: 'abs', 7668040L: 'all', 7668104L: 'any', 7668168L: 'apply', 7668232L: 'bin', 7668296L: 'callable', 7668360L: 'chr', 7668424L: 'cmp', 7668488L: 'coerce', 7668552L: 'compile', 7668616L: 'delattr', 7668680L: 'dir', 7668744L: 'divmod', 7668808L: 'eval', 7668872L: 'execfile', 7668936L: 'filter', 7669000L: 'format', 7669064L: 'getattr', 7669128L: 'globals', 7669192L: 'hasattr', 7669256L: 'hash', 7669320L: 'hex', 7669384L: 'id', 7669448L: 'input', 7669512L: 'intern', 7669576L: 'isinstance', 7669640L: 'issubclass', 7669704L: 'iter', 7669768L: 'len', 7669832L: 'locals', 7669896L: 'map', 7669960L: 'max', 7670024L: 'min', 7670088L: 'next', 7670152L: 'oct', 7670216L: 'open', 7670280L: 'ord', 7670344L: 'pow', 7670408L: 'print', 7670472L: 'range', 7670536L: 'raw_input', 7670600L: 'reduce', 7670664L: 'reload', 7670728L: 'repr', 7670792L: 'round', 7670856L: 'setattr', 7670920L: 'sorted', 7670984L: 'sum', 7671048L: 'unichr', 7671112L: 'vars', 7671176L: 'zip', 7671856L: '__doc__', 42518736L: 'quit', 42519744L: 'credits', 42520136L: 'exit', 42520472L: 'copyright', 42520528L: 'license', 42541184L: 'help', 505892160L: 'bool', 505892552L: 'False', 505892576L: 'True', 505893072L: 'buffer', 505901968L: 'bytearray', 505909408L: 'complex', 505913744L: 'property', 505918816L: 'dict', 505922256L: 'enumerate', 505922656L: 'reversed', 505923424L: 'BaseException', 505923824L: 'Exception', 505924224L: 'StandardError', 505924624L: 'TypeError', 505925024L: 'StopIteration', 505925424L: 'GeneratorExit', 505925904L: 'SystemExit', 505926304L: 'KeyboardInterrupt', 505926704L: 'ImportError', 505927328L: 'EnvironmentError', 505927728L: 'IOError', 505928128L: 'OSError', 505928736L: 'WindowsError', 505929136L: 'EOFError', 505929536L: 'RuntimeError', 505929936L: 'NotImplementedError', 505930336L: 'NameError', 505930736L: 'UnboundLocalError', 505931136L: 'AttributeError', 505931824L: 'SyntaxError', 505932224L: 'IndentationError', 505932624L: 'TabError', 505933024L: 'LookupError', 505933424L: 'IndexError', 505933824L: 'KeyError', 505934224L: 'ValueError', 505934624L: 'UnicodeError', 505935264L: 'UnicodeEncodeError', 505935664L: 'UnicodeDecodeError', 505936064L: 'UnicodeTranslateError', 505936464L: 'AssertionError', 505936864L: 'ArithmeticError', 505937264L: 'FloatingPointError', 505937664L: 'OverflowError', 505938064L: 'ZeroDivisionError', 505938464L: 'SystemError', 505938864L: 'ReferenceError', 505939264L: 'MemoryError', 505939664L: 'BufferError', 505940064L: 'Warning', 505940464L: 'UserWarning', 505940864L: 'DeprecationWarning', 505941264L: 'PendingDeprecationWarning', 505941664L: 'SyntaxWarning', 505942064L: 'RuntimeWarning', 505942464L: 'FutureWarning', 505942864L: 'ImportWarning', 505943264L: 'UnicodeWarning', 505943664L: 'BytesWarning', 505949072L: 'file', 505952480L: 'float', 505956800L: 'classmethod', 505957200L: 'staticmethod', 505960240L: 'int', 505964608L: 'list', 505967136L: 'long', 505969280L: 'memoryview', 505971768L: 'None', 505971784L: 'NotImplemented', 505973376L: 'xrange', 505977792L: 'set', 505978192L: 'frozenset', 505979296L: 'Ellipsis', 505979312L: 'slice', 505988080L: 'basestring', 505988480L: 'str', 505993824L: 'tuple', 505995952L: 'type', 505996352L: 'object', 505996752L: 'super', 506047328L: 'unicode'}¶
-
decode_from_socket
(sock)¶
-
decode_sub_object
()¶
-
encode
(obj)¶
-
encode_sub_object
(obj)¶
-
-
class
hutil.pyrpc.
DelProxyMessage
(session, *args)¶ Bases:
hutil.pyrpc.MessageOnObject
Remove a proxy to a remote object.
-
handle_ignoring_exceptions
(ignored_obj)¶
-
-
class
hutil.pyrpc.
DirMessage
(session, *args)¶ Bases:
hutil.pyrpc.MessageOnObject
Return the result of dir on the remote object.
-
arg_names
= ('object_id',)¶
-
handle_ignoring_exceptions
(obj)¶
-
-
class
hutil.pyrpc.
GetClassInfoMessage
(session, *args)¶ Bases:
hutil.pyrpc.Message
Return information about a remote class. This message is invoked on with the class object’s object id.
-
arg_names
= ('class_object_id',)¶
-
handle
()¶
-
-
class
hutil.pyrpc.
ImportModuleMessage
(session, *args)¶ Bases:
hutil.pyrpc.Message
Import a remote module.
-
arg_names
= ('module_name',)¶
-
handle
()¶
-
-
class
hutil.pyrpc.
InstanceCheckMessage
(session, *args)¶ Bases:
hutil.pyrpc.MessageOnObject
Return whether a proxy to a remote object is an instance of a proxy to a remote class. This message is invoked on the proxy to the remote class.
-
arg_names
= ('object_id', 'marshalled_object')¶
-
handle_ignoring_exceptions
(cls, obj)¶
-
-
exception
hutil.pyrpc.
InvalidSession
¶ Bases:
exceptions.Exception
This exception is raised when the client uses proxies from a different RPC Session.
-
class
hutil.pyrpc.
Message
(session, *args)¶ Bases:
object
-
classmethod
receive
(session)¶ Build an instance of a Message subclass from the data decoded from the socket and handle that message.
-
send
()¶
-
send_and_receive
()¶
-
classmethod
-
class
hutil.pyrpc.
MessageOnObject
(session, *args)¶ Bases:
hutil.pyrpc.Message
A helper base class for messages involving a proxy to a remote object.
-
arg_names
= ('object_id',)¶
-
handle
()¶
-
-
class
hutil.pyrpc.
RPCServer
(port)¶ Bases:
SocketServer.TCPServer
-
allow_reuse_address
= True¶
-
finish_request
(sock, client_address)¶
-
-
class
hutil.pyrpc.
RemoteClassProxy
¶ Bases:
abc.ABCMeta
-
class
hutil.pyrpc.
RemoteObjectProxy
(session, remote_object_id)¶ Bases:
object
-
class
hutil.pyrpc.
ReturnMessage
(session, *args)¶ Bases:
hutil.pyrpc.Message
Receiving this message unmarshals and returns its value, or raises an exception if it represents a raised exception.
-
arg_names
= ('marshalled_value', 'is_exception')¶
-
extract_result
()¶
-
-
class
hutil.pyrpc.
Session
(sock)¶ Bases:
object
Both the client and the server create Session objects.
-
class
ObjectAndCount
(obj)¶ Bases:
object
Stores an object and its reference count (i.e. the number of proxy objects on the client that refer to it.
-
class
RemoteClassInfo
(session, class_object_id, class_name, base_builtin_class_name, special_method_names)¶ Bases:
object
Stores information about a class on the remote server, including how to construct a proxy for an instance of the class and for the class itself.
-
get_class_by_id
(class_object_id)¶
-
marshal
(obj)¶ Return an object that can be encoded by DataSerializer to be sent remotely.
-
remove_object_by_id
(object_id)¶
-
unmarshal
(obj)¶ Given data decoded by DataSerializer, return a value to be used by the client.
-
class
-
hutil.pyrpc.
import_remote_module
(module_name, server_name='127.0.0.1', port=10888)¶
-
hutil.pyrpc.
start_server
(port=10888, use_thread=True)¶
hutil.username module¶
-
hutil.username.
currentUserName
()¶ Return the login name of the current user, or “unknown” if it couldn’t be determined.
hutil.web module¶
Web-related utility functions.
-
class
hutil.web.
FileArg
(contents, file_name, content_type='application/octet-stream')¶ Bases:
object
This class provides a way for the user to encode a file when passed as a value into encode_multipart_form_data.
-
hutil.web.
encode_multipart_form_data
(fields)¶ Given a sequence of (field_name, field_value) pairs, return a (content_type, post_data) tuple. The content type header is necessary because it identifies the data as multipart/text and it contains the boundary.
Note that field_value may be a FileArg instance.
-
hutil.web.
readURL
(url, post_data=None, extra_headers=(), require_content_length=False, timeout=None, disable_proxy=False)¶ Read the contents of a URL and return an (http_response_code, content_type, content) tuple. If the connection generated a socket error then it raises urllib2.URLError.
-
hutil.web.
readURLContents
(url, post_data=None, extra_headers=(), require_content_length=False, disable_proxy=False)¶ Read the data at a URL. Return None if the URL could not be read.
-
hutil.web.
read_url
(url, post_data=None, extra_headers=(), require_content_length=False, timeout=None, disable_proxy=False)¶ Read the contents of a URL and return an (http_response_code, content_type, content) tuple. If the connection generated a socket error then it raises urllib2.URLError.
-
hutil.web.
read_url_contents
(url, post_data=None, extra_headers=(), require_content_length=False, disable_proxy=False)¶ Read the data at a URL. Return None if the URL could not be read.
-
hutil.web.
save_url_to_file
(url, file_name, post_data=None, extra_headers=(), progress_callback=None, callback_additional_kwargs={}, disable_proxy=False)¶ This helper function reads the contents of a URL and saves it to a file.
On an error, it raises an urllib2.URLError exception. Possible errors are a non-200 http response or a missing Content-Length header.
- If progress_callback is provided, it will be called periodically as follows:
- progress_callback(bytes_downloaded, total_num_bytes, callback_additional_kwargs)