0:
uploadsrc2 = form["filename2"].filename
elif "url2" in args and type(args["url2"]) is str and len(args["url2"]) > 0:
uploadsrc2 = args["url2"]
if uploadsrc2.startswith("draft-"):
rev_match = re.search("(.*-)([0-9][0-9])(.txt)?$", uploadsrc2)
if rev_match:
uploadsrc2 = "http://www.ietf.org/archive/id/"+uploadsrc2;
else:
uploadsrc2 = "http://tools.ietf.org/id/"+uploadsrc2;
name_match = re.search("^(.*?)(.txt)?$", uploadsrc2)
if name_match:
draft = name_match.group(1)
try:
attrs = attrib.readline("/www/tools.ietf.org/draft/%s/now" % draft)
uploadsrc2 = "%s-%s" % (draft, attrs.docrev.string)
except:
pass
if not uploadsrc2.endswith(".txt"):
uploadsrc2 += ".txt"
else:
match = re.search("^[rR][fF][cC] ?([0-9]+)", uploadsrc2)
if match:
uploadsrc2 = "http://www.ietf.org/rfc/rfc"+match.group(1)+".txt"
else:
uploadmsg = "Upload failed - no source file name for file 2."
if "filename1" in args or "url1" in args or uploadsrc2:
if "filename1" in args and len(args["filename1"]) > 0:
uploadsrc1 = form["filename1"].filename
elif "url1" in args and type(args["url1"]) is str and len(args["url1"]) > 0:
uploadsrc1 = args["url1"]
if uploadsrc1.startswith("draft-"):
rev_match = re.search("(.*-)([0-9][0-9])(.txt)?$", uploadsrc1)
if rev_match:
uploadsrc1 = "http://www.ietf.org/archive/id/"+uploadsrc1;
else:
uploadsrc1 = "http://tools.ietf.org/id/"+uploadsrc1;
if not uploadsrc1.endswith(".txt"):
uploadsrc1 += ".txt"
if not uploadsrc2:
match = re.match("(.*-)([0-9][0-9])(\..*)", uploadsrc1)
if match:
rev = int(match.group(2))
uploadsrc2= "%s%02d%s" % (match.group(1), rev+1, match.group(3))
uploadmsg = ""
else:
match = re.search("^[rR][fF][cC] ?([0-9]+)", uploadsrc1)
if match:
uploadsrc1 = "http://www.ietf.org/rfc/rfc"+match.group(1)+".txt"
elif uploadsrc2:
try:
match = re.match("(.*-)([0-9][0-9])(\..*)", uploadsrc2)
if match:
rev = int(match.group(2))
if rev > 0:
uploadsrc1= "%s%02d%s" % (match.group(1), rev-1, match.group(3))
elif rev == 0:
match = re.match(".*-(rfc)?([0-9][0-9][0-9]+)bis-.*", uploadsrc2)
if match:
rfcnum = match.group(2)
uploadsrc1 = "http://www.ietf.org/rfc/rfc%s.txt" % rfcnum
else:
# Check if this document is a draft which
# replaces another...
match = re.match(".*/(draft-[^.]*)(\.txt)?", uploadsrc2)
if match:
draft = match.group(1)
if re.search("-[0-9][0-9]$", draft):
draft = draft[:-3]
try:
attrs = attrib.readline("/www/tools.ietf.org/draft/%s/now" % draft)
if "docreplaces" in attrs.__dict__:
uploadsrc1= "http://www.ietf.org/archive/id/%s" % attrs.docreplaces
except Exception, e:
info = str(e)
pass
match = re.match(".*/([Rr][Ff][Cc])([0-9]+)(\..*)", uploadsrc2)
if match:
num = int(match.group(2))
if num > 0:
try:
attrs = attrib.readline("/www/tools.ietf.org/draft/rfc%s/now" % num)
if "document" in attrs.__dict__:
uploadsrc1= "http://www.ietf.org/archive/id/%s" % attrs.document
except Exception, e:
info = str(e)
pass
except Exception, e:
info = str(e)
pass
if uploadsrc1:
uploadname = basename(re.sub("\\\\","/", uploadsrc1))
if re.match("^[a-zA-Z0-9_.,-]*$", uploadname):
if uploadsrc1.startswith("http://") or uploadsrc1.startswith("ftp://"):
try:
import httplib
import urllib2 as urllib
uploadfile = urllib.urlopen(uploadsrc1)
except:
uploadmsg = "Couldn't retrieve file 1 (%s) - please check the URL." % uploadsrc1
if uploadfile and re.search("-[0-9][0-9](\.txt)?$", uploadsrc1) and uploadsrc1 != uploadfile.geturl():
uploadmsg = "Couldn't retrieve file 1 (%s) - got a redirect to '%s' instead." % (uploadsrc1, uploadfile.geturl())
uploadfile = None
elif "filename1" in args and form["filename1"].file:
uploadfile = form["filename1"].file
else:
uploadmsg = "Couldn't retrieve file 1 (%s) - unknown URL format." % uploadsrc1
if uploadname and uploadfile:
if not hasattr(uploadfile, "info") or uploadfile.info()["content-type"].startswith("text/plain"):
uploadname = os.path.join("/a/tmp/1", uploadname)
outputfile = open(uploadname, "w")
while linecount1 < 32000: # arbitrary number of lines
line = uploadfile.readline()
if not line: break
# try to handle files with mac line endings well:
for l in line.rstrip("\n\r").split("\r"):
outputfile.write(l.rstrip("\n\r"))
outputfile.write("\n")
linecount1 += 1
outputfile.close()
os.chmod(uploadname, 0666)
filename1 = uploadname
if not linecount1:
uploadmsg = "File 1 seems to be empty"
else:
uploadmsg = "The mime-type of file 1 is '%s', but 'text/plain' was expected" % uploadfile.info()["content-type"]
else:
uploadmsg = "Upload aborted, got (%s) but a text file without odd characters in the name is expected here." % uploadname
else:
uploadmsg = "Upload failed - no source file name for file 1"
if uploadsrc2:
uploadname = basename(re.sub("\\\\","/", uploadsrc2))
if re.match("^[a-zA-Z0-9_.,-]*$", uploadname):
if uploadsrc2.startswith("http://") or uploadsrc2.startswith("ftp://"):
try:
import httplib
import urllib2 as urllib
uploadfile = urllib.urlopen(uploadsrc2)
except:
uploadmsg = "Couldn't retrieve file 2 (%s) - please check the URL." % uploadsrc2
if uploadfile and re.search("-[0-9][0-9](\.txt)?$", uploadsrc2) and uploadsrc2 != uploadfile.geturl():
uploadmsg = "Couldn't retrieve file 2 (%s) - got a redirect to '%s'." % (uploadsrc2, uploadfile.geturl())
uploadfile = None
if uploadsrc2.startswith("http://tools.ietf.org/id/draft-"):
# Try to get the document from the master site, instead:
uploadsrc2b = uploadsrc2.replace("http://tools.ietf.org/id/", "http://www.ietf.org/internet-drafts/")
try:
uploadfile = urllib.urlopen(uploadsrc2b)
except:
pass
elif "filename2" in args and form["filename2"].file:
uploadfile = form["filename2"].file
else:
uploadmsg = "Couldn't retrieve file 2 (%s) - unknown URL format." % uploadsrc2
if uploadname and uploadfile:
if not hasattr(uploadfile, "info") or uploadfile.info()["content-type"].startswith("text/plain"):
uploadname = os.path.join("/a/tmp/2", uploadname)
outputfile = open(uploadname, "w")
while linecount2 < 32000:
line = uploadfile.readline()
if not line: break
# try to handle files with mac line endings well:
for l in line.rstrip("\n\r").split("\r"):
outputfile.write(l.rstrip("\n\r"))
outputfile.write("\n")
linecount2 += 1
outputfile.close()
if not linecount2:
uploadmsg = "File 2 seems to be empty..."
os.chmod(uploadname, 0666)
filename2 = uploadname
else:
uploadmsg = "The mime-type of file 2 is '%s', but 'text/plain' was expected" % uploadfile.info()["content-type"]
else:
uploadmsg = "Upload aborted, got (%s) but a text file without odd characters in the name is expected here." % uploadname
if "--width" in args and args["--width"]:
width="--width "+args["--width"]
else:
width=""
if "--oldcolour" in args and args["--oldcolour"]:
oldcolour = "--oldcolour "+args["--oldcolour"]
else:
oldcolour = ""
if "--newcolour" in args and args["--newcolour"]:
newcolour = "--newcolour "+args["--newcolour"]
else:
newcolour = ""
if "difftype" in args:
difftype = args["difftype"]
else:
difftype = ""
if "--larger" in args:
larger = "--larger"
else:
larger = ""
if debuginfo: out("\n\n" % (debuginfo.replace('"','\\"')))
if filename1 and filename2 and linecount1 and linecount2:
uploadmsg = "Upload complete."
print "X-Debug-Info: %s" % debuginfo
if difftype in ("--abdiff", "--chbars"):
print("Content-Type: text/plain\n\n")
else:
print("Content-Type: text/html\n\n")
os.system("./rfcdiff --stdout --links %s %s %s %s %s %s %s" % (width, difftype, oldcolour, newcolour, larger, filename1, filename2))
#os.unlink(uploadname)
sys.exit(0)
?>
Rfcdiff Tool
Version: 0.11
Author:
Rfcdiff Web Service
You can also use this web-service with an URL query-string of the form:
?url1=http-url-to-doc-1&url2=http-url-to-doc-2
which makes it possible to send around links to diffs between document
versions withouth actually generating the diff yourself, as long as the two
document versions are available by http.
Example (yes, it is long - no way to get around that... - but you could use tinyurl.com to get a short alias to one of these):