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


Python URL.getInputStream方法代码示例

本文整理汇总了Python中java.net.URL.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Python URL.getInputStream方法的具体用法?Python URL.getInputStream怎么用?Python URL.getInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.URL的用法示例。


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

示例1: open

# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getInputStream [as 别名]
    def open(self, url_or_req):
        try:
            if isinstance(url_or_req, Request):
                connection = URL(url_or_req.get_full_url()).openConnection()
                for header in self.addheaders:
                    connection.setRequestProperty(header[0], header[1])
                for key, value in url_or_req.header_items():
                    connection.setRequestProperty(key, value)
                
                connection.setRequestMethod(url_or_req.get_method())
                
                if url_or_req.get_data() != None:
                    connection.setDoOutput(True)
                    outstream = connection.getOutputStream()
                    outstream.write(url_or_req.get_data())
            else:
                connection = URL(url_or_req).openConnection()
                for header in self.addheaders:
                    connection.setRequestProperty(header[0], header[1])

            instream = connection.getInputStream()
            doc = ""
            reader = BufferedReader(InputStreamReader(instream))
            line = reader.readLine()
            while line:
                doc += line
                line = reader.readLine()
            return Response(doc)
        except:
            traceback.print_exc()
            raise
开发者ID:rossrowe,项目名称:sc,代码行数:33,代码来源:java_urllib2.py

示例2: download_request

# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getInputStream [as 别名]
    def download_request(url, file_path, user_agent, referer_url, timeout, max_redirects, log):
        import jarray
        from java.net import URL, HttpURLConnection
        from java.io import FileOutputStream
        try:
            input_stream = None
            file_output_stream = FileOutputStream(file_path)
            HttpURLConnection.setFollowRedirects(True)
            first_request = True
            is_redirect = False
            cookies = None
            redirect_counter = 0
            while is_redirect or first_request:
                http_url_connection = URL(url).openConnection()
                http_url_connection.setFollowRedirects(True)
                http_url_connection.setInstanceFollowRedirects(True)
                http_url_connection.setRequestProperty("Accept-Language", "en-US,en;q=0.8")
                http_url_connection.setConnectTimeout(timeout)
                http_url_connection.setReadTimeout(timeout)
                http_url_connection.setRequestMethod("GET")
                http_url_connection.setRequestProperty("User-Agent", user_agent)
                http_url_connection.setRequestProperty("Accept-Language", "en-US,en;q=0.8")
                if cookies != None and len(cookies) > 0:
                    http_url_connection.setRequestProperty("Cookie", cookies)
                if referer_url != None:
                    # Note: Referer not Referrer! (see: Wikipedia)
                    #           ^           ^^
                    http_url_connection.setRequestProperty("Referer", referer_url);
                http_url_connection.connect()
                first_request = False

                # check for redirect
                is_redirect = False
                status_code = http_url_connection.getResponseCode()

                if status_code == HttpURLConnection.HTTP_NOT_FOUND:
                    raise ScratchtobatHTTP404Error("HTTP 404 NOT FOUND for URL: " + url)

                if status_code != HttpURLConnection.HTTP_OK:
                    if status_code == HttpURLConnection.HTTP_MOVED_TEMP \
                    or status_code == HttpURLConnection.HTTP_MOVED_PERM \
                    or status_code == HttpURLConnection.HTTP_SEE_OTHER:

                        redirect_counter += 1
                        if redirect_counter > max_redirects:
                            raise ScratchtobatError("Maximum number of HTTP redirects " \
                                                    "{} reached!".format(max_redirects))

                        is_redirect = True
                        referer_url = url
                        # set redirect URL from "location" header field as new URL
                        url = http_url_connection.getHeaderField("Location")
                        cookies = http_url_connection.getHeaderField("Set-Cookie")
                        log.debug("Redirecting to URL: {}".format(url))

            input_stream = http_url_connection.getInputStream()
            byte_buffer = jarray.zeros(4096, "b")
            length = input_stream.read(byte_buffer)
            while length > 0:
                file_output_stream.write(byte_buffer, 0, length)
                length = input_stream.read(byte_buffer)
        finally:
            try:
                if input_stream != None:
                    input_stream.close()
            except:
                if file_output_stream != None:
                    file_output_stream.close()
