Code Duplication    Length = 29-33 lines in 2 locations

src/ocrd_models/ocrd_page_generateds.py 2 locations

@@ 14134-14166 (lines=33) @@
14131
    return rootObj, rootElement, mapping, reverse_mapping
14132
14133
14134
def parseString(inString, silence=False, print_warnings=True):
14135
    '''Parse a string, create the object tree, and export it.
14136
14137
    Arguments:
14138
    - inString -- A string.  This XML fragment should not start
14139
      with an XML declaration containing an encoding.
14140
    - silence -- A boolean.  If False, export the object.
14141
    Returns -- The root object in the tree.
14142
    '''
14143
    parser = None
14144
    rootNode= parsexmlstring_(inString, parser)
14145
    gds_collector = GdsCollector_()
14146
    rootTag, rootClass = get_root_tag(rootNode)
14147
    if rootClass is None:
14148
        rootTag = 'PcGts'
14149
        rootClass = PcGts
14150
    rootObj = rootClass.factory()
14151
    rootObj.build(rootNode, gds_collector_=gds_collector)
14152
    if not SaveElementTreeNode:
14153
        rootNode = None
14154
##     if not silence:
14155
##         sys.stdout.write('<?xml version="1.0" ?>\n')
14156
##         rootObj.export(
14157
##             sys.stdout, 0, name_=rootTag,
14158
##             namespacedef_='xmlns:pc="http://schema.primaresearch.org/PAGE/gts/pagecontent/2019-07-15"')
14159
    if print_warnings and len(gds_collector.get_messages()) > 0:
14160
        separator = ('-' * 50) + '\n'
14161
        sys.stderr.write(separator)
14162
        sys.stderr.write('----- Warnings -- count: {} -----\n'.format(
14163
            len(gds_collector.get_messages()), ))
14164
        gds_collector.write_messages(sys.stderr)
14165
        sys.stderr.write(separator)
14166
    return rootObj
14167
14168
14169
def parseLiteral(inFileName, silence=False, print_warnings=True):
@@ 14169-14197 (lines=29) @@
14166
    return rootObj
14167
14168
14169
def parseLiteral(inFileName, silence=False, print_warnings=True):
14170
    parser = None
14171
    doc = parsexml_(inFileName, parser)
14172
    gds_collector = GdsCollector_()
14173
    rootNode = doc.getroot()
14174
    rootTag, rootClass = get_root_tag(rootNode)
14175
    if rootClass is None:
14176
        rootTag = 'PcGts'
14177
        rootClass = PcGts
14178
    rootObj = rootClass.factory()
14179
    rootObj.build(rootNode, gds_collector_=gds_collector)
14180
    # Enable Python to collect the space used by the DOM.
14181
    if not SaveElementTreeNode:
14182
        doc = None
14183
        rootNode = None
14184
##     if not silence:
14185
##         sys.stdout.write('#from ocrd_page_generateds import *\n\n')
14186
##         sys.stdout.write('import ocrd_page_generateds as model_\n\n')
14187
##         sys.stdout.write('rootObj = model_.rootClass(\n')
14188
##         rootObj.exportLiteral(sys.stdout, 0, name_=rootTag)
14189
##         sys.stdout.write(')\n')
14190
    if print_warnings and len(gds_collector.get_messages()) > 0:
14191
        separator = ('-' * 50) + '\n'
14192
        sys.stderr.write(separator)
14193
        sys.stderr.write('----- Warnings -- count: {} -----\n'.format(
14194
            len(gds_collector.get_messages()), ))
14195
        gds_collector.write_messages(sys.stderr)
14196
        sys.stderr.write(separator)
14197
    return rootObj
14198
14199
14200
def main():