ccpnmodel.ccpncore.memops.scripts.core package

Submodules

ccpnmodel.ccpncore.memops.scripts.core.FileModelAdapt module

Module Documentation here

class ccpnmodel.ccpncore.memops.scripts.core.FileModelAdapt.FileModelAdapt[source]

Bases: ccpnmodel.ccpncore.memops.scripts.core.ModelAdapt.ModelAdapt

Python-specific version of ModelAdapt

ccpnmodel.ccpncore.memops.scripts.core.LanguageInterface module

Module Documentation here

class ccpnmodel.ccpncore.memops.scripts.core.LanguageInterface.LanguageInterface[source]

Bases: object

addAllCollection(var, collection, isUnique, isOrdered, varType=None)[source]
addAllList(var, collection, varType=None)[source]
addCollection(var, collection, isUnique, isOrdered, varType=None)[source]
addList(var, collection, varType=None)[source]
arithmetic(expression1, op, expression2)[source]
boolean(expression)[source]
breakLoop()[source]
callFunc(func, obj=None, params=None, doWrite=True)[source]
callKwFunc(func, obj=None, params=None, setVarTo=None, kwDict={})[source]

call function with keyword-value parameters. kwDict keys are assumed to be strings, kwDict values are assumed to be printable as given (hint - use toLiteral for literals). the result is set to setVarTo, unless this is None

NB for languages that do not accept keyword-value parameters, the information is passed in a dictionary variable that is put last on the variable list. callKwFunc will only work for functions that have this behaviour.

castVar(castType, var)[source]
catchException(exception=None, exceptionVar='ex')[source]
collectionIsEmpty(collection, isUnique, isOrdered, varType=None)[source]
collectionIsNotEmpty(collection, isUnique, isOrdered, varType=None)[source]
collectionNotNoneAndNotEmpty(collection, isUnique, isOrdered, varType=None)[source]

NBNB TBD do we need this and the following?

comparison(expression1, func, expression2)[source]
concatenateCollection(newCollection, isUnique, isOrdered, varType=None, *collections)[source]
concatenateList(newCollection, varType=None, *collections)[source]
constructorFuncname(clazz)[source]
continueLoop()[source]
countInCollection(var, collection, isUnique, isOrdered, varType=None)[source]
countInList(var, collection, varType=None)[source]
currentTime()[source]
defineVar(var, varType)[source]
dictIsEmpty(dictVar)[source]
dictIsNotEmpty(dictVar)[source]
elseIf(condition=None)[source]
endBlock()[source]
endFunc()[source]
endIf()[source]
endIndexLoop()[source]
endLoop()[source]
endTry()[source]
endWhile()[source]
equals(expression1, expression2)[source]
exceptionClass(exception=None)[source]
finaliseException()[source]
funcDeclaration(op)[source]
getByIndexInCollection(index, collection, isUnique, isOrdered, varType=None)[source]

get value by index. Works only on ordered collections. Returns an expression

getByIndexInList(index, collection, varType=None)[source]
getClass(var)[source]

Get class of object passed in. Expression

getClassname(var)[source]

Get string class name of object passed in. Expression

getCollection(var, collection, isUnique, isOrdered, varType=None)[source]
getDictEntry(dictVar, key, castType=None, defaultValue=None, keyIsMandatory=False)[source]
getDictKeys(dictVar)[source]

set dict keys as collection or iterable NB must be valid as initValue to newCollection

getDictValues(dictVar)[source]

set dict values as collection or iterable NB must be valid as initValue to newCollection

getDocString(op, inClass=None)[source]
getFuncParams(op, defineFunc=True)[source]

get parameters as list of strings. If defineFunc get strings for function definition. Else get strings for function calls, assuming you use same variable names as the definition. This second form is used e.g. to call constructors in factory functions.

getList(var, collection, varType=None)[source]
getListSlice(collection, lo=0, hi=None, varType=None)[source]
getOpValueType(op)[source]
getReturnType(op)[source]
getThrowsTypes(op)[source]
inEnumeration(value, enumeration)[source]
incrementInteger(var)[source]
indexInCollection(var, collection, isUnique, isOrdered, varType=None)[source]

expression giving index of var in collection. Must work on ordered collections as well as any unordered collections that are implemented as sequences.

indexInList(var, collection, varType=None)[source]
isInCollection(var, collection, isUnique, isOrdered, varType=None)[source]
isInList(var, collection, varType=None)[source]
isInstance(var, className)[source]

Boolean - is (string) var an instance of (string) clazz?

