MCPcopy
hub / github.com/iBaa/PlexConnect / XML_ExpandLine

Function XML_ExpandLine

XMLConverter.py:558–600  ·  view source on GitHub ↗
(CommandCollection, src, srcXML, line)

Source from the content-addressed store, hash-verified

556
557
558def XML_ExpandLine(CommandCollection, src, srcXML, line):
559 pos = 0
560 while True:
561 cmd_start = line.find('{{',pos)
562 cmd_end = line.find('}}',pos)
563 next_start = line.find('{{',cmd_start+2)
564 while next_start!=-1 and next_start<cmd_end:
565 cmd_end = line.find('}}',cmd_end+2)
566 next_start = line.find('{{',next_start+2)
567
568 if cmd_start==-1 or cmd_end==-1 or cmd_start>cmd_end:
569 break;
570
571 dprint(__name__, 2, "XML_ExpandLine: {0}", line)
572
573 cmd = line[cmd_start+2:cmd_end]
574 if cmd[-1]!=')':
575 dprint(__name__, 0, "XML_ExpandLine - closing bracket missing: {0} ", line)
576
577 parts = cmd.split('(',1)
578 cmd = parts[0]
579 param = parts[1][:-1] # remove ending bracket
580
581 if hasattr(CCommandCollection, 'ATTRIB_'+cmd): # expand line, work VAL, EVAL...
582
583 try:
584 param = XML_ExpandLine(CommandCollection, src, srcXML, param) # expand any attributes in the parameter
585 res = getattr(CommandCollection, 'ATTRIB_'+cmd)(src, srcXML, param)
586 line = line[:cmd_start] + res + line[cmd_end+2:]
587 pos = cmd_start+len(res)
588 except:
589 dprint(__name__, 0, "XML_ExpandLine - Error in {0}\n{1}", line, traceback.format_exc())
590 line = line[:cmd_start] + "((ERROR:"+cmd+"))" + line[cmd_end+2:]
591
592 elif hasattr(CCommandCollection, 'TREE_'+cmd): # check other known cmds: COPY, CUT
593 dprint(__name__, 2, "XML_ExpandLine - stumbled over {0} in line {1}", cmd, line)
594 pos = cmd_end
595 else:
596 dprint(__name__, 0, "XML_ExpandLine - Found unknown cmd {0} in line {1}", cmd, line)
597 line = line[:cmd_start] + "((UNKNOWN:"+cmd+"))" + line[cmd_end+2:]
598
599 dprint(__name__, 2, "XML_ExpandLine: {0} - done", line)
600 return line
601
602
603

Callers 2

XML_ExpandNodeFunction · 0.85
XML_ExpandAllAttribFunction · 0.85

Calls 1

dprintFunction · 0.85

Tested by

no test coverage detected