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


Python re.re_compile函数代码示例

本文整理汇总了Python中re.re_compile函数的典型用法代码示例。如果您正苦于以下问题:Python re_compile函数的具体用法?Python re_compile怎么用?Python re_compile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: search

    def search(self, what, cat='all'):
        """ Performs search """
        #prepare query
        cat = self.supported_categories[cat.lower()]
        query = "".join((self.url, "/files/?category=", cat, "&subcategory=All&quality=All&seeded=2&external=2&query=", what, "&uid=0&sort=S"))

        data = retrieve_url(query)

        add_res_list = re_compile("/files.*page=[0-9]+")
        torrent_list = re_compile("start torrent list -->(.*)<!-- end torrent", DOTALL)
        data = torrent_list.search(data).group(0)
        list_results = add_res_list.findall(data)

        parser = self.MyHtmlParseWithBlackJack(self.url)
        parser.feed(data)

        del data

        if list_results:
            for search_query in islice((add_res_list.search(result).group(0) for result in list_results[1].split(" | ")), 0, 5):
                response = retrieve_url(self.url + search_query)
                parser.feed(torrent_list.search(response).group(0))
                parser.close()

        return
开发者ID:ATGardner,项目名称:qBittorrent,代码行数:25,代码来源:demonoid.py

示例2: search

    def search(self, what, cat='all'):
        """ Performs search """
        connection = https("www.demonoid.pw")

        #prepare query
        cat = self.supported_categories[cat.lower()]
        query = "".join(("/files/?category=", cat, "&subcategory=All&quality=All&seeded=2&external=2&query=", what, "&to=1&uid=0&sort=S"))

        connection.request("GET", query)
        response = connection.getresponse()
        if response.status != 200:
            return

        data = response.read().decode("utf-8")
        add_res_list = re_compile("/files.*page=[0-9]+")
        torrent_list = re_compile("start torrent list -->(.*)<!-- end torrent", DOTALL)
        data = torrent_list.search(data).group(0)
        list_results = add_res_list.findall(data)

        parser = self.MyHtmlParseWithBlackJack(self.url)
        parser.feed(data)

        del data

        if list_results:
            for search_query in islice((add_res_list.search(result).group(0) for result in list_results[1].split(" | ")), 0, 5):
                connection.request("GET", search_query)
                response = connection.getresponse()
                parser.feed(torrent_list.search(response.read().decode('utf-8')).group(0))
                parser.close()

        connection.close()
        return
开发者ID:JXPrime,项目名称:qBittorrent,代码行数:33,代码来源:demonoid.py

示例3: search

    def search(self, what, cat="all"):
        """ Performs search """
        query = "".join(
            (
                self.url,
                "/index.php?page=torrents&search=",
                what,
                "&category=",
                self.supported_categories.get(cat, "0"),
                "&active=1",
            )
        )

        get_table = re_compile('(?s)<table\sclass="lista".*>(.*)</table>')
        data = get_table.search(retrieve_url(query)).group(0)
        # extract first ten pages of next results
        next_pages = re_compile('(?m)<option value="(.*)">[0-9]+</option>')
        next_pages = ["".join((self.url, page)) for page in next_pages.findall(data)[:10]]

        parser = self.MyHtmlParseWithBlackJack(self.url)
        parser.feed(data)
        parser.close()

        for page in next_pages:
            parser.feed(get_table.search(retrieve_url(page)).group(0))
            parser.close()
开发者ID:Burrex,项目名称:qBittorrent,代码行数:26,代码来源:legittorrents.py