keyIsInDict(dictVar, key)[source]
lenCollection(collection, isUnique, isOrdered, varType=None)[source]
lenDict(dictVar)[source]
lenList(collection, varType=None)[source]
lenString(string)[source]
listIsEmpty(collection, varType=None)[source]
listIsNotEmpty(collection, varType=None)[source]
listNotNoneAndNotEmpty(collection, varType=None)[source]
logicalOp(expression1, op, expression2)[source]
negate(condition)[source]
newCollection(collection, isUnique, isOrdered, varType=None, initValues=None, isFrozen=False, needDeclType=False, useAdd=False)[source]

make new collection, possibly initialising it.

  • collection is the variable name to set the new collection to.

If collection is set, newCollection code will set the variable. If collection is None an expression will be returned.

  • if initValues if a string expression the new collection will be

initialised from this string expression at runtime.

. If initValues is a collection of literals the code will initialise

the new collection to these values. NB this requires collection != None

  • if isFrozen the new collection will be frozen.

  • if initValuesObject is True, initValues represents an object rather than a collection

  • useAdd is a Java hack

newDict(dictVar=None, keyType=None, valueType=None, needDeclType=False)[source]

if dictVar is None returns expression, else write statement

newList(collection, varType=None, initValues=None, isFrozen=False, needDeclType=False)[source]
newStack(stack, varType=None, initValues=None, needDeclType=False)[source]
noStatement()[source]
optionalValue(var, collection, defaultVar, isUnique, isOrdered, varType=None)[source]
peekStack(stack, var=None, varType=None, castType=None)[source]
popCollection(var, collection, isUnique, isOrdered, varType=None, castType=None)[source]
popList(var, collection, varType=None, castType=None)[source]
popStack(stack, var=None, varType=None, castType=None, doWrite=True)[source]
printMessage(message, *objs)[source]
pushStack(stack, var)[source]
raiseApiError(errorMsg, obj=None, obj2=None, obj3=None, inOp=None)[source]
removeCollection(var, collection, isUnique, isOrdered, varType=None)[source]
removeDictEntry(dictVar, key)[source]
removeList(var, collection, varType=None)[source]
replaceInCollection(oldvar, newvar, collection, isUnique, isOrdered, varType=None)[source]

replace oldVar with newvar in collection. Will raise appropriate error if oldvar not present If the result breaks uniqueness or type constraints the collection is left unmodified and an error is raised.

replaceInList(oldvar, newvar, collection, varType=None)[source]
reraiseException(exceptionVar='exc', exceptionClass=None)[source]
returnStatement(value=None)[source]
reverseList(collection)[source]
setByIndexInCollection(indexvar, var, collection, isUnique, isOrdered, varType=None)[source]

set value by index of var in collection. Must work on ordered collections as well as any unordered collections that are implemented as sequences.

setByIndexInList(indexvar, var, collection, varType=None)[source]
setDictEntry(dictVar, key, value)[source]
setVar(var, value, varType=None, castType=None)[source]
stackIsEmpty(stack)[source]
stackIsNotEmpty(stack)[source]
stackSize(stack)[source]
startBlock()[source]
startFunc(funcname, params=None, docString=None, returnType=None, throwsTypes=None)[source]
startIf(condition)[source]
startIndexLoop(iVar, nVar, isReversed=False)[source]
startLoop(var, collection, isUnique, isOrdered, varType=None)[source]
startLoopOverDictKeys(dictVar, keyVar, varType=None)[source]
startTry()[source]
startWhile(condition)[source]
stringIsNotEmpty(val)[source]
stringReplace(val, stringToMatch, stringToReplace)[source]
stringSlice(val, fromStart=0, fromEnd=None)[source]
subtractIntegers(var1, var2)[source]
toLiteral(value)[source]

String representation of ‘value’ that will work as a literal in an expression. For languages that makes the distinction this will be an ‘object’ rather than a ‘raw’ literal. NB for objects that have no equivalent literal, behaviour is unpredictable

valueNotNoneAndIfCollectionNotEmpty(value, isUnique, isOrdered, varType=None)[source]

NBNB TBD do we need this and the preceding?

valueNotNoneAndIfListNotEmpty(value, varType=None)[source]

ccpnmodel.ccpncore.memops.scripts.core.ModelAdapt module

Module Documentation here

class ccpnmodel.ccpncore.memops.scripts.core.ModelAdapt.ModelAdapt[source]

Bases: ccpnmodel.ccpncore.memops.metamodel.ModelTraverse.ModelTraverse

This class processes and modifies an input model, specifically adding operations that are absent in the basic model but needed for generation. Assumes that basic model is valid. All additions in this file are independent of language, implementation and task. May be overridden in subclasses to handle specific changes.

addClassOperations(inClass)[source]

