How to use _sanitize_path method in stestr

Best Python code snippet using stestr_python

hugo.py

Source:hugo.py Github

copy

Full Screen

...41 def _update_attachments(content: str, location: str) -> str:42 pattern = r"\/?\.attachments\/"43 return re.sub(pattern, location, content)44 @staticmethod45 def _sanitize_path(path: str) -> str:46 # https://docs.microsoft.com/es-es/windows/win32/fileio/naming-a-file47 pattern = r'[<>:"/\\|?*]'48 return re.sub(pattern, "__", path)49 @classmethod50 def _create_index_page(cls, dir_: str, title: str = None) -> None:51 index_path = os.path.join(dir_, "_index.md")52 if os.path.exists(index_path):53 return54 logger.info(f"Creating {index_path}")55 with open(index_path, "x", encoding="utf-8") as f:56 title = title if title else os.path.basename(dir_)57 content = cls._get_front_matter(title, True) + "{{< toc-tree >}}"58 f.write(content)59 def create_content(self, projects: List[Project], site_dir: str) -> None:60 logger.info("Creating content")61 content_dir = os.path.join(site_dir, "content")62 self.__class__._empty_directory(content_dir)63 static_dir = os.path.join(site_dir, "static")64 self.__class__._empty_directory(static_dir)65 for project in projects:66 project_directory = os.path.join(content_dir, self.__class__._sanitize_path(project.name))67 for wiki in project.wikis:68 wiki_directory = os.path.join(project_directory, self.__class__._sanitize_path(wiki.name))69 for page in wiki.pages:70 if not page.content:71 continue72 page_directories = list(map(lambda item: self.__class__._sanitize_path(item), page.path.split("/")))73 if page.is_parent:74 page_directory = os.path.join(wiki_directory, *page_directories)75 file_path = os.path.join(page_directory, "_index.md")76 else:77 page_directory = os.path.join(wiki_directory, *page_directories[:-1])78 file_path = os.path.join(page_directory, f"{page_directories[-1]}.md")79 self._extract_attachments(project.id, wiki.id, page.content, static_dir)80 content = self.__class__._update_attachments(page.content, "/")81 content = self.__class__._get_front_matter(page.title, page.is_parent) + content82 self.__class__._create_file(file_path, content)83 self.__class__._create_index_page(content_dir, self._azure_devops.organization)84 for root, dirs, files in os.walk(content_dir):85 for dir_ in dirs:86 self.__class__._create_index_page(os.path.join(root, dir_))...

Full Screen

Full Screen

service.py

Source:service.py Github

copy

Full Screen