示例4: __WriteGHDLSection

	def __WriteGHDLSection(self, binPath):
		if (self._host.Platform == "Windows"):
			ghdlPath = binPath / "ghdl.exe"
		else:
			ghdlPath = binPath / "ghdl"

		if not ghdlPath.exists():
			raise ConfigurationException("Executable '{0!s}' not found.".format(ghdlPath)) from FileNotFoundError(
				str(ghdlPath))

		# get version and backend
		output = check_output([str(ghdlPath), "-v"], universal_newlines=True)
		version = None
		backend = None
		versionRegExpStr = r"^GHDL (.+?) "
		versionRegExp = re_compile(versionRegExpStr)
		backendRegExpStr = r"(?i).*(mcode|gcc|llvm).* code generator"
		backendRegExp = re_compile(backendRegExpStr)
		for line in output.split('\n'):
			if version is None:
				match = versionRegExp.match(line)
				if match is not None:
					version = match.group(1)

			if backend is None:
				match = backendRegExp.match(line)
				if match is not None:
					backend = match.group(1).lower()

		if ((version is None) or (backend is None)):
			raise ConfigurationException("Version number or back-end name not found in '{0!s} -v' output.".format(ghdlPath))

		self._host.PoCConfig[self._section]['Version'] = version
		self._host.PoCConfig[self._section]['Backend'] = backend
开发者ID:Paebbels,项目名称:PoC,代码行数:34,代码来源:GHDL.py

示例5: __init__

 def __init__(self, *args, **kwargs):
     """
 Parameters
 ----------
 ``*args`` and ``**kwargs``
     Parameters that shall be used for the substitution. Note that you can
     only provide either ``*args`` or ``**kwargs``, furthermore most of the
     methods like `get_sectionsf` require ``**kwargs`` to be provided."""
     if len(args) and len(kwargs):
         raise ValueError("Only positional or keyword args are allowed")
     self.params = args or kwargs
     patterns = {}
     all_sections = self.param_like_sections + self.text_sections
     for section in self.param_like_sections:
         patterns[section] = re_compile(
             '(?<=%s\n%s\n)(?s)(.+?)(?=\n\n\S+|$)' % (
                 section, '-'*len(section)))
     all_sections_patt = '|'.join(
         '%s\n%s\n' % (s, '-'*len(s)) for s in all_sections)
     # examples and see also
     for section in self.text_sections:
         patterns[section] = re_compile(
             '(?<=%s\n%s\n)(?s)(.+?)(?=%s|$)' % (
                 section, '-'*len(section), all_sections_patt))
     self.patterns = patterns
开发者ID:Chilipp,项目名称:psyplot,代码行数:25,代码来源:docstring.py

示例6: parse_scorematrix

def parse_scorematrix(name, smpath):
    with open(smpath) as fh:
        ws = re_compile(r'\s+')
        comment = re_compile(r'^\s*#')
        S = fh.read().split('\n')
        T = [s.strip() for s in S if not comment.match(s)]
        U = [ws.sub(' ', t).split(' ') for t in T if len(t) > 0]
        V = [u[1:] for u in U[1:]]
        W = [[int(w) for w in v] for v in V]
        lettersX = ''.join(U[0]).upper()
        lettersY = ''.join([u[0] for u in U[1:]]).upper()
        if len(lettersX) >= 20:
            letters = pletters
            klass = ProteinScoreMatrix
        else:
            letters = dletters
            klass = DNAScoreMatrix
        if not set(letters).issubset(set(lettersX + lettersY)):
            msg = "scoring matrix '%s' is insufficiently descriptive" % smpath
            raise RuntimeError(msg)
        if lettersX != lettersY or lettersX[:len(letters)] != letters:
            cols = [lettersX.index(l) for l in letters]
            rows = [lettersY.index(l) for l in letters]
            return klass(name, [[W[i][j] for j in cols] for i in rows])
        else:
            return klass(name, W)
开发者ID:nlhepler,项目名称:BioExt,代码行数:26,代码来源:_scorematrix.py

