"Fossies" - the Fresh Open Source Software Archive

Member "rfcdiff-1.48/rfcdiff.pyht" (7 Aug 2020, 16149 Bytes) of package /linux/privat/rfcdiff-1.48.tgz:


The requested HTML page contains a <FORM> tag that is unusable on "Fossies" in "automatic" (rendered) mode so that page is shown as HTML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "rfcdiff.pyht": 1.46_vs_1.47.

    1 <?python # -*- html -*-
    2     import re, os, time, string, stat, sys
    3     from raw2event import attrib
    4 
    5     path  = os.path.realpath(".")
    6     tool  = os.path.basename(path)
    7     Tool  = string.capitalize(tool)
    8 
    9     # Handle possible uploaded files.
   10 
   11     uploadmsg = ""
   12     filename1 = None
   13     filename2 = None
   14     linecount1 = 0
   15     linecount2 = 0
   16     uploadsrc1 = ""
   17     uploadsrc2 = ""
   18     uploadfile = None
   19     info = ""
   20     debuginfo = ""
   21     errors = ""
   22 
   23     def norm(url):
   24     import urlparse
   25     # Normalize scheme, to avoid complaints for redirects from http to https
   26     scheme, host, path, query, fragment = urlparse.urlsplit(url)
   27     if scheme == 'https':
   28         scheme = 'http'
   29     return (scheme, host, path, query, fragment)
   30 
   31     for a in args:
   32     if not a in ["url1", "url2", "filename1", "filename2", "difftype",
   33              "--width", "--oldcolour", "--newcolour", "--larger",
   34              "--fold", "submit", ]:
   35         errors += "Unexpected query parameter: <b>%s</b><br>" % a
   36 
   37     if "filename2" in args or "url2" in args:
   38     if "filename2" in args and len(args["filename2"]) > 0:
   39         uploadsrc2 = form["filename2"].filename
   40     elif "url2" in args and type(args["url2"]) is str and len(args["url2"]) > 0:
   41         uploadsrc2 = args["url2"].split('?',1)[0]
   42         if uploadsrc2.startswith("draft-"):
   43         rev_match = re.search("(.*-)([0-9][0-9])(.txt)?$", uploadsrc2)
   44         if not rev_match:
   45             name_match = re.search("^(.*?)(.txt)?$", uploadsrc2)
   46             if name_match:
   47             draft = name_match.group(1)
   48             try:
   49                 attrs = attrib.readline("/www/tools.ietf.org/draft/%s/now" % draft)
   50                 uploadsrc2 = "%s-%s" % (draft, attrs.docrev.string)
   51             except:
   52                 pass
   53             uploadsrc2 = "https://tools.ietf.org/id/"+uploadsrc2;
   54         if not uploadsrc2.endswith(".txt"):
   55             uploadsrc2 += ".txt"
   56         else:
   57         match = re.search("^[rR][fF][cC] ?([0-9]+)", uploadsrc2)
   58         if match:
   59             uploadsrc2 = "https://tools.ietf.org/rfc/rfc"+match.group(1)+".txt"
   60     else:
   61         uploadmsg = "Upload failed - no source file name for file 2."
   62 
   63     if "filename1" in args or "url1" in args or uploadsrc2:
   64     if "filename1" in args and len(args["filename1"]) > 0:
   65         uploadsrc1 = form["filename1"].filename
   66     elif "url1" in args and type(args["url1"]) is str and len(args["url1"]) > 0:
   67         uploadsrc1 = args["url1"].split('?',1)[0]
   68         if uploadsrc1.startswith("draft-"):
   69             uploadsrc1 = "https://tools.ietf.org/id/"+uploadsrc1;
   70         if not uploadsrc1.endswith(".txt"):
   71             uploadsrc1 += ".txt"
   72             if not uploadsrc2:
   73             match = re.match("(.*-)([0-9][0-9])(\..*)", uploadsrc1)
   74             if match:
   75             rev = int(match.group(2))
   76             uploadsrc2= "%s%02d%s" % (match.group(1), rev+1, match.group(3))
   77             uploadmsg = ""
   78         else:
   79         match = re.search("^[rR][fF][cC] ?([0-9]+)", uploadsrc1)
   80         if match:
   81             uploadsrc1 = "https://tools.ietf.org/rfc/rfc"+match.group(1)+".txt"
   82     elif uploadsrc2:
   83         try:
   84         match = re.match("(.*-)([0-9][0-9])(\..*)", uploadsrc2)
   85         if match:
   86             rev = int(match.group(2))
   87             if rev > 0:
   88             uploadsrc1= "%s%02d%s" % (match.group(1), rev-1, match.group(3))
   89             elif rev == 0:
   90             match = re.match(".*-(rfc)?([0-9][0-9][0-9]+)bis-.*", uploadsrc2)
   91             if match:
   92                 rfcnum = match.group(2)
   93                 uploadsrc1 = "https://tools.ietf.org/rfc/rfc%s.txt" % rfcnum
   94             else:
   95                 # Check if this document is a draft which
   96                 # replaces another...
   97                 match = re.match(".*/(draft-[^.]*)(\.txt)?", uploadsrc2)
   98                 if match:
   99                 draft = match.group(1)
  100                 if re.search("-[0-9][0-9]$", draft):
  101                     draft = draft[:-3]
  102                 try:
  103                     attrs = attrib.readline("/www/tools.ietf.org/draft/%s/now" % draft)
  104                     if "docreplaces" in attrs.__dict__:
  105                     uploadsrc1= "https://tools.ietf.org/id/%s" % attrs.docreplaces
  106                 except Exception, e:
  107                     info += str(e)
  108                     pass
  109 
  110         match = re.match(".*/([Rr][Ff][Cc])([0-9]+)(\..*)", uploadsrc2)
  111         if match:
  112             num = int(match.group(2))
  113             if num > 0:
  114             try:
  115                 attrs = attrib.readline("/www/tools.ietf.org/draft/rfc%s/now" % num)
  116                 if "document" in attrs.__dict__:
  117                 uploadsrc1= "https://tools.ietf.org/id/%s" % attrs.document
  118             except Exception, e:
  119                 info += str(e)
  120                 pass
  121         
  122         except Exception, e:
  123         info += str(e)
  124         pass
  125 
  126     if uploadsrc1:
  127         uploadname = basename(re.sub("\\\\","/", uploadsrc1))
  128         if re.match("^[a-zA-Z0-9_.,-]*$", uploadname):
  129         if uploadsrc1.startswith("http://") or uploadsrc1.startswith("https://") or uploadsrc1.startswith("ftp://"):
  130             try:
  131             import httplib
  132             import urllib2 as urllib
  133             uploadfile = urllib.urlopen(uploadsrc1)
  134             except:
  135             uploadmsg = "Couldn't retrieve file 1 (%s) - please check the URL." % uploadsrc1
  136             if uploadfile and re.search("-[0-9][0-9](\.txt)?$", uploadsrc1) and norm(uploadsrc1) != norm(uploadfile.geturl()):
  137             uploadmsg = "Couldn't retrieve file 1 (%s) - got a redirect to '%s' instead." % (uploadsrc1, uploadfile.geturl())
  138             uploadfile = None
  139         elif "filename1" in args and form["filename1"].file:
  140             uploadfile = form["filename1"].file
  141         else:
  142             uploadmsg = "Couldn't retrieve file 1 (%s) - unknown URL format." % uploadsrc1
  143         if uploadname and uploadfile:
  144             if not hasattr(uploadfile, "info") or uploadfile.info()["content-type"].startswith("text/plain"):
  145             uploadname = os.path.join("tmp/1", uploadname)
  146             outputfile = open(uploadname, "w")
  147             while linecount1 < 64000: # arbitrary number of lines
  148                 line = uploadfile.readline()
  149                 if not line: break
  150                 # try to handle files with mac line endings well:
  151                 for l in line.rstrip("\n\r").split("\r"):
  152                 outputfile.write(l.rstrip("\n\r"))
  153                 outputfile.write("\n")
  154                 linecount1 += 1
  155             outputfile.close()
  156             os.chmod(uploadname, 0666)
  157             filename1 = uploadname
  158             if not linecount1:
  159                 uploadmsg = "File 1 seems to be empty"
  160             else:
  161             uploadmsg = "The mime-type of file 1 is '%s', but 'text/plain' was expected" % uploadfile.info()["content-type"]
  162         else:
  163         uploadmsg = "Upload aborted, got (%s) but a text file without odd characters in the name is expected here." % uploadname
  164     else:
  165         uploadmsg = "Upload failed - no source file name for file 1"
  166 
  167     if uploadsrc2:
  168         uploadname = basename(re.sub("\\\\","/", uploadsrc2))
  169         if re.match("^[a-zA-Z0-9_.,-]*$", uploadname):
  170         if uploadsrc2.startswith("http://") or uploadsrc2.startswith("https://") or uploadsrc2.startswith("ftp://"):
  171             try:
  172             import httplib
  173             import urllib2 as urllib
  174             uploadfile = urllib.urlopen(uploadsrc2)
  175             except:
  176             uploadmsg = "Couldn't retrieve file 2 (%s) - please check the URL." % uploadsrc2
  177             if uploadfile and re.search("-[0-9][0-9](\.txt)?$", uploadsrc2) and norm(uploadsrc2) != norm(uploadfile.geturl()):
  178             uploadmsg = "Couldn't retrieve file 2 (%s) - got a redirect to '%s'." % (uploadsrc2, uploadfile.geturl())
  179             uploadfile = None
  180             if uploadsrc2.startswith("https://tools.ietf.org/id/draft-"):
  181                 # Try to get the document from the master site, instead:
  182                 uploadsrc2b = uploadsrc2.replace("https://tools.ietf.org/id/", "https://www.ietf.org/internet-drafts/")
  183                 try:
  184                 uploadfile = urllib.urlopen(uploadsrc2b)
  185                 except:
  186                 pass
  187                 
  188         elif "filename2" in args and form["filename2"].file:
  189             uploadfile = form["filename2"].file
  190         else:
  191             uploadmsg = "Couldn't retrieve file 2 (%s) - unknown URL format." % uploadsrc2
  192             
  193         if uploadname and uploadfile:
  194             if not hasattr(uploadfile, "info") or uploadfile.info()["content-type"].startswith("text/plain"):
  195             uploadname = os.path.join("tmp/2", uploadname)
  196             outputfile = open(uploadname, "w")
  197             while linecount2 < 64000:
  198                 line = uploadfile.readline()
  199                 if not line: break
  200                 # try to handle files with mac line endings well:
  201                 for l in line.rstrip("\n\r").split("\r"):
  202                 outputfile.write(l.rstrip("\n\r"))
  203                 outputfile.write("\n")
  204                 linecount2 += 1
  205             outputfile.close()
  206             if not linecount2:
  207                 uploadmsg = "File 2 seems to be empty..."
  208             os.chmod(uploadname, 0666)
  209             filename2 = uploadname
  210             else:
  211             uploadmsg = "The mime-type of file 2 is '%s', but 'text/plain' was expected" % uploadfile.info()["content-type"]
  212         else:
  213         uploadmsg = "Upload aborted, got (%s) but a text file without odd characters in the name is expected here." % uploadname
  214 
  215     # argument cleaning
  216     if "--width" in args and args["--width"].isdigit():
  217         width = "--width "+args["--width"]
  218     else:
  219     width=""
  220 
  221     # argument cleaning
  222     if "--fold" in args and args["--fold"].isdigit():
  223         fold = "--fold "+args["--fold"]
  224     else:
  225     fold=""
  226 
  227     colours = [ "aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "orange", "purple", "red", "silver", "teal", "white", "yellow"]
  228     if "--oldcolour" in args and args["--oldcolour"] in colours:
  229     oldcolour = "--oldcolour "+args["--oldcolour"]
  230     else:
  231     oldcolour = ""
  232 
  233     if "--newcolour" in args and args["--newcolour"] in colours:
  234     newcolour = "--newcolour "+args["--newcolour"]
  235     else:
  236     newcolour = ""
  237 
  238     difftypes = ["html", "chbars", "diff", "wdiff", "hwdiff", "abdiff" ]
  239     difftype = ""
  240     if "difftype" in args:
  241         if type(args["difftype"]) == type([]):
  242             args["difftype"] = args["difftype"][0]
  243         if args["difftype"].lstrip('-') in difftypes:
  244             difftype = args["difftype"]
  245 
  246     if "--larger" in args:
  247     larger = "--larger"
  248     else:
  249     larger = ""
  250 
  251     if debuginfo:
  252         out("\n\n<script type='text/javascript' language='JavaScript1.1'>alert(\"%s\");</script>" % (debuginfo.replace('"','\\"')))
  253     if not (info or errors) and filename1 and filename2 and linecount1 and linecount2:
  254     uploadmsg = "Upload complete."
  255     if difftype in ("--abdiff", "--chbars"):
  256         print("Content-Type: text/plain\n\n")
  257     else:
  258         print("Content-Type: text/html\n\n")
  259     os.system("./rfcdiff --stdout --links %s %s %s %s %s %s %s %s" % (fold, width, difftype, oldcolour, newcolour, larger, filename1, filename2))
  260     # if 'filename1' in args:
  261     #     del args['filename1']
  262     # if 'filename2' in args:
  263     #     del args['filename2']
  264     # out("<!-- args: %s -->" % repr(args))
  265 
  266     #os.unlink(uploadname)
  267     sys.exit(0)
  268 
  269 ?>
  270 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  271 <html>
  272 <head>
  273   <title><?python tool ?></title>
  274   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  275   <meta http-equiv="Content-Style-Type" content="text/css" />
  276   <link rel="stylesheet" href="/css/wg-page.css" type="text/css" />
  277   <script language="javascript1.1" src="/js/hide.js" type="text/javascript"></script>
  278   <script language="javascript1.1" src="/js/updated.js" type="text/javascript"></script>
  279   <?python 
  280       tryinclude("../autocomplete/autocomplete_header.html")
  281   ?>
  282 </head>
  283 <body >
  284 <div class="page">
  285    <table border="0" width="100%" >
  286       <tr>
  287      <!-- Left column -->
  288      <?python
  289        virtualinc("/inc/narrow-menu.pyht")
  290      ?>
  291      <!--#include virtual="/inc/narrow-menu.html" -->
  292      <!-- Right column -->
  293      <td valign="top">
  294         <div class="content">
  295 
  296            <div>
  297           <!-- Caption -->
  298           <table width="100%">
  299              <tr>
  300             <td rowspan="2">
  301                <h2 align="left">Rfcdiff Tool</h2>
  302                <i></i>
  303             </td>
  304 
  305             <td class="version" style="color: black; font-size:11pt;">
  306             </td>
  307              </tr>
  308              <tr>
  309             <!-- left column inherited from previous row -->
  310             <td class="chairs">
  311                <i>Version:</i> 0.12
  312                <br />
  313 
  314                <i>Author:</i>
  315                <script type="text/javascript"> showEmail("henrik", "levkowetz.com", "Henrik Levkowetz "); </script>
  316 
  317             </td>
  318              </tr>
  319           </table>
  320           <b>
  321              <!--
  322              <a href="webservice">Idspell Webservice</a> | 
  323              <a href="changelog">Change log</a> |
  324              <a href="code">Browse code</a> | 
  325              <script type="text/javascript"> showEmail("tools-discuss", "ietf.org?subject=Idspell-0.11%20feedback", "Feedback"); </script> |
  326              <a href="copyright">Copyright</a>
  327              -->
  328           </b>
  329            </div>
  330            <hr/>
  331 
  332 
  333            <h3>Rfcdiff Web Service</h3>
  334            <?python
  335           if errors:
  336               out("<div style='background-color: #F88;'>%s</div>" % errors)
  337            ?>
  338            <form action="" method="post" enctype="multipart/form-data">
  339           <table border="0" cellpadding="8" cellspacing="0" >
  340              <tbody>
  341             <tr valign="top">
  342                <td>File 1 - &nbsp;</td>
  343                <td>Upload file: &nbsp; </td>
  344                <td><input name="filename1" type="file" size="40"></td>
  345             </tr>
  346             <tr>
  347                <td />
  348                <td>or enter URL or draft name:  &nbsp; </td>
  349                <td><input name="url1" id="url1" type="text" size="50"></td>
  350             </tr>
  351             <tr><td colspan="3">&nbsp;</td></tr>
  352             <tr valign="top">
  353                <td>File 2 - &nbsp;</td>
  354                <td>Upload file: &nbsp; </td>
  355                <td><input name="filename2" type="file" size="40"></td>
  356             </tr>
  357             <tr>
  358                <td />
  359                <td>or enter URL or draft name:  &nbsp; </td>
  360                <td><input name="url2" id="url2" type="text" size="50"></td>
  361             </tr>
  362             <tr><td colspan="3">&nbsp;</td></tr>
  363             <tr valign="top">
  364                <td colspan="2">Output format:</td>
  365                <td>
  366                   <input name="difftype" value="--html" checked="checked" type="radio">Side-by-side diff<br>
  367                   <input name="difftype" value="--abdiff" type="radio">Before-after diff<br>
  368                   <input name="difftype" value="--chbars" type="radio">Changebars<br>
  369                   
  370                   <input name="difftype" value="--hwdiff" type="radio">Html wdiff<br>
  371                   <table>
  372                 <tr valign="top"><td width="16"></td><td colspan="2">Html Wdiff Options:</td><tr>
  373                 <tr><td/><td>Colour of old text: </td><td><input name="--oldcolour" value="red" type="text"></td></tr>
  374                 <tr><td/><td>Colour of new text: </td><td><input name="--newcolour" value="green" type="text">     </td></tr>
  375                 <tr><td/><td>Larger diff text:   </td><td><input name="--larger" type="checkbox">      </td></tr>
  376                   </table>
  377                </td>
  378             </tr>
  379             <tr valign="top">
  380                <td colspan="2">Column width:</td>
  381                <td><input name="--width" size="4" type="text"></td>
  382             </tr>
  383 
  384             <tr valign="top">
  385                <td colspan="2">Fold lines:</td>
  386                <td><input name="--fold" size="4" type="text"></td>
  387             </tr>
  388 
  389             <tr>
  390                <td colspan="3" align="right">
  391                   <input name="submit" value="Generate diff" type="submit">
  392                </td>
  393             </tr>
  394              </tbody></table>
  395 
  396            </form>
  397 
  398            <div style="margin: 2em;">
  399           <p>
  400              You can also use this web-service with an URL query-string of the form:
  401           </p>
  402           <p>
  403              <tt><small><?python urlpath+"/"+basename(urlname) ?>?url1=<i>http-url-to-doc-1</i>&amp;url2=<i>http-url-to-doc-2</i></small></tt>
  404           </p>
  405           <p>
  406              which makes it possible to send around links to diffs between document
  407              versions withouth actually generating the diff yourself, as long as the two
  408              document versions are available by http.
  409           </p>
  410           <p>
  411              Example (yes, it is long - no way to get around that... - but you could use <a href="https://tinyurl.com/">tinyurl.com</a> to get a short alias to one of these):
  412           </p>
  413           <p>
  414 
  415              <a href="<?python 'https://'+servername+urlname ?>?url1=https://tools.ietf.org/id/draft-ietf-atompub-format-10.txt&url2=https://tools.ietf.org/id/draft-ietf-atompub-format-11.txt"><?python "https://"+servername+urlname ?>?<br/>
  416             &nbsp;&nbsp;url1=https://tools.ietf.org/id/draft-ietf-atompub-format-10.txt<br/>
  417             &nbsp;&nbsp;&amp;url2=https://tools.ietf.org/id/draft-ietf-atompub-format-11.txt</a>
  418 
  419           </p>
  420            </div>
  421         </div>
  422         <br/>
  423         <br/>
  424         <br/>
  425      </td>
  426       </tr>
  427    </table>
  428 
  429 
  430   <table width="100%" style="margin-top: 10em;">
  431     <tr valign="bottom">
  432       <td style=" font-size: 9pt; font-style: italic; text-align: left; ">Generated from <a href="/tools/pyht/">PyHt</a> script <a href="<?python urlname ?>?showcode=1"><?python urlname ?></a></td>
  433       <td style=" font-size: 9pt; font-style: italic; text-align: right; ">Latest update: <?python filedate() ?> - <script type="text/javascript" language="JavaScript1.1">; showAddr("henrik", "levkowetz.com"); </script></td>
  434     </tr>
  435   </table>
  436   <?python
  437     if uploadmsg or info: out("<script type='text/javascript' language='JavaScript1.1'>alert(\"%s\");</script>" % (uploadmsg+". "+info).replace('"','\\"'))
  438   ?>
  439 </div>
  440 </body>
  441 </html>