本文整理汇总了Python中fabric.utils.RingBuffer类的典型用法代码示例。如果您正苦于以下问题:Python RingBuffer类的具体用法?Python RingBuffer怎么用?Python RingBuffer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RingBuffer类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, chan, attr, stream, capture, timeout):
self.chan = chan
self.stream = stream
self.capture = capture
self.timeout = timeout
self.read_func = getattr(chan, attr)
self.prefix = "[%s] %s: " % (env.host_string, "out" if attr == "recv" else "err")
self.printing = getattr(output, "stdout" if (attr == "recv") else "stderr")
self.linewise = env.linewise or env.parallel
self.reprompt = False
self.read_size = 4096
self.write_buffer = RingBuffer([], maxlen=len(self.prefix))
示例2: __init__
def __init__(self, chan, attr, stream, capture, timeout):
self.chan = chan
self.stream = stream
self.capture = capture
self.timeout = timeout
self.read_func = getattr(chan, attr)
self.prefix = get_prefix("out" if attr == 'recv' else "err")
self.printing = getattr(output, 'stdout' if (attr == 'recv') else 'stderr')
self.linewise = (env.linewise or env.parallel)
self.reprompt = False
self.read_size = 4096
self.write_buffer = RingBuffer([], maxlen=len(self.prefix))
示例3: __init__
def __init__(self, chan, attr, stream, capture, timeout, prefix="", linewise = False):
self.chan = chan
self.stream = stream
self.capture = capture
self.timeout = timeout
self.read_func = getattr(chan, attr)
self.prefix = prefix
self.printing = getattr(output, 'stdout' if (attr == 'recv') else 'stderr')
self.linewise = linewise
self.reprompt = False
self.read_size = 4096
self.write_buffer = RingBuffer([], maxlen=len(self.prefix))
示例4: __init__
def __init__(self, chan, attr, stream, capture, timeout, run_label=None):
self.chan = chan
self.stream = stream
self.capture = capture
self.timeout = timeout
self.read_func = getattr(chan, attr)
if run_label is None:
self.prefix = "[%s] %s: " % (
env.host_string,
"out" if attr == 'recv' else "err"
)
else:
self.prefix = "[%s, %s] %s: " % (
env.host_string,
run_label,
"out" if attr == 'recv' else "err"
)
self.printing = getattr(output, 'stdout' if (attr == 'recv') else 'stderr')
self.linewise = (env.linewise or env.parallel)
self.reprompt = False
self.read_size = 4096
self.write_buffer = RingBuffer([], maxlen=len(self.prefix))
示例5: setUp
def setUp(self):
self.b = RingBuffer([], maxlen=5)
示例6: TestRingBuffer
class TestRingBuffer(TestCase):
def setUp(self):
self.b = RingBuffer([], maxlen=5)
def test_append_empty(self):
self.b.append('x')
eq_(self.b, ['x'])
def test_append_full(self):
self.b.extend("abcde")
self.b.append('f')
eq_(self.b, ['b', 'c', 'd', 'e', 'f'])
def test_extend_empty(self):
self.b.extend("abc")
eq_(self.b, ['a', 'b', 'c'])
def test_extend_overrun(self):
self.b.extend("abc")
self.b.extend("defg")
eq_(self.b, ['c', 'd', 'e', 'f', 'g'])
def test_extend_full(self):
self.b.extend("abcde")
self.b.extend("fgh")
eq_(self.b, ['d', 'e', 'f', 'g', 'h'])
示例7: OutputLooper
class OutputLooper(object):
def __init__(self, chan, attr, stream, capture, timeout):
self.chan = chan
self.stream = stream
self.capture = capture
self.timeout = timeout
self.read_func = getattr(chan, attr)
self.prefix = "[%s] %s: " % (
env.host_string,
"out" if attr == 'recv' else "err"
)
self.printing = getattr(output, 'stdout' if (attr == 'recv') else 'stderr')
self.linewise = (env.linewise or env.parallel)
self.reprompt = False
self.read_size = 4096
self.write_buffer = RingBuffer([], maxlen=len(self.prefix))
def _flush(self, text):
if isinstance(text, bytes):
text = text.decode('ascii')
self.stream.write(text)
# Actually only flush if not in linewise mode.
# When linewise is set (e.g. in parallel mode) flushing makes
# doubling-up of line prefixes, and other mixed output, more likely.
if not env.linewise:
self.stream.flush()
self.write_buffer.extend(text)
def loop(self):
"""
Loop, reading from <chan>.<attr>(), writing to <stream> and buffering to <capture>.
Will raise `~fabric.exceptions.CommandTimeout` if network timeouts
continue to be seen past the defined ``self.timeout`` threshold.
(Timeouts before then are considered part of normal short-timeout fast
network reading; see Fabric issue #733 for background.)
"""
# Initialize loop variables
initial_prefix_printed = False
seen_cr = False
line = []
# Allow prefix to be turned off.
if not env.output_prefix:
self.prefix = ""
start = time.time()
while True:
# Handle actual read
try:
bytelist = self.read_func(self.read_size)
except socket.timeout:
elapsed = time.time() - start
if self.timeout is not None and elapsed > self.timeout:
raise CommandTimeout(timeout=self.timeout)
continue
# Empty byte == EOS
if len(bytelist) == 0:
# If linewise, ensure we flush any leftovers in the buffer.
if self.linewise and line:
self._flush(self.prefix)
self._flush("".join(line))
break
# A None capture variable implies that we're in open_shell()
if self.capture is None:
# Just print directly -- no prefixes, no capturing, nada
# And since we know we're using a pty in this mode, just go
# straight to stdout.
self._flush(bytelist)
# Otherwise, we're in run/sudo and need to handle capturing and
# prompts.
else:
# Print to user
if self.printing:
printable_bytes = bytelist
# Small state machine to eat \n after \r
if printable_bytes[-1] == "\r":
seen_cr = True
if printable_bytes[0] == "\n" and seen_cr:
printable_bytes = printable_bytes[1:]
seen_cr = False
while _has_newline(printable_bytes) and printable_bytes != "":
# at most 1 split !
cr = re.search("(\r\n|\r|\n)", printable_bytes)
if cr is None:
break
end_of_line = printable_bytes[:cr.start(0)]
printable_bytes = printable_bytes[cr.end(0):]
if not initial_prefix_printed:
self._flush(self.prefix)
if _has_newline(end_of_line):
end_of_line = ''
if self.linewise:
self._flush("".join(line) + end_of_line + "\n")
line = []
else:
#.........这里部分代码省略.........
示例8: test_None_maxlen_extend
def test_None_maxlen_extend(self):
b = RingBuffer([], maxlen=None)
b.extend('abcdefghijklmnop')
eq_(''.join(b), 'abcdefghijklmnop')
示例9: test_None_maxlen_append
def test_None_maxlen_append(self):
b = RingBuffer([], maxlen=None)
b.append('a')
eq_(b, ['a'])
示例10: test_zero_maxlen_extend
def test_zero_maxlen_extend(self):
b = RingBuffer([], maxlen=0)
b.extend('abcdefghijklmnop')
eq_(b, [])
示例11: test_zero_maxlen_append
def test_zero_maxlen_append(self):
b = RingBuffer([], maxlen=0)
b.append('a')
eq_(b, [])
示例12: TestRingBuffer
class TestRingBuffer(TestCase):
def setUp(self):
self.b = RingBuffer([], maxlen=5)
def test_append_empty(self):
self.b.append('x')
eq_(self.b, ['x'])
def test_append_full(self):
self.b.extend("abcde")
self.b.append('f')
eq_(self.b, ['b', 'c', 'd', 'e', 'f'])
def test_extend_empty(self):
self.b.extend("abc")
eq_(self.b, ['a', 'b', 'c'])
def test_extend_overrun(self):
self.b.extend("abc")
self.b.extend("defg")
eq_(self.b, ['c', 'd', 'e', 'f', 'g'])
def test_extend_full(self):
self.b.extend("abcde")
self.b.extend("fgh")
eq_(self.b, ['d', 'e', 'f', 'g', 'h'])
def test_plus_equals(self):
self.b += "abcdefgh"
eq_(self.b, ['d', 'e', 'f', 'g', 'h'])
def test_oversized_extend(self):
self.b.extend("abcdefghijklmn")
eq_(self.b, ['j', 'k', 'l', 'm', 'n'])
def test_zero_maxlen_append(self):
b = RingBuffer([], maxlen=0)
b.append('a')
eq_(b, [])
def test_zero_maxlen_extend(self):
b = RingBuffer([], maxlen=0)
b.extend('abcdefghijklmnop')
eq_(b, [])
def test_None_maxlen_append(self):
b = RingBuffer([], maxlen=None)
b.append('a')
eq_(b, ['a'])
def test_None_maxlen_extend(self):
b = RingBuffer([], maxlen=None)
b.extend('abcdefghijklmnop')
eq_(''.join(b), 'abcdefghijklmnop')
示例13: OutputLooper
class OutputLooper(object):
def __init__(self, chan, attr, stream, capture):
self.chan = chan
self.stream = stream
self.capture = capture
self.read_func = getattr(chan, attr)
self.prefix = "[%s] %s: " % (
env.host_string,
"out" if attr == 'recv' else "err"
)
self.printing = getattr(output, 'stdout' if (attr == 'recv') else 'stderr')
self.linewise = (env.linewise or env.parallel)
self.reprompt = False
self.read_size = 4096
self.write_buffer = RingBuffer([], maxlen=len(self.prefix))
def _flush(self, text):
self.stream.write(text)
self.stream.flush()
self.write_buffer.extend(text)
def loop(self):
"""
Loop, reading from <chan>.<attr>(), writing to <stream> and buffering to <capture>.
"""
# Internal capture-buffer-like buffer, used solely for state keeping.
# Unlike 'capture', nothing is ever purged from this.
_buffer = []
# Initialize loop variables
initial_prefix_printed = False
seen_cr = False
line = []
# Allow prefix to be turned off.
if not env.output_prefix:
self.prefix = ""
while True:
# Handle actual read
try:
bytelist = self.read_func(self.read_size)
except socket.timeout:
continue
# Empty byte == EOS
if bytelist == '':
# If linewise, ensure we flush any leftovers in the buffer.
if self.linewise and line:
self._flush(self.prefix)
self._flush("".join(line))
break
# A None capture variable implies that we're in open_shell()
if self.capture is None:
# Just print directly -- no prefixes, no capturing, nada
# And since we know we're using a pty in this mode, just go
# straight to stdout.
self._flush(bytelist)
# Otherwise, we're in run/sudo and need to handle capturing and
# prompts.
else:
# Print to user
if self.printing:
printable_bytes = bytelist
# Small state machine to eat \n after \r
if printable_bytes[-1] == "\r":
seen_cr = True
if printable_bytes[0] == "\n" and seen_cr:
printable_bytes = printable_bytes[1:]
seen_cr = False
while _has_newline(printable_bytes) and printable_bytes != "":
# at most 1 split !
cr = re.search("(\r\n|\r|\n)", printable_bytes)
if cr is None:
break
end_of_line = printable_bytes[:cr.start(0)]
printable_bytes = printable_bytes[cr.end(0):]
if not initial_prefix_printed:
self._flush(self.prefix)
if _has_newline(end_of_line):
end_of_line = ''
if self.linewise:
self._flush("".join(line) + end_of_line + "\n")
line = []
else:
self._flush(end_of_line + "\n")
initial_prefix_printed = False
if self.linewise:
line += [printable_bytes]
else:
if not initial_prefix_printed:
self._flush(self.prefix)
initial_prefix_printed = True
self._flush(printable_bytes)
# Now we have handled printing, handle interactivity
#.........这里部分代码省略.........
示例14: OutputLooper
class OutputLooper(object):
def __init__(self, chan, attr, stream, capture, timeout, prefix="", linewise = False):
self.chan = chan
self.stream = stream
self.capture = capture
self.timeout = timeout
self.read_func = getattr(chan, attr)
self.prefix = prefix
self.printing = getattr(output, 'stdout' if (attr == 'recv') else 'stderr')
self.linewise = linewise
self.reprompt = False
self.read_size = 4096
self.write_buffer = RingBuffer([], maxlen=len(self.prefix))
def _flush(self, text):
self.stream.write(text)
self.stream.flush()
self.write_buffer.extend(text)
def loop(self):
"""
Loop, reading from <chan>.<attr>(), writing to <stream> and buffering to <capture>.
Will raise `~fabric.exceptions.CommandTimeout` if network timeouts
continue to be seen past the defined ``self.timeout`` threshold.
(Timeouts before then are considered part of normal short-timeout fast
network reading; see Fabric issue #733 for background.)
"""
# Initialize loop variables
initial_prefix_printed = False
seen_cr = False
line = []
dont_capture_next_cr = False
start = time.time()
while True:
# Handle actual read
try:
bytelist = self.read_func(self.read_size)
except socket.timeout:
elapsed = time.time() - start
if self.timeout is not None and elapsed > self.timeout:
raise CommandTimeout
continue
# Empty byte == EOS
if bytelist == '':
# If linewise, ensure we flush any leftovers in the buffer.
if line:
if self.linewise:
outputLock.acquire()
self._flush(self.prefix)
initial_prefix_printed = True
self._flush("".join(line))
break
# A None capture variable implies that we're in open_shell()
if self.capture is None:
# Just print directly -- no prefixes, no capturing, nada
# And since we know we're using a pty in this mode, just go
# straight to stdout.
self._flush(bytelist)
if self.linewise:
outputLock.release()
# Otherwise, we're in run/sudo and need to handle capturing and
# prompts.
else:
# Print to user
if self.printing:
printable_bytes = bytelist
# Small state machine to eat \n after \r
if printable_bytes[-1] == "\r":
seen_cr = True
if printable_bytes[0] == "\n" and seen_cr:
printable_bytes = printable_bytes[1:]
seen_cr = False
while _has_newline(printable_bytes) and printable_bytes != "":
# at most 1 split !
cr = re.search("(\r\n|\r|\n)", printable_bytes)
if cr is None:
break
end_of_line = printable_bytes[:cr.start(0)]
printable_bytes = printable_bytes[cr.end(0):]
if not initial_prefix_printed:
if self.linewise:
outputLock.acquire()
self._flush(self.prefix)
initial_prefix_printed = True
if _has_newline(end_of_line):
end_of_line = ''
if self.linewise:
self._flush("".join(line) + end_of_line + "\n")
line = []
else:
self._flush(end_of_line + "\n")
initial_prefix_printed = False
if self.linewise:
#.........这里部分代码省略.........