def construct_common_model(finetune, conv_model, sent_embedder): if finetune: model = Common(conv_model, n_filters=conv_model.get_n_blocks() * args.n_filters, encoder=sent_embedder) else: model = Common(conv_model, n_filters=conv_model.get_n_blocks() * args.n_filters) return model
def send_request(self, query): """Send request to secure DNS server from the TCP Socket""" common = Common() sock = common.tls_socket() sock.sendall(query) data = sock.recv(1024) return data
def main(): with open(os.path.join(SHARE, 'version')) as buf: tor_browser_launcher_version = buf.read().strip() print _('Tor Browser Launcher') print _('By Micah Lee, licensed under MIT') print _('version {0}').format(tor_browser_launcher_version) print 'https://github.com/micahflee/torbrowser-launcher' common = Common(tor_browser_launcher_version) # is torbrowser-launcher already running? tbl_pid = common.get_pid(common.paths['tbl_bin'], True) if tbl_pid: print _('Tor Browser Launcher is already running (pid {0}), bringing to front').format(tbl_pid) common.bring_window_to_front(tbl_pid) sys.exit() if '-settings' in sys.argv: # settings mode app = Settings(common) else: # launcher mode app = Launcher(common)
def main(): # parse arguments parser = argparse.ArgumentParser() parser.add_argument('--settings', action='store_true', dest='settings', help='Open Tor Browser Launcher settings') parser.add_argument('url', nargs='*', help='URL to load') args = parser.parse_args() settings = bool(args.settings) url_list = args.url # load the version and print the banner with open(os.path.join(SHARE, 'version')) as buf: tor_browser_launcher_version = buf.read().strip() print _('Tor Browser Launcher') print _('By Micah Lee, licensed under MIT') print _('version {0}').format(tor_browser_launcher_version) print 'https://github.com/micahflee/torbrowser-launcher' common = Common(tor_browser_launcher_version) if settings: # settings mode app = Settings(common) else: # launcher mode app = Launcher(common, url_list)
def run(hostname, cmd, port=None, username=None, password=None, pkey=None, timeout=None): try: localIP = socket.gethostbyname(socket.gethostname()) try: hostnameIP = socket.gethostbyname(hostname) if localIP == hostnameIP: result = local_run(cmd=cmd) return { hostname: { "stdout": result['stdout'], "stderr": result['stderr'] }, "status": result['status'] } else: common = Common(hostname=hostname, port=port, username=username, password=password, pkey=pkey, timeout=timeout) result = common.run(cmd=cmd) return result except socket.error as error: print("{} {}".format(hostname, error)) except Exception as error: print("{}".format(error)) return {'status': False}
def __init__(self, service=None): self.common = Common() self.filename = 'input.yml' #self.category = 'localhost' self.category = 'sakura' self.command = 'systemctl status firewalld' self.cmd_option_key = 'systemctl' self.conts = 0 self.max_conts = 3 self.ptn = re.compile(r'\s*(Active:)\s+(active)\s+(\(running\))') if service is not None: self.command = 'systemctl status {service}'.format(service=service) else: try: if sys.argv[1] == 'httpd' or sys.argv[1] == 'firewalld': self.command = 'systemctl status {service}'.format( service=sys.argv[1]) elif sys.argv[2] == 'httpd' or sys.argv[2] == 'firewalld': self.command = 'systemctl status {service}'.format( service=sys.argv[2]) else: sys.exit(1) except: raise IndexError( "Three command arguments are required. {args}".format( args=' '.join(sys.argv[0]))) self.column_order = [ 'timestamp', 'success', 'execute_conts', 'command', 'stdout', 'stderr' ]
def __init__(self): ChassisBase.__init__(self) self._api_common = Common() self._api_config = self._api_common.get_config_path() self.__initialize_fan() self.__initialize_psu()
def __init__(self): """ Constructor: Used to initialize all the class variables """ self.utility = Utility() self.file_handling = FileHandling() self.common = Common()
class ClientUtils: CLIENT_PROTOCOL_ID = 2 com = Common() sock = None def startClient(self, addr, port): initialPackage = [] initialPackage.append(self.com.IDENTIFY) initialPackage.append(self.CLIENT_PROTOCOL_ID) self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) #self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.com.sendPackage(addr, port, self.sock, initialPackage[0], initialPackage[1]) print("Waiting for server response...") package = self.waitPackage(self.sock, initialPackage[0], initialPackage[1]) if (package[0] == self.com.SUCCESS and package[1] == 1): print("Indetification success!") return True else: print("Indetification problem") return False pass def sendPackage(self, addr, port, operation, value): self.com.sendPackage(addr, port, self.sock, operation, value) print("Waiting for server response...") package = self.waitPackage(self.sock, operation, value) return package def waitPackage(self, sock, operation, value): while True: data, addr = sock.recvfrom(1024) offset = 0 response = struct.unpack_from(">BB", data, offset) offset += struct.calcsize(">BB") if (response is not None): print("Response received from server [%s]:[%s]" % (addr[0], addr[1])) #pack = self.handlePackage(sock, addr, response, operation, value) #if(pack is not None): return response pass pass pass def close(self): self.sock.close() pass
def send_request(self, query): """Send request to secure DNS server from the UDP Socket""" common = Common() sock = common.tls_socket() tcp_query = common.get_tcp_from_udp(query).encode('cp1252') sock.send(tcp_query) data = sock.recv(1024) return data
def pre_test(self): self.common = Common() self.hall_page = Hall_Page() self.game_page = Game_Page() # 初始化Luadriver self.luadriver = self.common.setupdriver() # self.common.deletefile(self.luadriver) self.common.closeactivity_switchserver(self.luadriver)
def __init__(self, index, conf=None, fan_conf=None): PsuBase.__init__(self) self._psu_index = index self._config = conf self._api_common = Common(self._config) self._fan_conf = fan_conf self._initialize_psu_fan()
def setUp(self): c = Common() self.fname = c.static_dir + "ccode.c" self.bcomment = "/* Begin generated code: tagy */\n" self.ecomment = "/* End generated code: tagy */\n" with open(self.fname, 'w') as f: f.write(self.bcomment) f.write(self.ecomment)
def __init__(self, index, psu_index=0, conf=None): PsuBase.__init__(self) self.psu_index = index self._config = conf self._api_common = Common() self._name = self.get_name()
def doparse(self): if self._stockpath[-1] != "/": self._stockpath += "/" items = os.path.basename(os.path.dirname(self._stockpath)).split("-") self._id = int(items[1]) self._name = Globals.get_instance().sin.getname(self._id) self._fh = FinancialHistory(self._stockpath + "/finance") self._fh.doparse() self._latestfd = self._fh.getlatest() #最新季报净利润/每股收益 = 总股数 self._totalstocks = self._latestfd.profit / self._latestfd.per_share_earnings #每股收益 = 最近365天净利润 / 总股数 self._pershareearnings = self.get365Profit( self._latestfd) / self._totalstocks #[15% ~ 10% ~ 5%]区间收益 self._pricesRange = Common().pricesRange(self._pershareearnings) #parse adding ... #报告季增长 self.adding["in report"] = self._latestfd.profit_adding / 100 #最近两个365增长,即最新季度往前推一年,和更早的一年,之间净利润的增长 prev_fd = self._fh.getreport(self._latestfd.year - 1, self._latestfd.season) #上一年同季净利润 prev_profit365 = self.get365Profit(prev_fd) profit365 = self.get365Profit(self._latestfd) adding = (profit365 - prev_profit365) / prev_profit365 self.adding["adjacent 365"] = adding #持续增长分析 self._continued = self.continueParsing() self.adding["average"] = self._continued[1] #增长加快评级 self._increase_fasten = self.increaseAdding() #净资产收益率 self._asset_adding2 = self._pershareearnings / self._latestfd.per_share_asset #净资产收益率近年平均值 self._average_asset_adding2 = self.getAverageAssetAdding2() #扣非净利率增长 self.adding["profit2"] = self._latestfd.profit2_adding / 100 if self.adding["profit2"] < -0.9999: #skip such stupid data self.adding["profit2"] = -0.9999 #扣非净利率平均增长 self.adding["average profit2"] = self.average_profit2_adding() note = Note(os.path.dirname(self._stockpath) + "/note.xml") try: note.doparse() self._note = note._note self.adding["manual"] = note._adding self._summary = note._summary except: self._note = None self.adding["manual"] = None self._summary = ""
def __init__(self): """ Constructor: Used to initialize all the class variables """ self.utility = Utility() self.file_handling = FileHandling() self.common = Common() self.indexer = Indexer() self.query_expansion_object = Query_Expansion()
def __init__(self): super().__init__() self.common = Common() # convert_into_lines(datapath_oq, 'controversial-data.csv', outname) # write_to_text(datapath_oq, 'controversial-data-separate-lines-sample-single.csv', 'segment-labeling-sample-single.txt') self.convert_into_lines(self.datapath_sbm, self.readfile_sbm, self.newfile_sbm, self.newdir_path)
def __init__(self, short, priest): super().__init__(short, priest) self.common = Common(short, priest) self.show_numbers = False self._psalms = [] for i in range(1, 151): psalm = load("texts/slav/psalter/" + str(i) + ".txt") psalm = psalm.split("\n") self._psalms.append(psalm)
def __init__(self): """ Constructor: Used to initialize all the class variables """ self.utility = Utility() self.file_handling = FileHandling() self.common = Common() self.query_highlight = Query_Highlight() self.baseline_runs = Baseline_Runs()
def handleLedState(self, package): com = Common() if len(package) > 0 and package[0] == com.LED_STATE: ledVal = package[1] print("The LED STATE is currently at: [%d]" % ledVal) pass elif len( package) > 0 and package[0] == com.SUCCESS and package[1] == 0: print("An error occurred attempting to get LED STATE") pass
def __init__(self, master=None): tk.Frame.__init__(self, master) self.pack() # self.text_box = None self.config_text_box() self.common = Common(self.logger) self.create_widgets() self.welcome()
def __init__(self, index, drawer_index, is_psu_fan=False, psu_index=0, conf=None): FanBase.__init__(self) self.fan_index = index self.drawer_index = drawer_index self._config = conf self._api_common = Common() self._name = self.get_name() self._is_psu_fan = is_psu_fan
def __init__(self): """ Constructor: Used to initialize all the class variables """ self.utility = Utility() self.frequency_map = defaultdict() self.synonyms_map = defaultdict() self.file_handling = FileHandling() self.common = Common() self.indexer = Indexer()
def handlePackageReturn(self, package): com = Common() if (len(package) > 0 and package[0] == com.SUCCESS and package[1] == 1): print("Command executed") pass else: print("An error occured trying to execute command") pass pass
def __init__(self): """ Constructor: Used to initialize all the class variables """ self.utility = Utility() self.file_handling = FileHandling() self.common = Common() self.indexer = Indexer() self.baseline_runs = Baseline_Runs() self.threshold_length = 20
def __init__(self, short, priest): super().__init__(short, priest) # Heavenly King, Trisagion, Our Father, etc. self.lent = False self.alleluia = False self.typika_sign = TypikaSign.Ferial self.common = Common(short, priest) self.ectenia = Ectenia(short, priest) self.psalter = Psalter(short, priest) self.day = Day.Sat
def login(username, password): common = Common() logger = common.create_logger('mylogger', 'zhihu.log') homepage = r"https://www.zhihu.com/" html = common.opener.open(homepage).read() soup = BS(html, "html.parser") _xsrf = soup.find("input", {'type': 'hidden'}).get("value") # 根据email和手机登陆得到的参数名不一样,email登陆传递的参数是‘email’,手机登陆传递的是‘phone_num’ # username = raw_input("Please input username: "******"Please input your password: "******"@" in username: account_name = 'email' else: account_name = 'phone_num' logger.info("save captcha to local machine.") captchaURL = r"https://www.zhihu.com/captcha.gif?type=login" # 验证码url common.save_captcha(captcha_url=captchaURL, out_path="captcha.jpg") post_data = { '_xsrf': _xsrf, account_name: username, 'password': password, 'remember_me': 'true', 'captcha': raw_input("Please input captcha by captcha.jpg: ") } header = { 'Accept': '*/*', 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8', 'X-Requested-With': 'XMLHttpRequest', 'Referer': 'https://www.zhihu.com/', 'Accept-Language': 'en-GB,en;q=0.8,zh-CN;q=0.6,zh;q=0.4', 'Accept-Encoding': 'gzip, deflate, br', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36', 'Host': 'www.zhihu.com' } url = r"https://www.zhihu.com/login/" + account_name common.set_request_data(url, post_data, header) resText = common.get_html_text() jsonText = json.loads(resText) if jsonText["r"] == 0: logger.info("Login success!") else: logger.error("Login Failed!") logger.error("Error info ---> " + jsonText["msg"]) text = common.opener.open(homepage).read() common.output(text, "home.html")
def __init__(self, index, is_psu_fan=False, psu_index=0, conf=None): FanBase.__init__(self) self._fan_index = index self._config = conf self._api_common = Common() self._is_psu_fan = is_psu_fan if self._is_psu_fan: self._initialize_psu_fan(psu_index) self._name = self.get_name()
def listen_udp(): """Listen on requested port for UDP DNS requests""" try: common, udp = Common(), Udp() sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((common.proxy_host(), int(common.proxy_port()))) logging.info('Listening for UDP requests') while True: data, addr = sock.recvfrom(1024) thread.start_new_thread(udp.handler, (data, addr, sock, None, "udp")) except Exception as e: logging.error(e) sock.close()
def __init__(self, topic_name): super().__init__() self.common = Common() basepath = os.path.dirname(os.path.abspath(__file__)) datapath_oq = basepath + "/result/{}/".format(topic_name) readfile_oq = '{}-original.csv'.format(topic_name) filename_oq = '{}.csv'.format(topic_name) newfile_oq = os.path.join(datapath_oq, filename_oq) self.remove_fields(readfile_oq, datapath_oq, newfile_oq)