Skip to content

Commit 453c6cc

Browse files
committed
Refactor CompletedNetcat class + doc string
1 parent 75cca5e commit 453c6cc

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/pync/__init__.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# -*- coding: utf-8 -*-
22

3-
import argparse
43
import io
54

65
from .netcat import (
@@ -18,11 +17,30 @@
1817
readwrite,
1918
)
2019

21-
22-
class CompletedNetcat(argparse.Namespace):
20+
21+
class CompletedNetcat(object):
2322
"""
24-
This class gets returned from the :func:`pync.run` function.
23+
A Netcat instance that has finished running.
24+
This is returned by the :func:`pync.run` function.
25+
26+
:param args: The args string given to run the Netcat instance.
27+
:type args: str
28+
29+
:param returncode: The exit code of the Netcat instance.
30+
:type returncode: int
31+
32+
:param stdout: The standard output (None if not captured).
33+
:type stdout: file, optional
34+
35+
:param stderr: The standard error (None if not captured).
36+
:type stderr: file, optional
2537
"""
38+
39+
def __init__(self, args, returncode, stdout=None, stderr=None):
40+
self.args = args
41+
self.returncode = returncode
42+
self.stdout = stdout
43+
self.stderr = stderr
2644

2745

2846
def run(args, stdin=None, stdout=None, stderr=None,
@@ -94,14 +112,10 @@ def run(args, stdin=None, stdout=None, stderr=None,
94112
:caption: Connect to a local TCP server and capture output to a byte string.
95113
96114
import pync
97-
response = pync.run('localhost 8000', capture_output=True)
98-
print(response.stdout.decode())
115+
result = pync.run('localhost 8000', capture_output=True)
116+
print(result.stdout.decode())
99117
"""
100-
result = CompletedNetcat()
101-
result.returncode = 1
102-
result.args = args
103-
result.stdout = None
104-
result.stderr = None
118+
result = CompletedNetcat(args, returncode=1)
105119

106120
stdin_io = stdin or Netcat.stdin
107121
stdout_io = stdout or Netcat.stdout

0 commit comments

Comments
 (0)