MCPcopy Index your code
hub / github.com/python/cpython / MockSocket

Class MockSocket

Lib/test/mock_socket.py:35–111  ·  view source on GitHub ↗

Mock socket object used by the smtplib tests.

Source from the content-addressed store, hash-verified

33
34
35class MockSocket:
36 """Mock socket object used by the smtplib tests.
37 """
38 def __init__(self, family=None):
39 global _reply_data
40 self.family = family
41 self.output = []
42 self.lines = []
43 if _reply_data:
44 self.lines.append(_reply_data)
45 _reply_data = None
46 self.conn = None
47 self.timeout = None
48
49 def queue_recv(self, line):
50 self.lines.append(line)
51
52 def recv(self, bufsize, flags=None):
53 data = self.lines.pop(0) + b'\r\n'
54 return data
55
56 def fileno(self):
57 return 0
58
59 def settimeout(self, timeout):
60 if timeout is None:
61 self.timeout = _defaulttimeout
62 else:
63 self.timeout = timeout
64
65 def gettimeout(self):
66 return self.timeout
67
68 def setsockopt(self, level, optname, value):
69 pass
70
71 def getsockopt(self, level, optname, buflen=None):
72 return 0
73
74 def bind(self, address):
75 pass
76
77 def accept(self):
78 self.conn = MockSocket()
79 return self.conn, 'c'
80
81 def getsockname(self):
82 return ('0.0.0.0', 0)
83
84 def setblocking(self, flag):
85 pass
86
87 def listen(self, backlog):
88 pass
89
90 def makefile(self, mode='r', bufsize=-1):
91 handle = MockFile(self.lines)
92 return handle

Callers 3

acceptMethod · 0.70
socketFunction · 0.70
create_connectionFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…