def find_attribute_in_tag(block, offset, attr_name):
 (end_block, boundary) = next_tag_boundary(block, offset)
 if boundary.is_start:
  return (None, None)
 end_offset = boundary.offset
 end_pos = (end_block.blockNumber(), end_offset)
 (current_block, current_offset) = (block, offset)
 found_attr = False
 while True:
  (current_block, boundary) = next_attr_boundary(current_block, current_offset)
  if ((current_block is None) or ((current_block.blockNumber(), boundary.offset) > end_pos)):
   return (None, None)
  current_offset = boundary.offset
  if found_attr:
   if ((boundary.type is not ATTR_VALUE) or (boundary.data is not ATTR_START)):
    return (None, None)
   return (current_block, current_offset)
  else:
   if ((boundary.type is ATTR_NAME) and (boundary.data.lower() == attr_name.lower())):
    found_attr = True
   current_offset += 1

def find_attribute_in_tag ( block , offset , attr_name ) : ( end_block , boundary ) = next_tag_boundary ( block , offset ) if boundary . is_start : return ( None , None ) end_offset = boundary . offset end_pos = ( end_block . blockNumber ( ) , end_offset ) ( current_block , current_offset ) = ( block , offset ) found_attr = False while True : ( current_block , boundary ) = next_attr_boundary ( current_block , current_offset ) if ( ( current_block is None ) or ( ( current_block . blockNumber ( ) , boundary . offset ) > end_pos ) ) : return ( None , None ) current_offset = boundary . offset if found_attr : if ( ( boundary . type is not ATTR_VALUE ) or ( boundary . data is not ATTR_START ) ) : return ( None , None ) return ( current_block , current_offset ) else : if ( ( boundary . type is ATTR_NAME ) and ( boundary . data . lower ( ) == attr_name . lower ( ) ) ) : found_attr = True current_offset += 1
return the start of the attribute value as block .