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


Python URL.openStream方法代码示例

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


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

示例1: crawl

# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import openStream [as 别名]
    def crawl(site, trm , depth, linksfile):
        from java.net import URL
        from org.w3c.tidy import Tidy
        pattern = re.compile('href="/wiki/(.*?)"')
        f = open(linksfile, 'a+')
        #try:
        if depth < MAX_DEPTH:
            print 'crawling [%s]...' % trm,
            print >> f, '[%s]' % trm

            td = Tidy()
            td.setXmlOut(1)

            u = URL(site + trm)

            input = BufferedInputStream(u.openStream())
            output = ByteArrayOutputStream()
            #tidy.setInputEncoding("UTF8")
            #tidy.setOutputEncoding("UTF8")

            td.parse(input, output)
            content = output.toString()
            hits = pattern.findall(content)

            for hit in hits:
                if hit.find(":") == -1:
                    print >> f, hit
            print 'done.'
            print >> f, ''
            for hit in hits:
                if hit.find(":") == -1:
                    crawl(site, hit, depth + 1, linksfile)
        #except:
        #    print "wrong"
        f.close()
开发者ID:gidiko,项目名称:gridapp,代码行数:37,代码来源:examples.py

示例2: _get_map_file

# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import openStream [as 别名]
 def _get_map_file(self):
     map_param = self.getParameter('map')
     map_url = URL(self.getDocumentBase(), map_param)
     self.showStatus('Loading ' + map_url.toString())
     map_is = map_url.openStream()
     map_buf = ""
     i = map_is.read()
     while i != -1:
         map_buf = map_buf + chr(i)
         i = map_is.read()
     return StringIO(map_buf)
开发者ID:borsboom,项目名称:babal,代码行数:13,代码来源:JGLBabalApplet.py

示例3: handler

# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import openStream [as 别名]
def handler(environ, start_response):
    reload(sys)
    sys.setdefaultencoding('UTF8')
    welcomeString = "<html><head><title>atom2rss converter &bull; Atom to RSS2 converter</title><style>body { padding: 20px 40px; font-family: Verdana, Helvetica, Sans-Serif; font-size: medium; }</style></head><body><form method=\"post\"><h1>atom2rss converter written with Jython</h1><p>This tool will let you convert your atom 1.0 feed into an RSS2 feed that can be imported into WordPress.</p><p>Please read the full instructions before starting.</p><p><input type=\"text\" name=\"atom\" style=\"width: 400px;\"><input type=\"submit\" value=\"Convert\"></p><h2>Instructions</h2><p><strong>Step 1</strong>: Enter the url of an atom feed urls, e.g. <i>http://yoursite.com/atom.xml</i><br /></p><p><strong>Step 2</strong>: After clicking the \"Convert\" button, head to File / Save As... and save the file as rss.xml to your desktop.</p><p><strong>Step 3</strong>: Use this rss.xml file to import your data into WordPress under Import / RSS.</p><h2>About</h2><p>This tool is online as a convenience designed by <a href=\"http://kevin.9511.net/\">Kevin Li</a>.</p><p>Your can use it to import GoogleReader or Blogger data into Wordpress.</p></form></body></html>"
    response_parts = []
    header_str = ''
    if environ['REQUEST_METHOD'] == 'POST':
        post = environ['j2ee.request']
        if post.getParameterValues('atom') is None:
            bs = welcomeString
        else:
            try:
                atom = post.getParameterValues('atom')[0]
                
                atomUrl = URL(str(atom))
                atomSource = StreamSource(InputStreamReader(atomUrl.openStream(), "utf-8"))

                file = open(os.path.join(os.getcwd(), 'webapp/atom2rss.xsl'))
                xsltString = file.read()
                file.close()
                xsltSource = StreamSource(StringReader(xsltString))

                outputBuffer = StringWriter()

                transFactory = javax.xml.transform.TransformerFactory.newInstance("org.apache.xalan.processor.TransformerFactoryImpl",Thread.currentThread().getContextClassLoader())

                transformer = transFactory.newTransformer(xsltSource)
                transformer.transform(atomSource, StreamResult(outputBuffer))
                bs = outputBuffer.buffer.toString()
                header_str = 'text/xml;charset=utf-8'
            except MalformedURLException, mue:
                bs = "url format error"
            except TransformerException, te:
                bs = "transforme failed"
            except IOException, ie:
                bs = ie.getMessage()
开发者ID:rui7905,项目名称:atom2rss-jython,代码行数:38,代码来源:main.py

示例4: createTranslatorURLfromDTO

# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import openStream [as 别名]
for i in itObjs:
  counter = counter + 1

  if counter == tenPercent:
    counter = 0
    sys.stdout.write(str(percentageFinished))
    sys.stdout.write("#")
    percentageFinished = percentageFinished + 10

  transURL = createTranslatorURLfromDTO( overwrite, i, tID, tpw, transversion)

  # with admin key
  myURL = URL( "http", destURL, "/import_gameobjects_original.php?"+transURL+"&akey="+akey )
  #myURL = URL( "http", destURL, "/import_gameobjects_original.php?"+transURL )
  bufReader = BufferedReader( InputStreamReader(myURL.openStream()))
  inputLine = bufReader.readLine()
  if inputLine== "500":
    print "Wrong username/password/adminkey"
    break;

  if inputLine== "200":
    objectWritten200 = objectWritten200 + 1
  elif inputLine== "201":
    objectExists201 = objectExists201 + 1
  elif inputLine== "406":
    objectDoesNotExist406 = objectDoesNotExist406 + 1
  elif inputLine== "402":
    objectIncomplete402 = objectIncomplete402 + 1
  elif inputLine== "403":
    objectObjectIsSame403 = objectObjectIsSame403 + 1
开发者ID:BackupTheBerlios,项目名称:wdbmgr-svn,代码行数:32,代码来源:wddg_ger_gobj.py

示例5: update

# 需要导入模块: from java.net import URL [as 别名]
# 或者: from java.net.URL import openStream [as 别名]
    def update(self):
        """Update information shown by the dialog with those of
           currently selected error
        """
        from java.net import URL, URLEncoder
        from javax.xml.parsers import DocumentBuilderFactory
        error = self.app.selectedError
        check = error.check
        view = check.view
        tool = view.tool

        #user info
        if error.user is not None:
            errorUserName = error.user.getName()
            errorUserId = str(error.user.getId())

            #download user info from OSM API
            accountDate = None
            changesetsNumber = None

            if errorUserId in self.app.users:
                userInfo = self.app.users[errorUserId]
                accountDate = userInfo["account date"]
                changesetsNumber = userInfo["changesets number"]
            else:
                docFactory = DocumentBuilderFactory.newInstance()
                docBuilder = docFactory.newDocumentBuilder()
                url = URL("http://api.openstreetmap.org/api/0.6/user/" + errorUserId)
                try:
                    stream = url.openStream()
                    doc = docBuilder.parse(stream)
                    rootElement = doc.getDocumentElement()
                    userNode = rootElement.getElementsByTagName("user").item(0)
                    accountDate = userNode.getAttributes().getNamedItem("account_created").getNodeValue()
                    changesetsNode = rootElement.getElementsByTagName("changesets").item(0)
                    changesetsNumber = changesetsNode.getAttributes().getNamedItem("count").getNodeValue()
                except:
                    print "I could not download user info from:\n", url
                    pass
                if accountDate is not None:
                    self.app.users[errorUserId] = {"account date": accountDate,
                                                   "changesets number": changesetsNumber}

            #user links
            encodedErrorUserName = URLEncoder.encode(errorUserName, "UTF-8").replace("+", "%20")
            userUrl = "http://www.openstreetmap.org/user/%s/" % encodedErrorUserName
            msgUrl = "http://www.openstreetmap.org/message/new/%s" % encodedErrorUserName

            #update user info
            text = "<html><table>"
            text += "<tr><td>%s</td>" % self.app.strings.getString("User_name")
            text += "<td><a href='%s'>%s</a></td></tr>" % (userUrl, errorUserName)
            if accountDate is not None:
                text += "<tr>"
                text += "<td>%s</td>" % self.app.strings.getString("Changesets")
                text += "<td>%s</td>" % changesetsNumber
                text += "</tr><tr>"
                text += "<td>%s</td>" % self.app.strings.getString("Mapper_since")
                text += "<td>%s</td>"  % accountDate[:10]
                text += "</tr>"
            text += "</table>"
            text += "<a href='%s'>%s</a>" % (msgUrl, self.app.strings.getString("Send_a_message"))
            text += "</html>"
            self.userInfoPanel.setText(text)

        #error info
        text = "<html>"
        #tool
        text += "%s:<br>%s" % (self.app.strings.getString("Error_reported_by_the_tool"),
                               tool.title)
        if tool.uri != "":
            text += "<br>%s" % self.link(tool.uri)

        #error type
        if not tool.isLocal:
            text += "<br><br>%s:" % self.app.strings.getString("Type_of_error")
            text += "<br>%s --> %s" % (view.title,
                                       check.title)

        #error help, usually a link to a Wiki page describing this errror type
        #error link, e.g. a link to the error on the tool web page
        for propName, prop in ((self.app.strings.getString("Error_help"),\
            check.helpUrl), (self.app.strings.getString("Error_link"), tool.error_url(error))):
            if prop != "":
                text += "<br><br>%s:" % propName
                text += "<br>%s" % self.link(prop)

        #error description, usually some info contained in the error file
        if error.desc != "":
            text += "<br><br>%s:" % self.app.strings.getString("Description")
            text += "<br>%s" % error.desc

        #OSM object
        if error.osmId != "":
            osmType = {"n": "node", "w": "way", "r": "relation"}
            osmLinks = ""
            osmIds = error.osmId.split("_")
            for i, osmId in enumerate(osmIds):
                osmIdUrl = "http://www.openstreetmap.org/%s/%s" % (osmType[osmId[0]],
                                                                   osmId[1:])
#.........这里部分代码省略.........
开发者ID:floscher,项目名称:qat_script,代码行数:103,代码来源:ErrorInfoDialog.py


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