本文整理汇总了Python中w3af.core.data.parsers.doc.sgml.SGMLParser类的典型用法代码示例。如果您正苦于以下问题:Python SGMLParser类的具体用法?Python SGMLParser怎么用?Python SGMLParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SGMLParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_extract_emails_mailto
def test_extract_emails_mailto(self):
body = u'<a href="mailto:[email protected]">test</a>'
resp = build_http_response(self.url, body)
p = SGMLParser(resp)
p.parse()
expected_res = {u'[email protected]'}
self.assertEqual(p.get_emails(), expected_res)
开发者ID:andresriancho,项目名称:w3af,代码行数:8,代码来源:test_sgml.py
示例2: test_mailto_ignored_in_links
def test_mailto_ignored_in_links(self):
body = u'<a href="mailto:[email protected]">a</a>'
resp = build_http_response(self.url, body)
p = SGMLParser(resp)
p.parse()
parsed, _ = p.references
self.assertEqual(parsed, [])
开发者ID:andresriancho,项目名称:w3af,代码行数:8,代码来源:test_sgml.py
示例3: test_get_emails_filter
def test_get_emails_filter(self):
resp = build_http_response(self.url, '')
p = SGMLParser(resp)
p._emails = {'[email protected]', '[email protected]'}
self.assertEqual(p.get_emails(), {'[email protected]', '[email protected]'})
self.assertEqual(p.get_emails(domain='w3af.com'), ['[email protected]'])
self.assertEqual(p.get_emails(domain='not.com'), ['[email protected]'])
开发者ID:andresriancho,项目名称:w3af,代码行数:9,代码来源:test_sgml.py
示例4: close
def close(self):
"""
Called by the parser when it ends
"""
SGMLParser.close(self)
# Don't call clear() here! That would call clear() on SGMLParser and
# remove all the forms, references, etc.
self._html_internals_clear()
开发者ID:0x554simon,项目名称:w3af,代码行数:9,代码来源:html.py
示例5: _handle_textarea_tag_inside_form
def _handle_textarea_tag_inside_form(self, tag, tag_name, attrs):
"""
Handler for textarea tag inside a form
"""
SGMLParser._handle_textarea_tag_start(self, tag, tag_name, attrs)
# Set the data and name
self._text_area_data = tag.text
self._text_area_tag_name = get_value_by_key(attrs, 'name', 'id')
开发者ID:0x554simon,项目名称:w3af,代码行数:9,代码来源:html.py
示例6: test_mailto_subject_body
def test_mailto_subject_body(self):
body = u'<a href="mailto:[email protected]?subject=testing out mailto'\
u'&body=Just testing">test</a>'
resp = build_http_response(self.url, body)
p = SGMLParser(resp)
p.parse()
expected_res = {u'[email protected]'}
self.assertEqual(p.get_emails(), expected_res)
开发者ID:andresriancho,项目名称:w3af,代码行数:9,代码来源:test_sgml.py
示例7: test_get_clear_text_body
def test_get_clear_text_body(self):
html = 'header <b>ABC</b>-<b>DEF</b>-<b>XYZ</b> footer'
clear_text = 'header ABC-DEF-XYZ footer'
headers = Headers([('Content-Type', 'text/html')])
r = build_http_response(self.url, html, headers)
p = SGMLParser(r)
p.parse()
self.assertEquals(clear_text, p.get_clear_text_body())
开发者ID:andresriancho,项目名称:w3af,代码行数:10,代码来源:test_sgml.py
示例8: test_meta_tags
def test_meta_tags(self):
body = HTML_DOC % \
{'head': META_REFRESH + META_REFRESH_WITH_URL,
'body': ''}
resp = build_http_response(self.url, body)
p = SGMLParser(resp)
p.parse()
self.assertTrue(2, len(p.meta_redirs))
self.assertTrue("2;url=http://crawler.w3af.com/" in p.meta_redirs)
self.assertTrue("600" in p.meta_redirs)
self.assertEquals([URL('http://crawler.w3af.com/')], p.references[0])
开发者ID:everping,项目名称:w3af,代码行数:11,代码来源:test_sgml.py
示例9: test_nested_with_text
def test_nested_with_text(self):
body = '<html><a href="/abc">foo<div>bar</div></a></html>'
url = URL('http://www.w3af.com/')
headers = Headers()
headers['content-type'] = 'text/html'
resp = HTTPResponse(200, body, headers, url, url, charset='utf-8')
p = SGMLParser(resp)
tags = p.get_tags_by_filter(('a', 'b'), yield_text=True)
tags = list(tags)
self.assertEqual([Tag('a', {'href': '/abc'}, 'foo')], tags)
开发者ID:andresriancho,项目名称:w3af,代码行数:12,代码来源:test_sgml.py
示例10: _handle_script_tag_start
def _handle_script_tag_start(self, tag, tag_name, attrs):
"""
Handle the script tags
"""
SGMLParser._handle_script_tag_start(self, tag, tag_name, attrs)
if tag.text is not None:
re_extract = ReExtract(tag.text.strip(),
self._base_url,
self._encoding)
re_extract.parse()
self._re_urls.update(re_extract.get_references())
开发者ID:0x554simon,项目名称:w3af,代码行数:12,代码来源:html.py
示例11: test_meta_tags_with_single_quotes
def test_meta_tags_with_single_quotes(self):
body = HTML_DOC % {'head': META_REFRESH + META_REFRESH_WITH_URL_AND_QUOTES,
'body': ''}
resp = build_http_response(self.url, body)
p = SGMLParser(resp)
p.parse()
self.assertEqual(2, len(p.meta_redirs))
self.assertIn("2;url='http://crawler.w3af.com/'", p.meta_redirs)
self.assertIn("600", p.meta_redirs)
self.assertEqual([URL('http://crawler.w3af.com/')], p.references[0])
开发者ID:andresriancho,项目名称:w3af,代码行数:12,代码来源:test_sgml.py
示例12: test_none
def test_none(self):
body = '<html><a href="/abc">foo<div>bar</div></a></html>'
url = URL('http://www.w3af.com/')
headers = Headers()
headers['content-type'] = 'text/html'
resp = HTTPResponse(200, body, headers, url, url, charset='utf-8')
p = SGMLParser(resp)
tags = p.get_tags_by_filter(None)
tags = list(tags)
tag_names = [tag.name for tag in tags]
self.assertEqual(tag_names, ['html', 'body', 'a', 'div'])
开发者ID:andresriancho,项目名称:w3af,代码行数:13,代码来源:test_sgml.py
示例13: test_reference_with_colon
def test_reference_with_colon(self):
body = """
<html>
<a href="d:url.html?id=13&subid=3">foo</a>
</html>"""
r = build_http_response(self.url, body)
p = SGMLParser(r)
p.parse()
parsed_refs = p.references[0]
#
# Finding zero URLs is the correct behavior based on what
# I've seen in Opera and Chrome.
#
self.assertEquals(0, len(parsed_refs))
开发者ID:andresriancho,项目名称:w3af,代码行数:14,代码来源:test_sgml.py
示例14: _handle_form_tag_start
def _handle_form_tag_start(self, tag, tag_name, attrs):
"""
Handle the form tags.
This method also looks if there are "pending inputs" in the
self._saved_inputs list and parses them.
"""
SGMLParser._handle_form_tag_start(self, tag, tag_name, attrs)
method = attrs.get('method', 'GET').upper()
action = attrs.get('action', None)
form_encoding = attrs.get('enctype', DEFAULT_FORM_ENCODING)
autocomplete = attrs.get('autocomplete', None)
if action is None:
action = self._source_url
else:
action = self._decode_url(action)
try:
action = self._base_url.url_join(action,
encoding=self._encoding)
except ValueError:
# The URL in the action is invalid, the best thing we can do
# is to guess, and our best guess is that the URL will be the
# current one.
action = self._source_url
# Create the form object and store everything for later use
form_params = FormParameters(encoding=self._encoding,
method=method,
action=action,
form_encoding=form_encoding,
attributes=attrs,
hosted_at_url=self._source_url)
form_params.set_autocomplete(autocomplete)
self._forms.append(form_params)
# Now I verify if there are any input tags that were found
# outside the scope of a form tag
for input_attrs in self._saved_inputs:
# Parse them just like if they were found AFTER the
# form tag opening
self._handle_input_tag_inside_form(tag, 'input', input_attrs)
# All parsed, remove them.
self._saved_inputs = []
开发者ID:everping,项目名称:w3af,代码行数:47,代码来源:html.py
示例15: test_parsed_references
def test_parsed_references(self):
# The *parsed* urls *must* come both from valid tags and tag attributes
# Also invalid urls like must be ignored (like javascript instructions)
body = """
<html>
<a href="/x.py?a=1" Invalid_Attr="/invalid_url.php">
<form action="javascript:history.back(1)">
<tagX href="/py.py"/>
</form>
</html>"""
r = build_http_response(self.url, body)
p = SGMLParser(r)
p.parse()
parsed_refs = p.references[0]
self.assertEquals(1, len(parsed_refs))
self.assertEquals(
'http://w3af.com/x.py?a=1', parsed_refs[0].url_string)
开发者ID:andresriancho,项目名称:w3af,代码行数:17,代码来源:test_sgml.py
示例16: test_get_clear_text_body_encodings
def test_get_clear_text_body_encodings(self):
raise SkipTest('Not sure why this one is failing :S')
for lang_desc, (body, encoding) in TEST_RESPONSES.iteritems():
encoding_header = 'text/html; charset=%s' % encoding
headers = Headers([('Content-Type', encoding_header)])
encoded_body = body.encode(encoding)
r = build_http_response(self.url, encoded_body, headers)
p = SGMLParser(r)
p.parse()
ct_body = p.get_clear_text_body()
# These test strings don't really have tags, so they should be eq
self.assertEqual(ct_body, body)
开发者ID:andresriancho,项目名称:w3af,代码行数:18,代码来源:test_sgml.py
示例17: __init__
def __init__(self, http_resp):
# An internal list to be used to save input tags found
# outside of the scope of a form tag.
self._saved_inputs = []
# For <textarea> elems parsing
self._text_area_tag_name = None
self._text_area_data = None
# Save for using in form parsing
self._source_url = http_resp.get_url()
self._re_urls = set()
# For <select> and <option> parsing
self._select_option_values = set()
self._select_input_name = None
# Call parent's __init__
SGMLParser.__init__(self, http_resp)
开发者ID:0x554simon,项目名称:w3af,代码行数:19,代码来源:html.py
示例18: test_get_clear_text_issue_4402
def test_get_clear_text_issue_4402(self):
"""
:see: https://github.com/andresriancho/w3af/issues/4402
"""
test_file_path = 'core/data/url/tests/data/encoding_4402.php'
test_file = os.path.join(ROOT_PATH, test_file_path)
body = file(test_file, 'rb').read()
sample_encodings = [encoding for _, (_, encoding) in TEST_RESPONSES.iteritems()]
sample_encodings.extend(['', 'utf-8'])
for encoding in sample_encodings:
encoding_header = 'text/html; charset=%s' % encoding
headers = Headers([('Content-Type', encoding_header)])
r = build_http_response(self.url, body, headers)
p = SGMLParser(r)
p.parse()
p.get_clear_text_body()
开发者ID:andresriancho,项目名称:w3af,代码行数:21,代码来源:test_sgml.py
示例19: test_case_sensitivity
def test_case_sensitivity(self):
"""
Ensure handler methods are *always* called with lowered-cased
tag and attribute names
"""
def islower(s):
il = False
if isinstance(s, basestring):
il = s.islower()
else:
il = all(k.islower() for k in s)
assert il, "'%s' is not lowered-case" % s
return il
def start_wrapper(orig_start, tag):
islower(tag.tag)
islower(tag.attrib)
return orig_start(tag)
tags = (A_LINK_ABSOLUTE, INPUT_CHECKBOX_WITH_NAME, SELECT_WITH_NAME,
TEXTAREA_WITH_ID_AND_DATA, INPUT_HIDDEN)
ops = "lower", "upper", "title"
for indexes in combinations(range(len(tags)), 2):
body_elems = []
for index, tag in enumerate(tags):
ele = tag
if index in indexes:
ele = getattr(tag, choice(ops))()
body_elems.append(ele)
body = HTML_DOC % {'head': '', 'body': ''.join(body_elems)}
resp = build_http_response(self.url, body)
p = SGMLParser(resp)
orig_start = p.start
wrapped_start = partial(start_wrapper, orig_start)
p.start = wrapped_start
p.parse()
开发者ID:andresriancho,项目名称:w3af,代码行数:40,代码来源:test_sgml.py
示例20: _handle_select_tag_end
def _handle_select_tag_end(self, tag):
"""
Handler for select end tag
"""
SGMLParser._handle_select_tag_end(self, tag)
if not self._forms:
return
if not self._select_input_name:
return
attrs = {'name': self._select_input_name,
'values': list(self._select_option_values),
'type': INPUT_TYPE_SELECT}
# Work with the last form
form_params = self._forms[-1]
form_params.add_field_by_attrs(attrs)
# Reset selects container
self._select_option_values = set()
self._select_input_name = None
开发者ID:0x554simon,项目名称:w3af,代码行数:23,代码来源:html.py
注:本文中的w3af.core.data.parsers.doc.sgml.SGMLParser类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论