Add operations not linked to an element (e.g. init, delete, checkValid)

addDataObjTypeOperations(inClass)[source]

Add operations not linked to an element (e.g. init, checkValid)

addGetters(elem, inClass)[source]

select, and find or create ‘get’ functions

addModifiers(elem, inClass)[source]

select, and find or create modifiers (set, add, remove)

addOperationExceptions(op, inClass)[source]

NBNB TBD add exceptions raised

Add element and getter for parent link (synonym for the real one) Must be treated as special case later.

addRoleOperations(elem, inClass)[source]

select, and find or create operations specific for roles or DataObjType attrs (findFirst, findAll, new)

checkOpForDerived(elem, inClass, opType)[source]

verify existence of op for derived element and check the op.

checkOpParameter(par, inClass, params)[source]

check an existing operation parameter conforms to the rules.

checkOperation(op, opData, inClass, opSubType=None)[source]

check an existing operation conforms to the rules, and adds missing information (target, parameters) where it can be deduced from context.

endClass(clazz)[source]

processing actions for end of class

endComplexDataType(complexDataType)[source]

processing actions for end of complexDataType

endDataObjType(dataObjType)[source]

processing actions for end of class

getOpData(target, opType, inClass=None)[source]

Get opData for opType, taking special cases into account

getOpDocumentation(opData, inClass, opSubType=None, copyElemDoc=True)[source]

get documentation for generated operation

getOperationName(target, opType, opSubType=None)[source]

get name of operation - NB does not use actual operation object, which may not exist yet

Note that opSubType!=None is used as an operation name suffix. If subOp is found and contains a ‘suffix’ item, this will be used instead.

initClass(complexDataType)

processing actions for start of complexDataType

initComplexDataType(complexDataType)[source]

processing actions for start of complexDataType

initDataObjType(complexDataType)

processing actions for start of complexDataType

makeOperations(target, opType, inClass, elem=None)[source]

get existing operation and check it, or create a new one Some error checking and bookkeeping for existing operations

NB elem passed in separately for the ‘new’ operations, where it is the childRole pointing to the class to create. Otherwise it is set equal to the target.

newElement(clazz, **params)[source]

make new element of class clazz using parameter dict params Sets isImplicit to True and the Guid to a dummy value, if not already set.

newOpParameter(op, inClass, params)[source]

Delegate Operation parameter creation to appropriate function

newOperation(opData, inClass, opSubType=None)[source]

create a new operation

opDocTemplate = '%s for %s'
opParameterData(parData, op)[source]

Delegate Operation parameter creation to appropriate function

parDocTemplate = ' the %s'
parDocumentation(parData)[source]

make documentation for generated parameter

preprocessModel()[source]

pre-process model - handle multiple inheritance and select implementation-dependent classes

processAttribute(elem, inClass)[source]

processing actions for attribute

processClass(clazz)[source]

processing actions for class

processDataObjType(dataObjType)[source]

processing actions for class

processModel()[source]

top function that does all actions. Only function that should be called from outside the module.

processOperation(op, inClass)[source]

processing actions for operation

processRole(elem, inClass)[source]

processing actions for role

sortAttributes(clazz)[source]

sort attributes within clazz

sortOperations(elem)[source]

sort operations within class by name

sortRoles(clazz)[source]

sort roles within clazz

stdOpParameterData(parData)[source]
stdOperationData(opData, opSubType=None)[source]

get data describing a normal operation for checking or creation

ccpnmodel.ccpncore.memops.scripts.core.PyFileModelAdapt module

Module Documentation here

class ccpnmodel.ccpncore.memops.scripts.core.PyFileModelAdapt.PyFileModelAdapt(**kw)[source]

Bases: ccpnmodel.ccpncore.memops.scripts.core.PyModelAdapt.PyModelAdapt, ccpnmodel.ccpncore.memops.scripts.core.FileModelAdapt.FileModelAdapt

Python-specific version of ModelAdapt

ccpnmodel.ccpncore.memops.scripts.core.PyFileModelAdapt.processModel(modelPortal, **kw)[source]

process model to adapt it for Python

Only function that should be called directly by ‘make’ scripts etc.

ccpnmodel.ccpncore.memops.scripts.core.PyLanguage module

Module Documentation here

class ccpnmodel.ccpncore.memops.scripts.core.PyLanguage.PyLanguage[source]

Bases: ccpnmodel.ccpncore.memops.scripts.core.LanguageInterface.LanguageInterface, ccpnmodel.ccpncore.memops.metamodel.TextWriter.TextWriter, object

