Best Python code snippet using gabbi_python
__init__.py
Source:__init__.py  
...647                data = self._url_re.sub(functools.partial(self._url_replace, path), data)648                return "{% raw %}<style type=\"text/css\">\n" + data + "\n</style>{% endraw %}"649        tagcontent = match.group("attributes")650        return '<link%s%s>' % (tagcontent, "" if tagcontent[-1] == "/" else "/")651    def _url_replace(self, path, match):652        url = match.group("url").strip("'").strip("\"")653        if self._check_uri(url):654            path = os.path.dirname(path)655            if url.startswith("/") or not path:656                absurl = self.static + "/" + url.lstrip("/")657            else:658                absurl = path + "/" + url659            absurl = os.path.normpath(absurl).replace(os.sep, "/")660            if absurl.startswith(self.static + "/"):661                url = absurl[len(self.static)+1:]662                ext = url[url.rfind(".")+1:]663                if ext in ("gif", "png", "jpg") and utils.get_resource_exists(absurl):664                    data = "data:image/" + ext + ";base64," + base64.b64encode(utils.get_resource_data(absurl))665                    return "url({% endraw %}{% if uridata_support %}" + data + "{% else %}'" + url + "'{% endif %}{% raw %})"...1.text_cleaning.py
Source:1.text_cleaning.py  
...64    text = text.strip()65    for rgx in remove_regx_map:66        text = re.sub(rgx, remove_regx_map[rgx], text)67    return text68def _url_replace(text):69    """ url 龿¥æ¿æ¢ï¼æ³¨æçæ¡ä¸ä¹åå¨ urlï¼é¢æµå®çæ¡åå mapping 忥 """70    for url in url_map_dict:71        if url in text:72            text = text.replace(url, url_map_dict[url])73    return text74def _clean_duplacte_words(text):75    """76    å»é¤å¾å¤éå¤çè¯åæ ç¹ç¬¦å·77    """78    reg = r'([^0-9IX]+)(\1){2,}'79    for i in range(6):80        temp = text81        text = re.sub(reg, lambda m: m.group(1), text)82        if len(text) == len(temp):83            break84    return text85def clean_document(document, answers=None):86    title = document['title']87    paragraphs = document['paragraphs']88    # --------------------- clean title ---------------------89    title = _remove_html_tag(title)90    title = _remove_by_regex(title)91    # remove website name92    if '_' in title:93        title = ''.join(title.split('_')[:-1])94    elif '-' in title:95        title = ''.join(title.split('-')[:-1])96    # --------------------- clean paragraphs ---------------------97    # ans_has_html = re.match('<[a-zA-Z]+>', ''.join(answers), flags=0) is not None98    new_paragraphs = []99    for paragraph in paragraphs:100        # 大éurl龿¥çæ¸
æ´101        paragraph = paragraph.replace('httpï¼//', 'http://')102        paragraph = paragraph.replace('httpsï¼//', 'https://')103        paragraph = _url_replace(paragraph)104        # å¦æçæ¡å
嫿 ç¾å䏿¸
æ´htmlæ ç¾105        # if not ans_has_html:106        paragraph = _remove_html_tag(paragraph)107        # é误è¯ç纠æ£108        paragraph = _clean_error_word(paragraph)109        # æç
§æ£å表达å¼å»é¤ç¹å®ææ¬110        paragraph = _remove_by_regex(paragraph)111        # å»é¤ç©ºæ ¼112        paragraph = _remove_space(paragraph)113        # å»é¤éå¤çè¯114        paragraph = _clean_duplacte_words(paragraph)115        # å»é¤ç©ºæ®µè½åé夿®µè½116        if paragraph != '' and paragraph not in new_paragraphs:117            new_paragraphs.append(paragraph)...test.py
Source:test.py  
...18    c = re.compile(p)19    print c.match('Isaac Asimov')20 21def test2():22    def _url_replace(matchobj):23        return '<a href=\'http://www.15yueliang.com\'>%s</a>'%matchobj.group('mp')24    a='''<a go='http://wwwbaidu.com'>123</a>456<a go='http://www.youxi.com'>112233</a>'''25    rs=re.subn('<a go=\'.*?\'>(?P<mp>.*?)</a>',_url_replace,a)26    print rs27def test3():28    s='<div class="goods_ref" itemprop="6910"><a isconvert="1" href="http://detail.tmall.com/item.htm?id=43538143059" rel="nofollow" target="_blank"><img src="http://img2.tbcdn.cn/tfscom/i3/749311050/TB2Zt9XhFXXXXXhXpXXXXXXXXXX_!!749311050.jpg"/></a><a isconvert="1" href="http://detail.tmall.com/item.htm?id=43538143059" rel="nofollow" target="_blank"><h3>è´äº² å¤åè½æä¹³æ å奶æåå¦åºä¹³æåºä¹³æå«å奶æ¤è
° å©´å¿æ±æ</h3></a><div class="info"><em>ä»·æ ¼:</em><span class="price">249.00å
å
é®</span><span class="mall"><a href="http://www.15yueliang.com/go/tmall/mall/0.html" rel="nofollow" target="_blank">天ç«</a></span><span class="volume">éé:27</span></div><div class="ad"></div></div>'29    30    m=re.match(r'<div class=["\']{1}goods_ref["\']{1}.*?</div></div>',s)31    print m32if __name__ == '__main__':    33    # print test2()%({'meida_url':'http://www.youxi16.com'})34    # test2()...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
