📄 stafmarshalling.py
字号:
unmarshall(data[dataIndex:colonIndex2 + itemLength + 1],
context, flags).getPrimaryObject())
dataIndex = colonIndex2 + itemLength + 1
return STAFMarshallingContext(list)
if data.startswith(MAP_MARKER):
colonIndex = data.find(':')
dataIndex = data.find(':', colonIndex + 1) + 1
map = {}
while dataIndex < len(data):
# Get key first
keyColonIndex1 = data.find(':', dataIndex)
keyColonIndex2 = data.find(':', keyColonIndex1 + 1)
keyLength = int(data[keyColonIndex1 + 1:keyColonIndex2])
key = data[keyColonIndex2 + 1:keyColonIndex2 + 1 + keyLength]
dataIndex = keyColonIndex2 + 1 + keyLength
# Now, get the object
colonIndex1 = data.find(':', dataIndex)
colonIndex2 = data.find(':', colonIndex1 + 1)
itemLength = int(data[colonIndex1 + 1:colonIndex2])
map[key] = unmarshall(
data[dataIndex:colonIndex2 + itemLength + 1],
context, flags).getPrimaryObject()
dataIndex = colonIndex2 + itemLength + 1
return STAFMarshallingContext(map)
if data.startswith(MC_INSTANCE_MARKER):
colonIndex = data.find(':')
colonIndex2 = data.find(':', colonIndex + 1)
colonIndex = data.find(':', colonIndex2 + 1)
colonIndex2 = data.find(':', colonIndex + 1)
mapClassNameLength = int(data[colonIndex + 1:colonIndex2])
mapClassName = data[colonIndex2 + 1 :
colonIndex2 + 1 + mapClassNameLength]
dataIndex = colonIndex2 + 1 + mapClassNameLength
map = { 'staf-map-class-name': mapClassName }
mapClass = context.getMapClassDefinition(mapClassName)
keys = mapClass.keys()
keyIndex = 0
while dataIndex < len(data):
colonIndex = data.find(':', dataIndex)
colonIndex2 = data.find(':', colonIndex + 1)
itemLength = int(data[colonIndex + 1:colonIndex2])
map[keys[keyIndex]['key']] = unmarshall(
data[dataIndex:colonIndex2 + itemLength + 1],
context, flags).getPrimaryObject()
dataIndex = colonIndex2 + itemLength + 1
keyIndex = keyIndex + 1
return STAFMarshallingContext(map)
if data.startswith(CONTEXT_MARKER):
colonIndex = data.find(':')
contextIndex = data.find(':', colonIndex + 1) + 1
contextLength = int(data[colonIndex + 1:contextIndex - 1])
colonIndex = data.find(':', contextIndex)
mapIndex = contextIndex
mapDataIndex = data.find(':', colonIndex + 1) + 1
mapLength = int(data[colonIndex + 1:mapDataIndex - 1])
contextMap = unmarshall(data[mapIndex:mapDataIndex + mapLength],
context, flags).getPrimaryObject()
mapClassMap = contextMap['map-class-map']
newContext = STAFMarshallingContext(None, mapClassMap)
colonIndex = data.find(':', mapDataIndex + mapLength)
rootObjIndex = mapDataIndex + mapLength
rootObjDataIndex = data.find(':', colonIndex + 1) + 1
rootObjLength = int(data[colonIndex + 1:rootObjDataIndex - 1])
newContext.setRootObject(
unmarshall(data[rootObjIndex:rootObjDataIndex + rootObjLength],
newContext, flags).getPrimaryObject())
return newContext
if data.startswith(MARSHALLED_DATA_MARKER):
# Here, we don't know what the type is
return STAFMarshallingContext(data)
return STAFMarshallingContext(data)
# Formatting function
#
# Note:
# The flags option is not currently used (it's for future use)
def formatObject(obj, context = None, indentLevel = 0, flags = 0):
# Build a list of strings to output and join them for performance reasons
output = []
if type(obj) == types.ListType:
list = obj
output.append('[')
indentLevel = indentLevel + 1
if len(list) > 0:
output.append(os.linesep)
# Format each object in the list
i = 0
for item in list:
indent = indentLevel * INDENT_DELTA
output.append(SPACES[: indent])
if (type(item) == types.ListType or
type(item) == types.DictType or
isinstance(item, STAFMarshallingContext)):
output.append(formatObject(item, context, indentLevel, flags))
elif item is None:
output.append(NONE_STRING)
else:
output.append(str(item))
if i < (len(list) - 1):
output.append(ENTRY_SEPARATOR)
output.append(os.linesep)
indentLevel = indentLevel - 1
if len(list) > 0:
indent = indentLevel * INDENT_DELTA
output.append(SPACES[: indent])
output.append(']')
elif type(obj) == types.DictType:
dict = obj
output.append('{')
indentLevel = indentLevel + 1
if len(dict) > 0:
output.append(os.linesep)
# Check if the map object has a map class key and if the context
# is valid and contains a map class definition for this map class.
# If not, treat as a plain map class.
if (dict.has_key(MAP_CLASS_NAME_KEY) and
(context is not None) and
isinstance(context, STAFMarshallingContext) and
context.hasMapClassDefinition(dict[MAP_CLASS_NAME_KEY])):
mapClass = context.getMapClassDefinition(dict[MAP_CLASS_NAME_KEY])
# Determine maximum key length
maxKeyLength = 0
for theKey in mapClass.keys():
theKeyString = theKey['key']
if theKey.has_key(DISPLAY_NAME_KEY):
theKeyString = theKey[DISPLAY_NAME_KEY]
if len(theKeyString) > maxKeyLength:
maxKeyLength = len(theKeyString)
# Now print each object in the map
i = 0
for theKey in mapClass.keys():
theKeyString = theKey['key']
if theKey.has_key(DISPLAY_NAME_KEY):
theKeyString = theKey[DISPLAY_NAME_KEY]
indent = indentLevel * INDENT_DELTA
output.append('%s%s' % (SPACES[: indent], theKeyString))
indent = maxKeyLength - len(theKeyString)
output.append('%s: ' % (SPACES[: indent]))
if dict.has_key(theKey['key']):
thisObj = dict[theKey['key']]
else:
thisObj = None
if (type(thisObj) == types.ListType or
type(thisObj) == types.DictType or
isinstance(thisObj, STAFMarshallingContext)):
output.append(formatObject(thisObj, context, indentLevel, flags))
elif thisObj is None:
output.append(NONE_STRING)
else:
output.append(str(thisObj))
if i < (len(dict) - 1):
output.append(ENTRY_SEPARATOR)
output.append(os.linesep)
i = i + 1
else:
# Determine maximum key length
maxKeyLength = 0
for theKeyString in dict.keys():
if len(theKeyString) > maxKeyLength:
maxKeyLength = len(theKeyString)
# Now print each object in the map
i = 0
for theKeyString in dict.keys():
indent = indentLevel * INDENT_DELTA
output.append('%s%s' % (SPACES[: indent], theKeyString))
indent = maxKeyLength - len(theKeyString)
output.append('%s: ' % (SPACES[: indent]))
thisObj = dict[theKeyString]
if (type(thisObj) == types.ListType or
type(thisObj) == types.DictType or
isinstance(thisObj, STAFMarshallingContext)):
output.append(formatObject(thisObj, context, indentLevel, flags))
elif thisObj is None:
output.append(NONE_STRING)
else:
output.append(str(thisObj))
if i < (len(dict) - 1):
output.append(ENTRY_SEPARATOR)
output.append(os.linesep)
i = i + 1
indentLevel = indentLevel - 1
if len(dict) > 0:
indent = indentLevel * INDENT_DELTA
output.append(SPACES[: indent])
output.append('}')
elif isinstance(obj, STAFMarshallingContext):
inputContext = obj
return formatObject(inputContext.getRootObject(), inputContext,
indentLevel, flags)
elif obj is None:
return NONE_STRING
else:
return str(obj)
return ''.join(output)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -