Parse Cross Section Links Method

def xSectionLink(lines):
    """
    Parse Cross Section Links Method
    """
    # Constants
    KEYWORDS = ('LINK',
                'DX',
                'TRAPEZOID',
                'TRAPEZOID_ERODE',
                'TRAPEZOID_SUBSURFACE',
                'ERODE_TRAPEZOID',
                'ERODE_SUBSURFACE',
                'SUBSURFACE_TRAPEZOID',
                'SUBSURFACE_ERODE',
                'TRAPEZOID_ERODE_SUBSURFACE',
                'TRAPEZOID_SUBSURFACE_ERODE',
                'ERODE_TRAPEZOID_SUBSURFACE',
                'ERODE_SUBSURFACE_TRAPEZOID',
                'SUBSURFACE_TRAPEZOID_ERODE',
                'SUBSURFACE_ERODE_TRAPEZOID',
                'BREAKPOINT',
                'BREAKPOINT_ERODE',
                'BREAKPOINT_SUBSURFACE',
                'ERODE_BREAKPOINT',
                'ERODE_SUBSURFACE',
                'SUBSURFACE_BREAKPOINT',
                'SUBSURFACE_ERODE',
                'BREAKPOINT_ERODE_SUBSURFACE',
                'BREAKPOINT_SUBSURFACE_ERODE',
                'ERODE_BREAKPOINT_SUBSURFACE',
                'ERODE_SUBSURFACE_BREAKPOINT',
                'SUBSURFACE_BREAKPOINT_ERODE',
                'SUBSURFACE_ERODE_BREAKPOINT',
                'TRAP',
                'TRAP_ERODE',
                'TRAP_SUBSURFACE',
                'ERODE_TRAP',
                'ERODE_SUBSURFACE',
                'SUBSURFACE_TRAP',
                'SUBSURFACE_ERODE',
                'TRAP_ERODE_SUBSURFACE',
                'TRAP_SUBSURFACE_ERODE',
                'ERODE_TRAP_SUBSURFACE',
                'ERODE_SUBSURFACE_TRAP',
                'SUBSURFACE_TRAP_ERODE',
                'SUBSURFACE_ERODE_TRAP',
                'NODES',
                'NODE',
                'XSEC')



    ERODE = ('TRAPEZOID_ERODE',
             'TRAP_ERODE',
             'TRAP_SUBSURFACE_ERODE',
             'TRAP_ERODE_SUBSURFACE',
             'BREAKPOINT_ERODE',
             'TRAPEZOID_SUBSURFACE_ERODE',
             'TRAPEZOID_ERODE_SUBSURFACE',
             'BREAKPOINT_SUBSURFACE_ERODE',
             'BREAKPOINT_ERODE_SUBSURFACE')

    SUBSURFACE = ('TRAPEZOID_SUBSURFACE',
                  'TRAP_SUBSURFACE',
                  'TRAP_SUBSURFACE_ERODE',
                  'TRAP_ERODE_SUBSURFACE',
                  'BREAKPOINT_SUBSURFACE',
                  'TRAPEZOID_SUBSURFACE_ERODE',
                  'TRAPEZOID_ERODE_SUBSURFACE',
                  'BREAKPOINT_SUBSURFACE_ERODE',
                  'BREAKPOINT_ERODE_SUBSURFACE')

    result  =  {'type': 'XSEC',
                'header': {'link': None,
                           'dx': None,
                           'xSecType': None,
                           'nodes': None,
                           'erode': False,
                           'subsurface': False},
                'xSection': None,
                'nodes': []}

    chunks = pt.chunk(KEYWORDS, lines)

    # Parse chunks associated with each key
    for key, chunkList in iteritems(chunks):
        # Parse each chunk in the chunk list
        for chunk in chunkList:
            # Cases
            if key == 'NODE':
                # Extract node x and y
                result['nodes'].append(nodeChunk(chunk))

            elif key == 'XSEC':
                # Extract cross section information
                result['xSection'] = xSectionChunk(chunk)

            elif ('TRAPEZOID' in key) or ('BREAKPOINT' in key) or ('TRAP' in key):
                # Cross section type handler
                result['header']['xSecType'] = key

            elif key in ERODE:
                # Erode handler
                result['header']['erode'] = True

            elif key in SUBSURFACE:
                # Subsurface handler
                result['header']['subsurface'] = True

            else:
                # Extract all other variables into header
                result['header'][key.lower()] = chunk[0].strip().split()[1]

    return result