mò
Œµ Cc           @   sÝ   d  Z  d d d d g Z d k Z d k Z d k Z d k Z d k Z d k Z d k Z d k	 l	 Z	 d k
 Z
 d k Z d f  d „  ƒ  YZ d „  Z d f  d	 „  ƒ  YZ d
 „  Z d „  Z d „  Z d e i f d „  ƒ  YZ d S(   s   0.1t   pyinkHTTPRequestHandlert   glt   rest   rdResN(   s   StringIOc           B   s>   t  Z d Z d Z d Z d Z d Z d Z d Z d Z	 d	 Z
 RS(
   Ns   Check<br>Nozzles   Clean<br>Nozzles   Align<br>Heads   Reset<br>Printers   Change<br>Cartridges   State:t
   Preferencet   OKs   Port Choice:(   t   __name__t
   __module__t   checkt   cleant   alignt   resett	   cartridget   printerStatet   preft   okt	   cfgDevice(    (    (    t/   /home/jj/mtink-1.0.12/pyink/pyinkHTTPHandler.pyR      s   c          C   s)  t  i d ƒ }  t |  ƒ d j o |  d  }  n d }  |  d d !i ƒ  |  d i ƒ  }  t d d ƒ } x²t oª| i	 ƒ  } | d j o Pn | d	  } |  | d d !j oj| GH| i d
 ƒ } | d | !} | | d } xJ t oB | i d ƒ } | d	 j o Pn | d | !d | | d } qÞ W| d j o | t _ q| d j o | t _ q| d j o | t _ q| d j o | t _ q| d j o | t _ q| d j o | t _ q| d j o | t _ q| d j o | t _ q| d j o | t _ qqi qi W| i ƒ  d  S(   Nt   LANGi   t   eni    i   s	   Pyink.rest   rt    iÿÿÿÿt   :i   s   \ns   <br>R   R	   R
   R   R   R   R   R   t
   cfg2Device(   t   ost   getenvt   langt   lent   uppert   lowert   opent   ft   Truet   readlinet   mt   findt   colont   idt   ret   brR   R   R	   R
   R   R   R   R   R   R   t   close(   R   R   R"   R&   R$   R'   R%   (    (    R   R   "   sT    ! 
 "c           B   sP   t  Z d Z d Z d Z e Z e Z e Z	 e Z
 e Z e Z d Z d Z d Z RS(   NR   (   R   R   t   devfilet   modelt   modelTypR    t   enCheckt   enCleant   Falset   enAlignt   enResett
   enExchanget   initt   confDirt   workDirt   tmpDir(    (    (    R   R   X   s   c          C   s»  t  i i t i d ƒ ot t i d d ƒ }  xvt on|  i ƒ  } | d j o Pn | i
 ƒ  } | i d ƒ } | i d j o!| d d j o | d t _ q¤| d d j o | d t _ q¤| d d	 j o | d t _ q¤| d d
 j o
 t } n t } | d d j o | t _ q¤| d d j o | t _ q¤| d d j o | t _ q¤| d d j o | t _ q¤| d d j o | t _ q¤q3 q3 W|  i ƒ  n d  S(   Ns   /htink.confR   R   t   =i   i    t
   deviceFilet	   modelNameR+   R    R   R	   R
   R   t   exchange(   R   t   patht   existsR   R5   R   R   R    R!   t   lt   stript   splitt   wt   countR)   R*   R+   t   stR.   R,   R-   R/   R0   t
   enSxchangeR(   (   R   R<   RA   R?   (    (    R   t   readConfi   s<     
c         C   s`  x‰ t  o |  i ƒ  } | d  } | i ƒ  } | d j o Pn | d j o Pn | i d ƒ } | d i ƒ  | d <| d i ƒ  | d <q Wt  t _ t  t _	 t  t _
 t t i d d ƒ } | i d	 t i d
 ƒ | i d t i d
 ƒ t i t  j o | i d ƒ n | i d ƒ t i t  j o | i d ƒ n | i d ƒ | i ƒ  t  t _ d  S(   Niÿÿÿÿs   .ENDR   R   i    i   s   /htink.confR?   s   deviceFile=s   
s	   modelTyp=s   align=True
s   align=False
s   exchange=True
s   exchange=False
(   R    t   pR!   R<   R=   R>   R?   R   R,   R-   R0   R   R5   t   cft   writeR)   R+   R/   R1   R(   R2   (   RD   R<   RE   R?   (    (    R   t   setOpts‘   s4     
				
c         C   s  |  i ƒ  } | d  } | i ƒ  } | i ƒ  | i d ƒ } t | ƒ } d } d } xS | | j  oE | | } | d j o | | } n | d | | } | d } qV W| d d j oÃ | t _ t t i d d	 ƒ } x“ t o‹ | i ƒ  }
 |
 d j o Pn |
 i d ƒ }
 |
 d
  }
 |
 i d ƒ } | d d j o0 | d i ƒ  }	 |	 | j o t | ƒ PqjqÜ qÜ W| i ƒ  n d  S(   Niþÿÿÿt    i   R   t   _i    t   Styluss   /printer.descR   iÿÿÿÿR   s   .name(   R   R!   R<   R=   R>   t   wsR   t   ct   it   nR?   R   R+   R   R3   RD   R    t   plt   wpt   pnRG   R(   (   R   RL   RM   R<   RN   RD   RK   R?   RP   RQ   RO   (    (    R   t   StoreConfigº   s@    

 
	 

c           B   sH   t  Z d e Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   Ns
   pyinkHTTP/c         C   s÷  t  i d j o d t  i d } n d } |  i d j o
 d } n |  i d j oŠ d } t d d ƒ } |  i d ƒ |  i	 d	 d
 ƒ |  i	 d t
 t i | i ƒ  ƒ d ƒ ƒ |  i ƒ  |  i | |  i ƒ | i ƒ  d Snµ|  i d j o: t t  _ d t  _ t i i d ƒ o t i d ƒ q“nk|  i d j o+ t i d t  i | d t  i d ƒ n0|  i d j o8 t i d t  i | d t  i d ƒ t i d ƒ nè |  i d j o
 d } nÎ |  i d j o
 d } n´ |  i d j o[ d d t  i | d t  i d GHt i d t  i | d t  i d ƒ t i d ƒ nI |  i i d ƒ } | i d j o& | d  d! j o | d t  _ q“n t i d t  i | d" t  i d ƒ t  i t j oy t i i t  i d# ƒ o. t t  i d# d ƒ } t | ƒ | i ƒ  qCt t  i d# d$ ƒ } | i d% ƒ | i ƒ  n t t  i d# d ƒ } |  i  | ƒ | i ƒ  t t  i d& d ƒ } |  i d ƒ |  i	 d	 d' ƒ |  i	 d t
 t i | i ƒ  ƒ d ƒ ƒ |  i ƒ  |  i | |  i ƒ | i ƒ  d S((   s   Serve a GET request.R   s    -m RH   t   /s   /spacer.gifs
   spacer.gifR   iÈ   s   Content-types	   image/gifs   Content-Lengthi   Ns   /Configs
   htink.confs   /Resets   ttink -u -d s    -r >s   /ttink.response 2>&1s   /Cleans    -c >s   /ttinkx.response 2>&1i   s   /Aligns	   /exchanges   /Checks   call: s    -n >i   t   ?i   i    s   /DevSels    >s   /ttink.responseR?   s   No answer from ttink!s   /ttink.htmls	   text/html(!   R   R+   t   modCmdt   selfR:   t   nocallR   R   t   send_responset   send_headert   strR   t   fstatt   filenot   end_headerst   copyfilet   wfileR(   R.   R2   R)   R;   t   unlinkt   systemR5   t   timet   sleepR>   t   cmdsR@   RR   RF   t	   buildFile(   RV   RW   R   Rd   RU   (    (    R   t   do_GETæ   sr     
)

		+'

#''

)
c         C   s   t  i | | ƒ d  S(   N(   t   shutilt   copyfileobjt   sourcet
   outputfile(   RV   Ri   Rj   (    (    R   R^   7  s    c         C   sÑ  t  t i d d ƒ } t i d j o |  i | ƒ d  Sn | i ƒ  } | d  } | i ƒ  } | d  } | | j o | i ƒ  } | d  } n d } | i d ƒ d j o) t i | d ƒ } t i | d ƒ } n | i ƒ  d } xUd oM| i ƒ  } | d  } | d j o Pn | i d ƒ d j o t i | d ƒ } n | d i ƒ  } | d i ƒ  } | d j o | }	 | }
 n¯ | d j o | } | } n’ | d	 j o | } | } nu | d
 j o | } | } nX | d j o | } | } n; | d j o | } | } n | d j o | } | } n | d } qæ W| d j ot| i! d d d d d d d d d d d d d d d d d d d  d d! d d d" d# d d$ d% d& d' d( | d) d* d+ d, d- d. d/ d- d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d/ d- d= d> d? d@ dA dB d, d- d. d/ d- d0 d1 d2 d3 dC dD dE dF t" i# dG d8 d9 d: d; d< d/ d- d= d> d? d* dH dI ƒ n| d j o| d  t _$ | i! dJ ƒ | i! dK t i$ dL ƒ | d j o |  i% | |
 |	 dM t& ƒ n | d j oO |  i% | | | dN t' ƒ |  i% | | | dO t' ƒ |  i% | | | dP t' ƒ n | d j o6 |  i% | | | dQ t' ƒ |  i% | | | dR t' ƒ n | d j o |  i% | | | ƒ n | i! dS t" i( dT | dU ƒ |  i) | dV t" i* dW dX t i+ ƒ |  i) | dV t" i, dY dZ t i- ƒ |  i) | dV t" i. d[ d\ t i/ ƒ |  i) | dV t" i0 d] d^ t i1 ƒ |  i) | dV t" i2 d_ d` t i3 ƒ | i! da ƒ | i4 ƒ  n d  S(b   Ns   /ttink.htmlR?   R   iÿÿÿÿR   i    i   iýÿÿÿi   i   i   i   i   s   <html>
sJ   <HEAD><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
s   </HEAD>
s)   <body bgColor="#dddddd" onLoad="hide()">
s!    <script type="text/javascript">
s     <!--
s       function hide()
s       {
s          host=location.hostname;
s          port=location.port;
s          file=location.pathname;
s          if ( file != "/" )
s	          {
s4              //location.href="http://"+host+":"+port;
s:              location.replace("http://"+host+":"+port+"/");
s	          }
s       }
s       function bg(elem,color) {
s3         document.getElementById(elem).bgColor=color;
s       function send(cmd) {
s8          //location.href="http://"+host+":"+port+"/"+cmd;
s:          location.replace("http://"+host+":"+port+"/"+cmd);
s     //-->
s    </script>
s/    <table align="center" width="100%" border="0">s     <tr>
s       <td align="left" colspan="3">s   <br><br></td>
s     </tr>
s#      <td align="center" width="30%">
s=       <table border=0 cellpadding=0 cellspacing=0 witdh="10%">
s
        <tr>
s_         <td colspan=3 BGCOLOR="White"><img src="spacer.gif" border=0 height=1 width="100%"></td>
s        </tr>
sP         <td BGCOLOR="White" width=1 ><img src="spacer.gif" border=0 width=1></td>
s         <TD width="100%">
sA          <Table width="100%" border=0 cellpadding=0 cellspacing=0>
s           <tr>
sC            <td width="100%" BGCOLOR="#cccccc" align="center" id="ok"
sM               onMouseOver="bg('ok','#eeeeee')" onMouseOut="bg('ok','#cccccc')"
s                onClick="send('')">
s.             <font style="color:Black">OK</font>
s            </td>
s           </tr>
s          </table>
s         </TD>
sO         <td BGCOLOR="Black" width=1><img src="spacer.gif" border=0 width=1></td>
sR         <td colspan=3 BGCOLOR="Black"><img src="spacer.gif" border=0 height=1></td>
s        </TR>
s       </TABLE>
s      </td>  
s      <td>  </td>  
s"      <td align="center" width="30%">sD            <td width="100%" BGCOLOR="#cccccc" align="center" id="cfg"
sO               onMouseOver="bg('cfg','#eeeeee')" onMouseOut="bg('cfg','#cccccc')"
s&               onClick="send('Config')">
s$             <font style="color:Black">s   </font>
s
    </table>
s   </body></html>sƒ   <html>
<HEAD><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</HEAD>
<body bgcolor="#dddddd"  onLoad="hide()">
s—   <table width="100%" border="0" bgColor="#dddddd">
  <tbody ><p>
    <TR><TD colspan="2" align="center" bgColor="White"><font size="+2" color="Blue"><b>sH   </b></font></TD></TR>
    <TR><TD colspan="2" height="10px"> </TD></TR>
s   #000000s   #00ffffs   #ff00ffs   #ffff00s   #a0ffffs   #ffa0ffs>       <TR><TD colspan="2"><BR></TD></TR>
    <TR><TD width="1%">s   </TD><TD width="99%">s  </TD></TR>
    <TR><TD colspan="2"><BR></TD></TR>
  </tbody>
</table>
<!-- Push buttons -->

<script type="text/javascript">
<!--
  function hide()
  {
     host=location.hostname;
     port=location.port;
     file=location.pathname;
     if ( file != "/" )
     {
         //location.href="http://"+host+":"+port;
         location.replace("http://"+host+":"+port+"/");
     }
  }
  function bg(elem,color) {
    document.getElementById(elem).bgColor=color;
  }
  function send(cmd) {
     host=location.hostname;
     port=location.port;
     //location.href="http://"+host+":"+port+"/"+cmd;
     location.replace("http://"+host+":"+port+"/"+cmd);
  }
//-->
</script>
      <TABLE width="100%"  border="0" bgcolor="#dddddd" align="left" cellspacing="0" cellpadding="5">
        <TR>
t   18R   t   CheckR	   t   CleanR
   t   AlignR   t   Resett   ext   Exchanges,           </TR
>      </TABLE>
</body>
</html>(5   R   R   R5   RA   R)   RV   t   askDevR   R!   t   t1t   statusRN   R#   t   stringR>   RK   R=   RM   t   st   blackt   blacknt   cyant   cyannt   magentat   magentant   yellowt   yellownt   lcyant   lcyannt   lmagentat	   lmagentant   greyt   greynRF   R   R   R*   t
   printColorR    R.   R   t   printButtonR   R,   R	   R-   R
   R/   R   R0   R   R1   R(   (   RV   R   R}   R„   R{   RN   R   R~   R‚   Rw   Rx   Rz   Rt   R€   R   RK   RA   Ry   RM   Rƒ   Rs   R|   Rv   (    (    R   Re   :  s–    


 







ÿ uU #"""""c   	      C   s€   t  t | ƒ ƒ } t  d t | ƒ ƒ } d } | o
 d } n | i d | d | d | d | d | d	 | d
 ƒ d  S(   Nid   t   Blackt   Whites$       <TR>
     <TD width="1%" nowrap>s·  </TD>
     <TD width="99%">
      <table border=0 cellpadding=0 cellspacing=0 width="100%">
       <tr>
        <td colspan=3 BGCOLOR="Black"><img src="spacer.gif" border=0 height=1 width="100%"></td>
       </tr>
       <tr>
        <td BGCOLOR="Black" width=1 ><img src="spacer.gif" border=0 width=1></td>
        <TD width="100%" >
         <Table width="100%" border=0 cellpadding=0 cellspacing=0>
          <tr>
           <td width="s   %" BGCOLOR="s   " align="center"><font color="s   ">s$   %</font></td>
           <td width="s'  %"></td>
          </tr>
         </table>
        </TD>
        <td BGCOLOR="White" width=1><img src="spacer.gif" border=0 width=1></td>
       </tr>
       <tr>
        <td colspan=3 BGCOLOR="White"><img src="spacer.gif" border=0 height=1></td>
       </TR>
      </TABLE>
     </TD>
    </TR>(   RZ   t   longt   valuet   val1t   val2t   txtColort   invertRA   RF   t   namet   cname(	   RV   RA   R   RŠ   R   RŽ   R   RŒ   R‹   (    (    R   R…     s    
c         C   sô   d } | t j o
 d } n | i d | d d d d d d d	 d
 d d d | d ƒ | o1 | i d d | d | d d | d ƒ n | i d ƒ | i d | d | d d d d d d d d d d d d  ƒ d  S(!   NR‡   t   Greys   <TD width="s   %" align="center">
s;    <TABLE border=0 cellpadding=0 cellspacing=0 width="100%">
s     <TR>
s\      <TD colspan=3 BGCOLOR="White"><img src="spacer.gif" border=0 height=1 width="100%"></TD>
s     </TR>
sM      <TD BGCOLOR="White" width=1 ><img src="spacer.gif" border=0 width=1></TD>
s      <TD width="100%">
s>       <Table width="100%" border=0 cellpadding=0 cellspacing=0>
s
        <TR>
s<         <TD width="100%" BGCOLOR="#cccccc" align="center" id="t   "s   
s           onMouseOver="bg('s   ','#eeeeee')" onMouseOut="bg('s   ','#cccccc')"
s           onClick="send('s   ')">
s   >
s          <font style="color:s   ">s   </font>
s         </TD>
s        </TR>
s       </TABLE>
s	      </TD>
sL      <TD BGCOLOR="Black" width=1><img src="spacer.gif" border=0 width=1></TD>
sO      <TD colspan=3 BGCOLOR="Black"><img src="spacer.gif" border=0 height=1></TD>
s
    </TABLE>
s   </TD>
(	   R   t   actifR.   RA   RF   t   szR%   t   commandt   text(   RV   RA   R”   R–   R%   R•   R“   R   (    (    R   R†   /  s    
E1c         C   sÔ  t  i } t i d ƒ | i d d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d d d d | d  d! d" d# ƒ t d$ d% ƒ } xI t	 oA | i
 ƒ  } | i ƒ  | d& j o Pn | i d' | d( ƒ qÍ W| i ƒ  | i d) d* d d+ d, d- d. d/ d0 d1 d2 d3 d1 d4 d5 d6 d7 d8 d9 d: d; t  i d# d< d= d> d? d@ d3 d1 dA d3 dB dC d. dD dE dF d* dG dH ƒ d  S(I   NsP   (ls -c /var/mtink/*;ls -cr /dev/lp*;ls -c /dev/usb/lp*) >deviceFiles 2>/dev/nulls   <html>
sJ   <HEAD><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
s   </HEAD>
s)   <body bgColor="#dddddd" onLoad="hide()">
s!    <script type="text/javascript">
s     <!--
s       function hide()
s       {
s          host=location.hostname;
s          port=location.port;
s          file=location.pathname;
s          if ( file != "/" )
s	          {
s:              location.replace("http://"+host+":"+port+"/");
s	          }
s       }
s       function bg(elem,color) {
s3         document.getElementById(elem).bgColor=color;
s       function send(cmd) {
s          // check for selction
s0          sd=document.getElementById("dev").value;
s          if ( sd != "")
s"             host=location.hostname;
s             port=location.port;
sD             location.replace("http://"+host+":"+port+"/"+cmd+"?"+sd);
s     //-->
s    </script>
s"    <table align="center" border="0">s     <tr>
s)      <td align="left" valign="top"  nowrap>s   </td>
s      <td align="left">
s<       <FORM action="Select">
     <select id="dev" size="10">
s   
t   deviceFilesR   R   s          <option>s
   </option>
s%         </select>
    </FORM>
   </td>
s     </tr>
s      <td colspan="2">
s2       <table width="100%"align="center" border="0">
s
        <tr>
s         <td></td>
s&         <td align="center" width="20%">
sA          <TABLE border=0 cellpadding=0 cellspacing=0 width="100%">
s           <tr>
sT            <td colspan=3 BGCOLOR="White"><img src="spacer.gif" border=0 width=1></td>
s           </tr>
s            <td>
sO             <Table width="100%" border=0 cellpadding=0 cellspacing=0 border="0">
s              <tr>
sV               <td BGCOLOR="White" width=1 ><img src="spacer.gif" border=0 width=1></td>
sF               <td width="100%" BGCOLOR="#cccccc" align="center" id="ok"
sP                  onMouseOver="bg('ok','#eeeeee')" onMouseOut="bg('ok','#cccccc')"
s)                  onClick="send('DevSel')">
s                s               </td>
sV               <td BGCOLOR="Black" width=1 ><img src="spacer.gif" border=0 width=1></td>
s              </tr>
s             </table>
s            </td>
sT            <td colspan=3 BGCOLOR="Black"><img src="spacer.gif" border=0 width=1></td>
s          </TABLE>
s         </td>
s        </tr>
s       </TABLE>
s	      </td>
s
    </table>
s   </body></html>(   R   R   Rs   R   Ra   RA   RF   R   t   dR    R!   t   dfR=   R(   R   (   RV   RA   R˜   R™   Rs   (    (    R   Rr   Q  s    	¥' 

(
   R   R   t   __version__t   server_versionRf   R^   Re   R…   R†   Rr   (    (    (    R   R    ã   s   
	Q		Ô	!	"(   Rš   t   __all__R   t	   posixpatht   BaseHTTPServert   urllibt   cgiRg   t	   mimetypest   StringIORu   Rb   R   R   R   RC   RG   RR   t   BaseHTTPRequestHandlerR    (   R    R¡   Rg   R   Rœ   R¢   R   R   RŸ   R    R   RC   Rb   Rž   RR   Rš   R   RG   Ru   (    (    R   RT      s2   									  	4  	' 	( 	( 