Changeset 4375


Ignore:
Timestamp:
27 Jun 2009, 15:26:24 (16 years ago)
Author:
uli
Message:

Add helper function to extract 'inner' HTML parts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/utils/helpers.py

    r4188 r4375  
    11"""General helper functions for WAeUP.
    22"""
    3 
    43import os
     4import re
    55import sys
    66import shutil
     
    6363            removeFileOrDirectory(itemsrc)
    6464    return not_copied
     65
     66
     67def getInnerHTMLPart(html_code):
     68    """Return the 'inner' part of a complete HTML snippet.
     69
     70    If there is a form part, get this.
     71
     72    If there is no form part, try to return the body part contents.
     73
     74    If there is no body, return as-is.
     75    """
     76
     77    try:
     78        result = re.match('^.+(<forms[^\>]*>.*</form>).+$', html_code,
     79                          re.DOTALL).groups()[0]
     80        return result
     81    except AttributeError:
     82        # No <form> part included
     83        try:
     84            result = re.match('^.+<body[^\>]*>(.*)</body>.*$', html_code,
     85                              re.DOTALL).groups()[0]
     86            return result
     87        except AttributeError:
     88            # No <form> and no <body> tag...
     89            pass
     90    return html_code
     91
Note: See TracChangeset for help on using the changeset viewer.