示例#1
0
 def _getFinalHash_default(self, hashObj, path, readCfg, stats):
     bases = Bases()
     
     h = hashObj.hexdigest()
     if 'limit:head' in readCfg['slot:cfg']:
         h = h[0:16]
         #print "i have read %.2fMb" % ((stats['head_sz']+stats['data_sz']+stats['tail_sz'])/float(1024*1024))
         return "FCHV2,sha1f:%s,mt:%s,sz:%s" % (h, bases.toBase62(path.mtime*1000), bases.toBase62(path.size))
     
     return "FCHV2,sha1:%s,mt:%s,sz:%s" % (h, bases.toBase62(path.mtime*1000), bases.toBase62(path.size))
示例#2
0
 def _getFinalHash_default(self, hashObj, path, readCfg, stats):
     bases = Bases()
     
     h = hashObj.hexdigest()
     if 'limit:head' in readCfg['slot:cfg']:
         h = h[0:16]
         #print "i have read %.2fMb" % ((stats['head_sz']+stats['data_sz']+stats['tail_sz'])/float(1024*1024))
         return "FCHV2,sha1f:%s,mt:%s,sz:%s" % (h, bases.toBase62(path.mtime*1000), bases.toBase62(path.size))
     
     return "FCHV2,sha1:%s,mt:%s,sz:%s" % (h, bases.toBase62(path.mtime*1000), bases.toBase62(path.size))
示例#3
0
    def hash(self, path):
        try:
            fi = open(path.path, 'rb')
        except IOError:
            return "FileNotFound"
            
        md5 = hashlib.md5()
        sha1 = hashlib.sha1()
        sha512 = hashlib.sha512()

        cpos = 0
        while True:
            data = fi.read(int(1*1024*1024))
            dl = len(data)
            cpos+= dl
            if not data:
                break
            
            md5.update(data)
            sha1.update(data)
            sha512.update(data)

        fi.close()
        
        bases = Bases()
        return "FullContentHashV1,md5:%s,sha1:%s,sha512:%s,sz:%s" % (md5.hexdigest(), sha1.hexdigest(), sha512.hexdigest(), bases.toBase16(path.size))
示例#4
0
 def __init__(self, overview):
     self.away_team = Team(overview.away_name_abbrev,
                           overview.away_team_runs, overview.away_team_name)
     self.home_team = Team(overview.home_name_abbrev,
                           overview.home_team_runs, overview.home_team_name)
     self.inning = Inning(overview)
     self.bases = Bases(overview)
     self.pitches = Pitches(overview)
     self.outs = Outs(overview)
     self.game_status = overview.status
示例#5
0
    def __init__(self, overview):
        self.away_team = Team(overview.away_name_abbrev,
                              overview.away_team_runs, overview.away_team_name)
        self.home_team = Team(overview.home_name_abbrev,
                              overview.home_team_runs, overview.home_team_name)
        self.inning = Inning(overview)
        self.bases = Bases(overview)
        self.pitches = Pitches(overview)
        self.outs = Outs(overview)
        self.game_status = overview.status

        try:
            self.note = overview.note
        except:
            self.note = None

        try:
            self.reason = overview.reason
        except:
            self.reason = None
示例#6
0
 def _getFinalHash(self, hashObj, path, readCfg, stats):
     bases = Bases()
     return "FastContentHashV1,sha1:%s,sz:%s" % (hashObj.hexdigest(), bases.toBase62(path.size))
示例#7
0
 def _getFinalHash_ignore_hash(self, hashObj, path, readCfg, stats):
     bases = Bases()
     stat = os.stat(path.path)
     return "FCHV2,mt:%s,ct:%s,sz:%s,id:%s" % (bases.toBase62(path.mtime*1000), bases.toBase62(path.ctime*1000), bases.toBase62(path.size), bases.toBase62(stat.st_ino))
示例#8
0
 def _getFinalHash_ignore_mtime(self, hashObj, path, readCfg, stats):
     bases = Bases()
     return "FCHV2,sha1:%s,sz:%s" % (hashObj.hexdigest(), bases.toBase62(path.size))
示例#9
0
 def _getFinalHash(self, hashObj, path):
     bases = Bases()
     return "FastAttributeHashV1,ct:%s,sz:%s" % (bases.toBase62(path.ctime), bases.toBase62(path.size), )
示例#10
0
import math
import unittest
import random
from bases import Bases

bases = Bases()

class Test(unittest.TestCase):

	def test_zero(self):
		# for convenience, bases that begin with zero:
		BASES_BEGINNING_WITH_ZERO = [2, 8, 10, 16, 32, 36, 62]
		# test zero across those bases:
		for base in BASES_BEGINNING_WITH_ZERO:
			self.assertEqual(bases.toBase(0, base), '0')

	def test_base10(self):
		# test base-10 with random numbers (fuzzy/smokescreen tests):
		# note that extremely large numbers (e.g. 39415337704122060) cause bugs due
		# to precision (e.g. that % 10 == 4 somehow), so we limit the digits to 16.
		i = 0
		while i < 20:
			num = math.floor(10000000000000000 * random.random())
			self.assertEqual(bases.toBase10(num), str(int(num)))
			i += 1

	def test_data(self):
		# the test data below is a map from base to lists of [input, exp]:
		DATA = { 
			2:
				[ [1, '1']
示例#11
0
 def _getFinalHash(self, hashObj, path, readCfg, stats):
     bases = Bases()
     return "FastContentHashV1,sha1:%s,sz:%s" % (hashObj.hexdigest(),
                                                 bases.toBase62(path.size))
示例#12
0
 def _getFinalHash_ignore_hash(self, hashObj, path, readCfg, stats):
     bases = Bases()
     stat = os.stat(path.path)
     return "FCHV2,mt:%s,ct:%s,sz:%s,id:%s" % (bases.toBase62(path.mtime*1000), bases.toBase62(path.ctime*1000), bases.toBase62(path.size), bases.toBase62(stat.st_ino))
示例#13
0
 def _getFinalHash_ignore_mtime(self, hashObj, path, readCfg, stats):
     bases = Bases()
     return "FCHV2,sha1:%s,sz:%s" % (hashObj.hexdigest(), bases.toBase62(path.size))
示例#14
0
from bases import Bases

if __name__ == "__main__":
    base = Bases()
    b64_encode = base.to_b64
    b64_decode = base.from_b64

    inp = b"ABCDEFGHIJ"
    out = "QUJDREVGR0hJSg=="
    assert b64_encode(inp) == out, "invalid base64 encoding"

    inp = b"QUJDREVGR0hJSg=="
    out = "ABCDEFGHIJ"
    assert b64_decode(inp) == out, "invalid base64 decoding"
示例#15
0
 def _getFinalHash(self, hashObj, path):
     bases = Bases()
     return "FastAttributeHashV1,ct:%s,sz:%s" % (
         bases.toBase62(path.ctime),
         bases.toBase62(path.size),
     )