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


Python re.DOTALL属性代码示例

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


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

示例1: ssh_edit_file

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def ssh_edit_file(adress, user, passw, remotefile, regex, replace):
        client = paramiko.SSHClient()
        client.load_system_host_keys()
        client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        trans = paramiko.Transport((adress, 22))
        trans.connect(username=user, password=passw)
        sftp = paramiko.SFTPClient.from_transport(trans)
        f_in = sftp.file(remotefile, "r")
        c_in = f_in.read()
        pattern = re.compile(regex, re.MULTILINE | re.DOTALL)
        c_out = pattern.sub(replace, c_in)
        f_out = sftp.file(remotefile, "w")
        f_out.write(c_out)
        f_in.close()
        f_out.close()
        sftp.close()
        trans.close() 
开发者ID:dsp-jetpack,项目名称:JetPack,代码行数:19,代码来源:ssh.py

示例2: update_sys_cfg_file

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def update_sys_cfg_file(uninstall_distro_dir_name):
    """
    Main function to remove uninstall distro specific operations.
    :return:
    """

    sys_cfg_file = os.path.join(config.usb_mount, "multibootusb", "syslinux.cfg")
    if not os.path.exists(sys_cfg_file):
        gen.log("syslinux.cfg file not found for updating changes.")
    else:
        gen.log("Updating syslinux.cfg file...")
        string = open(sys_cfg_file).read()
        string = re.sub(r'#start ' + re.escape(uninstall_distro_dir_name)
                        + '.*?' + '#end '
                        + re.escape(uninstall_distro_dir_name)
                        + r'\s*', '', string, flags=re.DOTALL)
        config_file = open(sys_cfg_file, "w")
        config_file.write(string)
        config_file.close() 
开发者ID:mbusb,项目名称:multibootusb,代码行数:21,代码来源:uninstall_distro.py

示例3: update_grub_cfg_file

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def update_grub_cfg_file(uninstall_distro_dir_name):
    """
    Main function to remove uninstall distro name from the grub.cfg file.
    :return:
    """

    grub_cfg_file = os.path.join(config.usb_mount, "multibootusb",
                                 "grub", "grub.cfg")
    if not os.path.exists(grub_cfg_file):
        gen.log("grub.cfg file not found for updating changes.")
    else:
        gen.log("Updating grub.cfg file...")
        string = open(grub_cfg_file).read()
        string = re.sub(r'#start ' + re.escape(uninstall_distro_dir_name)
                        + '.*?' + '#end '
                        + re.escape(uninstall_distro_dir_name)
                        + r'\s*', '', string, flags=re.DOTALL)
        config_file = open(grub_cfg_file, "w")
        config_file.write(string)
        config_file.close() 
开发者ID:mbusb,项目名称:multibootusb,代码行数:22,代码来源:uninstall_distro.py

示例4: render_re

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def render_re(regex):
  """Renders a repr()-style value for a compiled regular expression."""
  actual_flags = []
  if regex.flags:
    flags = [
      (re.IGNORECASE, 'IGNORECASE'),
      (re.LOCALE, 'LOCALE'),
      (re.UNICODE, 'UNICODE'),
      (re.MULTILINE, 'MULTILINE'),
      (re.DOTALL, 'DOTALL'),
      (re.VERBOSE, 'VERBOSE'),
    ]
    for val, name in flags:
      if regex.flags & val:
        actual_flags.append(name)
  if actual_flags:
    return 're.compile(%r, %s)' % (regex.pattern, '|'.join(actual_flags))
  else:
    return 're.compile(%r)' % regex.pattern 
开发者ID:luci,项目名称:recipes-py,代码行数:21,代码来源:magic_check_fn.py

示例5: parse

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def parse(self, response):
        soup = BeautifulSoup(response.content.decode("utf-8", "ignore"), "lxml")
        # image_divs = soup.find_all('script')
        image_divs = soup.find_all(name="script")
        for div in image_divs:
            # txt = div.text
            txt = str(div)
            # if not txt.startswith('AF_initDataCallback'):
            if "AF_initDataCallback" not in txt:
                continue
            if "ds:0" in txt or "ds:1" not in txt:
                continue
            # txt = re.sub(r"^AF_initDataCallback\({.*key: 'ds:(\d)'.+data:function\(\){return (.+)}}\);?$",
            #             "\\2", txt, 0, re.DOTALL)
            # meta = json.loads(txt)
            # data = meta[31][0][12][2]
            # uris = [img[1][3][0] for img in data if img[0] == 1]

            uris = re.findall(r"http.*?\.(?:jpg|png|bmp)", txt)
            return [{"file_url": uri} for uri in uris] 