...19 def set_base_path(self, base_path):20 self.__base_path = base_path21 Finder.logger.debug('Change to location: {}'.format(base_path))22 def get(self, path):23 path = self._sanitize_path(path)24 actual_path = self._resolve_path(path)25 fs_node = FSNode(path, actual_path)26 if not fs_node.exists:27 raise NotFoundError(path)28 return fs_node29 def put(self, path, content):30 path = self._sanitize_path(path)31 fs_node = self.get(path)32 if not fs_node.exists:33 raise NotFoundError(path)34 # Update the content35 fs_node.content = content36 fs_node.save()37 def delete(self, path):38 path = self._sanitize_path(path)39 fs_node = self.get(path)40 # Remove the content41 try:42 fs_node.delete()43 except FSNodeNotFoundError as e:44 raise NotFoundError('{}: {}'.format(path, e.message))45 def find(self, path):46 """ Find FS nodes. """47 path = self._sanitize_path(path)48 actual_iterating_path = self._resolve_path(path)49 fs_nodes = []50 if not os.path.exists(actual_iterating_path):51 raise NotFoundError('Failed to iterating on {} ({})'.format(path, actual_iterating_path))52 sub_paths = os.listdir(actual_iterating_path)53 sub_paths.sort()54 for fs_node_name in sub_paths:55 next_path = os.path.join(path, fs_node_name)56 actual_path = self._resolve_path(next_path)57 fs_node = FSNode(next_path, actual_path)58 fs_nodes.append(fs_node)59 return fs_nodes60 def move(self, old_path, new_path):61 """ Find FS nodes. """62 old_path = self._resolve_path(self._sanitize_path(old_path))63 new_path = self._resolve_path(self._sanitize_path(new_path))64 if not os.path.exists(old_path):65 raise NotFoundError('Unable to find the source node at {}'.format(old_path))66 shutil.move(old_path, new_path)67 def create_folder(self, path, name):68 """ Create a blank folder. """69 referred_path = os.path.join(path, name)70 actual_path = self._resolve_path(referred_path)71 if os.path.exists(actual_path):72 return False73 os.makedirs(actual_path)74 return True75 def create_file(self, path, name):76 """ Create a blank file. """77 referred_path = os.path.join(path, name)78 actual_path = self._resolve_path(referred_path)79 if os.path.exists(actual_path):80 return False81 with open(actual_path, 'w') as f:82 f.write('')83 return True84 def _is_abspath(self, path):85 return '/' == path[0] if path else False86 def _resolve_path(self, path):87 if self._is_abspath(path):88 return path89 return os.path.join(self.base_path, path)90 def _sanitize_path(self, path):91 return self.__illegal_pattern.sub('', path)92class BroadcastService(object):93 def __init__(self, WebSocketInterfaceClass):94 self.WebSocketInterfaceClass = WebSocketInterfaceClass95 def broadcast(self, message):96 channels = self.WebSocketInterfaceClass._channel_table97 for object_hash in channels:98 channel = channels[object_hash]...

Full Screen

Full Screen

binwalk_module.py

Source:binwalk_module.py Github

copy

Full Screen

...30 for module in binwalk.scan(self.file_path, signature=True, opcodes=True, extract=True, matryoshka=True, depth=100, entropy=True, nplot=True, directory=self.save_directory, hexdump=self.hexdump, quiet=True):31 for result in module.results:32 if result.module == "Entropy":33 if self._check_entropy(result.description):34 self._save_in_output("\t%s %s 0x%.8X %s" % (result.module, self._sanitize_path(result.file.path), result.offset, result.description))35 else:36 if result.file:37 self._save_in_output("\t%s %s 0x%.8X %s" % (result.module, self._sanitize_path(result.file.path), result.offset, result.description))38 if module.extractor.output.has_key(result.file.path):39 # These are files that binwalk carved out of the original firmware image, a la dd40 if module.extractor.output[result.file.path].carved.has_key(result.offset):41 self._save_in_output("Carved data from offset 0x%X to %s" % (result.offset, self._sanitize_path(module.extractor.output[result.file.path].carved[result.offset])) )42 # These are files/directories created by extraction utilities (gunzip, tar, unsquashfs, etc)43 if module.extractor.output[result.file.path].extracted.has_key(result.offset):44 self._save_in_output("Extracted %d files from offset 0x%X to '%s' using '%s'" % (len(module.extractor.output[result.file.path].extracted[result.offset].files),45 result.offset,46 self._sanitize_path(module.extractor.output[result.file.path].extracted[result.offset].files[0]),47 module.extractor.output[result.file.path].extracted[result.offset].command) )48 def mprint(self):49 if len(self.output) > 0:50 print "###### "+self.name+" ######"51 if self.usefull_urls:52 print "Usefull "+self.name+" URLS:"53 for val in self.usefull_urls:54 print val55 print56 57 for out in self.output:58 print out59 print "###### "+self.name+" END ######\n"60 def _save_in_output(self, out):61 self.output.append(self.check_found(out))62 def _check_entropy(self, entropy):63 if (float(entropy) > self.current_entropy+0.05) or (float(entropy) < self.current_entropy-0.05):64 self.current_entropy = float(entropy)65 return True66 return False67 def _sanitize_path(self,path):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stestr automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful