本文整理匯總了Python中Crypto.Random.atfork方法的典型用法代碼示例。如果您正苦於以下問題:Python Random.atfork方法的具體用法?Python Random.atfork怎麽用?Python Random.atfork使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Crypto.Random
的用法示例。
在下文中一共展示了Random.atfork方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __getitem__
# 需要導入模塊: from Crypto import Random [as 別名]
# 或者: from Crypto.Random import atfork [as 別名]
def __getitem__(self, item):
if self.first_run:
Random.atfork()
self.first_run = False
content = [random.randrange(0, len(self.chars)) for _ in range(self.n_chars)]
s = ''.join([self.chars[i] for i in content])
d = self.gen.generate(s)
d = Image.open(d)
label = torch.full((self.n_chars + 2, ), self.tokenizer.EOS_token, dtype=torch.long)
ts = self.tokenizer.tokenize(s)
label[:ts.shape[0]] = torch.tensor(ts)
return img_trans(d), label
示例2: gen_key
# 需要導入模塊: from Crypto import Random [as 別名]
# 或者: from Crypto.Random import atfork [as 別名]
def gen_key():
'''
Generates a new label or shared key.
'''
rpool = Random.new()
Random.atfork()
return rpool.read(16).encode("hex")
示例3: gen_lbl
# 需要導入模塊: from Crypto import Random [as 別名]
# 或者: from Crypto.Random import atfork [as 別名]
def gen_lbl():
'''
Generate a new Label.
'''
rpool = Random.new()
Random.atfork()
return rpool.read(16).encode("hex")
示例4: post_fork
# 需要導入模塊: from Crypto import Random [as 別名]
# 或者: from Crypto.Random import atfork [as 別名]
def post_fork(server, worker):
# Reset the Random library to ensure it won't raise the "PID check failed." error after
# gunicorn forks.
Random.atfork()
示例5: wrap_message
# 需要導入模塊: from Crypto import Random [as 別名]
# 或者: from Crypto.Random import atfork [as 別名]
def wrap_message(msg):
Random.atfork()
aes_key = randfile.read(32)
aes_obj = AES.new(aes_key, AES.MODE_CBC, "0" * 16)
enc_msg = aes_obj.encrypt(msg)
aes_key_int = int.from_bytes(aes_key, byteorder="little")
c0, c1 = elgamal_enc(pub_key, aes_key_int)
blob = c0.x.to_bytes(35, byteorder="little", signed=False) \
+ c0.y.to_bytes(35, byteorder="little", signed=False) \
+ c1.to_bytes(42, byteorder="little", signed=False) \
+ enc_msg
return blob
示例6: enc_all
# 需要導入模塊: from Crypto import Random [as 別名]
# 或者: from Crypto.Random import atfork [as 別名]
def enc_all(msg, num_layer):
Random.atfork()
blob = wrap_message(msg)
for _ in range(num_layer - 1):
new_blob = wrap_message(blob)
blob = new_blob
return blob
示例7: atfork
# 需要導入模塊: from Crypto import Random [as 別名]
# 或者: from Crypto.Random import atfork [as 別名]
def atfork(self):
"""
Terminate this Transport without closing the session. On posix
systems, if a Transport is open during process forking, both parent
and child will share the underlying socket, but only one process can
use the connection (without corrupting the session). Use this method
to clean up a Transport object without disrupting the other process.
@since: 1.5.3
"""
self.sock.close()
self.close()
示例8: _init_db
# 需要導入模塊: from Crypto import Random [as 別名]
# 或者: from Crypto.Random import atfork [as 別名]
def _init_db(self):
"""We need this to be executed each time we are in a new process"""
if self._autoreindex:
subscribers.init()
Random.atfork()
self.__conn_refs = {}
self.__thread_local = threading.local()
self.__thread_watcher = ThreadWatcher()
self._storage = client_storage(**self.__storage_kwargs)
self._db = SubDB(self._storage, **self.__db_kwargs)
self._conn_open()
示例9: start_client
# 需要導入模塊: from Crypto import Random [as 別名]
# 或者: from Crypto.Random import atfork [as 別名]
def start_client(self, event=None):
"""
Negotiate a new SSH2 session as a client. This is the first step after
creating a new L{Transport}. A separate thread is created for protocol
negotiation.
If an event is passed in, this method returns immediately. When
negotiation is done (successful or not), the given C{Event} will
be triggered. On failure, L{is_active} will return C{False}.
(Since 1.4) If C{event} is C{None}, this method will not return until
negotation is done. On success, the method returns normally.
Otherwise an SSHException is raised.
After a successful negotiation, you will usually want to authenticate,
calling L{auth_password <Transport.auth_password>} or
L{auth_publickey <Transport.auth_publickey>}.
@note: L{connect} is a simpler method for connecting as a client.
@note: After calling this method (or L{start_server} or L{connect}),
you should no longer directly read from or write to the original
socket object.
@param event: an event to trigger when negotiation is complete
(optional)
@type event: threading.Event
@raise SSHException: if negotiation fails (and no C{event} was passed
in)
"""
self.active = True
if event is not None:
# async, return immediately and let the app poll for completion
self.completion_event = event
self.start()
return
# synchronous, wait for a result
self.completion_event = event = threading.Event()
self.start()
Random.atfork()
while True:
event.wait(0.1)
if not self.active:
e = self.get_exception()
if e is not None:
raise e
raise SSHException('Negotiation failed.')
if event.isSet():
break