當前位置: 首頁>>代碼示例>>Python>>正文


Python glob.escape方法代碼示例

本文整理匯總了Python中glob.escape方法的典型用法代碼示例。如果您正苦於以下問題:Python glob.escape方法的具體用法?Python glob.escape怎麽用?Python glob.escape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在glob的用法示例。


在下文中一共展示了glob.escape方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _load

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def _load(self):
        """Load text to memory"""

        corpus_directory = glob.escape(self.corpus_directory)
        file_list = sorted(glob.glob(os.path.join(corpus_directory, "*.txt")))

        for path in file_list:
            with open(path, "r", encoding="utf8") as text:
                # Read content from text file
                content = text.read()

                # Preprocessing
                content = self._preprocessing(content)

                # Create text instance
                text = Text(path, os.path.basename(path), content)

                # Add text to corpus
                self.__corpus.append(text) 
開發者ID:KrakenAI,項目名稱:SynThai,代碼行數:21,代碼來源:utils.py

示例2: percentparse

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def percentparse(s: str, format: str, table: Dict[str, str]) -> Optional[Dict[str, str]]:
    table = {key: '(?P<{}>{})'.format(key, value) for key, value in table.items()}
    used = set()  # type: Set[str]
    pattern = ''
    for token in percentsplit(re.escape(format).replace('\\%', '%')):
        if token.startswith('%'):
            c = token[1]
            if c not in used:
                pattern += table[c]
                used.add(c)
            else:
                pattern += r'(?P={})'.format(c)
        else:
            pattern += token
    m = re.match(pattern, s)
    if not m:
        return None
    return m.groupdict() 
開發者ID:online-judge-tools,項目名稱:oj,代碼行數:20,代碼來源:format_utils.py

示例3: check_escape

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def check_escape(self, arg, expected):
        self.assertEqual(glob.escape(arg), expected)
        self.assertEqual(glob.escape(os.fsencode(arg)), os.fsencode(expected)) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:5,代碼來源:test_glob.py

示例4: __excludes2string

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def __excludes2string(self):
        if 'rclone_excludes' not in self.config:
            return ''

        return ' '.join(
            "--exclude=%s" % (
                cmd_quote(glob.escape(value) if value.startswith(os.path.sep) else value) if isinstance(value,
                                                                                                        str) else value)
            for value in
            self.config['rclone_excludes']).replace('=None', '').strip() 
開發者ID:l3uddz,項目名稱:cloudplow,代碼行數:12,代碼來源:rclone.py

示例5: glob_escape

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def glob_escape(pathname):
        """
        Escape all special characters.
        """
        drive, pathname = os.path.splitdrive(pathname)
        pathname = _magic_check.sub(r'[\1]', pathname)
        return drive + pathname 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:9,代碼來源:glob.py

示例6: check_dimension

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def check_dimension(self):
        if os.path.getsize(self.file_name) > 50 * 1024 * 1023:
            os.system('split -b 49M "{0}" "{1}"'.format(self.file_name, self.file_name))
            os.remove(self.file_name)
        return glob(escape(self.file_name) + '*') 
開發者ID:deepserket,項目名稱:telegram-bot-youtube-downloader,代碼行數:7,代碼來源:vid_utils.py

示例7: _preprocessing

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def _preprocessing(self, content):
        """Text preprocessing"""

        # Remove new line
        content = re.sub(r"(\r\n|\r|\n)+", r"", content)

        # Convert one or multiple non-breaking space to space
        content = re.sub(r"(\xa0)+", r"\s", content)

        # Convert multiple spaces to only one space
        content = re.sub(r"\s{2,}", r"\s", content)

        # Trim whitespace from starting and ending of text
        content = content.strip(string.whitespace)

        if self.word_delimiter and self.tag_delimiter:
            # Trim word delimiter from starting and ending of text
            content = content.strip(self.word_delimiter)

            # Convert special characters (word and tag delimiter)
            # in text's content to escape character
            find = "{0}{0}{1}".format(re.escape(self.word_delimiter),
                                      re.escape(self.tag_delimiter))
            replace = "{0}{2}{1}".format(re.escape(self.word_delimiter),
                                         re.escape(self.tag_delimiter),
                                         re.escape(constant.ESCAPE_WORD_DELIMITER))
            content = re.sub(find, replace, content)

            find = "{0}{0}".format(re.escape(self.tag_delimiter))
            replace = "{1}{0}".format(re.escape(self.tag_delimiter),
                                      re.escape(constant.ESCAPE_TAG_DELIMITER))
            content = re.sub(find, replace, content)

        # Replace distinct quotation mark into standard quotation
        content = re.sub(r"\u2018|\u2019", r"\'", content)
        content = re.sub(r"\u201c|\u201d", r"\"", content)

        return content 
開發者ID:KrakenAI,項目名稱:SynThai,代碼行數:40,代碼來源:utils.py

示例8: get_token_list

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def get_token_list(self, index):
        """Get list of (word, tag) pair"""

        if not self.word_delimiter or not self.tag_delimiter:
            return list()

        # Get content by index
        content = self.__corpus[index].content

        # Empty file
        if not content:
            return list()

        # Split each word by word delimiter
        token_list = content.split(self.word_delimiter)

        for idx, token in enumerate(token_list):
            # Empty or Spacebar
            if token == "" or token == constant.SPACEBAR:
                word = constant.SPACEBAR
                tag = constant.PAD_TAG_INDEX

            # Word
            else:
                # Split word and tag by tag delimiter
                datum = token.split(self.tag_delimiter)
                word = datum[0]
                tag = datum[-2]

                # Replace escape character to proper character
                word = word.replace(constant.ESCAPE_WORD_DELIMITER, self.word_delimiter)
                tag = tag.replace(constant.ESCAPE_TAG_DELIMITER, self.tag_delimiter)

            # Replace token with word and tag pair
            token_list[idx] = (word, tag)

        return token_list 
開發者ID:KrakenAI,項目名稱:SynThai,代碼行數:39,代碼來源:utils.py

示例9: find_data_files

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def find_data_files():
    """Setuptools package_data globbing is stupid, so make this work ourselves."""
    data_files = []
    for pathname in glob.glob("antismash/**/*", recursive=True):
        if pathname.endswith('.pyc'):
            continue
        if pathname.endswith('.py'):
            continue
        if '__pycache__' in pathname:
            continue
        if pathname[:-1].endswith('.hmm.h3'):
            continue
        if pathname.endswith('bgc_seeds.hmm'):
            continue
        pathname = glob.escape(pathname)
        pathname = pathname[10:]
        data_files.append(pathname)
    if "HARDCODE_ANTISMASH_GIT_VERSION" in os.environ:
        version_file = os.path.join('antismash', 'git_hash')
        with open(version_file, 'wt') as handle:
            try:
                git_version = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'],
                                                      universal_newlines=True).strip()
                changes = subprocess.check_output(['git', 'status', '--porcelain'],
                                                  universal_newlines=True).splitlines()
                if len(changes) != 0:
                    git_version += "(changed)"
                handle.write(git_version)
            except (OSError, subprocess.CalledProcessError):
                pass
        data_files.append(version_file)
    return data_files 
開發者ID:antismash,項目名稱:antismash,代碼行數:34,代碼來源:setup.py

示例10: _make_glob_patterns

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def _make_glob_patterns(path):
        formatter = string.Formatter()
        tokens = formatter.parse(path)
        escaped = "".join(glob.escape(text) + "*" * (name is not None) for text, name, *_ in tokens)

        root, ext = os.path.splitext(escaped)

        if not ext:
            return [escaped, escaped + ".*"]

        return [escaped, escaped + ".*", root + ".*" + ext, root + ".*" + ext + ".*"] 
開發者ID:Delgan,項目名稱:loguru,代碼行數:13,代碼來源:_file_sink.py

示例11: glob_with_format

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def glob_with_format(directory: pathlib.Path, format: str) -> List[pathlib.Path]:
    if os.name == 'nt':
        format = format.replace('/', '\\')
    table = {}
    table['s'] = '*'
    table['e'] = '*'
    pattern = (glob.escape(str(directory) + os.path.sep) + percentformat(glob.escape(format).replace(glob.escape('%'), '%'), table))
    paths = list(map(pathlib.Path, glob.glob(pattern)))
    for path in paths:
        log.debug('testcase globbed: %s', path)
    return paths 
開發者ID:online-judge-tools,項目名稱:oj,代碼行數:13,代碼來源:format_utils.py

