def _process_error(self, reason):
        """
		Called when there is an error processing the request.
		
		*reason* (``twisted.internet.failure.Failure``) is the reason for
		failure.
		"""
        try:
            if not isinstance(reason, failure.Failure):
                # LIES! This is not an error.
                return

            # Log errors.
            log.err(reason, str(self))

            if self._disconnected or self.finished:
                # Since we are disconnected, return and do nothing.
                return

            if self._resp_error_cb:
                # Call error callback.
                try:
                    self._resp_error_cb(self, reason, self._resp_started,
                                        *self._resp_error_args,
                                        **self._resp_error_kw)
                except Exception as e:
                    log.err(e, str(self))

            if not self._resp_started:
                # Display Internal Server Error.
                code = http.INTERNAL_SERVER_ERROR
                if self.site.displayTracebacks:
                    body = _server_traceback_html.format(
                        path=urllib.escape(self.uri),
                        traceback=webutil.formatFailure(reason))
                else:
                    body = _server_error_html.format(
                        path=urllib.escape(self.uri))
                self.setResponseCode(code)
                self.setResponseEncoding(self._resp_enc or 'UTF-8')
                self.write(body)

            elif 'text/html' in self.responseHeaders.getRawHeaders(
                    'content-type', ('', ))[0]:
                # Since an error occured but we've already started writing the
                # response, do what we can.
                if self.site.displayTracebacks:
                    body = _server_traceback_html.format(
                        path=urllib.escape(self.uri),
                        traceback=webutil.formatFailure(reason))
                else:
                    body = "<h1>...Internal Server Error!</h1>"
                self.write(body)

        except Exception as e:
            log.err(e, str(self))

        finally:
            self.finish()
示例#2
0
def GET_params(**params):
  final = ''
  first = True
  for param in params.iteritems():
    if first: 
      final += '?'
      first = False
    else: final += '&'
    final += '%s=%s' % (escape(param[0]),escape(param[1]))
  return final
	def _process_error(self, reason):
		"""
		Called when there is an error processing the request.
		
		*reason* (``twisted.internet.failure.Failure``) is the reason for
		failure.
		"""
		try:
			if not isinstance(reason, failure.Failure):
				# LIES! This is not an error.
				return
		
			# Log errors.
			log.err(reason, str(self))
		
			if self._disconnected or self.finished:
				# Since we are disconnected, return and do nothing.
				return
			
			if self._resp_error_cb:
				# Call error callback.
				try:
					self._resp_error_cb(self, reason, self._resp_started, *self._resp_error_args, **self._resp_error_kw)
				except Exception as e:
					log.err(e, str(self))
		
			if not self._resp_started:
				# Display Internal Server Error.
				code = http.INTERNAL_SERVER_ERROR
				if self.site.displayTracebacks:
					body = _server_traceback_html.format(path=urllib.escape(self.uri), traceback=webutil.formatFailure(reason))
				else:
					body = _server_error_html.format(path=urllib.escape(self.uri))
				self.setResponseCode(code)
				self.setResponseEncoding(self._resp_enc or 'UTF-8')
				self.write(body)
			
			elif 'text/html' in self.responseHeaders.getRawHeaders('content-type', ('',))[0]:
				# Since an error occured but we've already started writing the
				# response, do what we can.
				if self.site.displayTracebacks:
					body = _server_traceback_html.format(path=urllib.escape(self.uri), traceback=webutil.formatFailure(reason))
				else:
					body = "<h1>...Internal Server Error!</h1>"
				self.write(body)
				
		except Exception as e:
			log.err(e, str(self))
			
		finally:
			self.finish()
示例#4
0
def pagelink(page, **options):
  if isinstance(page,list):
    return list_to_human([pagelink(ind_page,**options) for ind_page in page])
  elif isinstance(page,dict) and page.has_key('name'):
    return pagelink(page['name'])
  else:
    return link(page,'/show/%s' % escape(page), **options)
示例#5
0
 def quote_json(self, anime_id):
   # Make series safe to search for
   anime_id = escape(anime_id.strip(), '')
   req = Request(self.REQ_URL % anime_id, headers=self.REQ_HEADERS)
   f = urlopen(req)
   quotes = json.loads(f.read())['quotes']
   f.close()
   logger.info("Got quotes for anime_id: '%s'" % anime_id)
   return quotes
示例#6
0
def send_email(recipient, subject, body):
    global mail_open
    address = """mailto:%s?subject=%s&body=%s""" % (recipient, escape(subject), escape(body))
    mail_open = """window.open("%s")""" % address
示例#7
0
def pageurl(page, **params):
  return url('/show/%s' % escape(page), **params)