PythonQt
Classes | Public Types | Static Public Member Functions | List of all members
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 More...
 
static void writeCompiledModule (PyCodeObject *co, const QString &filename, long mtime, long sourceSize)
 writes the python code to disk, marshalling and writing the time stamp More...
 
static PyObjectunmarshalCode (const QString &path, const QByteArray &data, time_t mtime)
 
static PyObjectcompileSource (const QString &path, const QByteArray &data)
 
static PyObjectgetCodeFromData (const QString &path, int isbytecode=0, int ispackage=0, time_t mtime=0)
 
static PyObjectgetModuleCode (PythonQtImporter *self, const char *fullname, QString &modpath, QString &cachemodpath)
 
static PyObjectgetCodeFromPyc (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 More...
 
static ModuleInfo getModuleInfo (PythonQtImporter *self, const QString &fullname)
 Return if module exists and is a package or a module. More...
 
static QString getSubName (const QString &str)
 get the last name of a dot chain (first.second.last) More...
 
static long getLong (unsigned char *buf)
 
static time_t getMTimeOfSource (const QString &path)
 get time stamp of file More...
 
static QString replaceExtension (const QString &str, const QString &ext)
 replace extension of file More...
 
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. More...
 
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. More...
 

Detailed Description

implements importing of python files into PythonQt

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

Definition at line 67 of file PythonQtImporter.h.

Member Enumeration Documentation

◆ ModuleType

Enumerator
MI_NOT_FOUND 
MI_MODULE 
MI_PACKAGE 
MI_SHAREDLIBRARY 

Definition at line 71 of file PythonQtImporter.h.

Member Function Documentation

◆ compileSource()

static 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()

static 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()

static 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()

static 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()

static 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()

static 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()

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

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

◆ getMTimeOfSource()

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

get time stamp of file

◆ getSourceFilename()

static 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()

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

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

◆ init()

static void PythonQtImport::init ( )
static

initialize

◆ replaceExtension()

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

replace extension of file

◆ unmarshalCode()

static 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()

static 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: