本文整理汇总了Python中core.data.parsers.url.URL类的典型用法代码示例。如果您正苦于以下问题:Python URL类的具体用法?Python URL怎么用?Python URL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_default_proto
def test_default_proto(self):
'''
http is the default protocol, we can provide URLs with no proto
'''
u = URL('w3af.com')
self.assertEqual(u.get_domain(), 'w3af.com')
self.assertEqual(u.get_protocol(), 'http')
示例2: search
def search(self, query, start, count=10):
'''
Search the web with Bing.
This method is based from the msn.py file from the massive enumeration toolset,
coded by pdp and released under GPL v2.
'''
url = 'http://www.bing.com/search?'
query = urllib.urlencode({'q': query,
'first': start + 1,
'FORM': 'PERE'})
url_instance = URL(url + query)
response = self._uri_opener.GET(url_instance, headers=self._headers,
cache=True, grep=False)
# This regex might become outdated, but the good thing is that we have
# test_bing.py which is going to fail and tell us that it's outdated
re_match = re.findall('<a href="((http|https)(.*?))" h="ID=SERP,',
response.get_body())
results = set()
for url, _, _ in re_match:
try:
url = URL(url)
except:
pass
else:
if url.get_domain() not in self.BLACKLISTED_DOMAINS:
bing_result = BingResult(url)
results.add(bing_result)
return results
示例3: test_url_join_case03
def test_url_join_case03(self):
u = URL('http://w3af.com/def/jkl/')
self.assertEqual(u.url_join('/def/abc.html').url_string,
u'http://w3af.com/def/abc.html')
self.assertEqual(u.url_join('def/abc.html').url_string,
u'http://w3af.com/def/jkl/def/abc.html')
示例4: test_simplest_url
def test_simplest_url(self):
u = URL('http://w3af.com/foo/bar.txt')
self.assertEqual(u.path, '/foo/bar.txt')
self.assertEqual(u.scheme, 'http')
self.assertEqual(u.get_file_name(), 'bar.txt')
self.assertEqual(u.get_extension(), 'txt')
示例5: test_encode_decode
def test_encode_decode(self):
'''Encode and Decode should be able to run one on the result of the
other and return the original'''
original = URL(u'https://w3af.com:443/file.asp?id=1%202')
encoded = original.url_encode()
decoded = URL(encoded).url_decode()
self.assertEqual(original, decoded)
示例6: test_url_join_case01
def test_url_join_case01(self):
u = URL('http://w3af.com/foo.bar')
self.assertEqual(u.url_join('abc.html').url_string,
u'http://w3af.com/abc.html')
self.assertEqual(u.url_join('/abc.html').url_string,
u'http://w3af.com/abc.html')
示例7: do_ALL
def do_ALL(self):
global global_first_request
if global_first_request:
global_first_request = False
om.out.information("The user is navigating through the spider_man proxy.")
# Convert to url_object
path = URL(self.path)
if path == TERMINATE_URL:
om.out.information("The user terminated the spider_man session.")
self._send_end()
self._spider_man.stop_proxy()
return
om.out.debug("[spider_man] Handling request: %s %s" % (self.command, path))
# Send this information to the plugin so it can send it to the core
freq = self._create_fuzzable_request()
self._spider_man.append_fuzzable_request(freq)
grep = True
if path.get_domain() != self.server.w3afLayer.target_domain:
grep = False
try:
response = self._send_to_server(grep=grep)
except Exception, e:
self._send_error(e)
示例8: from_httplib_resp
def from_httplib_resp(cls, httplibresp, original_url=None):
'''
Factory function. Build a HTTPResponse object from a httplib.HTTPResponse
instance
:param httplibresp: httplib.HTTPResponse instance
:param original_url: Optional 'url_object' instance.
:return: A HTTPResponse instance
'''
resp = httplibresp
code, msg, hdrs, body = (resp.code, resp.msg, resp.info(), resp.read())
hdrs = Headers(hdrs.items())
if original_url:
url_inst = URL(resp.geturl(), original_url.encoding)
url_inst = url_inst.url_decode()
else:
url_inst = original_url = URL(resp.geturl())
if isinstance(resp, urllib2.HTTPError):
# This is possible because in errors.py I do:
# err = urllib2.HTTPError(req.get_full_url(), code, msg, hdrs, resp)
charset = getattr(resp.fp, 'encoding', None)
else:
# The encoding attribute is only set on CachedResponse instances
charset = getattr(resp, 'encoding', None)
return cls(code, body, hdrs, url_inst, original_url,
msg, charset=charset)
示例9: test_remove_fragment
def test_remove_fragment(self):
u = URL('http://w3af.com/foo/bar.txt?id=3#foobar')
self.assertEqual(u.remove_fragment().url_string,
u'http://w3af.com/foo/bar.txt?id=3')
u = URL('http://w3af.com/foo/bar.txt#foobar')
self.assertEqual(u.remove_fragment().url_string,
u'http://w3af.com/foo/bar.txt')
示例10: http_request
def http_request(self, req):
url_instance = URL(req.get_full_url())
url_instance.set_param(self._url_parameter)
new_request = HTTPRequest(url_instance, headers=req.headers,
origin_req_host=req.get_origin_req_host(),
unverifiable=req.is_unverifiable())
return new_request
示例11: test_from_url
def test_from_url(self):
o = URL('http://w3af.com/foo/bar.txt')
u = URL.from_URL(o)
self.assertEqual(u.path, '/foo/bar.txt')
self.assertEqual(u.scheme, 'http')
self.assertEqual(u.get_file_name(), 'bar.txt')
self.assertEqual(u.get_extension(), 'txt')
o = URL('w3af.com')
u = URL.from_URL(o)
self.assertEqual(u.get_domain(), 'w3af.com')
self.assertEqual(u.get_protocol(), 'http')
示例12: test_set_params
def test_set_params(self):
u = URL('http://w3af.com/;id=1')
u.set_param('file=2')
self.assertEqual(u.get_params_string(), 'file=2')
u = URL('http://w3af.com/xyz.txt;id=1?file=2')
u.set_param('file=3')
self.assertEqual(u.get_params_string(), 'file=3')
self.assertEqual(u.get_path_qs(), '/xyz.txt;file=3?file=2')
示例13: xssed_dot_com
class xssed_dot_com(InfrastructurePlugin):
'''
Search in xssed.com to find xssed pages.
:author: Nicolas Crocfer ([email protected])
:author: Raul Siles: set "." in front of the root domain to limit search
'''
def __init__(self):
InfrastructurePlugin.__init__(self)
#
# Could change in time,
#
self._xssed_url = URL("http://www.xssed.com")
self._fixed = "<img src='http://data.xssed.org/images/fixed.gif'> FIXED</th>"
@runonce(exc_class=w3afRunOnce)
def discover(self, fuzzable_request):
'''
Search in xssed.com and parse the output.
:param fuzzable_request: A fuzzable_request instance that contains
(among other things) the URL to test.
'''
target_domain = fuzzable_request.get_url().get_root_domain()
try:
check_url = self._xssed_url.url_join(
"/search?key=." + target_domain)
response = self._uri_opener.GET(check_url)
except w3afException, e:
msg = 'An exception was raised while running xssed_dot_com'\
' plugin. Exception: "%s".' % e
om.out.debug(msg)
else:
示例14: __init__
def __init__(self):
InfrastructurePlugin.__init__(self)
#
# Could change in time,
#
self._xssed_url = URL("http://www.xssed.com")
self._fixed = "<img src='http://data.xssed.org/images/fixed.gif'> FIXED</th>"
示例15: test_from_parts
def test_from_parts(self):
u = URL.from_parts('http', 'w3af.com', '/foo/bar.txt', None, 'a=b',
'frag')
self.assertEqual(u.path, '/foo/bar.txt')
self.assertEqual(u.scheme, 'http')
self.assertEqual(u.get_file_name(), 'bar.txt')
self.assertEqual(u.get_extension(), 'txt')