本文整理匯總了Python中multiprocessing.AuthenticationError方法的典型用法代碼示例。如果您正苦於以下問題:Python multiprocessing.AuthenticationError方法的具體用法?Python multiprocessing.AuthenticationError怎麽用?Python multiprocessing.AuthenticationError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類multiprocessing
的用法示例。
在下文中一共展示了multiprocessing.AuthenticationError方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_answer_challenge_auth_failure
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import AuthenticationError [as 別名]
def test_answer_challenge_auth_failure(self):
class _FakeConnection(object):
def __init__(self):
self.count = 0
def recv_bytes(self, size):
self.count += 1
if self.count == 1:
return multiprocessing.connection.CHALLENGE
elif self.count == 2:
return b'something bogus'
return b''
def send_bytes(self, data):
pass
self.assertRaises(multiprocessing.AuthenticationError,
multiprocessing.connection.answer_challenge,
_FakeConnection(), b'abc')
#
# Test Manager.start()/Pool.__init__() initializer feature - see issue 5585
#
示例2: test_deliver_challenge_auth_failure
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import AuthenticationError [as 別名]
def test_deliver_challenge_auth_failure(self):
class _FakeConnection(object):
def recv_bytes(self, size):
return b'something bogus'
def send_bytes(self, data):
pass
self.assertRaises(multiprocessing.AuthenticationError,
multiprocessing.connection.deliver_challenge,
_FakeConnection(), b'abc')
示例3: deliver_challenge
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import AuthenticationError [as 別名]
def deliver_challenge(connection, authkey):
import hmac
assert isinstance(authkey, bytes)
message = os.urandom(MESSAGE_LENGTH)
connection.send_bytes(CHALLENGE + message)
digest = hmac.new(authkey, message).digest()
response = connection.recv_bytes(256) # reject large message
if response == digest:
connection.send_bytes(WELCOME)
else:
connection.send_bytes(FAILURE)
raise AuthenticationError('digest received was wrong')
示例4: answer_challenge
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import AuthenticationError [as 別名]
def answer_challenge(connection, authkey):
import hmac
assert isinstance(authkey, bytes)
message = connection.recv_bytes(256) # reject large message
assert message[:len(CHALLENGE)] == CHALLENGE, 'message = %r' % message
message = message[len(CHALLENGE):]
digest = hmac.new(authkey, message).digest()
connection.send_bytes(digest)
response = connection.recv_bytes(256) # reject large message
if response != WELCOME:
raise AuthenticationError('digest sent was rejected')
#
# Support for using xmlrpclib for serialization
#
示例5: run
# 需要導入模塊: import multiprocessing [as 別名]
# 或者: from multiprocessing import AuthenticationError [as 別名]
def run(self, host, port):
""" Run a similarity server serving requests that come in at the given port """
address = (host, port) # Family is deduced to be 'AF_INET'
# Load the secret password that clients must use to authenticate themselves
try:
with open("resources/SimilarityServerKey.txt", "rb") as file:
secret_password = file.read()
except FileNotFoundError:
raise InternalError(
"Server key file missing: resources/SimilarityServerKey.txt"
)
except:
raise InternalError(
"Unable to load server key when starting similarity server"
)
print(
"Greynir similarity server started\nListening for connections on port {0}".format(
port
)
)
with Listener(address, authkey=secret_password) as listener:
self._corpus = ReynirCorpus()
self._load_topics()
while True:
try:
conn = listener.accept()
print("Connection accepted from {0}".format(listener.last_accepted))
# Launch a thread to handle commands from this client
Thread(target=self._command_loop, args=(conn,)).start()
except AuthenticationError:
print("Authentication failed for client")
pass
except Exception as ex:
print("Exception when listening for connections: {0}".format(ex))
pass
finally:
sys.stdout.flush()