addAllCollection(var, collection, isUnique, isOrdered, varType=None)[source]
addCollection(var, collection, isUnique, isOrdered, varType=None)[source]
arithmetic(expression1, op, expression2)[source]
boolean(expression)[source]
breakLoop()[source]
callFunc(func, obj=None, params=None, doWrite=True)[source]

call function with normal parameters

callKwFunc(func, obj=None, params=None, setVarTo=None, kwDict={})[source]

call function with keyword-value parameters. kwDict keys are assumed to be strings, kwDict values are assumed to be printable as given (hint - use toLiteral for literals). the result is set to setVarTo, unless this is None

NB for languages that do not accept keyword-value parameters, the information is passed in a dictionary variable that is put last on the variable list. callKwFunc will only work for functions that have this behaviour.

castVar(castType, var)[source]
catchException(exception=None, exceptionVar='ex')[source]
collectionIsEmpty(collection, isUnique, isOrdered, varType=None)[source]
collectionIsNotEmpty(collection, isUnique, isOrdered, varType=None)[source]
collectionNotNoneAndNotEmpty(collection, isUnique, isOrdered, varType=None)[source]

NBNB TBD do we need this and the following?

comparison(expression1, func, expression2)[source]
concatenateCollection(newCollection, isUnique, isOrdered, varType=None, *collections)[source]
constructorFuncname(clazz)[source]
continueLoop()[source]
countInCollection(var, collection, isUnique, isOrdered, varType=None)[source]
createDir(dirName)[source]

set up as recursive function (instead of using os.makedirs) as some implementations might want to do other things in each directory.

currentTime()[source]
defineVar(var, varType)[source]
dictIsEmpty(dictVar)[source]
dictIsNotEmpty(dictVar)[source]
elseIf(condition=None)[source]
endBlock()[source]
endFunc()[source]
endIf()[source]
endIndexLoop()[source]
endLoop()[source]
endTry()[source]
endWhile()[source]
equals(expression1, expression2)[source]
exceptionClass(exception=None)[source]
finaliseException()[source]
funcDeclaration(op)[source]
getByIndexInCollection(index, collection, isUnique, isOrdered, varType=None)[source]

get value by index. Works only on ordered collections. Returns an expression

getClass(var)[source]

Get class of object passed in. Expression

getClassname(var)[source]

Get string class name of object passed in. Expression

getCollection(var, collection, isUnique, isOrdered, varType=None)[source]

Get first element from ordered collection, and random element from others. Works whether modifiable or not.

getDictEntry(dictVar, key, castType=None, defaultValue=None, keyIsMandatory=False)[source]
getDictKeys(dictVar)[source]

set dict keys as collection or iterable NB must be valid as initValue to newCollection

getDictValues(dictVar)[source]

set dict values as collection or iterable NB must be valid as initValue to newCollection

getDocString(op, inClass=None)[source]
getFuncParams(op, defineFunc=True)[source]

get parameters as list of strings. If defineFunc get strings for function definition. Else get strings for function calls, assuming you use same variable names as the definition. This second form is used e.g. to call constructors in factory functions.

getListSlice(collection, lo=0, hi=None, varType=None)[source]

get slice out of list

getOpValueType(op)[source]
getReturnType(op)[source]
getThrowsTypes(op)[source]
inEnumeration(value, enumeration)[source]
incrementInteger(var)[source]
indexInCollection(var, collection, isUnique, isOrdered, varType=None)[source]

expression giving index of var in collection. Must work on ordered collections as well as any unordered collections that are implemented as sequences.

isInCollection(var, collection, isUnique, isOrdered, varType=None)[source]
isInstance(var, className)[source]

Boolean - is (string) var an instance of (string) clazz?

keyIsInDict(dictVar, key)[source]
lenCollection(collection, isUnique, isOrdered, varType=None)[source]
lenDict(dictVar)[source]
lenString(string)[source]
logicalOp(expression1, op, expression2)[source]
negate(condition)[source]
newCollection(collection, isUnique, isOrdered, varType=None, initValues=None, isFrozen=False, needDeclType=False, useAdd=False)[source]

initValues must be a string variable name (referring to an iterable) an iterable of literals, or None

newDict(dictVar=None, keyType=None, valueType=None, needDeclType=False)[source]

if dictVar is None returns expression, else write statement

newStack(stack, varType=None, initValues=None, needDeclType=False)[source]
noStatement()[source]
optionalValue(var, collection, defaultVar, isUnique, isOrdered, varType=None)[source]
peekStack(stack, var=None, varType=None, castType=None)[source]
popCollection(var, collection, isUnique, isOrdered, varType=None, castType=None)[source]
popStack(stack, var=None, varType=None, castType=None, doWrite=True)[source]
printMessage(*objs)[source]
pushStack(stack, var)[source]
raiseApiError(errorMsg, obj=None, obj2=None, obj3=None, inOp=None)[source]

