Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(3)  |  Call(3)  |  Derive(0)  |  Import(0)

        def main(hasher = HashFunction):
  global TEST_MODE
  global HASH_MODE

  systemArgs = sys.argv[1:] # ignore program name

  mode = HASH_MODE
  sum = hasher.INIT

  optlist, args = [], []
  try:
    optlist, args = getopt(systemArgs, "s:th", ["sum=", "test", "help"])
  except Exception, e:
    usage()

  if len(optlist) < 1 and len(args) < 1:
    usage()

  for option, value in optlist:
    if option == "-h" or option == "--help":
      usage()
    elif option == "-t" or option == "--test":
      mode = TEST_MODE
    elif option == "-s" or option == "--sum":
      try:
        sum = hasher.unformatDigest(value)
        if not hasher.sumValid(sum):
          raise Exception
      except Exception, e:
        raise "Requires: %s" % (hasher.SUM_REQ)

  hasher = hasher()

  if mode == TEST_MODE:
    result = hasher.test()

    if result == hasher.OK:
      print result
    else:
      print "test data: " + result["test data"]
      print "test formatted hash: " + result["test formatted hash"]
      print "resultant formatted hash: " + result["resultant formatted hash"]
  elif mode == HASH_MODE:
    for file in args:
      f = None
      try:
        f = open(file, "rb")
      except Exception, e:
        print "Could not open %s" % (file)
      else:
        hasher.reset()

        for line in f:
          hasher.update(line)

        f.close()

        print hasher.formatDigest()
        


src/m/c/mcandre-HEAD/python/fractionfiles/CRC32.py   mcandre(Download)
 
if __name__ == "__main__":
  HashFunction.main(CRC32)
 

src/m/c/mcandre-HEAD/python/downloader/CRC32.py   mcandre(Download)
 
if __name__ == "__main__":
  HashFunction.main(CRC32)
 

src/m/c/mcandre-HEAD/python/bethefirst/Adler32.py   mcandre(Download)
 
if __name__ == "__main__":
  HashFunction.main(Adler32)