示例7: __init__

 def __init__(self, configuration=None, name=None):
     SimpleService.__init__(self, configuration=configuration, name=name)
     self.regex = dict(disks=re_compile(r' (?P<array>[a-zA-Z_0-9]+) : active .+\['
                                        r'(?P<total_disks>[0-9]+)/'
                                        r'(?P<inuse_disks>[0-9]+)\]'),
                       status=re_compile(r' (?P<array>[a-zA-Z_0-9]+) : active .+ '
                                         r'(?P<operation>[a-z]+) =[ ]{1,2}'
                                         r'(?P<operation_status>[0-9.]+).+finish='
                                         r'(?P<finish>([0-9.]+))min speed='
                                         r'(?P<speed>[0-9]+)'))
开发者ID:swinsey,项目名称:netdata,代码行数:10,代码来源:mdstat.chart.py

示例8: setExclude

	def setExclude(self, exclude):
		if exclude:
			self._exclude = (
				[re_compile(x) for x in exclude[0]],
				[re_compile(x) for x in exclude[1]],
				[re_compile(x) for x in exclude[2]],
				exclude[3]
			)
		else:
			self._exclude = ([], [], [], [])
开发者ID:Hains,项目名称:enigma2-plugins,代码行数:10,代码来源:AutoTimerComponent.py

示例9: setInclude

	def setInclude(self, include):
		if include:
			self._include = (
				[re_compile(x) for x in include[0]],
				[re_compile(x) for x in include[1]],
				[re_compile(x) for x in include[2]],
				include[3]
			)
		else:
			self._include = ([], [], [], [])
开发者ID:Hains,项目名称:enigma2-plugins,代码行数:10,代码来源:AutoTimerComponent.py

示例10: getphylo

    def getphylo(self, seqs, quiet=True):

        seqs = list(seqs)

        if self.__inputfile is None or not exists(self.__inputfile):
            fd, self.__inputfile = mkstemp()
            close(fd)

        with open(self.__inputfile, "w") as fh:
            SeqIO.write(seqs, fh, "fasta")

        newick_mangle = re_compile(r"[()]")

        id_descs = {}
        mangle = re_compile(r"[^a-zA-Z0-9]+", re_I)
        for r in seqs:
            newid = mangle.sub("_", "_".join((r.id, r.description))).rstrip("_")
            id_descs[newid] = (newick_mangle.sub("_", r.id).strip("_"), r.description)

        self.queuevar("_inputFile", self.__inputfile)
        self.runqueue()

        if not quiet:
            if self.stdout != "":
                print(self.stdout, file=stderr)
            if self.warnings != "":
                print(self.warnings, file=stderr)

        if self.stderr != "":
            raise RuntimeError(self.stderr)

        tree = self.getvar("tree", HyphyInterface.STRING)
        with closing(StringIO(self.getvar("ancestors", HyphyInterface.STRING))) as fh:
            fh.seek(0)
            ancestors = AlignIO.read(fh, "fasta")

        hyphymangling = re_compile(r"_[0-9]+$")

        for r in ancestors:
            key = r.id.rstrip("_unknown_description_").rstrip("_")
            if key not in id_descs:
                key = hyphymangling.sub("", key)
                if key not in id_descs:
                    continue
            # if the key exists, replace
            oldid, olddesc = id_descs[key]
            tree = tree.replace(r.id, oldid)
            r.id = oldid
            r.description = olddesc

        if tree[-1] != ";":
            tree += ";"

        return tree, ancestors
开发者ID:erikvolz,项目名称:idepi-ev0,代码行数:54,代码来源:_phylo.py

示例11: valid

    def valid(record, is_dna=False):
        if is_dna:
            regexp = re_compile(r'[^ACGT]')
        else:
            regexp = re_compile(r'[^ACDEFGHIKLMNPQRSTVWY]')

        seq = regexp.sub('', str(record.seq))

        record.letter_annotations.clear()
        record.seq = Seq(seq, record.seq.alphabet)

        return record
开发者ID:BioinformaticsArchive,项目名称:idepi,代码行数:12,代码来源:__init__.py

