def openNoVisit(self, url_or_path, data=None, site_relative=True): """ Copy/paste from zope.testbrowser.Browser.open() to allow opening an URL without changing the current page. See L{open}. @see zope.testbrowser.interfaces.IBrowser """ if site_relative: # In case url_or_path is an absolute URL, urljoin() will return # it, otherwise it is a relative path and will be concatenated to # ERP5 base URL url_or_path = urljoin(self._erp5_base_url, url_or_path) import mechanize if isinstance(data, dict): data = urllib.urlencode(data) response = None url_or_path = str(url_or_path) self._logger.debug("Opening: " + url_or_path) self._start_timer() try: try: try: response = self.mech_browser.open_novisit( url_or_path, data) except Exception, e: fix_exception_name(e) raise except mechanize.HTTPError, e: if e.code >= 200 and e.code <= 299: # 200s aren't really errors pass elif self.raiseHttpErrors: raise finally: self._stop_timer() # if the headers don't have a status, I suppose there can't be an error if 'Status' in self.headers: code, msg = self.headers['Status'].split(' ', 1) code = int(code) if self.raiseHttpErrors and code >= 400: raise mechanize.HTTPError(url_or_path, code, msg, self.headers, fp=None) return response
def openNoVisit(self, url_or_path, data=None, site_relative=True): """ Copy/paste from zope.testbrowser.Browser.open() to allow opening an URL without changing the current page. See L{open}. @see zope.testbrowser.interfaces.IBrowser """ if site_relative: # In case url_or_path is an absolute URL, urljoin() will return # it, otherwise it is a relative path and will be concatenated to # ERP5 base URL url_or_path = urljoin(self._erp5_base_url, url_or_path) import mechanize if isinstance(data, dict): data = urllib.urlencode(data) response = None url_or_path = str(url_or_path) self._logger.debug("Opening: " + url_or_path) self._start_timer() try: try: try: response = self.mech_browser.open_novisit(url_or_path, data) except Exception, e: fix_exception_name(e) raise except mechanize.HTTPError, e: if e.code >= 200 and e.code <= 299: # 200s aren't really errors pass elif self.raiseHttpErrors: raise finally: self._stop_timer() # if the headers don't have a status, I suppose there can't be an error if 'Status' in self.headers: code, msg = self.headers['Status'].split(' ', 1) code = int(code) if self.raiseHttpErrors and code >= 400: raise mechanize.HTTPError(url_or_path, code, msg, self.headers, fp=None) return response
def _clickSubmit(self, form, control, coord): # XXX gary 2010-03-08 bug=98437 # This change is taken from # https://bugs.launchpad.net/zope3/+bug/98437/comments/9 . It # should be pushed upstream, per that comment. labels = control.get_labels() if labels: label = labels[0].text else: label = None self.mech_browser.form = form self._start_timer() try: self.mech_browser.submit(id=control.id, name=control.name, label=label, coord=coord) except Exception as e: fix_exception_name(e) raise self._stop_timer()
def _clickSubmit(self, form, control, coord): # XXX gary 2010-03-08 bug=98437 # This change is taken from # https://bugs.launchpad.net/zope3/+bug/98437/comments/9 . It # should be pushed upstream, per that comment. labels = control.get_labels() if labels: label = labels[0].text else: label = None self.mech_browser.form = form self._start_timer() try: self.mech_browser.submit(id=control.id, name=control.name, label=label, coord=coord) except Exception as e: fix_exception_name(e) raise self._stop_timer()