本文整理汇总了Python中org.apache.commons.io.IOUtils.toInputStream方法的典型用法代码示例。如果您正苦于以下问题:Python IOUtils.toInputStream方法的具体用法?Python IOUtils.toInputStream怎么用?Python IOUtils.toInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.IOUtils
的用法示例。
在下文中一共展示了IOUtils.toInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __activate__
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
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()
示例2: __activate__
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
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)
示例3: __checkMetadataPayload
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
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)
示例4: __checkMetadataPayload
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def __checkMetadataPayload(self, identifier):
# We are just going to confirm the existance of
# 'metadata.json', or create an empty one if it
# doesn't exist. Makes curation function for this
# option and removes some log errors on the details
# screen.
try:
self.object.getPayload("metadata.json")
# all is good, the above will throw an exception if it doesn't exist
return
except Exception:
self.log.info("Creating 'metadata.json' payload for object '{}'", self.oid)
# Prep data
metadata = JsonSimple()
metadata.getJsonObject().put("recordIDPrefix", "")
metadata.writeObject("data")
# The only real data we require is the ID for curation
idHolder = metadata.writeObject("metadata")
idHolder.put("dc.identifier", identifier)
# Store it
inStream = IOUtils.toInputStream(metadata.toString(True), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(self.object, "metadata.json", inStream)
except StorageException, e:
self.log.error("Error creating 'metadata.json' payload for object '{}'", self.oid, e)
return
示例5: saveResponse
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
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)
示例6: updatePackageType
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def updatePackageType(self, tfPackage, toWorkflowId):
tfPackageJson = JsonSimple(tfPackage.open()).getJsonObject()
tfPackageJson.put("packageType", toWorkflowId)
inStream = IOUtils.toInputStream(tfPackageJson.toString(), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(self.object, tfPackage.getId(), inStream)
except StorageException:
print " ERROR updating dataset payload"
示例7: updateWorkFlowMetadata
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def updateWorkFlowMetadata(self, workflowMetadata, toWorkflowId, toWorkflowStage):
workflowMetaDataJson = JsonSimple(workflowMetadata.open()).getJsonObject()
workflowMetaDataJson.put("id", toWorkflowId)
workflowMetaDataJson.put("step", toWorkflowStage)
inStream = IOUtils.toInputStream(workflowMetaDataJson.toString(), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(self.object, "workflow.metadata", inStream)
except StorageException:
print " ERROR updating dataset payload"
示例8: __createOrUpdateArrayPayload
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def __createOrUpdateArrayPayload(self, oid, payloadName, newObject):
"""
Create or update a payload object in storage defined by oid
The content of this digital object is a JsonArray of objects
payloadName: name of the payload
newObject: new object to be appended, e.g. a JsonObject
"""
objList = self.__getPayloadJsonArray(oid, payloadName)
objList.add(newObject)
storedObj = self.Services.getStorage().getObject(oid)
StorageUtils.createOrUpdatePayload(storedObj, payloadName,IOUtils.toInputStream(objList.toString(), "UTF-8"))
示例9: __tidy
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def __tidy(self, content):
tidy = Tidy()
tidy.setIndentAttributes(False)
tidy.setIndentContent(False)
tidy.setPrintBodyOnly(True)
tidy.setSmartIndent(False)
tidy.setWraplen(0)
tidy.setXHTML(False)
tidy.setNumEntities(True)
out = ByteArrayOutputStream()
doc = tidy.parseDOM(IOUtils.toInputStream(content, "UTF-8"), out)
content = out.toString("UTF-8")
return content, doc
示例10: __updateMetadataPayload
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def __updateMetadataPayload(self, data):
# Get and parse
payload = self.object.getPayload("formData.tfpackage")
json = JsonSimple(payload.open())
payload.close()
# Basic test for a mandatory field
title = json.getString(None, ["dc:title"])
if title is not None:
# We've done this before
return
# Merge
json.getJsonObject().putAll(data)
# Store it
inStream = IOUtils.toInputStream(json.toString(True), "UTF-8")
try:
self.object.updatePayload("formData.tfpackage", inStream)
except StorageException, e:
self.log.error("Error updating 'formData.tfpackage' payload for object '{}'", self.oid, e)
示例11: __workflow
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def __workflow(self):
# Workflow data
WORKFLOW_ID = "Parties_People"
wfChanged = False
workflow_security = []
self.message_list = None
stages = self.config.getJsonSimpleList(["stages"])
initialStep = 0
try:
wfMeta = self.__getJsonPayload("workflow.metadata")
# Are we indexing because of a workflow progression?
targetStep = wfMeta.getString(None, ["targetStep"])
if targetStep is not None and targetStep != wfMeta.getString(None, ["step"]):
wfChanged = True
# Step change
wfMeta.getJsonObject().put("step", targetStep)
wfMeta.getJsonObject().remove("targetStep")
# This must be a re-index then
else:
targetStep = wfMeta.getString(None, ["step"])
# Security change
for stage in stages:
if stage.getString(None, ["name"]) == targetStep:
wfMeta.getJsonObject().put("label", stage.getString(None, ["label"]))
self.item_security = stage.getStringList(["visibility"])
workflow_security = stage.getStringList(["security"])
if wfChanged == True:
self.message_list = stage.getStringList(["message"])
except StorageException:
# No workflow payload, time to create
initialStage = stages.get(initialStep).getString(None, ["name"])
wfChanged = True
wfMeta = JsonSimple()
wfMetaObj = wfMeta.getJsonObject()
wfMetaObj.put("id", WORKFLOW_ID)
wfMetaObj.put("step", initialStage)
stages = self.config.getJsonSimpleList(["stages"])
for stage in stages:
if stage.getString(None, ["name"]) == initialStage:
wfMetaObj.put("label", stage.getString(None, ["label"]))
self.item_security = stage.getStringList(["visibility"])
workflow_security = stage.getStringList(["security"])
self.message_list = stage.getStringList(["message"])
# Has the workflow metadata changed?
if wfChanged == True:
inStream = IOUtils.toInputStream(wfMeta.toString(True), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(self.object, "workflow.metadata", inStream)
except StorageException:
print " ERROR updating dataset payload"
# Form processing
coreFields = ["title", "description"]
formData = wfMeta.getObject(["formData"])
if formData is not None:
formData = JsonSimple(formData)
# Core fields
description = formData.getStringList(["description"])
if description:
self.descriptionList = description
# Non-core fields
data = formData.getJsonObject()
for field in data.keySet():
if field not in coreFields:
self.customFields[field] = formData.getStringList([field])
# Workflow processing
wfStep = wfMeta.getString(None, ["step"])
self.utils.add(self.index, "workflow_id", wfMeta.getString(None, ["id"]))
self.utils.add(self.index, "workflow_step", wfStep)
self.utils.add(self.index, "workflow_step_label", wfMeta.getString(None, ["label"]))
for group in workflow_security:
self.utils.add(self.index, "workflow_security", group)
if self.owner is not None:
self.utils.add(self.index, "workflow_security", self.owner)
# set OAI-PMH status to deleted
if wfStep == "retired":
self.utils.add(self.index, "oai_deleted", "true")
示例12: __copyString
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def __copyString(self, s, out):
IOUtils.copy(IOUtils.toInputStream(String(s), "UTF-8"), out)
示例13: __authorize_with_service_account
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def __authorize_with_service_account(service_account_json):
credential = GoogleCredential.fromStream(IOUtils.toInputStream(service_account_json, StandardCharsets.UTF_8)).createScoped(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))
return credential
示例14: __activate__
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
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)
# get relevant dc:description from new object before you overwrite it with 'from' data, as this should exist from form data created in initial object packaging (packaging.py)
toTFPackageJson = JsonSimple(toTFPackage.open()).getJsonObject()
relevant_description = toTFPackageJson.get("dc:description")
fromInputStream = fromTFPackage.open()
try:
StorageUtils.createOrUpdatePayload(toObject, toTFPackage.getId(), fromInputStream)
except StorageException:
print "error setting tfPackage"
finally:
fromTFPackage.close()
tfMetaPropertyValue = self.formData.get("tfMetaPropertyValue")
if tfMetaPropertyValue == 'dmpToSelfSub':
# fetch recently created new 'to' object from storage to get all data
toTFPackage = self._getTFPackage(toObject)
toTFPackageJson = JsonSimple(toTFPackage.open()).getJsonObject()
self.setMultiDescription(toTFPackageJson, relevant_description)
inStream = IOUtils.toInputStream(toTFPackageJson.toJSONString(), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(toObject, toTFPackage.getId(), inStream)
except StorageException:
print "error setting description text in tfPackage"
finally:
inStream.close()
self.log.info(
"Completed migrating 'dc:description' to dc:decription.1.text' for oid: %s." % toTFPackage.getId())
self.log.debug("Result: %r" % toTFPackageJson)
fromTFPackageJson = JsonSimple(fromTFPackage.open()).getJsonObject()
self.log.debug('from json is: %r' % fromTFPackageJson)
if storeRelatedData != "false":
# add relatedOid info
fromTFPackageJson = self._addRelatedOid(JsonSimple(fromTFPackage.open()), toOid)
self.log.debug('from tfPackage json is now: %r' % fromTFPackageJson)
inStream = IOUtils.toInputStream(fromTFPackageJson.toJSONString(), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(fromObject, fromTFPackage.getId(), inStream)
except StorageException:
print "error setting tfPackage"
finally:
inStream.close()
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()
示例15: __workflow
# 需要导入模块: from org.apache.commons.io import IOUtils [as 别名]
# 或者: from org.apache.commons.io.IOUtils import toInputStream [as 别名]
def __workflow(self):
# Workflow data
WORKFLOW_ID = "dataset"
wfChanged = False
workflow_security = []
self.message_list = None
stages = self.config.getJsonSimpleList(["stages"])
if self.owner == "guest":
pageTitle = "Submission Request"
displayType = "submission-request"
initialStep = 0
else:
pageTitle = "Metadata Record"
displayType = "package-dataset"
initialStep = 1
try:
wfMeta = self.__getJsonPayload("workflow.metadata")
wfMeta.getJsonObject().put("pageTitle", pageTitle)
# Are we indexing because of a workflow progression?
targetStep = wfMeta.getString(None, ["targetStep"])
if targetStep is not None and targetStep != wfMeta.getString(None, ["step"]):
wfChanged = True
# Step change
wfMeta.getJsonObject().put("step", targetStep)
wfMeta.getJsonObject().remove("targetStep")
# This must be a re-index then
else:
targetStep = wfMeta.getString(None, ["step"])
# Security change
for stage in stages:
if stage.getString(None, ["name"]) == targetStep:
wfMeta.getJsonObject().put("label", stage.getString(None, ["label"]))
self.item_security = stage.getStringList(["visibility"])
workflow_security = stage.getStringList(["security"])
if wfChanged == True:
self.message_list = stage.getStringList(["message"])
except StorageException:
# No workflow payload, time to create
initialStage = stages.get(initialStep).getString(None, ["name"])
wfChanged = True
wfMeta = JsonSimple()
wfMetaObj = wfMeta.getJsonObject()
wfMetaObj.put("id", WORKFLOW_ID)
wfMetaObj.put("step", initialStage)
wfMetaObj.put("pageTitle", pageTitle)
stages = self.config.getJsonSimpleList(["stages"])
for stage in stages:
if stage.getString(None, ["name"]) == initialStage:
wfMetaObj.put("label", stage.getString(None, ["label"]))
self.item_security = stage.getStringList(["visibility"])
workflow_security = stage.getStringList(["security"])
self.message_list = stage.getStringList(["message"])
# Has the workflow metadata changed?
if wfChanged == True:
inStream = IOUtils.toInputStream(wfMeta.toString(True), "UTF-8")
try:
StorageUtils.createOrUpdatePayload(self.object, "workflow.metadata", inStream)
except StorageException:
print " ERROR updating dataset payload"
# Form processing
coreFields = ["title", "description", "manifest", "metaList", "relationships", "responses"]
formData = wfMeta.getObject(["formData"])
if formData is not None:
formData = JsonSimple(formData)
# Core fields
description = formData.getStringList(["description"])
if description:
self.descriptionList = description
# Non-core fields
data = formData.getJsonObject()
for field in data.keySet():
if field not in coreFields:
self.customFields[field] = formData.getStringList([field])
# Manifest processing (formData not present in wfMeta)
manifest = self.__getJsonPayload(self.packagePid)
formTitles = manifest.getStringList(["title"])
if formTitles:
for formTitle in formTitles:
if self.title is None:
self.title = formTitle
self.descriptionList = [manifest.getString("", ["description"])]
#Used to make sure we have a created date
createdDateFlag = False
formData = manifest.getJsonObject()
for field in formData.keySet():
if field not in coreFields:
value = formData.get(field)
if value is not None and value.strip() != "":
self.utils.add(self.index, field, value)
# We want to sort by date of creation, so it
# needs to be indexed as a date (ie. 'date_*')
if field == "dc:created":
#.........这里部分代码省略.........