当前位置: 首页>>代码示例>>Python>>正文


Python Popen.readerr方法代码示例

本文整理汇总了Python中subprocess.Popen.readerr方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.readerr方法的具体用法?Python Popen.readerr怎么用?Python Popen.readerr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在subprocess.Popen的用法示例。


在下文中一共展示了Popen.readerr方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: GPGEncryption

# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import readerr [as 别名]
class GPGEncryption():

    def __init__(self, encrypt_or_decrypt, iterable = None, user = None, passphrase = None, test_branch = False):
        self.test_branch = test_branch
        cmd = 'gpg -a -r ' + user + ' -e'
        #cmd = 'cat'
        self.total_sent = 0
        self.term_char = chr(0)
        self.chunk_size = CHUNK_SIZE
        self.stream_iter = iterable
        self.stream_iter_read = iterable.read
        self.gpg_closed = False
        self.padded = False
        self.finished_read = False
        self.first_read = True
        #shared variable between threads
        self.finished_write = False
        self.p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds = True, bufsize = CHUNK_SIZE)

        self.my_buffer = ''
        self.finished_write = False
        self.finished_read = False
        self.semaphore = threading.Semaphore()


    def print_errors(self):
        print self.p.readerr()

    def stringIterate(self, text, chunk_size):
        index = 0

        while index < len(text):
            yield text[index : index + chunk_size]
            index += chunk_size

    def padder(self, text, div, pad = chr(0)):
            size = (div - len(text) % div) + len(text)
            diff = size - len(text)
            text += pad * diff
            return text

    def readFromStream(self, read_size):
        chunk = self.stream_iter_read(read_size)
        while chunk:
            self.p.stdin.write(chunk)
            chunk = self.stream_iter_read(read_size)
        self.p.stdin.close()

    def read(self, read_size):
        read_size = self.chunk_size
        if self.first_read:
            self.first_read = False
            t = Thread(target = self.readFromStream, args = (read_size, ))
            t.start()
        chunk = self.p.stdout.read(read_size)
        if chunk and len(chunk) < read_size:
            chunk = self.padder(chunk, read_size)
        self.total_sent += len(chunk)
        #print 'returning chunk = ' + str(len(chunk))
        return chunk
开发者ID:houseurmusic,项目名称:my-swift,代码行数:62,代码来源:gpgencryption.py


注:本文中的subprocess.Popen.readerr方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。