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


Python io.IOUtils类代码示例

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


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

示例1: __load

 def __load(self, oid):
     template = """<div class="title" /><div class="page-toc" /><div class="body"><div>%s</div></div>"""
     print "Loading HTML preview for %s..." % oid
     if oid == "blank":
         return template % "<p>This page intentionally left blank.</p>"
     else:
         object = Services.getStorage().getObject(oid)
         
         # get preview payload or source if no preview
         pid = self.__getPreviewPid(object)
         payload = object.getPayload(pid)
         mimeType = payload.getContentType()
         
         print "pid=%s mimeType=%s" % (pid, mimeType)
         isHtml = mimeType in ["text/html", "application/xhtml+xml"]
         if isHtml or mimeType.startswith("text/"):
             out = ByteArrayOutputStream()
             IOUtils.copy(payload.open(), out)
             content = out.toString("UTF-8")
             if content.find('class="body"'):  ## assumes ICE content
                 return content
             elif isHtml:
                 return template % content
             elif mimeType == "text/plain":
                 return template % ('<pre>%s</pre>' % content)
             else:
                 return content
         elif mimeType.startswith("image/"):
             return template % ('<div rel="%s"><img src="%s" /></div>' % (oid, pid))
         else:
             return '<a href="%s" rel="%s">%s</a>' % (oid, mimeType, pid)
         payload.close()
         object.close()
开发者ID:kiranba,项目名称:the-fascinator,代码行数:33,代码来源:preview.py

示例2: getPayloadContent

 def getPayloadContent(self):
     format = self.__metadata.getField("dc_format")
     slash = self.__oid.rfind("/")
     pid = self.__oid[slash+1:]
     print " *** payload content, format: %s, pid: %s *** " % (format, pid)
     contentStr = ""
     if format.startswith("text"):
         contentStr = "<pre>"
         payload = self.__storage.getPayload(self.__oid, pid)
         str = StringWriter() 
         IOUtils.copy(payload.getInputStream(), str)
         contentStr += str.toString()
         contentStr += "</pre>"
     elif format.find("vnd.ms-")>-1 or format.find("vnd.oasis.opendocument.")>-1:
         #get the html version if exist....
         pid = pid[:pid.find(".")] + ".htm"
         payload = self.__storage.getPayload(self.__oid, pid)
         saxReader = SAXReader()
         document = saxReader.read(payload.getInputStream())
         slideNode = document.selectSingleNode("//div[@class='body']")
         #linkNodes = slideNode.selectNodes("//img")
         #contentStr = slideNode.asXML();
         # encode character entities correctly
         out = ByteArrayOutputStream()
         format = OutputFormat.createPrettyPrint()
         format.setSuppressDeclaration(True)
         writer = XMLWriter(out, format)
         writer.write(slideNode)
         writer.close()
         contentStr = out.toString("UTF-8")
     return contentStr
开发者ID:kiranba,项目名称:the-fascinator,代码行数:31,代码来源:detail.py

示例3: __getFile

 def __getFile(self, packageDir, filename):
     file = File(packageDir, filename)
     if not file.exists():
         out = FileOutputStream(file)
         IOUtils.copy(Services.getClass().getResourceAsStream("/workflows/" + filename), out)
         out.close()
     return file
开发者ID:kiranba,项目名称:the-fascinator,代码行数:7,代码来源:packaging.py

示例4: parseFFmpeg

 def parseFFmpeg(self, parent):
     if parent is not None:
         object = parent.getObject()
         if object is not None:
             payload = None
             try:
                 payload = object.getPayload("ffmpeg.info")
                 # Stream the content out to string
                 out = ByteArrayOutputStream()
                 IOUtils.copy(payload.open(), out)
                 payload.close()
                 self.__ffmpegRaw = out.toString("UTF-8")
                 out.close()
                 payload.close()
                 # And parse it
                 self.__ffmpegData = JsonSimple(self.__ffmpegRaw)
                 if self.__ffmpegData is None:
                     return False
                 else:
                     self.__ffmpegOutputs = self.__ffmpegData.getJsonSimpleMap(["outputs"])
                     return True
             except:
                 if payload is not None:
                     payload.close()
     return False
开发者ID:Paul-Nguyen,项目名称:mint,代码行数:25,代码来源:detail.py

示例5: pageContent

    def pageContent(self):
        # Object ID
        oid = self.metadata.get("id")
        # Determine MIME Type
        mimeType = "Unknown"
        mimeList = self.metadata.getList("dc_format")
        if mimeList is not None and not mimeList.isEmpty():
            mimeType = mimeList.get(0)

        # The HTML payload is the real object, display in a frame because we
        #  have no idea what kind of object it is.
        if mimeType == "text/html":
            objectPath = "http://%s:%s%s/%s/download/%s/" % \
            (self.req.serverName, self.serverPort, self.contextPath, self.portalId, oid)
            objectLink = '<a class="iframe-link-alt" href="%s">View outside the frame</a>' % objectPath
            objectFrame = '<iframe class="iframe-preview" src="%s"></iframe>' % objectPath
            return objectLink + "<br/>" + objectFrame

        # We are just rendering a HTML preview
        else:
            preview = self.metadata.get("preview")
            try:
                object = Services.getStorage().getObject(oid)
                payload = object.getPayload(preview)
                out = ByteArrayOutputStream()
                IOUtils.copy(payload.open(), out)
                payload.close()
                return out.toString("UTF-8")

            except StorageException, e:
                return
开发者ID:kiranba,项目名称:the-fascinator,代码行数:31,代码来源:detail.py

示例6: getPayloadContent

 def getPayloadContent(self):
     mimeType = self.__mimeType
     print " * single.py: payload content mimeType=%s" % mimeType
     contentStr = ""
     if mimeType.startswith("text/"):
         if mimeType == "text/html":
             contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s"></iframe>' % (
                 contextPath,
                 portalId,
                 self.__oid,
             )
         else:
             pid = self.__oid[self.__oid.rfind("/") + 1 :]
             payload = self.__storage.getPayload(self.__oid, pid)
             print " * single.py: pid=%s payload=%s" % (pid, payload)
             if payload is not None:
                 sw = StringWriter()
                 sw.write("<pre>")
                 IOUtils.copy(payload.getInputStream(), sw)
                 sw.write("</pre>")
                 sw.flush()
                 contentStr = sw.toString()
     elif (
         mimeType == "application/pdf"
         or mimeType.find("vnd.ms") > -1
         or mimeType.find("vnd.oasis.opendocument.") > -1
     ):
         # get the html version if exist...
         pid = os.path.splitext(self.__pid)[0] + ".htm"
         print " * single.py: pid=%s" % pid
         # contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s/%s"></iframe>' % \
         #    (contextPath, portalId, self.__oid, pid)
         payload = self.__storage.getPayload(self.__oid, pid)
         saxReader = SAXReader(Boolean.parseBoolean("false"))
         try:
             document = saxReader.read(payload.getInputStream())
             slideNode = document.selectSingleNode("//*[local-name()='body']")
             # linkNodes = slideNode.selectNodes("//img")
             # contentStr = slideNode.asXML();
             # encode character entities correctly
             slideNode.setName("div")
             out = ByteArrayOutputStream()
             format = OutputFormat.createPrettyPrint()
             format.setSuppressDeclaration(True)
             format.setExpandEmptyElements(True)
             writer = XMLWriter(out, format)
             writer.write(slideNode)
             writer.close()
             contentStr = out.toString("UTF-8")
         except:
             traceback.print_exc()
             contentStr = '<p class="error">No preview available</p>'
     elif mimeType.startswith("image/"):
         src = "%s/%s" % (self.__oid, self.__pid)
         contentStr = (
             '<a class="image" href="%(src)s"  style="max-width:98%%">'
             '<img src="%(src)s" style="max-width:100%%" /></a>' % {"src": self.__pid}
         )
     return contentStr
开发者ID:kiranba,项目名称:the-fascinator,代码行数:59,代码来源:single.py

