def links(self): """Extract links from one cell on the index""" divs = self._content.items('div') levels = [] for div in divs: content = strip_whitespace(div.text()) if content.startswith(u'\u043e'): level = 2 content = strip_whitespace(content.strip(u'\u043e')) elif content.startswith(u'\u2022'): level = 3 content = strip_whitespace(content.strip(u'\u2022')) else: level = 1 if level == len(levels): levels = levels[:-1] elif level < len(levels): levels = levels[:level-1] link = div.find('a') if link: url = link[0].attrib['href'] yield { 'title': content, 'parents': levels, 'url': url, } else: levels.append(content)
def on_ap_ssid(self, instance, value): if self.wifi_config and value != self.wifi_config.ap_ssid: value = strip_whitespace(value) Logger.debug("WirelessConfigView: got new ap ssid: {}".format(value)) self.wifi_config.ap_ssid = value self.wifi_config.stale = True self._wifi_modified()
def on_ap_ssid(self, instance, value): if self.wifi_config and value != self.wifi_config.ap_ssid: value = strip_whitespace(value) Logger.debug( "WirelessConfigView: got new ap ssid: {}".format(value)) self.wifi_config.ap_ssid = value self.wifi_config.stale = True self._wifi_modified()
def _process_row(row): cells = row.findall('td') if len(cells) == 2: name, change_date = cells return { 'name': strip_whitespace(name.text), 'until': iso_date(change_date.text), }
def on_ap_password(self, instance, value): if self.wifi_config and value != self.wifi_config.ap_password: value = strip_whitespace(value) Logger.debug("WirelessConfigView: got new ap password: {}".format(value)) password_len = len(value) warning = self.ids.ap_password_warn if self.wifi_config and password_len == 0 or password_len >= WifiConfig.WIFI_CONFIG_MINIMUM_AP_PASSWORD_LENGTH: self.wifi_config.ap_password = value self.wifi_config.stale = True self._wifi_modified() warning.text = '' else: warning.text = 'Password must be at least 8 characters'
def on_ap_password(self, instance, value): if self.wifi_config and value != self.wifi_config.ap_password: value = strip_whitespace(value) Logger.debug( "WirelessConfigView: got new ap password: {}".format(value)) password_len = len(value) warning = self.ids.ap_password_warn if self.wifi_config and password_len == 0 or password_len >= WifiConfig.WIFI_CONFIG_MINIMUM_AP_PASSWORD_LENGTH: self.wifi_config.ap_password = value self.wifi_config.stale = True self._wifi_modified() warning.text = '' else: warning.text = 'Password must be at least 8 characters'
def xml_filter(self, content): r"""Filter and preprocess xml content :param content: xml content :rtype: str """ content = utils.strip_whitespace(content, True) if self.__options['strip'] else content.strip() if not self.__options['encoding']: encoding = self.guess_xml_encoding(content) or self.__encoding self.set_options(encoding=encoding) if self.__options['encoding'].lower() != self.__encoding: # 编码转换去除xml头 content = self.strip_xml_header(content.decode(self.__options['encoding'], errors=self.__options['errors'])) if self.__options['unescape']: content = utils.html_entity_decode(content) return content
def on_entry_ytdl_fork_changed(self, entry, radiobutton): """Called from callback in self.setup_set_downloader_page(). Sets the youtube-dl fork to be used. See also self.on_button_ytdl_fork_toggled(). Args: entry (Gtk.Entry): The widget changed """ if radiobutton.get_active(): entry_text = utils.strip_whitespace(entry.get_text()) # (As in the preference window, if the 'other fork' option is # selected, but nothing is entered in the entry box, use # youtube-dl as the system default) if entry_text == '': self.ytdl_fork = None else: self.ytdl_fork = entry_text
def run_check_version(self): """Called by self.run(). Checking for a new release of Tartube doesn't involve any system commands or child processes, so it is handled separately by this function. There is a stable release at Sourceforge, and a development release at Github. Fetch the VERSION file from each, and store the stable/ development versions, so that mainapp.TartubeApp.info_manager_finished can display them. """ # Show information about the info operation in the Output Tab self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Starting info operation, checking for new releases of Tartube'), ) # Check the stable version, http://tartube.sourceforge.io/VERSION stable_path = __main__.__website__ + '/VERSION' self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Checking stable release...'), ) self.app_obj.main_win_obj.output_tab_write_system_cmd(1, stable_path) try: request_obj = requests.get( stable_path, timeout = self.app_obj.request_get_timeout, ) response = utils.strip_whitespace(request_obj.text) if not re.search('^\d+\.\d+\.\d+\s*$', response): self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Ignoring invalid version'), ) else: self.stable_version = response self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Retrieved version:') + ' ' + str(response), ) except: self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Connection failed'), ) # Check the development version, # http://raw.githubusercontent.com/axcore/tartube/master/VERSION dev_path = __main__.__website_dev__ + '/VERSION' self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Checking development release...'), ) self.app_obj.main_win_obj.output_tab_write_system_cmd(1, dev_path) try: request_obj = requests.get( dev_path, timeout = self.app_obj.request_get_timeout, ) response = utils.strip_whitespace(request_obj.text) if not re.search('^\d+\.\d+\.\d+\s*$', response): self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Ignoring invalid version'), ) else: self.dev_version = response self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Retrieved version:') + ' ' + str(response), ) except: self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Connection failed'), ) # Operation complete. self.success_flag is checked by # mainapp.TartubeApp.info_manager_finished() self.success_flag = True # Show a confirmation in the the Output Tab self.app_obj.main_win_obj.output_tab_write_stdout( 1, _('Info operation finished'), ) # Let the timer run for a few more seconds to prevent Gtk errors (for # systems with Gtk < 3.24) GObject.timeout_add( 0, self.app_obj.info_manager_halt_timer, )
def main(input_path: Path, output_path: Path): """ wire up argument and file parsing to run tokenizer """ with open(input_path) as input_file, open(output_path, 'w') as output_file: for token in wrapped_tokenize(strip_whitespace(input_file)): print(token, file=output_file)
def attempt_match(cls, cell): text = strip_whitespace(cell.text()) match = cls.regex.match(text) if match: return cls.process(cell, match)
def process(cell, match): incorp_date = iso_date(strip_whitespace(match.group('date'))) return dict( date_incorporated=incorp_date, )
def data(self): if not hasattr(self, '_data'): self._process() return strip_whitespace(self._data)
def main(input_path: Path, output_path: Path): """ wire up argument and file parsing to run code parser """ with open(input_path) as input_file, open(output_path, 'w') as output_file: for line in compile_jack(tokenize( strip_whitespace(input_file))).render(): print(line, file=output_file)