NB obj and obj2 and obj3 must evaluate to a single Python object More specifically you can pass in a tuple, like ‘(a,b,c)’ but not a comma-separated list, like ‘a,b,c’

removeCollection(var, collection, isUnique, isOrdered, varType=None)[source]
removeDictEntry(dictVar, key)[source]
replaceInCollection(oldvar, newvar, collection, isUnique, isOrdered, varType=None)[source]

resulting code may raise KeyError (for unique, nonordered) or ValueError (for all others)

reraiseException(exceptionVar='exc', exceptionClass=None)[source]
returnStatement(value=None)[source]
reverseList(collection)[source]
setByIndexInCollection(indexvar, var, collection, isUnique, isOrdered, varType=None)[source]

set value by index of var in collection. Must work on ordered collections as well as any unordered collections that are implemented as sequences.

setDictEntry(dictVar, key, value)[source]
setVar(var, value, varType=None, castType=None)[source]
stackIsEmpty(stack)[source]
stackIsNotEmpty(stack)[source]
stackSize(stack)[source]
startBlock()[source]
startFunc(funcname, params=None, docString=None, returnType=None, throwsTypes=None)[source]
startIf(condition)[source]
startIndexLoop(iVar, nVar, isReversed=False)[source]
startLoop(var, collection, isUnique, isOrdered, varType=None)[source]
startLoopOverDictKeys(dictVar, keyVar, varType=None)[source]
startTry()[source]
startWhile(condition)[source]
stringIsNotEmpty(val)[source]
stringReplace(val, stringToMatch, stringToReplace)[source]
stringSlice(val, fromStart=0, fromEnd=None)[source]

Slice string. Uses Python convention with positive and negative indices

subtractIntegers(var1, var2)[source]
toLiteral(value)[source]

String representation of ‘value’ that will work as a literal in an expression. For languages that makes the distinction this will be an ‘object’ rather than a ‘raw’ literal. NB for objects that have no equivalent literal, behaviour is unpredictable

valueNotNoneAndIfCollectionNotEmpty(value, isUnique, isOrdered, varType=None)[source]

NBNB TBD do we need this and the preceding?

ccpnmodel.ccpncore.memops.scripts.core.PyModelAdapt module

Module Documentation here

class ccpnmodel.ccpncore.memops.scripts.core.PyModelAdapt.PyModelAdapt[source]

Bases: ccpnmodel.ccpncore.memops.scripts.core.ModelAdapt.ModelAdapt

Python-specific version of ModelAdapt

addClassOperations(inClass)[source]

Add operations not linked to an element (e.g. init, delete, checkValid)

addDataObjTypeOperations(inClass)[source]

Add operations not linked to an element (e.g. init, delete, checkValid)

addMetaClassAttr(clazz)[source]
getOpDocumentation(opData, inClass, opSubType=None, copyElemDoc=False)[source]

get documentation for generated operation copyElemDoc defaults to False in Python we have the element documentation on the properties

initClass(complexDataType)

processing actions for class

initComplexDataType(complexDataType)[source]

processing actions for class

initDataObjType(complexDataType)

processing actions for class

ccpnmodel.ccpncore.memops.scripts.core.PyType module

Module Documentation here

class ccpnmodel.ccpncore.memops.scripts.core.PyType.PyType[source]

Bases: ccpnmodel.ccpncore.memops.scripts.core.TypeInterface.TypeInterface

collectionInterfaceType(collectionType=None)[source]
collectionType(elementOrString=None, isUnique=None, isOrdered=None, useCollection=False)[source]
dictInterfaceType(keyType=None, valueType=None)[source]
elementVarType(element)[source]
fileInterfaceType(mode='r')[source]
implementationType(element)[source]
interfaceType(element)[source]
listInterfaceType(listType=None)[source]
stackInterfaceType(stackType=None)[source]

ccpnmodel.ccpncore.memops.scripts.core.TypeInterface module

Module Documentation here

class ccpnmodel.ccpncore.memops.scripts.core.TypeInterface.TypeInterface[source]

Bases: object

collectionInterfaceType(collectionType=None)[source]
collectionType(elementOrString=None, isUnique=None, isOrdered=None, useCollection=False)[source]
dictInterfaceType(keyType=None, valueType=None)[source]
elementVarType(element)[source]
fileInterfaceType(mode='r')[source]
implementationType(element)[source]
interfaceType(element)[source]
listInterfaceType(listType=None)[source]
stackInterfaceType(stackType=None)[source]