def _match_path(path, included_patterns, excluded_patterns, case_sensitive): """Internal function same as :func:`match_path` but does not check arguments.""" if case_sensitive: path = PurePosixPath(path) else: included_patterns = {pattern.lower() for pattern in included_patterns} excluded_patterns = {pattern.lower() for pattern in excluded_patterns} path = PureWindowsPath(path) common_patterns = included_patterns & excluded_patterns if common_patterns: raise ValueError( 'conflicting patterns `{}` included and excluded'.format( common_patterns)) return (any(path.match(p) for p in included_patterns) and not any(path.match(p) for p in excluded_patterns))
def create_client( notebook: NotebookNode, source: str, nb_config: NbParserConfig, logger: LoggerType, read_fmt: None | dict = None, ) -> NotebookClientBase: """Create a notebook execution client, to update its outputs. This function may execute the notebook if necessary, to update its outputs, or populate from a cache. :param notebook: The notebook to update. :param source: Path to or description of the input source being processed. :param nb_config: The configuration for the notebook parser. :param logger: The logger to use. :param read_fmt: The format of the input source (to parse to jupyter cache) :returns: The updated notebook, and the (optional) execution metadata. """ # path should only be None when using docutils programmatically, # e.g. source="<string>" try: path = Path(source) if Path(source).is_file() else None except OSError: path = None # occurs on Windows for `source="<string>"` # check if the notebook is excluded from execution by pattern if path is not None and nb_config.execution_excludepatterns: posix_path = PurePosixPath(path.as_posix()) for pattern in nb_config.execution_excludepatterns: if posix_path.match(pattern): logger.info(f"Excluded from execution by pattern: {pattern!r}") return NotebookClientBase(notebook, path, nb_config, logger) # 'auto' mode only executes the notebook if it is missing at least one output missing_outputs = (len(cell.outputs) == 0 for cell in notebook.cells if cell["cell_type"] == "code") if nb_config.execution_mode == "auto" and not any(missing_outputs): logger.info("Skipped execution in 'auto' mode (all outputs present)") return NotebookClientBase(notebook, path, nb_config, logger) if nb_config.execution_mode in ("auto", "force"): return NotebookClientDirect(notebook, path, nb_config, logger) if nb_config.execution_mode == "cache": return NotebookClientCache(notebook, path, nb_config, logger, read_fmt=read_fmt) if nb_config.execution_mode == "inline": return NotebookClientInline(notebook, path, nb_config, logger) return NotebookClientBase(notebook, path, nb_config, logger)
def youtube_id(url): """Extract the YouTube ID from a YouTube URL >>> youtube_id("http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo") '1p3vcRhsYGo' >>> youtube_id("http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel") 'cKZDdG9FTKY' >>> youtube_id('http://www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub') 'yZ-K7nCVnBI' >>> youtube_id('http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I') 'NRHVzbJVx8I' >>> youtube_id('http://www.youtube.com/user/SilkRoadTheatre#p/a/u/2/6dwqZw0j_jY') '6dwqZw0j_jY' >>> youtube_id('http://youtu.be/6dwqZw0j_jY') '6dwqZw0j_jY' >>> youtube_id('http://www.youtube.com/watch?v=6dwqZw0j_jY&feature=youtu.be') '6dwqZw0j_jY' >>> youtube_id('http://youtu.be/afa-5HQHiAs') 'afa-5HQHiAs' >>> youtube_id('http://www.youtube.com/watch?v=cKZDdG9FTKY&feature=channel') 'cKZDdG9FTKY' >>> youtube_id('http://www.youtube.com/user/Scobleizer#p/u/1/1p3vcRhsYGo?rel=0') '1p3vcRhsYGo' >>> youtube_id('//www.youtube-nocookie.com/embed/up_lNV-yoK4?rel=0') 'up_lNV-yoK4' More from :url:`https://stackoverflow.com/a/27728417/297797`: , 'http://www.youtube.com/watch?v=yZ-K7nCVnBI&playnext_from=TL&videos=osPknwzXEas&feature=sub', 'http://www.youtube.com/ytscreeningroom?v=NRHVzbJVx8I', 'http://www.youtube.com/embed/nas1rJpm7wY?rel=0', 'http://www.youtube.com/watch?v=peFZbP64dsU', 'http://youtube.com/v/dQw4w9WgXcQ?feature=youtube_gdata_player', 'http://youtube.com/vi/dQw4w9WgXcQ?feature=youtube_gdata_player', 'http://youtube.com/?v=dQw4w9WgXcQ&feature=youtube_gdata_player', 'http://www.youtube.com/watch?v=dQw4w9WgXcQ&feature=youtube_gdata_player', 'http://youtube.com/?vi=dQw4w9WgXcQ&feature=youtube_gdata_player', 'http://youtube.com/watch?v=dQw4w9WgXcQ&feature=youtube_gdata_player', 'http://youtube.com/watch?vi=dQw4w9WgXcQ&feature=youtube_gdata_player', 'http://youtu.be/dQw4w9WgXcQ?feature=youtube_gdata_player', """ url_parts = urlsplit(url) p = PurePosixPath(url_parts.path) q = parse_qs(url_parts.query) f = url_parts.fragment if (q and 'v' in q): return q['v'][0] elif f: # f is a URL! fp = PurePosixPath(urlsplit(f).path) if fp.match("u/*/*"): return fp.name else: return p.name