How to use _url_replace method in gabbi

Best Python code snippet using gabbi_python

__init__.py

Source:__init__.py Github

copy

Full Screen

...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 %})"...

Full Screen

Full Screen

1.text_cleaning.py

Source:1.text_cleaning.py Github

copy

Full Screen

...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)...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...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()...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run gabbi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful