def fragment_fromstring(html, create_parent=False, base_url=None, parser=None, **kw):
 if (parser is None):
  parser = html_parser
 accept_leading_text = bool(create_parent)
 elements = fragments_fromstring(html, parser=parser, no_leading_text=(not accept_leading_text), base_url=base_url, **kw)
 if create_parent:
  if (not isinstance(create_parent, basestring)):
   create_parent = 'div'
  new_root = Element(create_parent)
  if elements:
   if isinstance(elements[0], basestring):
    new_root.text = elements[0]
    del elements[0]
   new_root.extend(elements)
  return new_root
 if (not elements):
  raise etree.ParserError('No elements found')
 if (len(elements) > 1):
  raise etree.ParserError(('Multiple elements found (%s)' % ', '.join([_element_name(e) for e in elements])))
 el = elements[0]
 if (el.tail and el.tail.strip()):
  raise etree.ParserError(('Element followed by text: %r' % el.tail))
 el.tail = None
 return el

def fragment_fromstring ( html , create_parent = False , base_url = None , parser = None , ** kw ) : if ( parser is None ) : parser = html_parser accept_leading_text = bool ( create_parent ) elements = fragments_fromstring ( html , parser = parser , no_leading_text = ( not accept_leading_text ) , base_url = base_url , ** kw ) if create_parent : if ( not isinstance ( create_parent , basestring ) ) : create_parent = 'div' new_root = Element ( create_parent ) if elements : if isinstance ( elements [ 0 ] , basestring ) : new_root . text = elements [ 0 ] del elements [ 0 ] new_root . extend ( elements ) return new_root if ( not elements ) : raise etree . ParserError ( 'No elements found' ) if ( len ( elements ) > 1 ) : raise etree . ParserError ( ( 'Multiple elements found (%s)' % ', ' . join ( [ _element_name ( e ) for e in elements ] ) ) ) el = elements [ 0 ] if ( el . tail and el . tail . strip ( ) ) : raise etree . ParserError ( ( 'Element followed by text: %r' % el . tail ) ) el . tail = None return el
parses a single html element; it is an error if there is more than one element .