convert coerced sha back into numeric list
490242
def decode_from_sha(sha):
    """"""
    if isinstance(sha, str):
        sha = sha.encode('utf-8')
    return codecs.decode(re.sub(rb'(00)*$', b'', sha), "hex_codec")
382436
def refs_to(cls, sha1, repo):
        """"""
        matching = []
        for refname in repo.listall_references():
            symref = repo.lookup_reference(refname)
            dref = symref.resolve()
            oid = dref.target
            commit = repo.get(oid)
            if commit.hex == sha1:
                matching.append(symref.shorthand)

        return matching
1790
def _my_hash(arg_list):
    # type: (List[Any]) -> int
    """"""
    res = 0
    for arg in arg_list:
        res = res * 31 + hash(arg)
    return res
734513
def _geohash_to_bits(value):
  """"""
  b = map(BASE32MAP.get, value)
  ret = []
  for i in b:
    out = []
    for z in range(5):
      out.append(i & 0b1)
      i = i >> 1
    ret += out[::-1]
  return ret
781239
def hash(hash_type, input_text):
    ''''''
    hash_funcs = {'MD5' : hashlib.md5,
                  'SHA1' : hashlib.sha1,
                  'SHA224' : hashlib.sha224,
                  'SHA256' : hashlib.sha256,
                  'SHA384' : hashlib.sha384,
                  'SHA512' : hashlib.sha512}
    if hash_type == 'All':
        hash_type = ['MD5', 'SHA1', 'SHA224', 'SHA256', 'SHA384', 'SHA512']
    else:
        hash_type = [hash_type]
    return [{'Algorithm' : h, 'Hash' : hash_funcs[h](input_text).hexdigest()}
            for h in hash_type]
658608
def numericise_all(input, empty2zero=False, default_blank="", allow_underscores_in_numeric_literals=False):
    """"""
    return [numericise(s, empty2zero, default_blank, allow_underscores_in_numeric_literals) for s in input]
1333027
def keys(self, args):
        
        results = {}
        # TODO: parallelize
        for shard_num in range(0, self.num_shards()):
            shard = self.get_shard_by_num(shard_num)
            results[shard_num] = shard.keys(args)
        return results
226034
def _toIntList(numstr, acceptX=0):
    
    res = []
    # Converting and removing invalid characters
    for i in numstr:
        if i in string.digits and i not in string.letters:
            res.append(int(i))

    # Converting control number into ISBN
    if acceptX and (numstr[-1] in 'Xx'):
        res.append(10)
    return res
536878
def encode_to_sha(msg):
    """"""
    if isinstance(msg, str):
        msg = msg.encode('utf-8')
    return (codecs.encode(msg, "hex_codec") + (b'00' * 32))[:64]
419375
def hash(value):
    ''''''
    if not value:
        return
    elif len(value) == 32:
        type = 'md5'
    elif len(value) == 40:
        type = 'sha1'
    elif len(value) == 64:
        type = 'sha256'
    else:
        return None
    return {'type': type, 'value': value}
530368
def hash(self, val):
        """"""

        if not isinstance(val, bytes):
            raise _TypeError("val", "bytes", val)

        rv = self.compute(val)

        if not isinstance(val, bytes):
            raise _TypeError("val", "bytes", rv)

        return rv
155934
def np_hash(a):
    """"""
    if a is None:
        return hash(None)
    # Ensure that hashes are equal whatever the ordering in memory (C or
    # Fortran)
    a = np.ascontiguousarray(a)
    # Compute the digest and return a decimal int
    return int(hashlib.sha1(a.view(a.dtype)).hexdigest(), 16)
1206893
def rehash(path, blocksize=1 << 20):
    # type: (str, int) -> Tuple[str, str]
    """"""
    h = hashlib.sha256()
    length = 0
    with open(path, 'rb') as f:
        for block in read_chunks(f, size=blocksize):
            length += len(block)
            h.update(block)
    digest = 'sha256=' + urlsafe_b64encode(
        h.digest()
    ).decode('latin1').rstrip('=')
    # unicode/str python2 issues
    return (digest, str(length))
1372532
def to_ordered_hash(opts={})
      force = opts.fetch(:force, false)
      sort_json_ld_keys = opts.fetch(:sort_json_ld_keys, true)

      unless force
        self.validate
      end

      export_hash = IIIF::OrderedHash.new

      if sort_json_ld_keys
        self.keys.select { |k| k.start_with?('@') }.sort!.each do |k|
          export_hash[k] = self.data[k]
        end
      end

      sub_opts = {
        include_context: false,
        sort_json_ld_keys: sort_json_ld_keys,
        force: force
      }
      self.keys.each do |k|
        unless sort_json_ld_keys && k.start_with?('@')
          if self.data[k].respond_to?(:to_ordered_hash) #.respond_to?(:to_ordered_hash)
            export_hash[k] = self.data[k].to_ordered_hash(sub_opts)

          elsif self.data[k].kind_of?(Hash)
            export_hash[k] = IIIF::OrderedHash.new
            self.data[k].each do |sub_k, v|

              if v.respond_to?(:to_ordered_hash)
                export_hash[k][sub_k] = v.to_ordered_hash(sub_opts)

              elsif v.kind_of?(Array)
                export_hash[k][sub_k] = []
                v.each do |member|
                  if member.respond_to?(:to_ordered_hash)
                    export_hash[k][sub_k] << member.to_ordered_hash(sub_opts)
                  else
                    export_hash[k][sub_k] << member
                  end
                end
              else
                export_hash[k][sub_k] = v
              end
            end

          elsif self.data[k].kind_of?(Array)
            export_hash[k] = []

            self.data[k].each do |member|
              if member.respond_to?(:to_ordered_hash)
                export_hash[k] << member.to_ordered_hash(sub_opts)

              elsif member.kind_of?(Hash)
                hsh = IIIF::OrderedHash.new
                export_hash[k] << hsh
                member.each do |sub_k,v|

                  if v.respond_to?(:to_ordered_hash)
                    hsh[sub_k] = v.to_ordered_hash(sub_opts)

                  elsif v.kind_of?(Array)
                    hsh[sub_k] = []

                    v.each do |sub_member|
                      if sub_member.respond_to?(:to_ordered_hash)
                        hsh[sub_k] << sub_member.to_ordered_hash(sub_opts)
                      else
                        hsh[sub_k] << sub_member
                      end
                    end
                  else
                    hsh[sub_k] = v
                  end
                end

              else
                export_hash[k] << member
                # there are no nested arrays, right?
              end
            end
          else
            export_hash[k] = self.data[k]
          end

        end
      end
      export_hash.remove_empties
      export_hash.camelize_keys
      export_hash
    end
1317195
def translate_list(cls, val):
        """"""
        escaped = ', '.join([cls.translate(v) for v in val])
        return 'Seq({})'.format(escaped)
238402
function createShardIterator(streamName, shardId, seq) {
  var encryptStr = [
      (new Array(14).join('0') + Date.now()).slice(-14),
      streamName,
      shardId,
      seq,
      new Array(37).join('0'), // Not entirely sure what would be making up all this data in production
    ].join('/'),
    cipher = crypto.createCipher('aes-256-cbc', exports.ITERATOR_PWD),
    buffer = Buffer.concat([
      new Buffer([0, 0, 0, 0, 0, 0, 0, 1]),
      cipher.update(encryptStr, 'utf8'),
      cipher.final(),
    ])
  return buffer.toString('base64')
}
1145562
def double_sha256(data):
    """"""
    return bytes_as_revhex(hashlib.sha256(hashlib.sha256(data).digest()).digest())