예제 #1
0
파일: patch.py 프로젝트: as/9front-work
 def extract(self, lr):
     line = lr.readline()
     self.hunk.append(line)
     while line and not line.startswith('literal '):
         line = lr.readline()
         self.hunk.append(line)
     if not line:
         raise PatchError(_('could not extract binary patch'))
     size = int(line[8:].rstrip())
     dec = []
     line = lr.readline()
     self.hunk.append(line)
     while len(line) > 1:
         l = line[0]
         if l <= 'Z' and l >= 'A':
             l = ord(l) - ord('A') + 1
         else:
             l = ord(l) - ord('a') + 27
         dec.append(base85.b85decode(line[1:-1])[:l])
         line = lr.readline()
         self.hunk.append(line)
     text = zlib.decompress(''.join(dec))
     if len(text) != size:
         raise PatchError(_('binary patch is %d bytes, not %d') %
                          len(text), size)
     self.text = text
예제 #2
0
 def extract(self, lr):
     line = lr.readline()
     self.hunk.append(line)
     while line and not line.startswith("literal "):
         line = lr.readline()
         self.hunk.append(line)
     if not line:
         raise PatchError(_("could not extract binary patch"))
     size = int(line[8:].rstrip())
     dec = []
     line = lr.readline()
     self.hunk.append(line)
     while len(line) > 1:
         l = line[0]
         if l <= "Z" and l >= "A":
             l = ord(l) - ord("A") + 1
         else:
             l = ord(l) - ord("a") + 27
         dec.append(base85.b85decode(line[1:-1])[:l])
         line = lr.readline()
         self.hunk.append(line)
     text = zlib.decompress("".join(dec))
     if len(text) != size:
         raise PatchError(_("binary patch is %d bytes, not %d") % len(text), size)
     self.text = text
예제 #3
0
def syncpull(repo, remote, gettransaction):
    """utility function to pull obsolete markers from a remote

    The `gettransaction` is function that return the pull transaction, creating
    one if necessary. We return the transaction to inform the calling code that
    a new transaction have been created (when applicable).

    Exists mostly to allow overridding for experimentation purpose"""
    tr = None
    if _enabled:
        repo.ui.debug('fetching remote obsolete markers\n')
        remoteobs = remote.listkeys('obsolete')
        if 'dump0' in remoteobs:
            tr = gettransaction()
            for key in sorted(remoteobs, reverse=True):
                if key.startswith('dump'):
                    data = base85.b85decode(remoteobs[key])
                    repo.obsstore.mergemarkers(tr, data)
            repo.invalidatevolatilesets()
    return tr
예제 #4
0
def pushmarker(repo, key, old, new):
    """Push markers over pushkey"""
    if not key.startswith('dump'):
        repo.ui.warn(_('unknown key: %r') % key)
        return 0
    if old:
        repo.ui.warn(_('unexpected old value') % key)
        return 0
    data = base85.b85decode(new)
    lock = repo.lock()
    try:
        tr = repo.transaction('pushkey: obsolete markers')
        try:
            repo.obsstore.mergemarkers(tr, data)
            tr.close()
            return 1
        finally:
            tr.release()
    finally:
        lock.release()
예제 #5
0
def syncpull(repo, remote, gettransaction):
    """utility function to pull obsolete markers from a remote

    The `gettransaction` is function that return the pull transaction, creating
    one if necessary. We return the transaction to inform the calling code that
    a new transaction have been created (when applicable).

    Exists mostly to allow overriding for experimentation purpose"""
    tr = None
    if _enabled:
        repo.ui.debug('fetching remote obsolete markers\n')
        remoteobs = remote.listkeys('obsolete')
        if 'dump0' in remoteobs:
            tr = gettransaction()
            for key in sorted(remoteobs, reverse=True):
                if key.startswith('dump'):
                    data = base85.b85decode(remoteobs[key])
                    repo.obsstore.mergemarkers(tr, data)
            repo.invalidatevolatilesets()
    return tr
예제 #6
0
def pushmarker(repo, key, old, new):
    """Push markers over pushkey"""
    if not key.startswith('dump'):
        repo.ui.warn(_('unknown key: %r') % key)
        return 0
    if old:
        repo.ui.warn(_('unexpected old value') % key)
        return 0
    data = base85.b85decode(new)
    lock = repo.lock()
    try:
        tr = repo.transaction('pushkey: obsolete markers')
        try:
            repo.obsstore.mergemarkers(tr, data)
            tr.close()
            return 1
        finally:
            tr.release()
    finally:
        lock.release()
예제 #7
0
def _pullobsolete(pullop):
    """utility function to pull obsolete markers from a remote

    The `gettransaction` is function that return the pull transaction, creating
    one if necessary. We return the transaction to inform the calling code that
    a new transaction have been created (when applicable).

    Exists mostly to allow overriding for experimentation purpose"""
    if 'obsmarkers' in pullop.stepsdone:
        return
    pullop.stepsdone.add('obsmarkers')
    tr = None
    if obsolete.isenabled(pullop.repo, obsolete.exchangeopt):
        pullop.repo.ui.debug('fetching remote obsolete markers\n')
        remoteobs = pullop.remote.listkeys('obsolete')
        if 'dump0' in remoteobs:
            tr = pullop.gettransaction()
            for key in sorted(remoteobs, reverse=True):
                if key.startswith('dump'):
                    data = base85.b85decode(remoteobs[key])
                    pullop.repo.obsstore.mergemarkers(tr, data)
            pullop.repo.invalidatevolatilesets()
    return tr
예제 #8
0
 def __init__(self, hashorctx):
     if isinstance(hashorctx, str):
         self._bs = hashorctx
         self._depth, self._vec = _split(base85.b85decode(hashorctx))
     else:
         self._vec = ctxpvec(hashorctx)
예제 #9
0
 def __init__(self, hashorctx):
     if isinstance(hashorctx, str):
         self._bs = hashorctx
         self._depth, self._vec = _split(base85.b85decode(hashorctx))
     else:
         self._vec = ctxpvec(hashorctx)
예제 #10
0
def base85decode(importx, infilepath, outfilepath, outputformat, raw, exportx):

    if importx == 'file':
    
        f = open(infilepath, 'r')
        raw = f.read()
        f.close()
        
    elif importx == 'print':
    
        raw = raw
        
    else:
    
        print('\033[1;31m[-]\033[0m Unknown error.')
        return False
        
    out = b85decode(raw)
    
    if outputformat == 'base64':
    
        output = base64.b64decode(out)
    
    elif outputformat == 'base32':
    
        output = base64.b32decode(out)
    
    elif outputformat == 'base16':
    
        output = base64.b16decode(out)
    
    elif outputformat == 'base58':
    
        output = base58.b58decode(out)
    
    elif outputformat == 'base85':
    
        print('\033[1;31m[-]\033[0m Option not available yet')
    
    elif outputformat == 'hex':
    
        output = out.decode('hex')
    
    elif outputformat == 'dec':
    
        print('\033[1;31m[-]\033[0m Option not available yet')
    
    elif outputformat == 'octal':
    
        print('\033[1;31m[-]\033[0m Option not available yet')
    
    elif outputformat == 'binary':
    
        output = text_from_bits(out)
        
    else:
    
        print('\033[1;31m[-]\033[0m Unknown error.')
        return False
        

    if exportx == 'file':
    
        f = open(outfilepath, 'w')
        f.write(output)
        f.close()
        return True
        
    elif exportx == 'print':
    
        return output
        
    else:
    
        print('\033[1;31m[-]\033[0m Unknown error.')
        return False