B
    18\              
   @   sv  d Z ddlZddlZddlZddlmZ ddlmZ dZdd Z	dd	 Z
d
d ZejfddZedkrre
e	eZdejkred ede ee ndejkrFdZed ZeejZeedTZdZxHeD ]@Zedreeed dZqeredrdZqee qW W dQ R X W dQ R X ee eee n,eekrZed neee ede dS )z
Utility for parsing HTML5 entity definitions available from:

    http://dev.w3.org/html5/spec/entities.json

Written by Ezio Melotti and Iuliia Proskurnia.

    N)urlopen)html5z*http://dev.w3.org/html5/spec/entities.jsonc          	   C   s,   t | }| d}W dQ R X t|S )zADownload the json file from the url and returns a decoded object.zutf-8N)r   readdecodejsonloads)urlfdata r   b/oak/stanford/groups/akundaje/marinovg/programs/Python-3.7.3/Tools/scripts/parse_html5_entities.pyget_json   s    
r   c             C   s0   i }x&|   D ]\}}|d ||d< qW |S )z3Create the html5 dict from the decoded json object.
characters&)itemslstrip)entities	new_html5namevaluer   r   r   create_dict   s    r   c             C   s  |  |    }|rLtdt| x$t|D ]}td|||  q0W |   |   }|rtdt| x$t|D ]}td|| |  q|W t }x@|   |  @ D ],}| | || kr||| | || f qW |rtdt| x t|D ]}tdj|  qW dS )z8Compare the old and new dicts and print the differences.z{} entitie(s) have been added:z  {!r}: {!r}z {} entitie(s) have been removed:z!{} entitie(s) have been modified:z  {!r}: {!r} -> {!r}N)keysprintformatlensortedsetadd)oldnewaddedr   Zremovedchangeditemr   r   r   compare_dicts    s$    r#   c             C   s\   t |  }t |tjd}td|d x$|D ]}td|| | |d q,W td|d dS )z8Write the items of the dictionary in the specified file.)keyz	html5 = {)filez    {!r}: {!a},}N)r   r   strlowerr   r   )r   r%   r   r   r   r   r   write_items5   s    

r)   __main__z--createzQ# map the HTML5 named character references to the equivalent Unicode character(s)z)# Generated by {}.  Do not edit manually.z--patchzLib/html/entities.pyz.tempwFz	html5 = {)r%   Tr&   z"The current dictionary is updated.zwRun "./python {0} --patch" to update Lib/html/entities.html or "./python {0} --create" to see the generated dictionary.)__doc__ossysr   urllib.requestr   html.entitiesr   Zentities_urlr   r   r#   stdoutr)   __name__r   argvr   r   __file__fnameZ
temp_fnameopenf1f2skipline
startswithwriteremoverenamer   r   r   r   <module>	   sL   





"