示例7: getResourceContent

 def getResourceContent(self, plugin, field):
     resource = self.getMetadata(plugin, field)
     stream = self.pageService.getResource(resource)
     if stream:
         writer = StringWriter()
         IOUtils.copy(stream, writer, "UTF-8")
         html = writer.toString()
         print " *** html:", html
         return html
     return "<em>'%s' not found!</em>" % (field)
开发者ID:kiranba,项目名称:the-fascinator,代码行数:10,代码来源:about.py

示例8: getPayloadContent

 def getPayloadContent(self):
     mimeType = self.__mimeType
     print " * detail.py: payload content mimeType=%s" % mimeType
     contentStr = ""
     if mimeType == "application/octet-stream":
         dcFormat = self.__json.get("response/docs/dc_format")
         if dcFormat is not None:
             dcFormat = dcFormat[1:-1]
         print dcFormat, mimeType
         if dcFormat != mimeType:
             return "<div><em>(File not found)</em></div>"
         else:
             return "<div><em>(Binary file)</em></div>"
     elif mimeType.startswith("text/"):
         if mimeType == "text/html":
             contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s"></iframe>' % \
                 (contextPath, portalId, self.__oid)
         else:
             pid = self.__oid[self.__oid.rfind("/")+1:]
             payload = self.__storage.getPayload(self.__oid, pid)
             #print " * detail.py: pid=%s payload=%s" % (pid, payload)
             if payload is not None:
                 sw = StringWriter()
                 sw.write("<pre>")
                 IOUtils.copy(payload.getInputStream(), sw)
                 sw.write("</pre>")
                 sw.flush()
                 contentStr = sw.toString()
     elif mimeType == "application/pdf" or mimeType.find("vnd.ms")>-1 or mimeType.find("vnd.oasis.opendocument.")>-1:
         # get the html version if exist...
         pid = os.path.splitext(self.__pid)[0] + ".htm"
         print " * detail.py: pid=%s" % pid
         #contentStr = '<iframe class="iframe-preview" src="%s/%s/download/%s/%s"></iframe>' % \
         #    (contextPath, portalId, self.__oid, pid)
         payload = self.__storage.getPayload(self.__oid, pid)
         saxReader = SAXReader(Boolean.parseBoolean("false"))
         try:
             document = saxReader.read(payload.getInputStream())
             slideNode = document.selectSingleNode("//*[local-name()='body']")
             #linkNodes = slideNode.selectNodes("//img")
             #contentStr = slideNode.asXML();
             # encode character entities correctly
             slideNode.setName("div")
             out = ByteArrayOutputStream()
             format = OutputFormat.createPrettyPrint()
             format.setSuppressDeclaration(True)
             format.setExpandEmptyElements(True)
             writer = XMLWriter(out, format)
             writer.write(slideNode)
             writer.close()
             contentStr = out.toString("UTF-8")
         except:
             traceback.print_exc()
             contentStr = "<p class=\"error\">No preview available</p>"
     return contentStr
开发者ID:kiranba,项目名称:the-fascinator,代码行数:55,代码来源:detail.py

示例9: getAboutPage

 def getAboutPage(self, plugin, type):
     if type is None or plugin is None:
         return "<em>This plugin has provided no information about itself.</em>"
     pid = plugin.replace("-", "_")
     resource = "plugin/%s/%s/about.html" % (type, pid)
     stream = self.pageService.getResource(resource)
     if stream:
         writer = StringWriter()
         IOUtils.copy(stream, writer, "UTF-8")
         html = writer.toString()
         return html
     return "<em>This plugin has provided no information about itself.</em>"
开发者ID:Deakin,项目名称:the-fascinator,代码行数:12,代码来源:about.py

示例10: getAboutPage

 def getAboutPage(self, plugin, type):
     if type is None or plugin is None:
         return "<em>'plugin/%s/%s/about.html' not found!</em>" % (type, plugin)
     pid = plugin.replace("-", "_")
     resource = "plugin/%s/%s/about.html" % (type, pid)
     stream = self.pageService.getResource(resource)
     if stream:
         writer = StringWriter()
         IOUtils.copy(stream, writer, "UTF-8")
         html = writer.toString()
         return html
     return "<em>'plugin/%s/%s/about.html' not found!</em>" % (type, pid)
