Changeset 4640 for exist


Ignore:
Timestamp:
15/12/08 14:19:55 (11 years ago)
Author:
cbyrom
Message:

Simplify wrapGetText and improve error handling when no data is returned.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • exist/trunk/python/ndgUtils/lib/utilities.py

    r4571 r4640  
    431431    Wraps a call to ET to get a text object in an error handler  
    432432    ''' 
    433     def none2txt(i): 
    434         if i is None:  
    435             return '' 
    436         return i 
    437  
    438433    if element is None: 
    439434        if multiple: 
     
    448443 
    449444    rr = [] 
    450     try: 
    451         rr=[i.text for i in r] 
    452     except: 
    453         rr=map(none2txt,rr)  
     445    for elem in r: 
     446        if elem and isinstance(elem, Element): 
     447            rr.append(elem.text) 
    454448 
    455449    if multiple: 
    456450        return rr 
    457451 
    458     return rr[0]  
     452    if len(rr) > 0: 
     453        return rr[0] 
     454    return ''  
    459455 
    460456 
Note: See TracChangeset for help on using the changeset viewer.