当前位置: 首页>>代码示例>>Python>>正文


Python http.HTTP类代码示例

本文整理汇总了Python中http.HTTP的典型用法代码示例。如果您正苦于以下问题:Python HTTP类的具体用法?Python HTTP怎么用?Python HTTP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTTP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fakeWSGIERRApp

def fakeWSGIERRApp(envir, responder):
    codedict = envir.get('CODE_DICT', {})
    body = envir.get('PATH_INFO')
    code = codedict.get(envir.get('PATH_INFO'), 200)
    if envir.get('PATH_INFO') not in codedict:
        body = bodydict.get(envir.get('PATH_INFO'))
    else:
        body = 'Complete Utter Failure'
    response = HTTP(code, body)
    retval = response.to(responder)
    return retval
开发者ID:dspiteself,项目名称:web2py,代码行数:11,代码来源:test_rewrite.py

示例2: render_GET

	def render_GET(self, req):
		# No archive no service
		if not os.path.isdir(self._sdsPath):
			msg = "SDS archive not found: %s" % self._sdsPath
			return HTTP.renderErrorPage(request, http.SERVICE_UNAVAILABLE, msg)

		# Parse and validate GET parameters
		try:
			ro = _DataSelectRequestOptions(req.args)
			ro.parse()
		except ValueError, e:
			Logging.warning(str(e))
			return HTTP.renderErrorPage(req, http.BAD_REQUEST, str(e))
开发者ID:salichon,项目名称:SC3_VM_seattle,代码行数:13,代码来源:wsdataselect.py

示例3: open_epub

    def open_epub(cls, url, content=None):
        """Cracks open an EPUB to expose its contents

        :param url: A url representing the EPUB, only used for errors and in
            the absence of the `content` parameter
        :param content: A string representing the compressed EPUB

        :return: A tuple containing a ZipFile of the EPUB and the path to its
        package
        """
        if not (url or content):
            raise ValueError("Cannot open epub without url or content")
        if url and not content:
            # Get the epub from the url if no content has been made available.
            content = HTTP.get_with_timeout(url).content
        content = StringIO(content)

        with ZipFile(content) as zip_file:
            if not cls.CONTAINER_FILE in zip_file.namelist():
                raise ValueError("Invalid EPUB file, not modifying: %s" % url)

            with zip_file.open(cls.CONTAINER_FILE) as container_file:
                container = container_file.read()
                rootfiles_element = etree.fromstring(container).find("{urn:oasis:names:tc:opendocument:xmlns:container}rootfiles")

                if rootfiles_element is None:
                    raise ValueError("Invalid EPUB file, not modifying: %s" % url)

                rootfile_element = rootfiles_element.find("{urn:oasis:names:tc:opendocument:xmlns:container}rootfile")
                if rootfile_element is None:
                    raise ValueError("Invalid EPUB file, not modifying: %s" % url)

                package_document_path = rootfile_element.get('full-path')
            yield zip_file, package_document_path
开发者ID:NYPL-Simplified,项目名称:server_core,代码行数:34,代码来源:epub.py

示例4: _processRequest

	def _processRequest(self, req, ro, dbq, exp):
		if req._disconnected:
			return False

		DataModel.PublicObject.SetRegistrationEnabled(False)

		# query event(s)
		ep = DataModel.EventParameters()
		if ro.eventIDs:
			for eID in ro.eventIDs:
				event = dbq.getEventByPublicID(eID)
				event = DataModel.Event.Cast(event)
				if event:
					ep.add(event)
		else:
			self._findEvents(ep, ro, dbq)

		if ep.eventCount() == 0:
			msg = "no matching events found"
			utils.writeTS(req,
			              HTTP.renderErrorPage(req, http.NO_CONTENT, msg, ro))
			return False

		Logging.debug("events found: %i" % ep.eventCount())

		if ro.format == 'csv' or not exp:
			req.setHeader('Content-Type', 'text/plain')
		else:
			req.setHeader('Content-Type', 'application/xml')

		if exp:
			return self._processRequestExp(req, ro, dbq, exp, ep)

		return self._processRequestText(req, ro, dbq, ep)
