prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|># OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock):<|fim▁hole|> self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context<|fim▁end|>
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): <|fim_middle|> <|fim▁end|>
"""OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): <|fim_middle|> def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): <|fim_middle|> def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): <|fim_middle|> def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): <|fim_middle|> def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): <|fim_middle|> def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
self.__iowait(self._connection.do_handshake)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): <|fim_middle|> def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
return self.__iowait(self._connection.connect, *args, **kwargs)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): <|fim_middle|> def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): <|fim_middle|> send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): <|fim_middle|> def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): <|fim_middle|> def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
return self.recv(bufsiz, flags)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): <|fim_middle|> def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
return self.sendall(buf, flags)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): <|fim_middle|> def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): <|fim_middle|> @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' <|fim_middle|> <|fim▁end|>
global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): <|fim_middle|> def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
return getattr(self._connection, attr)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: <|fim_middle|> time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
break
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: <|fim_middle|> except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
break
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: <|fim_middle|> time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
break
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: <|fim_middle|> def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
break
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored <|fim_middle|> raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
return 0
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): <|fim_middle|> return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
data = data.tobytes()
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: <|fim_middle|> try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
return self._connection.recv(min(pending, bufsiz))
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored <|fim_middle|> raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
return ''
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: <|fim_middle|> else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
self._connection = None if self._sock: socket.socket.close(self._sock)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: <|fim_middle|> else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
socket.socket.close(self._sock)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: <|fim_middle|> def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
self._makefile_refs -= 1
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: <|fim_middle|> protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): <|fim_middle|> elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
ssl_version = "TLSv1_2"
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): <|fim_middle|> elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
ssl_version = "TLSv1_1"
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): <|fim_middle|> else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
ssl_version = "TLSv1"
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: <|fim_middle|> if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
ssl_version = "SSLv23"
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": <|fim_middle|> logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
ssl_version = "TLSv1"
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: <|fim_middle|> else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: <|fim_middle|> ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok)
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def <|fim_middle|>(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
__init__
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def <|fim_middle|>(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
__getattr__
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def <|fim_middle|>(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
__iowait
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def <|fim_middle|>(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
accept
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def <|fim_middle|>(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
do_handshake
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def <|fim_middle|>(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
connect
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def <|fim_middle|>(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
__send
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def <|fim_middle|>(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
__send_memoryview
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def <|fim_middle|>(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
recv
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def <|fim_middle|>(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
read
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def <|fim_middle|>(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
write
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def <|fim_middle|>(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
close
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def <|fim_middle|>(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def context_builder(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
makefile
<|file_name|>openssl_wrap.py<|end_file_name|><|fim▁begin|> # OpenSSL is more stable then ssl # but OpenSSL is different then ssl, so need a wrapper import sys import os import OpenSSL SSLError = OpenSSL.SSL.WantReadError import select import time import socket import logging ssl_version = '' class SSLConnection(object): """OpenSSL Connection Wrapper""" def __init__(self, context, sock): self._context = context self._sock = sock self._connection = OpenSSL.SSL.Connection(context, sock) self._makefile_refs = 0 def __getattr__(self, attr): if attr not in ('_context', '_sock', '_connection', '_makefile_refs'): return getattr(self._connection, attr) def __iowait(self, io_func, *args, **kwargs): timeout = self._sock.gettimeout() or 0.1 fd = self._sock.fileno() time_start = time.time() while True: try: return io_func(*args, **kwargs) except (OpenSSL.SSL.WantReadError, OpenSSL.SSL.WantX509LookupError): sys.exc_clear() _, _, errors = select.select([fd], [], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break except OpenSSL.SSL.WantWriteError: sys.exc_clear() _, _, errors = select.select([], [fd], [fd], timeout) if errors: break time_now = time.time() if time_now - time_start > timeout: break def accept(self): sock, addr = self._sock.accept() client = OpenSSL.SSL.Connection(sock._context, sock) return client, addr def do_handshake(self): self.__iowait(self._connection.do_handshake) def connect(self, *args, **kwargs): return self.__iowait(self._connection.connect, *args, **kwargs) def __send(self, data, flags=0): try: return self.__iowait(self._connection.send, data, flags) except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and not data: # errors when writing empty strings are expected and can be ignored return 0 raise def __send_memoryview(self, data, flags=0): if hasattr(data, 'tobytes'): data = data.tobytes() return self.__send(data, flags) send = __send if sys.version_info >= (2, 7, 5) else __send_memoryview def recv(self, bufsiz, flags=0): pending = self._connection.pending() if pending: return self._connection.recv(min(pending, bufsiz)) try: return self.__iowait(self._connection.recv, bufsiz, flags) except OpenSSL.SSL.ZeroReturnError: return '' except OpenSSL.SSL.SysCallError as e: if e[0] == -1 and 'Unexpected EOF' in e[1]: # errors when reading empty strings are expected and can be ignored return '' raise def read(self, bufsiz, flags=0): return self.recv(bufsiz, flags) def write(self, buf, flags=0): return self.sendall(buf, flags) def close(self): if self._makefile_refs < 1: self._connection = None if self._sock: socket.socket.close(self._sock) else: self._makefile_refs -= 1 def makefile(self, mode='r', bufsize=-1): self._makefile_refs += 1 return socket._fileobject(self, mode, bufsize, close=True) @staticmethod def <|fim_middle|>(ca_certs=None, cipher_suites=('ALL:!RC4-SHA:!ECDHE-RSA-RC4-SHA:!ECDHE-RSA-AES128-GCM-SHA256:!AES128-GCM-SHA256',)): # 'ALL', '!aNULL', '!eNULL' global ssl_version if not ssl_version: if hasattr(OpenSSL.SSL, "TLSv1_2_METHOD"): ssl_version = "TLSv1_2" elif hasattr(OpenSSL.SSL, "TLSv1_1_METHOD"): ssl_version = "TLSv1_1" elif hasattr(OpenSSL.SSL, "TLSv1_METHOD"): ssl_version = "TLSv1" else: ssl_version = "SSLv23" if sys.platform == "darwin": ssl_version = "TLSv1" logging.info("SSL use version:%s", ssl_version) protocol_version = getattr(OpenSSL.SSL, '%s_METHOD' % ssl_version) ssl_context = OpenSSL.SSL.Context(protocol_version) if ca_certs: ssl_context.load_verify_locations(os.path.abspath(ca_certs)) ssl_context.set_verify(OpenSSL.SSL.VERIFY_PEER, lambda c, x, e, d, ok: ok) else: ssl_context.set_verify(OpenSSL.SSL.VERIFY_NONE, lambda c, x, e, d, ok: ok) ssl_context.set_cipher_list(':'.join(cipher_suites)) return ssl_context <|fim▁end|>
context_builder
<|file_name|>album.py<|end_file_name|><|fim▁begin|>from ..models import Album from ..resource import SingleResource, ListResource from ..schemas import AlbumSchema class SingleAlbum(SingleResource): schema = AlbumSchema()<|fim▁hole|> routes = ('/album/<int:id>/',) model = Album class ListAlbums(ListResource): schema = AlbumSchema(many=True) routes = ('/album/', '/tracklist/') model = Album<|fim▁end|>
<|file_name|>album.py<|end_file_name|><|fim▁begin|>from ..models import Album from ..resource import SingleResource, ListResource from ..schemas import AlbumSchema class SingleAlbum(SingleResource): <|fim_middle|> class ListAlbums(ListResource): schema = AlbumSchema(many=True) routes = ('/album/', '/tracklist/') model = Album <|fim▁end|>
schema = AlbumSchema() routes = ('/album/<int:id>/',) model = Album
<|file_name|>album.py<|end_file_name|><|fim▁begin|>from ..models import Album from ..resource import SingleResource, ListResource from ..schemas import AlbumSchema class SingleAlbum(SingleResource): schema = AlbumSchema() routes = ('/album/<int:id>/',) model = Album class ListAlbums(ListResource): <|fim_middle|> <|fim▁end|>
schema = AlbumSchema(many=True) routes = ('/album/', '/tracklist/') model = Album
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left":<|fim▁hole|> if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y)<|fim▁end|>
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): <|fim_middle|> class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): <|fim_middle|> def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.x = xPos self.y = yPos self.th = 32 self.tw = 32
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): <|fim_middle|> class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): <|fim_middle|> class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y)
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): <|fim_middle|> def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = []
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): <|fim_middle|> def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName))
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): <|fim_middle|> def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): <|fim_middle|> def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): <|fim_middle|> class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
image(self.im, self.x, self.y)
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): <|fim_middle|> <|fim▁end|>
def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y)
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): <|fim_middle|> def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
super(Block, self).__init__(xPos, yPos) self.state = "visible"
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): <|fim_middle|> def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.im = loadImage("block.png")
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): <|fim_middle|> <|fim▁end|>
if self.state == "visible": image(self.im, self.x, self.y)
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): <|fim_middle|> else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
return True
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: <|fim_middle|> class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
return False
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": <|fim_middle|> def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): <|fim_middle|> def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
return False
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": <|fim_middle|> elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": <|fim_middle|> elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.im = self.walkR[frameCount % 8] self.dx = self.speed
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": <|fim_middle|> elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.im = self.standing self.dx = 0
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": <|fim_middle|> elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.im = self.falling self.dx = 0 self.dy = 5
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": <|fim_middle|> else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": <|fim_middle|> elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.im = self.walkL[frameCount % 8] self.dx = -self.speed
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": <|fim_middle|> elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.im = self.standing self.dx = 0
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": <|fim_middle|> else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.im = self.falling self.dx = 0 self.dy = 5
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: <|fim_middle|> self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.dx = 0
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: <|fim_middle|> if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.x = 0
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: <|fim_middle|> def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
self.x = 640 -self.tw
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": <|fim_middle|> <|fim▁end|>
image(self.im, self.x, self.y)
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def <|fim_middle|>(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
__init__
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def <|fim_middle|>(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
checkCollision
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def <|fim_middle|>(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
__init__
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def <|fim_middle|>(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
loadPics
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def <|fim_middle|>(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
checkWall
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def <|fim_middle|>(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
move
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def <|fim_middle|>(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
display
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def <|fim_middle|>(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
__init__
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def <|fim_middle|>(self): self.im = loadImage("block.png") def display(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
loadPics
<|file_name|>sprites.py<|end_file_name|><|fim▁begin|>class Sprite(object): def __init__(self, xPos, yPos): self.x = xPos self.y = yPos self.th = 32 self.tw = 32 def checkCollision(self, otherSprite): if (self.x < otherSprite.x + otherSprite.tw and otherSprite.x < self.x + self.tw and self.y < otherSprite.y + otherSprite.th and otherSprite.y < self.y + self.th): return True else: return False class Actor(Sprite): def __init__(self, xPos, yPos): super(Actor, self).__init__(xPos, yPos) self.speed = 5 self.dy = 0 self.d = 3 self.dir = "right" # self.newdir = "right" self.state = "standing" self.walkR = [] self.walkL = [] def loadPics(self): self.standing = loadImage("gripe_stand.png") self.falling = loadImage("grfalling.png") for i in range(8): imageName = "gr" + str(i) + ".png" self.walkR.append(loadImage(imageName)) for i in range(8): imageName = "gl" + str(i) + ".png" self.walkL.append(loadImage(imageName)) def checkWall(self, wall): if wall.state == "hidden": if (self.x >= wall.x - self.d and (self.x + 32 <= wall.x + 32 + self.d)): return False def move(self): if self.dir == "right": if self.state == "walking": self.im = self.walkR[frameCount % 8] self.dx = self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 elif self.dir == "left": if self.state == "walking": self.im = self.walkL[frameCount % 8] self.dx = -self.speed elif self.state == "standing": self.im = self.standing self.dx = 0 elif self.state == "falling": self.im = self.falling self.dx = 0 self.dy = 5 else: self.dx = 0 self.x += self.dx self.y += self.dy if self.x <= 0: self.x = 0 if self.x >= 640 - self.tw: self.x = 640 -self.tw def display(self): image(self.im, self.x, self.y) class Block(Sprite): def __init__(self, xPos, yPos): super(Block, self).__init__(xPos, yPos) self.state = "visible" def loadPics(self): self.im = loadImage("block.png") def <|fim_middle|>(self): if self.state == "visible": image(self.im, self.x, self.y) <|fim▁end|>
display
<|file_name|>test_sql.py<|end_file_name|><|fim▁begin|># # GeoCoon - GIS data analysis library based on Pandas and Shapely # # Copyright (C) 2014 by Artur Wroblewski <[email protected]> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # <|fim▁hole|> import unittest from unittest import mock class SQLTestCase(unittest.TestCase): """ Test SQL GeoCoon SQL routines. """ @mock.patch('pandas.io.sql.read_sql') def test_read_sql(self, f_sql): """ Test SQL data frame read """ points = Point(1, 1), Point(2, 2), Point(3, 3) data = { 'a': PointSeries([p.wkb for p in points]), 'b': list(range(3)), } data = GeoDataFrame(data) data = data[['a', 'b']] f_sql.return_value = data result = read_sql('query', 'con', geom_col='a') self.assertEqual(PointSeries, type(result.a)) self.assertEqual(Point, type(result.a[0])) self.assertEqual(3, len(result.index)) self.assertTrue(all([1, 2, 3] == result.a.x)) self.assertTrue(all([1, 2, 3] == result.a.y)) # vim: sw=4:et:ai<|fim▁end|>
from shapely.geometry import Point from geocoon.sql import read_sql from geocoon.core import GeoDataFrame, PointSeries
<|file_name|>test_sql.py<|end_file_name|><|fim▁begin|># # GeoCoon - GIS data analysis library based on Pandas and Shapely # # Copyright (C) 2014 by Artur Wroblewski <[email protected]> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # from shapely.geometry import Point from geocoon.sql import read_sql from geocoon.core import GeoDataFrame, PointSeries import unittest from unittest import mock class SQLTestCase(unittest.TestCase): <|fim_middle|> # vim: sw=4:et:ai <|fim▁end|>
""" Test SQL GeoCoon SQL routines. """ @mock.patch('pandas.io.sql.read_sql') def test_read_sql(self, f_sql): """ Test SQL data frame read """ points = Point(1, 1), Point(2, 2), Point(3, 3) data = { 'a': PointSeries([p.wkb for p in points]), 'b': list(range(3)), } data = GeoDataFrame(data) data = data[['a', 'b']] f_sql.return_value = data result = read_sql('query', 'con', geom_col='a') self.assertEqual(PointSeries, type(result.a)) self.assertEqual(Point, type(result.a[0])) self.assertEqual(3, len(result.index)) self.assertTrue(all([1, 2, 3] == result.a.x)) self.assertTrue(all([1, 2, 3] == result.a.y))
<|file_name|>test_sql.py<|end_file_name|><|fim▁begin|># # GeoCoon - GIS data analysis library based on Pandas and Shapely # # Copyright (C) 2014 by Artur Wroblewski <[email protected]> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # from shapely.geometry import Point from geocoon.sql import read_sql from geocoon.core import GeoDataFrame, PointSeries import unittest from unittest import mock class SQLTestCase(unittest.TestCase): """ Test SQL GeoCoon SQL routines. """ @mock.patch('pandas.io.sql.read_sql') def test_read_sql(self, f_sql): <|fim_middle|> # vim: sw=4:et:ai <|fim▁end|>
""" Test SQL data frame read """ points = Point(1, 1), Point(2, 2), Point(3, 3) data = { 'a': PointSeries([p.wkb for p in points]), 'b': list(range(3)), } data = GeoDataFrame(data) data = data[['a', 'b']] f_sql.return_value = data result = read_sql('query', 'con', geom_col='a') self.assertEqual(PointSeries, type(result.a)) self.assertEqual(Point, type(result.a[0])) self.assertEqual(3, len(result.index)) self.assertTrue(all([1, 2, 3] == result.a.x)) self.assertTrue(all([1, 2, 3] == result.a.y))
<|file_name|>test_sql.py<|end_file_name|><|fim▁begin|># # GeoCoon - GIS data analysis library based on Pandas and Shapely # # Copyright (C) 2014 by Artur Wroblewski <[email protected]> # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # from shapely.geometry import Point from geocoon.sql import read_sql from geocoon.core import GeoDataFrame, PointSeries import unittest from unittest import mock class SQLTestCase(unittest.TestCase): """ Test SQL GeoCoon SQL routines. """ @mock.patch('pandas.io.sql.read_sql') def <|fim_middle|>(self, f_sql): """ Test SQL data frame read """ points = Point(1, 1), Point(2, 2), Point(3, 3) data = { 'a': PointSeries([p.wkb for p in points]), 'b': list(range(3)), } data = GeoDataFrame(data) data = data[['a', 'b']] f_sql.return_value = data result = read_sql('query', 'con', geom_col='a') self.assertEqual(PointSeries, type(result.a)) self.assertEqual(Point, type(result.a[0])) self.assertEqual(3, len(result.index)) self.assertTrue(all([1, 2, 3] == result.a.x)) self.assertTrue(all([1, 2, 3] == result.a.y)) # vim: sw=4:et:ai <|fim▁end|>
test_read_sql
<|file_name|>tasks.py<|end_file_name|><|fim▁begin|>from celery.task import Task import requests<|fim▁hole|>class StracksFlushTask(Task): def run(self, url, data): requests.post(url + "/", data=data)<|fim▁end|>
<|file_name|>tasks.py<|end_file_name|><|fim▁begin|>from celery.task import Task import requests class StracksFlushTask(Task): <|fim_middle|> <|fim▁end|>
def run(self, url, data): requests.post(url + "/", data=data)
<|file_name|>tasks.py<|end_file_name|><|fim▁begin|>from celery.task import Task import requests class StracksFlushTask(Task): def run(self, url, data): <|fim_middle|> <|fim▁end|>
requests.post(url + "/", data=data)