开发者ID:ReinhardHuetter,项目名称:ScratchToCatrobat,代码行数:70,代码来源:common.py

示例3: onAdvEvent

# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import getInputStream [as 别名]
	def onAdvEvent(self, event, npc, player):
		if event == 'ad':
			try:
				c = URL('http://duck5duck.mooo.com/l2jtw_ad/l2jtw_ad.php').openConnection()
				if c:
					c.setDoOutput(True)
					o = DataOutputStream(c.getOutputStream())
					s = self.param % (
						C.RATE_XP
						, C.RATE_SP
						, C.RATE_PARTY_XP
						, C.RATE_PARTY_SP
						, C.PARTY_XP_CUTOFF_LEVEL
						, C.PET_XP_RATE
						, C.RATE_DROP_ITEMS
						, C.RATE_DROP_ITEMS_BY_RAID
						, C.RATE_DROP_MANOR
						, C.RATE_QUEST_DROP
						, C.RATE_DROP_ITEMS_ID.get(57) or 1.0
						, C.BUFFS_MAX_AMOUNT
						, C.TRIGGERED_BUFFS_MAX_AMOUNT
						, C.DANCES_MAX_AMOUNT
						, C.RUN_SPD_BOOST
						, C.MAX_RUN_SPEED
						, C.MAX_PCRIT_RATE
						, C.MAX_MCRIT_RATE
						, C.MAX_PATK_SPEED
						, C.MAX_MATK_SPEED
						, C.MAX_EVASION
						, C.MAX_SUBCLASS
						, C.BASE_SUBCLASS_LEVEL
						, C.MAX_SUBCLASS_LEVEL
						, C.INVENTORY_MAXIMUM_NO_DWARF
						, C.INVENTORY_MAXIMUM_DWARF
						, C.INVENTORY_MAXIMUM_QUEST_ITEMS
						, C.WAREHOUSE_SLOTS_NO_DWARF
						, C.WAREHOUSE_SLOTS_DWARF
						, C.WAREHOUSE_SLOTS_CLAN
						, C.MAX_ADENA/100000000
						, C.MAXIMUM_ONLINE_USERS
						, C.ENCHANT_CHANCE_ELEMENT_STONE
						, C.ENCHANT_CHANCE_ELEMENT_CRYSTAL
						, C.ENCHANT_CHANCE_ELEMENT_JEWEL
						, C.ENCHANT_CHANCE_ELEMENT_ENERGY
						, C.ENCHANT_SAFE_MAX
						, C.ENCHANT_SAFE_MAX_FULL
						, C.CLAN_LEVEL_6_COST
						, C.CLAN_LEVEL_7_COST
						, C.CLAN_LEVEL_8_COST
						, C.CLAN_LEVEL_9_COST
						, C.CLAN_LEVEL_10_COST
						, C.CLAN_LEVEL_11_COST
						, C.CLAN_LEVEL_6_REQUIREMENT
						, C.CLAN_LEVEL_7_REQUIREMENT
						, C.CLAN_LEVEL_8_REQUIREMENT
						, C.CLAN_LEVEL_9_REQUIREMENT
						, C.CLAN_LEVEL_10_REQUIREMENT
						, C.CLAN_LEVEL_11_REQUIREMENT
						, L2World.getInstance().getAllPlayersCount()
						, self.getRealOnline()
						, URLEncoder.encode(self.link, 'utf-8')
						, URLEncoder.encode(self.intro, 'utf-8')
					)
					o.write(s)
					o.flush()
					o.close()
					i = c.getInputStream()
					r = ""
					while True:
						ch = i.read()
						if ch == -1:
							break
						r += chr(ch)
					if len(r):
						print r
					i.close()
					c.disconnect()
			except:
				return
开发者ID:6009821,项目名称:s4L2J,代码行数:81,代码来源:ad.py


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