开发者ID:kiranba,项目名称:the-fascinator,代码行数:12,代码来源:about.py

示例11: __activate__

    def __activate__(self, context):
        request = context["request"]
        storage = context["Services"].getStorage()
        auth = context["page"].authentication
        log = context["log"]
        
        username = auth.get_name()
        
        oid = request.getParameter("oid")
        approval = request.getParameter("approval")
        approval_comment = request.getParameter("approval_comment")
        
        storedObj = storage.getObject(oid)
        committeeResponses = None
        
        payloadList = storedObj.getPayloadIdList()
        if payloadList.contains("committee-responses.metadata"):
            committeeResponsePayload = storedObj.getPayload("committee-responses.metadata")
            committeeResponses = JsonSimple(committeeResponsePayload.open()).getJsonObject()
        else:
            committeeResponses = JsonObject()
        
        committeeResponse = JsonObject()
        committeeResponse.put("approval",approval)
        committeeResponse.put("approval_comment",approval_comment)
        
        committeeResponses.put(username,committeeResponse)

        log.debug(" %s: Committee %s, approval = %s, comment = %s"  % ( oid, username, approval, approval_comment))
        StorageUtils.createOrUpdatePayload(storedObj,"committee-responses.metadata",IOUtils.toInputStream(committeeResponses.toString(), "UTF-8"))
        context["response"].sendRedirect(context["portalPath"] +"/detail/"+oid)
开发者ID:qcif,项目名称:qcloud-arms,代码行数:31,代码来源:committee.py

示例12: __getJson

 def __getJson(self):
     rvtMap = HashMap()
     try:
         oid = formData.get("oid")
         object = Services.storage.getObject(oid)
         payload = object.getPayload("imsmanifest.xml")
         try:
             from xml.etree import ElementTree
             xmlStr = IOUtils.toString(payload.open(), "UTF-8")
             payload.close()
             xml = ElementTree.XML(xmlStr.encode("UTF-8"))
             ns = xml.tag[:xml.tag.find("}")+1]
             resources = {}
             for res in xml.findall(ns+"resources/"+ns+"resource"):
                 resources[res.attrib.get("identifier")] = res.attrib.get("href")
             organizations = xml.find(ns+"organizations")
             defaultName = organizations.attrib.get("default")
             organizations = organizations.findall(ns+"organization")
             organizations = [o for o in organizations if o.attrib.get("identifier")==defaultName]
             organization = organizations[0]
             title = organization.find(ns+"title").text
             rvtMap.put("title", title)
             items = organization.findall(ns+"item")
             rvtMap.put("toc", self.__getJsonItems(ns, items, resources))
         except Exception, e:
              data["error"] = "Error - %s" % str(e)
              print data["error"]
         object.close()
开发者ID:kiranba,项目名称:the-fascinator,代码行数:28,代码来源:json_ims.py