示例12: pattern

    def pattern(self, format):
        processed_format = ''
        regex_chars = re_compile('([\\\\.^$*+?\\(\\){}\\[\\]|])')
        format = regex_chars.sub('\\\\\\1', format)
        whitespace_replacement = re_compile('\\s+')
        format = whitespace_replacement.sub('\\s+', format)
        while '%' in format:
            directive_index = format.index('%') + 1
            processed_format = '%s%s%s' % (processed_format, format[:directive_index - 1], self[format[directive_index]])
            format = format[directive_index + 1:]

        return '%s%s' % (processed_format, format)
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:12,代码来源:_strptime.py

示例13: process_module

def process_module(rootpath, modulepath):
    """
    build the contents of fname
    """
    mods_to_process = []
    pys_to_process = []
    hidden_py_re = re_compile(r'^__.*__\.py$')
    reg_py_re = re_compile(r'.*\.py$')
    for fname in listdir(modulepath):
        new_mod = join(modulepath, fname)
        if isfile(join(new_mod, '__init__.py')):
            mods_to_process.append(new_mod)
        elif reg_py_re.match(fname) and not hidden_py_re.match(fname):
            pys_to_process.append(new_mod)
    rel_mod_path = relpath(modulepath, rootpath)
    mod_nice_name = rel_mod_path.split(sep)
    new_nice_name = mod_nice_name[-1]
    mod_nice_name = []
    if '_' in new_nice_name and new_nice_name[0] != '_':
        mod_nice_name += new_nice_name.split('_')
    else:
        mod_nice_name.append(new_nice_name)
    mod_nice_name = [x[0].upper()+x[1:] for x in mod_nice_name]
    new_nice_name = ' '.join(mod_nice_name)
    if len(mods_to_process) or len(pys_to_process):
        new_file = open("%s.rst"%(rel_mod_path.replace(sep, '.')), "w")
        new_file.write("""
%s Module
**************************************************************

"""%(new_nice_name))

        if len(mods_to_process):
            new_file.write("""
Contents:

.. toctree::
   :maxdepth: 2

""")
            for new_mod in mods_to_process:
                new_file.write("   "+relpath(new_mod, rootpath).replace(sep, '.')+"\n")
        for new_mod in pys_to_process:
            new_file.write("""
.. automodule:: %s
   :members:
   :private-members:

"""%('.'.join(relpath(new_mod, rootpath).replace(sep, '.').split('.')[1:-1])))
        new_file.close()
开发者ID:EMSL-MSC,项目名称:pacifica-docs,代码行数:50,代码来源:genrst.py

示例14: _infer_i

	def _infer_i(self):
		from re import compile as re_compile
		pattern = re_compile("\%[0-9]*\.?[0-9]*[uifd]")
		match = pattern.split(self.path_format)
		glob_pattern = '*'.join(match)
		fpaths = glob(os.path.join(self.recording_dir, glob_pattern))

		i_pattern = re_compile('(?<={})[0-9]*(?={})'.format(*match))
		try:
			max_i = max([int(i_pattern.findall(i)[0]) for i in fpaths])
			i = max_i + 1
		except ValueError:
			i = 0
		return i
开发者ID:gallantlab,项目名称:realtimefmri,代码行数:14,代码来源:preprocessing.py

示例15: preprocess_seqrecords

def preprocess_seqrecords(seqrecords):
    remove_unknown = re_compile(r'[^ACGTUWSMKRYBDHVN]', re_I)
    strip_front = re_compile(r'^[N]+', re_I)
    strip_rear = re_compile(r'[N]+$', re_I)

    for record in seqrecords:
        seq = str(record.seq)
        seq = remove_unknown.sub('', seq)
        seq = strip_front.sub('', seq)
        seq = strip_rear.sub('', seq)

        record.seq = Seq(seq, generic_nucleotide)

    return
开发者ID:stevenweaver,项目名称:hy454,代码行数:14,代码来源:_preprocessing.py


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