def parse_file(self, *args): self.css_selectors.clear() self.encodingerrors[:] = [] self.cssclasses.clear() self.cssfilesnotfound.clear() file = self.fetched_files[_file_listbox.curselection()[0]] parser = PyCSSParser(file) try: with open(file, "r") as handle: for linenum, line in enumerate(handle.readlines()): linenum += 1 parser.feed( line ) # parser looks for classes and ids in linked css files classes = re.findall(r'class=\"(.+?)\"', line) if classes: for html_class in classes: html_class = "." + html_class self.css_selectors[html_class] = linenum ids = re.findall(r'id=\"(.+?)\"', line) if ids: for html_id in ids: html_id = "#" + html_id self.css_selectors[html_id] = linenum handle.close() except UnicodeDecodeError: if file not in self.encodingerrors: self.encodingerrors.append(file) self.cssclasses, self.cssfilesnotfound = copy.deepcopy( parser.cssclasses), copy.deepcopy(parser.cssfilesnotfound) self._link_css_ids_and_classes(file)
def parse_file(self, *args): self.css_selectors.clear() self.encodingerrors[:] = [] self.cssclasses.clear() self.cssfilesnotfound.clear() file = self.fetched_files[_file_listbox.curselection()[0]] parser = PyCSSParser(file) try: with open(file, "r") as handle: for linenum, line in enumerate(handle.readlines()): linenum += 1 parser.feed(line) # parser looks for classes and ids in linked css files classes = re.findall(r'class=\"(.+?)\"', line) if classes: for html_class in classes: html_class = "." + html_class self.css_selectors[html_class] = linenum ids = re.findall(r'id=\"(.+?)\"', line) if ids: for html_id in ids: html_id = "#" + html_id self.css_selectors[html_id] = linenum handle.close() except UnicodeDecodeError: if file not in self.encodingerrors: self.encodingerrors.append(file) self.cssclasses, self.cssfilesnotfound = copy.deepcopy(parser.cssclasses), copy.deepcopy(parser.cssfilesnotfound) self._link_css_ids_and_classes(file)
for ext in ["shtml", "html", "xhtml"]: print("Searching file extension... ", ext) # recursive search of user directory or not if RECURSIVE: files = [os.path.join(dirpath, f) for dirpath, dirnames, files in os.walk(userdir) for f in files if f.endswith('.' + ext)] else: files = glob.glob(userdir + "*." + ext) print("number of files found:", len(files)) for file in files: parser = PyCSSParser(file) filecss = {} try: cssfound = False with open(file, "r") as handle: linenum = 1 for line in handle.readlines(): parser.feed(line) classes = re.findall(r'class=\"(.+?)\"', line) if classes:
print("Searching file extension... ", ext) # recursive search of user directory or not if RECURSIVE: files = [ os.path.join(dirpath, f) for dirpath, dirnames, files in os.walk(userdir) for f in files if f.endswith('.' + ext) ] else: files = glob.glob(userdir + "*." + ext) print("number of files found:", len(files)) for file in files: parser = PyCSSParser(file) filecss = {} try: cssfound = False with open(file, "r") as handle: linenum = 1 for line in handle.readlines(): parser.feed(line) classes = re.findall(r'class=\"(.+?)\"', line) if classes: