本文整理汇总了Python中mechanize.Browser.response方法的典型用法代码示例。如果您正苦于以下问题:Python Browser.response方法的具体用法?Python Browser.response怎么用?Python Browser.response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mechanize.Browser
的用法示例。
在下文中一共展示了Browser.response方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_comment_vote_with_wrong_record
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_comment_vote_with_wrong_record(self):
"""webcomment - vote for a comment using mismatching recid"""
# Juliet should not be able to vote for a comment she cannot access, especially through public recid
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'juliet'
br['p_pw'] = 'j123uliet'
br.submit()
br.open("%s/%s/%i/comments/vote?comid=%s&com_value=1&ln=en" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
if not "Authorization failure" in response:
self.fail("Oops, this user should not be able to report a deleted comment")
# Jekyll should also not be able to vote for the comment using the wrong recid
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'jekyll'
br['p_pw'] = 'j123ekyll'
br.submit()
br.open("%s/%s/%i/comments/vote?comid=%s&com_value=1&ln=en" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
if not "Authorization failure" in response:
self.fail("Oops, users should not be able to report using mismatching recid")
示例2: test_comment_subscribe_public_record_restricted_discussion
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_comment_subscribe_public_record_restricted_discussion(self):
"""webcomment - subscribe to a discussion restricted with 'viewcomment'"""
# Juliet should not be able to subscribe to the discussion
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'juliet'
br['p_pw'] = 'j123uliet'
br.submit()
br.open("%s/%s/%i/comments/subscribe?ln=en" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.restricted_discussion))
response = br.response().read()
if not "Authorization failure" in response:
self.fail("Oops, this user should not be able to subscribe to this discussion")
# Romeo should be able to subscribe
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'romeo'
br['p_pw'] = 'r123omeo'
br.submit()
br.open("%s/%s/%i/comments/subscribe?ln=en" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.restricted_discussion))
response = br.response().read()
if not "You have been subscribed" in response or \
"Authorization failure" in response:
print response
self.fail("Oops, this user should be able to subscribe to this discussion")
示例3: test_comment_reply_with_wrong_record
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_comment_reply_with_wrong_record(self):
"""webcomment - replying to comment using mismatching recid"""
# Juliet should not be able to reply to the comment, even through a public record
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'juliet'
br['p_pw'] = 'j123uliet'
br.submit()
br.open("%s/%s/%i/comments/add?action=REPLY&comid=%s&ln=en" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
if not self.msg2 in response and \
"Authorization failure" in response:
pass
else:
self.fail("Oops, users should not be able to reply to comment using mismatching recid")
# Jekyll should also not be able to reply the comment using the wrong recid
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'jekyll'
br['p_pw'] = 'j123ekyll'
br.submit()
br.open("%s/%s/%i/comments/add?action=REPLY&comid=%s&ln=en" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
if not self.msg2 in response and \
"Authorization failure" in response:
pass
else:
self.fail("Oops, users should not be able to reply to comment using mismatching recid")
示例4: test_comment_access_attachment_with_wrong_record
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_comment_access_attachment_with_wrong_record(self):
"""webcomment - accessing attachments using mismatching recid"""
# Juliet should not be able to access these files, especially with wrong recid
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'juliet'
br['p_pw'] = 'j123uliet'
br.submit()
try:
br.open("%s/%s/%i/comments/attachments/get/%i/file2" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
except HTTPError:
pass
else:
self.fail("Oops, users should not be able to access comment attachment using mismatching recid")
# Jekyll should also not be able to access these files when using wrong recid
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'jekyll'
br['p_pw'] = 'j123ekyll'
br.submit()
try:
br.open("%s/%s/%i/comments/attachments/get/%i/file2" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.restr_comid_1))
response = br.response().read()
response = br.response().read()
except HTTPError:
pass
else:
self.fail("Oops, users should not be able to access comment attachment using mismatching recid")
示例5: test_external_groups_visibility_messagespage
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_external_groups_visibility_messagespage(self):
"""webgroup - external group visibility in messages page"""
browser = Browser()
browser.open(cfg['CFG_SITE_SECURE_URL'] + "/youraccount/login")
browser.select_form(nr=0)
browser['nickname'] = 'admin'
browser['password'] = ''
browser.submit()
expected_response = "You are logged in as admin"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, login_response_body))
browser.open(cfg['CFG_SITE_SECURE_URL'] + "/yourgroups/search?query=groups&term=test")
expected_response = self.goodgroup
groups_body = browser.response().read()
try:
groups_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, groups_body))
not_expected_response = self.badgroup
try:
groups_body.index(not_expected_response)
except ValueError:
pass
else:
self.fail("Not expected to see %s, got %s." % \
(not_expected_response, groups_body))
示例6: test_external_groups_visibility_groupspage
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_external_groups_visibility_groupspage(self):
"""webgroup - external group visibility in groups page"""
browser = Browser()
browser.open(CFG_SITE_SECURE_URL + "/youraccount/login")
browser.select_form(nr=0)
browser['p_un'] = 'admin'
browser['p_pw'] = ''
browser.submit()
expected_response = "You are logged in as admin"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, login_response_body))
browser.open(CFG_SITE_SECURE_URL + "/yourgroups/display")
expected_response = self.goodgroup
groups_body = browser.response().read()
try:
groups_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, groups_body))
not_expected_response = self.badgroup
try:
groups_body.index(not_expected_response)
except ValueError:
pass
else:
self.fail("Not expected to see %s, got %s." % \
(not_expected_response, groups_body))
示例7: test_external_groups_visibility_messagespage
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_external_groups_visibility_messagespage(self):
"""webgroup - external group visibility in messages page"""
browser = Browser()
browser.open(CFG_SITE_SECURE_URL + "/youraccount/login")
browser.select_form(nr=0)
browser["p_un"] = "admin"
browser["p_pw"] = ""
browser.submit()
expected_response = "You are logged in as admin"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % (expected_response, login_response_body))
browser.open(CFG_SITE_SECURE_URL + "/yourmessages/write")
browser.select_form(nr=0)
browser["search_pattern"] = "b"
browser.submit(name="search_group")
expected_response = self.goodgroup
groups_body = browser.response().read()
try:
groups_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % (expected_response, groups_body))
not_expected_response = self.badgroup
try:
groups_body.index(not_expected_response)
except ValueError:
pass
else:
self.fail("Not expected to see %s, got %s." % (not_expected_response, groups_body))
示例8: test_comment_access_files_deleted_comment
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_comment_access_files_deleted_comment(self):
"""webcomment - access files of a deleted comment"""
# Juliet should not be able to access the files
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'juliet'
br['p_pw'] = 'j123uliet'
br.submit()
br.open("%s/%s/%i/comments/attachments/get/%i/file2" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.deleted_comid))
response = br.response().read()
if "You cannot access files of a deleted comment" in response:
pass
else:
self.fail("Oops, users should not have access to this deleted comment attachment")
# Jekyll should also not be able to access the files
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'jekyll'
br['p_pw'] = 'j123ekyll'
br.submit()
br.open("%s/%s/%i/comments/attachments/get/%i/file2" % \
(CFG_SITE_URL, CFG_SITE_RECORD, self.public_record, self.deleted_comid))
response = br.response().read()
if "Authorization failure" in response:
pass
else:
self.fail("Oops, users should not have access to this deleted comment attachment")
示例9: test_access_public_record_restricted_discussion_public_comment
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_access_public_record_restricted_discussion_public_comment(self):
"""webcomment - accessing "public" comment in a restricted discussion of a public record"""
# Guest user should not be able to access it
self.assertNotEqual([],
test_web_page_content("%s/record/%i/comments/" % (CFG_SITE_URL, self.restricted_discussion),
expected_text=self.msg2))
# Accessing a non existing file for a restricted comment should also ask to login
self.assertEqual([],
test_web_page_content("%s/record/%i/comments/attachments/get/%i/not_existing_file" % \
(CFG_SITE_URL, self.restricted_discussion, self.restr_comid_5),
expected_text='You can use your nickname or your email address to login'))
# Check accessing file of a restricted comment
self.assertEqual([],
test_web_page_content("%s/record/%i/comments/attachments/get/%i/file2" % \
(CFG_SITE_URL, self.restricted_discussion, self.restr_comid_5),
expected_text='You can use your nickname or your email address to login'))
# Juliet should not be able to access the comment
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'juliet'
br['p_pw'] = 'j123uliet'
br.submit()
br.open("%s/record/%i/comments/" % (CFG_SITE_URL, self.restricted_discussion))
response = br.response().read()
if not self.msg6 in response:
pass
else:
self.fail("Oops, this user should not have access to this comment")
# Juliet should not be able to access the attached files
br.open("%s/record/%i/comments/attachments/get/%i/file2" % \
(CFG_SITE_URL, self.restricted_discussion, self.restr_comid_5))
response = br.response().read()
if "You are not authorized" in response:
pass
else:
self.fail("Oops, this user should not have access to this comment attachment")
# Romeo should be able to access the comment
br = Browser()
br.open(CFG_SITE_URL + '/youraccount/login')
br.select_form(nr=0)
br['p_un'] = 'romeo'
br['p_pw'] = 'r123omeo'
br.submit()
br.open("%s/record/%i/comments/" % (CFG_SITE_URL, self.restricted_discussion))
response = br.response().read()
if not self.msg6 in response:
self.fail("Oops, this user should have access to this comment")
# Romeo should be able to access the attached files
br.open("%s/record/%i/comments/attachments/get/%i/file2" % \
(CFG_SITE_URL, self.restricted_discussion, self.restr_comid_5))
response = br.response().read()
self.assertEqual(self.attached_file2_content, response)
示例10: T1337x
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
class T1337x(Torrent):
def __init__(self, otherFilters, minSize, debug):
self._urlBase = "http://1337x.to"
self._urlSearch = u"http://1337x.to/search/{name} {episode}"
self._languageDict = {"english": 2, "spanish": 14}
#To MB
self._minSize = int(minSize) / 1048576
self._debug = debug
extraFilters = u"{otherFilters}"
if otherFilters != "":
self._otherFilers = u" "+otherFilters
else:
self._otherFilers = ""
self._urlSearch = ''.join([self._urlSearch, extraFilters.format(otherFilters=self._otherFilers), "/1/"])
self._browser = Browser()
self._browser.set_handle_robots(False)
self._cookieJar = cookielib.LWPCookieJar()
self._browser.set_cookiejar(self._cookieJar)
self._browser.addheaders = [('User-agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0'), ('Accept', '*/*'), ('Accept-Encoding',"gzip,deflate")]
self._browser.open(self._urlBase)
def episodeSearch(self, serie, episode):
searchQuery = self._urlSearch.format(name=serie,episode=episode["number"]).replace(" ","+")
logging.debug( u"searchURL: {}".format(searchQuery))
try:
self._browser.open(searchQuery)
gzipContent = self._browser.response().read()
html = gzip.GzipFile(fileobj=StringIO.StringIO(gzipContent)).read()
#Scrapping the page.
soup = BeautifulSoup(html)
if (soup.body.findAll(text=' No results were returned. ')):
logging.error(u"There wasn't results for: {}".format(searchQuery))
return None
items = soup.find('div', attrs={"class": "table-list-wrap"}).find('tbody').findAll('tr')
for item in items:
contentLength = item.find("td" ,{"class": re.compile("coll-4.*")}).text.split(' ')
if contentLength[1][:2] != 'GB' and float(contentLength[0]) < self._minSize:
logging.warning(u"Torrent to small: {}".format(' '.join([contentLength[0], contentLength[1] [:2]])))
continue
infoUrl = item.find("td", attrs={"class": re.compile("coll-1.*")}).findAll('a')[1]['href']
logging.info(u"Going to download: {}".format(infoUrl.split('/')[-1]))
logging.info(u"File size: {}".format(' '.join([contentLength[0], contentLength[1] [:2]])))
self._browser.open(''.join([self._urlBase, infoUrl]) )
gzipContent = self._browser.response().read()
html = gzip.GzipFile(fileobj=StringIO.StringIO(gzipContent)).read()
soup2 = BeautifulSoup(html)
magnetUri = soup2.find('a', attrs={"class": re.compile(".*btn-magnet")})['href']
return magnetUri
break
return None
except HTTPError, e:
logging.error( u"There was an error in the URL {}.".format(searchQuery))
return None
示例11: test_email_caseless
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_email_caseless(self):
"""webuser - check email caseless"""
browser = Browser()
browser.open(CFG_SITE_SECURE_URL + "/youraccount/register")
browser.select_form(nr=0)
browser['p_email'] = '[email protected]'
browser['p_nickname'] = 'foobar'
browser['p_pw'] = ''
browser['p_pw2'] = ''
browser.submit()
expected_response = "Account created"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, login_response_body))
browser = Browser()
browser.open(CFG_SITE_SECURE_URL + "/youraccount/register")
browser.select_form(nr=0)
browser['p_email'] = '[email protected]'
browser['p_nickname'] = 'foobar2'
browser['p_pw'] = ''
browser['p_pw2'] = ''
browser.submit()
expected_response = "Registration failure"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, login_response_body))
browser = Browser()
browser.open(CFG_SITE_SECURE_URL + "/youraccount/register")
browser.select_form(nr=0)
browser['p_email'] = '[email protected]'
browser['p_nickname'] = 'foobar2'
browser['p_pw'] = ''
browser['p_pw2'] = ''
browser.submit()
expected_response = "Registration failure"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % \
(expected_response, login_response_body))
示例12: test_email_caseless
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_email_caseless(self):
"""webuser - check email caseless"""
browser = Browser()
browser.open(cfg["CFG_SITE_SECURE_URL"] + "/youraccount/register")
browser.select_form(nr=0)
browser["email"] = "[email protected]"
browser["nickname"] = "foobar"
browser["password"] = "123456"
browser["password2"] = "123456"
browser.submit()
expected_response = "Account created"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % (expected_response, login_response_body))
browser = Browser()
browser.open(cfg["CFG_SITE_SECURE_URL"] + "/youraccount/register")
browser.select_form(nr=0)
browser["email"] = "[email protected]"
browser["nickname"] = "foobar2"
browser["password"] = "123456"
browser["password2"] = "123456"
browser.submit()
expected_response = "Registration failure"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % (expected_response, login_response_body))
browser = Browser()
browser.open(cfg["CFG_SITE_SECURE_URL"] + "/youraccount/register")
browser.select_form(nr=0)
browser["email"] = "[email protected]"
browser["nickname"] = "foobar2"
browser["password"] = "123456"
browser["password2"] = "123456"
browser.submit()
expected_response = "Registration failure"
login_response_body = browser.response().read()
try:
login_response_body.index(expected_response)
except ValueError:
self.fail("Expected to see %s, got %s." % (expected_response, login_response_body))
示例13: test_chap_form
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def test_chap_form(self):
"""this is a unit test for the chapters dropdown to
check that it is populated with the correct amount of chapters this
can be done by comapring the number of chapters in the db book_for
the selected book and then, comaring it with the actual number of
chapters in the chapters' dropdown"""
error_msg = """
you have a different number of chapters
in your dropdown than in your database
"""
books_from_db = BookInfo.objects.values_list('chaps', flat = True)
browser = Browser()
url = 'http://parallel-text.herokuapp.com/parallel_display/'
browser.open(url)
browser.select_form(name = 'book_form')
browser.submit()
self.html = browser.response().read()
soup = BeautifulSoup(self.html)
chapters_select = soup.findAll('select', id = "id_chapter_dd")
num_of_chapters = re.findall(r'<option value="(.*?)"',
str(chapters_select), re.DOTALL)
int_chap_dd = len(num_of_chapters)
int_chap_db = int(books_from_db[0])
self.assertEqual(int_chap_db, int_chap_dd, error_msg)
示例14: make_request
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
def make_request(letter, people):
browser = Browser()
browser.open("https://directory.andrew.cmu.edu/")
browser.select_form(nr=0)
browser.form['search[generic_search_terms]'] = letter
browser.submit()
with open("response.html", "w") as f:
f.write(browser.response().read())
f.close()
page = open("response.html", "r").read()
soup = BeautifulSoup(page)
table = soup.findAll('tr')
for row in table[1:]:
info = row.findAll('td')
data = {}
data["first"] = clean(info[0].contents[1].contents[0])
data["last"] = clean(info[1].contents[1].contents[0])
data["affiliation"] = clean(info[3].contents[0])
data["department"] = clean(info[4].contents[0])
andrew = info[2].contents[1].contents[0]
people[andrew] = data
示例15: Guarani
# 需要导入模块: from mechanize import Browser [as 别名]
# 或者: from mechanize.Browser import response [as 别名]
class Guarani(object):
def __init__(self, user, passwd):
self.br = Browser()
self.user = user
self.passwd = passwd
self._login()
def _login(self):
self.br.open("https://guarani.exa.unicen.edu.ar/Guarani3w/")
self.br.open("https://guarani.exa.unicen.edu.ar/Guarani3w/includes/barra.inc.php")
self.br.follow_link(text_regex="Iniciar")
self.br.select_form(nr=0)
self.br["fUsuario"] = self.user
self.br["fClave"] = self.passwd
self.br.submit()
def _parseNotas(self, html):
soup = BeautifulSoup(html)
s_notas = soup.findAll('tr', {'class' : 'normal'})
notas = []
for s_nota in s_notas:
materia, nota = [x.text for x in s_nota.findAll('td')[:2]]
if nota != '':
notas.append([materia, nota])
return notas
def getNotasFinales(self):
self.br.open("https://guarani.exa.unicen.edu.ar/Guarani3w/operaciones.php")
self.br.follow_link(url_regex="consultarActProvisoria")
return self._parseNotas(self.br.response().read())