σ
ίΘ[c           @` sI  d  d l  m Z m Z m Z m Z d d l m Z d d l m Z d  d l	 Z	 d  d l
 Z
 d  d l m Z d  d l Z d  d l Z d d l m Z m Z d d l m Z d	 d
 l m Z d Z d Z e	 j d    Z d  d  Z d   Z d   Z d   Z d   Z d d d  Z d g d d  Z  d d  Z! d d d d  Z" d S(   i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   six(   t   rangeN(   t   ceil(   t	   XMLWritert
   xml_escape(   t   online_docs_rooti   (   t
   exceptionsu₯   <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
        "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">
uβ  
body {
font-family: sans-serif
}
a {
text-decoration: none
}
.highlight {
color: red;
font-weight: bold;
text-decoration: underline;
}
.green { background-color: #ddffdd }
.red   { background-color: #ffdddd }
.yellow { background-color: #ffffdd }
tr:hover { background-color: #dddddd }
table {
        border-width: 1px;
        border-spacing: 0px;
        border-style: solid;
        border-color: gray;
        border-collapse: collapse;
        background-color: white;
        padding: 5px;
}
table th {
        border-width: 1px;
        padding: 5px;
        border-style: solid;
        border-color: gray;
}
table td {
        border-width: 1px;
        padding: 5px;
        border-style: solid;
        border-color: gray;
}
c         c` s   |  j  t  |  j d d d d d V |  j d  @ |  j d d  |  j d	 t  |  j d
  
 d  VWd  QXWd  QXWd  QXd  S(   Nu   htmlt   xmlnsu   http://www.w3.org/1999/xhtmlt   langu   en-USu   headu   titleu   VO Validation resultsu   styleu   body(   t   writet   html_headert   tagt   elementt   default_style(   t   w(    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   make_html_headerB   s    c         C` s€   t  | |  j d   } t  | | | d !j d   } t  | | d j d   } |  j d  |  j |  |  j d j |   |  j |  |  j d  d  S(   Nu   utf-8i   u     u!   <span class="highlight">{}</span>u   

(   R   t   decodeR   t   format(   R   t   linet   nchart   part1t   chart   part2(    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   write_source_lineN   s     c         C` s  t  j |  } | d s) |  j |  nζ |  j d j | d   | d rt |  j d j t | d | d   n  | d } t | d t j  s¦ | j	 d  } n  |  j t
 |   |  j d	  | d d
 k r| d t |  k  rt |  | | d d
 | d  n  d  S(   Nu   is_somethingu   Line {:d}: u   nlineu   warningu   <a href="{}/{}">{}</a>: u   doc_urlu   messageu   utf-8u   
i   u   nchar(   R
   t   parse_vowarningt   dataR   R   R	   t
   isinstanceR   t	   text_typeR   R   t   lenR   (   R   R   t	   xml_linest   warningt   msg(    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   write_warningZ   s    


&c         C` sͺ   t  j d |  } | r |  j d j t | j d   t | j d     t |  | t | j d   d t | j d   d  n |  j |  |  j d  d  S(   NuO   (WARNING|ERROR|INFO) \(l.(?P<line>[0-9]+), c.(?P<column>[0-9]+)\): (?P<rest>.*)u   Line {:d}: {}
u   lineu   resti   u   columnu   
(	   t   ret   searchR   R   t   intt   groupR   R   R   (   R   R   R!   t   match(    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   write_votlint_warningl   s    +c         C` s  d |  k r  |  d d  k	 r  d  S|  j   } | j   } t j j |  j   d  } t j | d d d } t	 |  } t
 |  σ| j d  : | j d d d	  | j |  j j d
   Wd  QXWd  QX| j d  | j d  4 | j   x" |  d D] } t | | |  qWWd  QX|  d t k rΑ| j d  | j d d  |  d } t | t j  s| j d
  } n  | j |  j   d d  } | j d   | j |  Wd  QXn  d |  k ru|  d t k ru| j d  | j d d  |  d } t | t j  s(| j d
  } n  | j d  6 | j   x$ | j   D] } t | | |  qOWWd  QXqun  Wd  QXWd  QXd  S(   Nu   network_erroru
   index.htmlu   wt   encodingu   utf-8u   pu   at   hrefu   vo.xmlu   asciiu   hru   preu   warningsu   xmllintu   xmllint results:u   xmllint_contentu   /u    u   votlintu   votlint results:u   votlint_content(   t   Nonet   get_xml_contentt
   splitlinest   ost   patht   joint   get_dirpatht   iot   openR   R   R   R   t   urlR   R   t   _flushR$   t   FalseR   R   R   t   replaceR*   (   t   resultt   xmlR!   R1   t   fdR   R   t   content(    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   write_resulty   sH    %



c         C` sέ  |  j  d  Θ|  j  d  n d | k rX | d d  k	 rX |  j | j j d   n1 |  j d | j j d  d d j | j    Wd  QXd | k r| d d  k	 r|  j d t j	 | d  d i d	 d
 6|  j d d  |  j d d  |  j d d  |  j d d  n»|  j d d d i d d
 6| d rNd	 } d } n2 | d rtd } t j	 | d  } n d } d } |  j d | d i | d
 6| d } | d d  k rΐd } n | d t
 k rΩd	 } n d } |  j d | d i | d
 6| d d k rd } d } n> | d d k r:d	 } d } n | d d k rYd } d } n  |  j d | d i | d
 6d | k rͺ| d rd } d } qΆd	 } d } n d } d } |  j d | d i | d
 6Wd  QXd  S(   Nu   tru   tdu   network_erroru   asciiu   aR,   u   {}/index.htmlt   attribu   redu   classu   -u   greenu   nexceptionsu   Fatalu	   nwarningsu   yellowu   versionu   xmllintu    u   expectedu   goodu   brokenu   netu	   incorrectu   invalidu   votlintu   Passedu   Failedu   ?(   R   R-   R   R6   R   R   R   t   get_htmlpathR   R   R8   (   R   R:   t   clsR#   (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   write_result_row¦   sd    
	

					
		u   resultsiτ  c         ` s³      f d   } t  t t t |   |    xut t d t t |  d  |   D]L\ } } | | | | !} t j j	 | d j
   |   }	 t j |	 d d d τ }
 t |
   t   Σ | |   j d |   j d	    j d
  e  j d d   j d d   j d d   j d d   j d d   j d d  Wd  QXx | D] } t  |  qxWWd  QX| |  Wd  QXWd  QXq_ Wd  S(   Nc         ` s   d k r d  S j  d  ο |  d k rU  j d d d d j   |  d  n  xy t   D]k } | |  k r  j t j | d   n/  j d t j | d  d d j   |   j d  qb W|   d k  r
 j d d	 d d j   |  d  n  Wd  QXd  S(
   Ni   u   centeri    u   au   << R,   u   {}_{:02d}.htmlu    u   >>(   R   R   R   R   R   R   R   (   t   jt   i(   t   basenamet   npagesR   (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   write_page_linksη   s    )i    i   u   {}_{:02d}.htmlu   wR+   u   utf-8u   h2u   tableu   tru   thu   URLu   Networku   Warningsu   Schemau   Expectedu   votlint(   R'   R   t   floatR    t	   enumerateR   t   maxR0   R1   R2   R   R4   R5   R   R   R   R   RB   (   RE   t   namet   resultst   roott
   chunk_sizeRG   RD   RC   t
   subresultsR1   R<   R:   (    (   RE   RF   R   s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   write_tableζ   s*    "4!
u   pc   	      C` s  |  j  d  	t |  } | d  k r7 t |  } n  | d k rL d } n t t |   | } |  j  d  f x | D] } |  j |  qy W|  j d | d d j |  x! t |  D] } |  j	 |  qΌ WWd  QXd j t |  |  } |  j  d   |  j
 |  Wd  QXWd  QXd  S(	   Nu   tri    g        u   tdu   aR,   u
   {}_00.htmlu   {:d} ({:.2%})(   R   t   listR-   R    RH   t   startR   R   t   reversedt   endR   (	   R   RE   RK   RO   t   insidet   totalt
   percentageR   t   numbers(    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt
   add_subset  s     	c         C` s©   t  j j | d  } t j | d d d v } t |  } t |  U | j d d  | j d  / x' |  D] } t	 | d t
 |  | qp WWd  QXWd  QXWd  QXd  S(	   Nu
   index.htmlu   wR+   u   utf-8u   h1u   VO Validation resultsu   tableRV   (   R0   R1   R2   R4   R5   R   R   R   R   RY   R    (   t   subsetsRL   RM   R1   R<   R   t   subset(    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   write_index'  s    c   	      C` sk   | d  k r t |  } n  t t |   | } d j t |  |  } t | | d | | |  |  d  S(   Nu   {:d} ({:.2%})u    (   R-   R    RH   R   RP   (	   RM   RE   RK   RO   RU   RV   RN   RW   RX   (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   write_index_table3  s
    (#   t
   __future__R    R   R   R   t   externR   t   extern.six.movesR   t
   contextlibR4   t   mathR   R0   R%   t   utils.xml.writerR   R   t    R	   R
   R   R   t   contextmanagerR   R   R$   R*   R>   RB   RP   R-   RY   R\   R]   (    (    (    s@   lib/python2.7/site-packages/astropy/io/votable/validator/html.pyt   <module>   s.   "'			-	@-