开发者ID:smellyfis,项目名称:seiscomp3,代码行数:34,代码来源:event.py

示例5: __init__

 def __init__(self, vulnerability, threads=0):
     self.vulnerability = vulnerability
     self.host = vulnerability['host']
     self.session = HTTP()
     self.output_folder = "output/{}/".format(self.host.host)
     self.output_git = self.output_folder + ".git/"
     self.threads = threads
开发者ID:simontoft,项目名称:VCSRip,代码行数:7,代码来源:RipperGIT.py

示例6: resumeProducing

	def resumeProducing(self):
		rec = None

		try: rec = self.rsInput.next()
		except Exception, e: Logging.warning("%s" % str(e)) # e.g. ArchiveException

		if not self.initialized:
			self.initialized = True
			# read first record to test if any data exists at all

			if not rec:
				msg = "No waveform data found"
				self.req.write(HTTP.renderErrorPage(self.req, http.NOT_FOUND, msg))
				self.req.unregisterProducer()
				self.req.finish()
				return

			self.req.setHeader("Content-Type", "application/vnd.fdsn.mseed")
			self.req.setHeader("Content-Disposition", "attachment; filename=%s" % \
			                   self.fileName)

		if not rec:
			self.req.unregisterProducer()
			self.req.finish()
			return

		self.req.write(rec.raw().str())
开发者ID:salichon,项目名称:SC3_VM_seattle,代码行数:27,代码来源:utils.py

示例7: resumeProducing

	def resumeProducing(self):
		rec = None

		try: rec = self.rsInput.next()
		except Exception, e: Logging.warning("%s" % str(e))

		if self.written == 0:
			# read first record to test if any data exists at all
			if not rec:
				msg = "no waveform data found"
				data = HTTP.renderErrorPage(self.req, http.NO_CONTENT, msg, self.ro)
				if data:
					self.req.write(data)
				self.req.unregisterProducer()
				self.req.finish()
				return

			self.req.setHeader('Content-Type', 'application/vnd.fdsn.mseed')
			self.req.setHeader('Content-Disposition', "attachment; " \
			                   "filename=%s" % self.fileName)

		if not rec:
			self.req.unregisterProducer()
			Logging.debug("%s: returned %i bytes of mseed data" % (
			               self.ro.service, self.written))
			utils.accessLog(self.req, self.ro, http.OK, self.written, None)
			self.req.finish()
			return

		data = rec.raw().str()
		self.req.write(data)
		self.written += len(data)
开发者ID:duperray,项目名称:seiscomp3,代码行数:32,代码来源:dataselect.py

示例8: render_GET

	def render_GET(self, req):
		# Parse and validate GET parameters
		ro = _EventRequestOptions(req.args)
		try:
			ro.parse()
		except ValueError, e:
			Logging.warning(str(e))
			return HTTP.renderErrorPage(req, http.BAD_REQUEST, str(e), ro)
开发者ID:salichon,项目名称:SC3_VM_seattle,代码行数:8,代码来源:event.py

示例9: render_POST

	def render_POST(self, req):
		# Parse and validate POST parameters
		ro = _StationRequestOptions()
		try:
			ro.parsePOST(req.content)
			ro.parse()
		except ValueError, e:
			Logging.warning(str(e))
			return HTTP.renderErrorPage(req, http.BAD_REQUEST, str(e), ro)
开发者ID:SeisComP3,项目名称:seiscomp3,代码行数:9,代码来源:station.py

示例10: _processRequest

	def _processRequest(self, req, ro, dbq, exp):
		if req._disconnected:
			return False

		DataModel.PublicObject.SetRegistrationEnabled(False)

		# query event(s)
		ep = DataModel.EventParameters()
		if ro.eventIDs:
			for eID in ro.eventIDs:
				obj = dbq.getEventByPublicID(eID)
				e = DataModel.Event.Cast(obj)
				if not e:
					continue

				if self._eventTypeWhitelist or self._eventTypeBlacklist:
					eType = None
					try: eType = DataModel.EEventTypeNames_name(e.type())
					except ValueException: pass
					if self._eventTypeWhitelist and \
					   not eType in self._eventTypeWhitelist: continue
					if self._eventTypeBlacklist and \
					   eType in self._eventTypeBlacklist: continue

				if self._evaluationMode is not None:
					obj = dbq.getObject(DataModel.Origin.TypeInfo(),
					                    e.preferredOriginID())
					o = DataModel.Origin.Cast(obj)
					try:
						if o is None or \
						   o.evaluationMode() != self._evaluationMode:
							continue
					except ValueException:
						continue

				ep.add(e)
		else:
			self._findEvents(ep, ro, dbq)

		if ep.eventCount() == 0:
			msg = "no matching events found"
			data = HTTP.renderErrorPage(req, http.NO_CONTENT, msg, ro)
			if data:
				utils.writeTS(req, data)
			return True

		Logging.debug("events found: %i" % ep.eventCount())

		if ro.format == 'csv' or not exp:
			req.setHeader('Content-Type', 'text/plain')
		else:
			req.setHeader('Content-Type', 'application/xml')

		if exp:
			return self._processRequestExp(req, ro, dbq, exp, ep)

		return self._processRequestText(req, ro, dbq, ep)
开发者ID:gomes310,项目名称:seiscomp3,代码行数:57,代码来源:event.py

示例11: checkObjects

def checkObjects(req, objCount, maxObj):
	if objCount > maxObj:
		msg = "The result set of your request exceeds the configured maximum " \
		      "number of objects (%i). Refine your request parameters." % maxObj
		writeTS(req, HTTP.renderErrorPage(req, http.REQUEST_ENTITY_TOO_LARGE,
		                                  msg))
		return False

	return True
开发者ID:salichon,项目名称:SC3_VM_seattle,代码行数:9,代码来源:utils.py

示例12: render_GET

	def render_GET(self, req):
		# Parse and validate GET parameters
		ro = _StationRequestOptions(req.args)
		try:
			ro.parse()
			# the GET operation supports exactly one stream filter
			ro.streams.append(ro)
		except ValueError, e:
			Logging.warning(str(e))
			return HTTP.renderErrorPage(req, http.BAD_REQUEST, str(e), ro)
开发者ID:SeisComP3,项目名称:seiscomp3,代码行数:10,代码来源:station.py

示例13: render_POST

	def render_POST(self, req):
		# Parse and validate POST parameters
		ro = _DataSelectRequestOptions()
		ro.userName = self.__user and self.__user.get('mail')
		try:
			ro.parsePOST(req.content)
			ro.parse()
		except ValueError, e:
			Logging.warning(str(e))
			return HTTP.renderErrorPage(req, http.BAD_REQUEST, str(e), ro)
开发者ID:aemanov,项目名称:seiscomp3,代码行数:10,代码来源:dataselect.py

示例14: render_GET

	def render_GET(self, req):
		# Parse and validate POST parameters
		ro = _DataSelectRequestOptions(req.args)
		ro.userName = self.__user and self.__user.get('mail')
		try:
			ro.parse()
			# the GET operation supports exactly one stream filter
			ro.streams.append(ro)
		except ValueError, e:
			Logging.warning(str(e))
			return HTTP.renderErrorPage(req, http.BAD_REQUEST, str(e), ro)
开发者ID:aemanov,项目名称:seiscomp3,代码行数:11,代码来源:dataselect.py

示例15: _finish

	def _finish(self):
		if self.written == 0:
			msg = "no waveform data found"
			HTTP.renderErrorPage(self.req, http.NO_CONTENT, msg, self.ro)

			if self.tracker:
				self.tracker.volume_status("fdsnws", "NODATA", 0, "")
				self.tracker.request_status("END", "")

		else:
			Logging.debug("%s: returned %i bytes of mseed data" % (
			              self.ro.service, self.written))
			utils.accessLog(self.req, self.ro, http.OK, self.written, None)

			if self.tracker:
				self.tracker.volume_status("fdsnws", "OK", self.written, "")
				self.tracker.request_status("END", "")


		self.req.unregisterProducer()
		self.req.finish()
开发者ID:preinh,项目名称:seiscomp3,代码行数:21,代码来源:dataselect.py


注:本文中的http.HTTP类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。