Code Duplication    Length = 29-33 lines in 2 locations

src/ocrd_models/ocrd_page_generateds.py 2 locations

@@ 16530-16562 (lines=33) @@
16527
    return rootObj, rootElement, mapping, reverse_node_mapping
16528
16529
16530
def parseString(inString, silence=False, print_warnings=True):
16531
    '''Parse a string, create the object tree, and export it.
16532
16533
    Arguments:
16534
    - inString -- A string.  This XML fragment should not start
16535
      with an XML declaration containing an encoding.
16536
    - silence -- A boolean.  If False, export the object.
16537
    Returns -- The root object in the tree.
16538
    '''
16539
    parser = None
16540
    rootNode= parsexmlstring_(inString, parser)
16541
    gds_collector = GdsCollector_()
16542
    rootTag, rootClass = get_root_tag(rootNode)
16543
    if rootClass is None:
16544
        rootTag = 'PcGts'
16545
        rootClass = PcGts
16546
    rootObj = rootClass.factory()
16547
    rootObj.build(rootNode, gds_collector_=gds_collector)
16548
    if not SaveElementTreeNode:
16549
        rootNode = None
16550
##     if not silence:
16551
##         sys.stdout.write('<?xml version="1.0" ?>\n')
16552
##         rootObj.export(
16553
##             sys.stdout, 0, name_=rootTag,
16554
##             namespacedef_='xmlns:pc="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15"')
16555
    if print_warnings and len(gds_collector.get_messages()) > 0:
16556
        separator = ('-' * 50) + '\n'
16557
        sys.stderr.write(separator)
16558
        sys.stderr.write('----- Warnings -- count: {} -----\n'.format(
16559
            len(gds_collector.get_messages()), ))
16560
        gds_collector.write_messages(sys.stderr)
16561
        sys.stderr.write(separator)
16562
    return rootObj
16563
16564
16565
def parseLiteral(inFileName, silence=False, print_warnings=True):
@@ 16565-16593 (lines=29) @@
16562
    return rootObj
16563
16564
16565
def parseLiteral(inFileName, silence=False, print_warnings=True):
16566
    parser = None
16567
    doc = parsexml_(inFileName, parser)
16568
    gds_collector = GdsCollector_()
16569
    rootNode = doc.getroot()
16570
    rootTag, rootClass = get_root_tag(rootNode)
16571
    if rootClass is None:
16572
        rootTag = 'PcGts'
16573
        rootClass = PcGts
16574
    rootObj = rootClass.factory()
16575
    rootObj.build(rootNode, gds_collector_=gds_collector)
16576
    # Enable Python to collect the space used by the DOM.
16577
    if not SaveElementTreeNode:
16578
        doc = None
16579
        rootNode = None
16580
##     if not silence:
16581
##         sys.stdout.write('#from ocrd_page_generateds import *\n\n')
16582
##         sys.stdout.write('import ocrd_page_generateds as model_\n\n')
16583
##         sys.stdout.write('rootObj = model_.rootClass(\n')
16584
##         rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
16585
##         sys.stdout.write(')\n')
16586
    if print_warnings and len(gds_collector.get_messages()) > 0:
16587
        separator = ('-' * 50) + '\n'
16588
        sys.stderr.write(separator)
16589
        sys.stderr.write('----- Warnings -- count: {} -----\n'.format(
16590
            len(gds_collector.get_messages()), ))
16591
        gds_collector.write_messages(sys.stderr)
16592
        sys.stderr.write(separator)
16593
    return rootObj
16594
16595
16596
def main():