示例13: __activate__

    def __activate__(self, context):
        self.auth = context["page"].authentication
        self.errorMsg = "" 
        self.request = context["request"]
        self.response = context["response"]
        self.formData = context["formData"]
        self.storage = context["Services"].getStorage()
        
        self.log = context["log"]
        self.reportManager = context["Services"].getService("reportManager")
            
        fromOid = self.formData.get("fromOid")
        fromObject = self.storage.getObject(fromOid)

        if (self.auth.is_logged_in()):
            if (self.auth.is_admin() == True):
                pass
            elif (self.__isOwner(fromObject)):
                pass
            else:
                self.errorMsg = "Requires Admin / Librarian / Reviewer / owner access." 
        else:
            self.errorMsg = "Please login."
        if self.errorMsg == "": 
             toOid = self.formData.get("toOid")
             toObject = self.storage.getObject(toOid)
             storeRelatedData = self.formData.get("relatedData")
             fromTFPackage = self._getTFPackage(fromObject)
             toTFPackage = self._getTFPackage(toObject)
             fromInputStream = fromTFPackage.open()
             
             try:
                 StorageUtils.createOrUpdatePayload(toObject, toTFPackage.getId(), fromInputStream)
             except StorageException:
                 print "error setting tfPackage"
                 
             fromTFPackage.close()
             fromTFPackageJson = JsonSimple(fromTFPackage.open()).getJsonObject()
             if storeRelatedData != "false" :
                # add relatedOid info
                fromTFPackageJson = self._addRelatedOid(JsonSimple(fromTFPackage.open()), toOid)
             
             inStream = IOUtils.toInputStream(fromTFPackageJson.toJSONString(), "UTF-8")
             
             try:
                 StorageUtils.createOrUpdatePayload(fromObject, fromTFPackage.getId(), inStream)
             except StorageException:
                 print "error setting tfPackage"
             
             tfMetaPropertyValue = self.formData.get("tfMetaPropertyValue")
             self._addPropertyValueToTFMeta(toObject, tfMetaPropertyValue)
             
             self._reharvestPackage()
                 
             result = '{"status": "ok", "url": "%s/workflow/%s", "oid": "%s" }' % (context["portalPath"], toOid , toOid)
        else:
            result = '{"status": "err", "message": "%s"}' % self.errorMsg
        writer = self.response.getPrintWriter("application/json; charset=UTF-8")
        writer.println(result)
        writer.close()
开发者ID:ozej8y,项目名称:redbox,代码行数:60,代码来源:copyTfPackage.py

示例14: __checkMetadataPayload

 def __checkMetadataPayload(self):
     try:
         # Simple check for its existance
         self.object.getPayload("formData.tfpackage")
         self.firstHarvest = False
     except Exception:
         self.firstHarvest = True
         # We need to create it
         self.log.info("Creating 'formData.tfpackage' payload for object '{}'", self.oid)
         # Prep data
         data = {
             "viewId": "default",
             "workflow_source": "Edgar Import",
             "packageType": "dataset",
             "redbox:formVersion": self.redboxVersion,
             "redbox:newForm": "true"
         }
         package = JsonSimple(JsonObject(data))
         # Store it
         inStream = IOUtils.toInputStream(package.toString(True), "UTF-8")
         try:
             self.object.createStoredPayload("formData.tfpackage", inStream)
             self.packagePid = "formData.tfpackage"
         except StorageException, e:
             self.log.error("Error creating 'formData.tfpackage' payload for object '{}'", self.oid, e)
             raise Exception("Error creating package payload: ", e)
开发者ID:DanielBaird,项目名称:TDH-Research-Data-Catalogue,代码行数:26,代码来源:directoryNames.py

示例15: saveResponse

    def saveResponse(self, context):
        """ Save into object storage key to assessor's name
            It has four keys: status, recommendation, size-agreement and comments
            when status == "submitted", reviewer sees it
        """
        oid = self.request.getParameter("oid")
        action = self.request.getParameter("action")
        if action and re.match("submit", action, re.I):
            status = "submitted"
        else:
            status = "draft"

        recommendation = self.request.getParameter("recommendation")
        sizeAgreement = self.request.getParameter("size-agreement")
        comments = self.request.getParameter("comments")

        storedObj, fileExisted = self.hasResponses(oid)
        if fileExisted:
            committeeResponses = self.getResponses(storedObj)
        else:
            committeeResponses = JsonObject()

        assessorResponse = JsonObject()
        assessorResponse.put("status", status)
        if status == 'submitted':
            assessorResponse.put("date",self._getToday())
        assessorResponse.put("recommendation",recommendation)
        assessorResponse.put("size-agreement",sizeAgreement)
        assessorResponse.put("comments",comments)

        committeeResponses.put(self.assessor,assessorResponse)

        StorageUtils.createOrUpdatePayload(storedObj,self.PAYLOAD,IOUtils.toInputStream(committeeResponses.toString(), "UTF-8"))
        context["response"].sendRedirect(context["portalPath"] +"/detail/"+oid)
开发者ID:qcif,项目名称:rdsi-arms,代码行数:34,代码来源:Assessment.py


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