当前位置: 首页>>代码示例>>Python>>正文


Python re.M属性代码示例

本文整理汇总了Python中re.M属性的典型用法代码示例。如果您正苦于以下问题:Python re.M属性的具体用法?Python re.M怎么用?Python re.M使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在re的用法示例。


在下文中一共展示了re.M属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: find_version

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def find_version(*file_paths):
    # Open in Latin-1 so that we avoid encoding errors.
    # Use codecs.open for Python 2 compatibility
    try:
        f = codecs.open(os.path.join(here, *file_paths), 'r', 'latin1')
        version_file = f.read()
        f.close()
    except:
        raise RuntimeError("Unable to find version string.")

    # The version line must have the form
    # __version__ = 'ver'
    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find version string.")


# Get the long description from the relevant file 
开发者ID:NatanaelAntonioli,项目名称:L.E.S.M.A,代码行数:22,代码来源:setup.py

示例2: re_show

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def re_show(regexp, string):
    """
    Search C{string} for substrings matching C{regexp} and wrap
    the matches with braces.  This is convenient for learning about
    regular expressions.

    @param regexp: The regular expression.
    @param string: The string being matched.
    @rtype: C{string}
    @return: A string with braces surrounding the matched substrings.
    """
    print re.compile(regexp, re.M).sub("{\g<0>}", string.rstrip())


##########################################################################
# READ FROM FILE OR STRING
##########################################################################

# recipe from David Mertz 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:21,代码来源:utilities.py

示例3: re_show

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def re_show(regexp, string, left="{", right="}"):
    """
    Return a string with markers surrounding the matched substrings.
    Search str for substrings matching ``regexp`` and wrap the matches
    with braces.  This is convenient for learning about regular expressions.

    :param regexp: The regular expression.
    :type regexp: str
    :param string: The string being matched.
    :type string: str
    :param left: The left delimiter (printed before the matched substring)
    :type left: str
    :param right: The right delimiter (printed after the matched substring)
    :type right: str
    :rtype: str
    """
    print(re.compile(regexp, re.M).sub(left + r"\g<0>" + right, string.rstrip()))


##########################################################################
# READ FROM FILE OR STRING
##########################################################################

# recipe from David Mertz 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:26,代码来源:util.py

示例4: getmatch

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def getmatch(self, haystack):
        if not isinstance(haystack, basestring):
            return None
        flags = 0
        if self.flags is not None:
            if "i" in self.flags or "I" in self.flags:
                flags |= re.I
            if "l" in self.flags or "L" in self.flags:
                flags |= re.L
            if "m" in self.flags or "M" in self.flags:
                flags |= re.M
            if "s" in self.flags or "S" in self.flags:
                flags |= re.S
            if "u" in self.flags or "U" in self.flags:
                flags |= re.U
            if "x" in self.flags or "X" in self.flags:
                flags |= re.X
        if re.match(self.pattern, haystack, flags=flags) is None:
            return None
        elif self.to is None:
            return Match(haystack, haystack)
        else:
            return Match(haystack, re.sub(self.pattern, self.to, haystack, flags=flags)) 
开发者ID:modelop,项目名称:hadrian,代码行数:25,代码来源:tools.py

示例5: find_version

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def find_version(*file_paths):
    """Read the version number from a source file.
    Why read it, and not import?
    see https://groups.google.com/d/topic/pypa-dev/0PkjVpcxTzQ/discussion
    """
    # Open in Latin-1 so that we avoid encoding errors.
    # Use codecs.open for Python 2 compatibility
    with codecs.open(os.path.join(here, *file_paths), 'r', 'latin1') as f:
        version_file = f.read()

    # The version line must have the form
    # __version__ = 'ver'
    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError("Unable to find version string.") 
开发者ID:addisonlynch,项目名称:pyTD,代码行数:19,代码来源:setup.py

示例6: get_incremented_filename

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def get_incremented_filename(filename, namestring):

    import re

    min_index = 1
    pattern = r"(.*?)(\s*)(\d*)$"
    basename, space, index_str = re.search(pattern, filename).groups()
    search_pattern = fr"^{re.escape(basename)}\s*(\d+)$"

    if index_str:
        min_index = int(index_str)
        zero_padding = len(index_str) if index_str.startswith("0") else 0
        naming_pattern = basename + space + "{:0" + str(zero_padding) + "d}"
    else:
        naming_pattern = basename + " {:02d}"

    names = re.finditer(search_pattern, namestring, re.I | re.M)
    inds = [int(name.group(1)) for name in names]
    max_index = min_index + len(inds)

    for i in range(min_index, max_index):
        if i not in inds:
            return naming_pattern.format(i)

    return naming_pattern.format(max_index) 
开发者ID:Epihaius,项目名称:panda3dstudio,代码行数:27,代码来源:file_dialog.py

示例7: versions_from_file

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def versions_from_file(filename):
    """Try to determine the version from _version.py if present."""
    try:
        with open(filename) as f:
            contents = f.read()
    except EnvironmentError:
        raise NotThisMethod("unable to read _version.py")
    mo = re.search(
        r"version_json = '''\n(.*)'''  # END VERSION_JSON", contents, re.M | re.S
    )
    if not mo:
        mo = re.search(
            r"version_json = '''\r\n(.*)'''  # END VERSION_JSON", contents, re.M | re.S
        )
    if not mo:
        raise NotThisMethod("no version_json in _version.py")
    return json.loads(mo.group(1)) 
