B
    18™\Ÿ  ã               @   s    d Z ddlZddlZe d¡Zddd„Zdd„ Zedkrœeej	ƒd	krVe
ej	d	 ƒZnejZeej	ƒd
kr|e
ej	d
 dƒZnejZe ¡ ZeeƒZeeeƒ dS )a¥   Utility for parsing HTML entity definitions available from:

      http://www.w3.org/ as e.g.
      http://www.w3.org/TR/REC-html40/HTMLlat1.ent

    Input is read from stdin, output is written to stdout in form of a
    Python snippet defining a dictionary "entitydefs" mapping literal
    entity name to character or numeric entity.

    Marc-Andre Lemburg, mal@lemburg.com, 1999.
    Use as you like. NO WARRANTIES.

é    Nz8<!ENTITY +(\w+) +CDATA +"([^"]+)" +-- +((?:.|\n)+?) *-->c             C   sX   d}|d krt | ƒ}i }x:t | ||¡}|s.P | ¡ \}}}||f||< | ¡ }qW |S )Nr   )ÚlenÚentityREÚsearchÚgroupsÚend)ÚtextÚposÚendposÚdÚmÚnameÚcharcodeÚcomment© r   ú[/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Tools/scripts/parseentities.pyÚparse   s    r   c             C   s    |   d¡ t| ¡ ƒ}xz|D ]r\}\}}|d d… dkrdt|dd… ƒ}|dk rZd| }qlt|ƒ}nt|ƒ}d | ¡ ¡}|   d|||f ¡ qW |   d	¡ d S )
Nzentitydefs = {
é   z&#éÿÿÿÿé   z'\%o'ú z    '%s':	%s,  	# %s
z
}
)ÚwriteÚsortedÚitemsÚintÚreprÚjoinÚsplit)ÚfÚdefsr   r   r   r   Úcoder   r   r   Ú	writefile"   s    


r    Ú__main__é   r   Úw)r   N)Ú__doc__ÚreÚsysÚcompiler   r   r    Ú__name__r   ÚargvÚopenÚinfileÚstdinÚoutfileÚstdoutÚreadr   r   r   r   r   r   Ú<module>   s   

