Beispiel #1
0
 def test_validator(self):
     res = validator.validate(self.urls)
     self.assertEquals(res, self.validUrls)
Beispiel #2
0
        urls = open(args.input).readlines()
    except IOError:
        print "Error: File \"%s\" not found." % args.input
        sys.exit()

    sel = 3  # default selection is quicksort
    if args.sort is not None: # try getting sort selection from command-line args
        sel = args.sort

    # remove trailing '\n' from urls
    urls = [x.rstrip('\n') for x in urls]
    urlsCopy = urls[:]

    # normalize and validate urls, if desired
    normUrls = normalizer.normalize(urls)
    validUrls = validator.validate(normUrls)
    if args.kind == "valid":
        urls = validUrls
    elif args.kind == "invalid":
        urls = filter(lambda x: x not in validUrls, normUrls)

    sorter = algos[sel](urls)
    sortedList = sorter.sort()
    outfile.write("\n".join(sortedList))

    # Terminal output
    for i in range(len(urlsCopy)):
        print "%-17s: %s" % ("Source url", urlsCopy[i])
        valid = normUrls[i] in validUrls
        print "%-17s: %s" % ("Valid", valid)
        print "%-17s: %s" % ("Canonical form", normUrls[i])
Beispiel #3
0
    except IOError:
        print "Error: Unable to open output file \"%s\"." % args.output
        sys.exit()

    try:
        urls = open(args.input).readlines()
    except IOError:
        print "Error: File \"%s\" not found." % args.input
        sys.exit()

    sel = 3  # default selection is quicksort
    if args.sort is not None:  # try getting sort selection from command-line args
        sel = args.sort

    # remove trailing '\n' from urls
    urls = [x.rstrip('\n') for x in urls]

    # normalize and validate urls, if desired
    normUrls = normalizer.normalize(urls)
    validUrls = validator.validate(normUrls)
    if args.kind == "valid":
        urls = validUrls
    elif args.kind == "invalid":
        urls = filter(lambda x: x not in validUrls, normUrls)

    sorter = algos[sel](urls)
    sortedList = sorter.sort()
    outfile.write("\n".join(sortedList))

# vim: set ai et ts=4 sw=4 sts=4 :
Beispiel #4
0
 def test_validator(self):
     res = validator.validate(self.urls)
     self.assertEquals(res, self.validUrls)