开发者ID:simonw,项目名称:datasette,代码行数:19,代码来源:versioneer.py

示例8: get_version

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def get_version():
    """
    Extracts the version number from the version.py file.
    """
    VERSION_FILE = '../dynamic_db_router/version.py'
    mo = re.search(r'^__version__ = [\'"]([^\'"]*)[\'"]', open(VERSION_FILE, 'rt').read(), re.M)
    if mo:
        return mo.group(1)
    else:
        raise RuntimeError('Unable to find version string in {0}.'.format(VERSION_FILE))

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))

# -- General configuration ------------------------------------------------ 
开发者ID:ambitioninc,项目名称:django-dynamic-db-router,代码行数:19,代码来源:conf.py

示例9: test_simple_usage

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def test_simple_usage(self):
        test_loop = asyncio.get_event_loop()
        console = SharedConsole(interval=0.0)

        async def add_lines():
            console.print("one")
            console.print("two")
            console.print("3")
            try:
                1 + "e"
            except Exception as e:
                console.print_error(e)
                console.print_error(e, sys.exc_info()[2])
            await asyncio.sleep(0.2)
            await console.stop()

        with catch_output() as (stdout, stderr):
            adder = asyncio.ensure_future(add_lines())
            displayer = asyncio.ensure_future(console.display())
            test_loop.run_until_complete(asyncio.gather(adder, displayer))

        output = stdout.read()
        test_loop.close()
        self.assertTrue(re.match(OUTPUT, output, re.S | re.M) is not None, output) 
开发者ID:loads,项目名称:molotov,代码行数:26,代码来源:test_sharedconsole.py

示例10: _get_version

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def _get_version():
    PATH_TO_INIT_PY = \
        os.path.join(
            os.path.abspath(os.path.dirname(__file__)),
            'aiohttp_jinja2',
            '__init__.py'
        )

    with codecs.open(PATH_TO_INIT_PY, 'r', 'latin1') as fp:
        try:
            for line in fp.readlines():
                if line:
                    line = line.strip()
                    version = re.findall(
                        r"^__version__ = '([^']+)'$", line, re.M
                    )
                    if version:
                        return version[0]
        except IndexError:
            raise RuntimeError('Unable to determine version.') 
开发者ID:aio-libs,项目名称:aiohttp-jinja2,代码行数:22,代码来源:setup.py

示例11: insertVbaCode

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def insertVbaCode(self, targetModule, targetFunction,targetLine, vbaCode):
        """
        Insert some code at targetLine (number) at targetFunction in targetModule
        """
        logging.debug("     [,] Opening "+ targetFunction + " in " + targetModule + " to inject code...")
        f = open(targetModule)
        content = f.readlines()
        f.close()
        
        for n,line in enumerate(content):
            matchObj = re.match( r'.*(Sub|Function)\s+%s\s*\(.*\).*'%targetFunction, line, re.M|re.I) 
            if matchObj:  
                logging.debug("     [,] Found " + targetFunction + " ") 
                content[n+targetLine] = content[n+targetLine]+ vbaCode+"\n"
                break
        
        
        logging.debug("     [,] New content: \n " + "".join(content) + "\n\n ") 
        f = open(targetModule, 'w')
        f.writelines(content)
        f.close() 
开发者ID:sevagas,项目名称:macro_pack,代码行数:23,代码来源:mp_module.py

示例12: get_version

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def get_version(string):
    """ Parse the version number variable __version__ from a script. """
    import re
    version_re = r"^__version__ = ['\"]([^'\"]*)['\"]"
    version_str = re.search(version_re, string, re.M).group(1)
    return version_str 
开发者ID:svviz,项目名称:svviz,代码行数:8,代码来源:setup.py

示例13: find_meta

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def find_meta(meta):
    """
    Extract __*meta*__ from META_FILE.
    """
    meta_match = re.search(r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), META_FILE, re.M)
    if meta_match:
        return meta_match.group(1)
    raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta))


# -- Project information ----------------------------------------------------- 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:13,代码来源:conf.py

示例14: find_meta

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def find_meta(meta):
    """
    Extract __*meta*__ from META_FILE.
    """
    meta_match = re.search(r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), META_FILE, re.M)
    if meta_match:
        return meta_match.group(1)
    raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta)) 
开发者ID:EvanKepner,项目名称:mutatest,代码行数:10,代码来源:setup.py

示例15: versions_from_file

# 需要导入模块: import re [as 别名]
# 或者: from re import M [as 别名]
def versions_from_file(filename):
    """Try to determine the version from _version.py if present."""
    try:
        with open(filename) as f:
            contents = f.read()
    except EnvironmentError:
        raise NotThisMethod("unable to read _version.py")
    mo = re.search(r"version_json = '''\n(.*)'''  # END VERSION_JSON",
                   contents, re.M | re.S)
    if not mo:
        mo = re.search(r"version_json = '''\r\n(.*)'''  # END VERSION_JSON",
                       contents, re.M | re.S)
    if not mo:
        raise NotThisMethod("no version_json in _version.py")
    return json.loads(mo.group(1)) 
开发者ID:spencerahill,项目名称:aospy,代码行数:17,代码来源:versioneer.py


注:本文中的re.M属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。