开发者ID:cwerner,项目名称:fastclass,代码行数:22,代码来源:googleparserfix.py

示例6: scanner

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def scanner(cls):
        if not getattr(cls, '_scanner', None):
            def h(tpe):
                return lambda sc, tk: cls.Token(tpe, tk)

            cls._scanner = re.Scanner([
                (r"(--|//).*?$",               h(cls.LINE_COMMENT)),
                (r"\/\*.+?\*\/",               h(cls.BLOCK_COMMENT)),
                (r'"(?:[^"\\]|\\.)*"',         h(cls.STRING)),
                (r"'(?:[^'\\]|\\.)*'",         h(cls.STRING)),
                (r"\$\$(?:[^\$\\]|\\.)*\$\$",  h(cls.STRING)),
                (r";",                         h(cls.SEMICOLON)),
                (r"\s+",                       h(cls.WHITESPACE)),
                (r".",                         h(cls.OTHER))
            ], re.MULTILINE | re.DOTALL)
        return cls._scanner 
开发者ID:Cobliteam,项目名称:cassandra-migrate,代码行数:18,代码来源:cql.py

示例7: helper

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def helper(self, term_instance):
        """
        Called at the start of a WAV file capture.  Calculates the length of the
        file and modifies `self.re_capture` with laser precision.
        """
        data = term_instance.capture
        self.wav_header = struct.unpack(
            '4si4s4sihhiihh4si', self.re_wav_header.match(data).group())
        self.wav_length = self.wav_header[1] + 8
        if not self.sent_message:
            channels = "mono"
            if self.wav_header[6] == 2:
                channels = "stereo"
            if self.wav_length != self.wav_header[12] + 44:
                # Corrupt WAV file
                message = _("WAV File is corrupted: Header data mismatch.")
                term_instance.send_message(message)
                term_instance.cancel_capture = True
            message = _("WAV File: %skHz (%s)" % (self.wav_header[7], channels))
            term_instance.send_message(message)
            self.sent_message = True
        # Update the capture regex with laser precision:
        self.re_capture = re.compile(
            b'(RIFF....WAVE.{%s})' % (self.wav_length-12), re.DOTALL) 
开发者ID:Wramberg,项目名称:TerminalView,代码行数:26,代码来源:terminal.py

示例8: show_system_resources

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def show_system_resources(self):
        self.xapi.op(cmd="show system resources", cmd_xml=True)
        result = self.xapi.xml_root()
        regex = re.compile(r"load average: ([\d.]+).* ([\d.]+)%id.*Mem:.*?([\d.]+)k total.*?([\d]+)k free", re.DOTALL)
        match = regex.search(result)
        if match:
            """
            return cpu, mem_free, load
            """
            return {
                'load': Decimal(match.group(1)),
                'cpu': 100 - Decimal(match.group(2)),
                'mem_total': int(match.group(3)),
                'mem_free': int(match.group(4)),
            }
        else:
            raise err.PanDeviceError("Problem parsing show system resources",
                                     pan_device=self) 
开发者ID:PaloAltoNetworks,项目名称:terraform-templates,代码行数:20,代码来源:firewall.py

示例9: __init__

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def __init__(self, exception, regexp=None):
        """
        Initialize an _AssertRaisesContextManager instance.

        Parameters
        ----------
        exception : class
            The expected Exception class.
        regexp : str, default None
            The regex to compare against the Exception message.
        """

        self.exception = exception

        if regexp is not None and not hasattr(regexp, "search"):
            regexp = re.compile(regexp, re.DOTALL)

        self.regexp = regexp 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:testing.py

示例10: str_flags_to_int

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def str_flags_to_int(str_flags):
    flags = 0
    if "i" in str_flags:
        flags |= re.IGNORECASE
    if "l" in str_flags:
        flags |= re.LOCALE
    if "m" in str_flags:
        flags |= re.MULTILINE
    if "s" in str_flags:
        flags |= re.DOTALL
    if "u" in str_flags:
        flags |= re.UNICODE
    if "x" in str_flags:
        flags |= re.VERBOSE

    return flags 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:18,代码来源:regex.py

示例11: add_decks

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def add_decks(dt: datetime.datetime, competition_id: int, final: Dict[str, int], s: str) -> int:
    # The HTML of this page is so badly malformed that BeautifulSoup cannot really help us with this bit.
    rows = re.findall('<tr style=">(.*?)</tr>', s, re.MULTILINE | re.DOTALL)
    decks_added, ds = 0, []
    matches: List[bs4.element.Tag] = []
    for row in rows:
        cells = BeautifulSoup(row, 'html.parser').find_all('td')
        d = tournament_deck(cells, competition_id, dt, final)
        if d is not None:
            if d.get('id') is None or not match.load_matches_by_deck(d):
                decks_added += 1
                ds.append(d)
                matches += tournament_matches(d)
    add_ids(matches, ds)
    insert_matches_without_dupes(dt, matches)
    guess_archetypes(ds)
    return decks_added 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:19,代码来源:gatherling.py

