Rfcdiff Tool |
|
Version: 0.12
Author: |
%s
" % a
if "filename2" in args or "url2" in args:
if "filename2" in args and len(args["filename2"]) > 0:
uploadsrc2 = form["filename2"].filename
elif "url2" in args and type(args["url2"]) is str and len(args["url2"]) > 0:
uploadsrc2 = args["url2"].split('?',1)[0]
if uploadsrc2.startswith("draft-"):
rev_match = re.search("(.*-)([0-9][0-9])(.txt)?$", uploadsrc2)
if not rev_match:
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
uploadsrc2 = "https://tools.ietf.org/id/"+uploadsrc2;
if not uploadsrc2.endswith(".txt"):
uploadsrc2 += ".txt"
else:
match = re.search("^[rR][fF][cC] ?([0-9]+)", uploadsrc2)
if match:
uploadsrc2 = "https://tools.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"].split('?',1)[0]
if uploadsrc1.startswith("draft-"):
uploadsrc1 = "https://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 = "https://tools.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 = "https://tools.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= "https://tools.ietf.org/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= "https://tools.ietf.org/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("https://") 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 norm(uploadsrc1) != norm(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("tmp/1", uploadname)
outputfile = open(uploadname, "w")
while linecount1 < 64000: # 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("https://") 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 norm(uploadsrc2) != norm(uploadfile.geturl()):
uploadmsg = "Couldn't retrieve file 2 (%s) - got a redirect to '%s'." % (uploadsrc2, uploadfile.geturl())
uploadfile = None
if uploadsrc2.startswith("https://tools.ietf.org/id/draft-"):
# Try to get the document from the master site, instead:
uploadsrc2b = uploadsrc2.replace("https://tools.ietf.org/id/", "https://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("tmp/2", uploadname)
outputfile = open(uploadname, "w")
while linecount2 < 64000:
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
# argument cleaning
if "--width" in args and args["--width"].isdigit():
width = "--width "+args["--width"]
else:
width=""
# argument cleaning
if "--fold" in args and args["--fold"].isdigit():
fold = "--fold "+args["--fold"]
else:
fold=""
colours = [ "aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "orange", "purple", "red", "silver", "teal", "white", "yellow"]
if "--oldcolour" in args and args["--oldcolour"] in colours:
oldcolour = "--oldcolour "+args["--oldcolour"]
else:
oldcolour = ""
if "--newcolour" in args and args["--newcolour"] in colours:
newcolour = "--newcolour "+args["--newcolour"]
else:
newcolour = ""
difftypes = ["html", "chbars", "diff", "wdiff", "hwdiff", "abdiff" ]
difftype = ""
if "difftype" in args:
if type(args["difftype"]) == type([]):
args["difftype"] = args["difftype"][0]
if args["difftype"].lstrip('-') in difftypes:
difftype = args["difftype"]
if "--larger" in args:
larger = "--larger"
else:
larger = ""
if debuginfo:
out("\n\n" % (debuginfo.replace('"','\\"')))
if not (info or errors) and filename1 and filename2 and linecount1 and linecount2:
uploadmsg = "Upload complete."
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 %s" % (fold, width, difftype, oldcolour, newcolour, larger, filename1, filename2))
# if 'filename1' in args:
# del args['filename1']
# if 'filename2' in args:
# del args['filename2']
# out("" % repr(args))
#os.unlink(uploadname)
sys.exit(0)
?>
Rfcdiff Web Service%sYou 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): |
Generated from PyHt script | Latest update: - |