示例12: match_with_format

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def match_with_format(directory: pathlib.Path, format: str, path: pathlib.Path) -> Optional[Match[str]]:
    if os.name == 'nt':
        format = format.replace('/', '\\')
    table = {}
    table['s'] = '(?P<name>.+)'
    table['e'] = '(?P<ext>in|out)'
    pattern = re.compile(re.escape(str(directory.resolve()) + os.path.sep) + percentformat(re.escape(format).replace(re.escape('%'), '%'), table))
    return pattern.match(str(path.resolve())) 
開發者ID:online-judge-tools,項目名稱:oj,代碼行數:10,代碼來源:format_utils.py

示例13: get_proton_installations

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def get_proton_installations(compat_tool_dir):
    """
    Return a list of custom Proton installations as a list of SteamApp objects
    """

    if not os.path.isdir(compat_tool_dir):
        return []

    comptool_files = glob.glob(
        os.path.join(
            glob.escape(compat_tool_dir), "*", "compatibilitytool.vdf"
        )
    )
    comptool_files += glob.glob(
        os.path.join(glob.escape(compat_tool_dir), "compatibilitytool.vdf")
    )

    custom_proton_apps = []

    for vdf_path in comptool_files:
        with open(vdf_path, "r") as f:
            content = f.read()

        vdf_data = vdf.loads(content)
        internal_name = list(
            vdf_data["compatibilitytools"]["compat_tools"].keys())[0]
        tool_info = vdf_data["compatibilitytools"]["compat_tools"][
            internal_name]

        install_path = tool_info["install_path"]
        from_oslist = tool_info["from_oslist"]
        to_oslist = tool_info["to_oslist"]

        if from_oslist != "windows" or to_oslist != "linux":
            continue

        # Installation path can be relative if the VDF was in
        # 'compatibilitytools.d/'
        # or '.' if the VDF was in 'compatibilitytools.d/TOOL_NAME'
        if install_path == ".":
            install_path = os.path.dirname(vdf_path)
        else:
            install_path = os.path.join(compat_tool_dir, install_path)

        custom_proton_apps.append(
            SteamApp(name=internal_name, install_path=install_path)
        )

    return custom_proton_apps 
開發者ID:Matoking,項目名稱:protontricks,代碼行數:51,代碼來源:steam.py

示例14: get_steam_apps

# 需要導入模塊: import glob [as 別名]
# 或者: from glob import escape [as 別名]
def get_steam_apps(steam_root, steam_path, steam_lib_paths):
    """
    Find all the installed Steam apps and return them as a list of SteamApp
    objects
    """
    steam_apps = []

    for path in steam_lib_paths:
        appmanifest_paths = []
        is_lowercase = os.path.isdir(os.path.join(path, "steamapps"))
        is_mixedcase = os.path.isdir(os.path.join(path, "SteamApps"))

        if is_lowercase:
            appmanifest_paths = glob.glob(
                os.path.join(
                    glob.escape(path), "steamapps", "appmanifest_*.acf"
                )
            )
        elif is_mixedcase:
            appmanifest_paths = glob.glob(
                os.path.join(
                    glob.escape(path), "SteamApps", "appmanifest_*.acf"
                )
            )

        if is_lowercase and is_mixedcase:
            # Log a warning if both 'steamapps' and 'SteamApps' directories
            # exist, as both Protontricks and Steam client have problems
            # dealing with it (see issue #51)
            logger.warning(
                "Both 'steamapps' and 'SteamApps' directories were found at "
                "%s. 'SteamApps' directory should be removed to prevent "
                "issues with app and Proton discovery.",
                path
            )

        for manifest_path in appmanifest_paths:
            steam_app = SteamApp.from_appmanifest(
                manifest_path, steam_lib_paths=steam_lib_paths
            )
            if steam_app:
                steam_apps.append(steam_app)

    # Get the custom Proton installations and non-Steam shortcuts as well
    steam_apps += get_custom_proton_installations(steam_root=steam_root)
    steam_apps += get_custom_windows_shortcuts(steam_path=steam_path)

    # Exclude games that haven't been launched yet
    steam_apps = [
        app for app in steam_apps if app.prefix_path_exists or app.is_proton
    ]

    # Sort the apps by their names
    steam_apps.sort(key=lambda app: app.name)

    return steam_apps 
開發者ID:Matoking,項目名稱:protontricks,代碼行數:58,代碼來源:steam.py


注:本文中的glob.escape方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。