示例12: medal_winners

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def medal_winners(s: str) -> Dict[str, int]:
    winners = {}
    # The HTML of this page is so badly malformed that BeautifulSoup cannot really help us with this bit.
    rows = re.findall('<tr style=">(.*?)</tr>', s, re.MULTILINE | re.DOTALL)
    for row in rows:
        player = BeautifulSoup(row, 'html.parser').find_all('td')[2]
        if player.find('img'):
            mtgo_username = aliased(player.a.contents[0])
            img = re.sub(r'styles/Chandra/images/(.*?)\.png', r'\1', player.img['src'])
            if img == WINNER:
                winners[mtgo_username] = 1
            elif img == SECOND:
                winners[mtgo_username] = 2
            elif img == TOP_4:
                winners[mtgo_username] = 3
            elif img == TOP_8:
                winners[mtgo_username] = 5
            elif img == 'verified':
                pass
            else:
                raise InvalidDataException('Unknown player image `{img}`'.format(img=img))
    return winners 
开发者ID:PennyDreadfulMTG,项目名称:Penny-Dreadful-Tools,代码行数:24,代码来源:gatherling.py

示例13: seasons

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def seasons(season_url = common.args.url):
	seasons = []
	season_data = connection.getURL(season_url)
	try:
		playlist = re.compile('"playlists":\s*(\[.*?\])', re.DOTALL).findall(season_data)[0]
		season_menu = simplejson.loads(playlist)
		for season_item in season_menu:
			seasons.append((season_item['name'],  SITE, 'episodes', FEED % season_item['guid'], -1, -1))
	except:
		try:
			season_tree = BeautifulSoup(season_data, 'html.parser', parse_only = SoupStrainer('div'))
			season_source = season_tree.find('div', id = 'TPVideoPlaylistTaxonomyContainer')['source']
			playlist_url = PLAYLIST % season_source
			playlist_data = connection.getURL(playlist_url)
			playlist_data = playlist_data.replace('$pdk.NBCplayer.ShowPlayerTaxonomy.GetList(', '').replace(');', '')
			season_menu = simplejson.loads(playlist_data)
			for season_item in season_menu['playlistTaxonomy']:
				season_name =  season_item['reference']['name']
				season_url = FEED % season_item['reference']['feed']
				seasons.append((season_name, SITE, 'episodes', season_url, -1, -1))
		except Exception:
			pass
	return seasons 
开发者ID:moneymaker365,项目名称:plugin.video.ustvvod,代码行数:25,代码来源:msnbc.py

示例14: play_video

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def play_video(video_url = common.args.url):
	stored_size = 0
	video_data = connection.getURL(video_url)
	video_model = re.compile('model: *(\[.*\]),\s*videoPlayer: _player,', re.DOTALL).findall(video_data)[0]
	video_model = simplejson.loads(video_model)
	try:
		sbitrate = long(addon.getSetting('quality')) * 1000
	except Exception as e:
		print "Exception: ", e
	hbitrate = -1
	print sbitrate
	for item in video_model[0]['flavors']:
		if item['format'] == 'mp4' and item['security_profile'][0] == 'progressive':
			bitrate = item['bitrate']
			if bitrate > hbitrate and bitrate <= sbitrate:
				hbitrate = bitrate
				url = item['url']
	finalurl = url
	xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path = finalurl)) 
开发者ID:moneymaker365,项目名称:plugin.video.ustvvod,代码行数:21,代码来源:marvelkids.py

示例15: parse

# 需要导入模块: import re [as 别名]
# 或者: from re import DOTALL [as 别名]
def parse(self, response):
        soup = BeautifulSoup(
            response.content.decode('utf-8', 'ignore'), 'lxml')
        image_divs = soup.find_all('script')
        for div in image_divs:
            txt = div.string
            if txt is None or not txt.startswith('AF_initDataCallback'):
                continue
            if 'ds:1' not in txt:
                continue
            txt = re.sub(r"^AF_initDataCallback\({.*key: 'ds:(\d)'.+data:function\(\){return (.+)}}\);?$",
                         "\\2", txt, 0, re.DOTALL)

            meta = json.loads(txt)
            data = meta[31][0][12][2]

            uris = [img[1][3][0] for img in data if img[0] == 1]
            return [{'file_url': uri} for uri in uris] 
开发者ID:hellock,项目名称:icrawler,代码行数:20,代码来源:google.py


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