PythonQt
PythonQtImport Class Reference

implements importing of python files into PythonQt More...

#include <PythonQtImporter.h>

Classes

struct  ModuleInfo

Public Types

enum  ModuleType { MI_NOT_FOUND , MI_MODULE , MI_PACKAGE , MI_SHAREDLIBRARY }

Static Public Member Functions

static void init ()
 initialize
static void writeCompiledModule (PyCodeObject *co, const QString &filename, long mtime, long sourceSize)
 writes the python code to disk, marshalling and writing the time stamp
static PyObject * unmarshalCode (const QString &path, const QByteArray &data, time_t mtime)
static PyObject * compileSource (const QString &path, const QByteArray &data)
static PyObject * getCodeFromData (const QString &path, int isbytecode=0, int ispackage=0, time_t mtime=0)
static PyObject * getModuleCode (PythonQtImporter *self, const char *fullname, QString &modpath, QString &cachemodpath)
static PyObject * getCodeFromPyc (const QString &file)
 gets the compiled code for the given *.py file if there is a valid pyc file, otherwise compiles the file and writes the pyc
static ModuleInfo getModuleInfo (PythonQtImporter *self, const QString &fullname)
 Return if module exists and is a package or a module.
static QString getSubName (const QString &str)
 get the last name of a dot chain (first.second.last)
static long getLong (unsigned char *buf)
static time_t getMTimeOfSource (const QString &path)
 get time stamp of file
static QString replaceExtension (const QString &str, const QString &ext)
 replace extension of file
static QString getCacheFilename (const QString &sourceFile, bool isOptimizedFilename)
 Returns the filename of the cache file for the given source file, e.g. test.pyc for test.py.
static QString getSourceFilename (const QString &cacheFile)
 Returns the filename of the source file for the given cache file, e.g. test.py for test.pyc.

Detailed Description

implements importing of python files into PythonQt

also compiles/marshalls/unmarshalls py/pyc files and handles time stamps correctly

Definition at line 65 of file PythonQtImporter.h.

Member Enumeration Documentation

◆ ModuleType

Enumerator
MI_NOT_FOUND 
MI_MODULE 
MI_PACKAGE 
MI_SHAREDLIBRARY 

Definition at line 69 of file PythonQtImporter.h.

Member Function Documentation

◆ compileSource()

PyObject * PythonQtImport::compileSource ( const QString & path,
const QByteArray & data )
static

Given a string buffer containing Python source code, compile it return and return a code object as a new reference.

◆ getCacheFilename()

QString PythonQtImport::getCacheFilename ( const QString & sourceFile,
bool isOptimizedFilename )
static

Returns the filename of the cache file for the given source file, e.g. test.pyc for test.py.

◆ getCodeFromData()

PyObject * PythonQtImport::getCodeFromData ( const QString & path,
int isbytecode = 0,
int ispackage = 0,
time_t mtime = 0 )
static

Return the code object for the module named by 'fullname' from the Zip archive as a new reference.

◆ getCodeFromPyc()

PyObject * PythonQtImport::getCodeFromPyc ( const QString & file)
static

gets the compiled code for the given *.py file if there is a valid pyc file, otherwise compiles the file and writes the pyc

◆ getLong()

long PythonQtImport::getLong ( unsigned char * buf)
static

Given a buffer, return the long that is represented by the first 4 bytes, encoded as little endian. This partially reimplements marshal.c:r_long()

◆ getModuleCode()

PyObject * PythonQtImport::getModuleCode ( PythonQtImporter * self,
const char * fullname,
QString & modpath,
QString & cachemodpath )
static

Get the code object associated with the module specified by 'fullname'. In Python3, modpath will always be the path to the *.py file and cachemodpath the path to the *.pyc file (if it exists).

◆ getModuleInfo()

ModuleInfo PythonQtImport::getModuleInfo ( PythonQtImporter * self,
const QString & fullname )
static

Return if module exists and is a package or a module.

◆ getMTimeOfSource()

time_t PythonQtImport::getMTimeOfSource ( const QString & path)
static

get time stamp of file

◆ getSourceFilename()

QString PythonQtImport::getSourceFilename ( const QString & cacheFile)
static

Returns the filename of the source file for the given cache file, e.g. test.py for test.pyc.

◆ getSubName()

QString PythonQtImport::getSubName ( const QString & str)
static

get the last name of a dot chain (first.second.last)

◆ init()

void PythonQtImport::init ( )
static

initialize

◆ replaceExtension()

QString PythonQtImport::replaceExtension ( const QString & str,
const QString & ext )
static

replace extension of file

◆ unmarshalCode()

PyObject * PythonQtImport::unmarshalCode ( const QString & path,
const QByteArray & data,
time_t mtime )
static

Given the contents of a .py[co] file in a buffer, unmarshal the data and return the code object. Return None if it the magic word doesn't match (we do this instead of raising an exception as we fall back to .py if available and we don't want to mask other errors). Returns a new reference.

◆ writeCompiledModule()

void PythonQtImport::writeCompiledModule ( PyCodeObject * co,
const QString & filename,
long mtime,
long sourceSize )
static

writes the python code to disk, marshalling and writing the time stamp


The documentation for this class was generated from the following file: