本文整理汇总了Python中java.net.URLDecoder类的典型用法代码示例。如果您正苦于以下问题:Python URLDecoder类的具体用法?Python URLDecoder怎么用?Python URLDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URLDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __search
def __search(self):
recordsPerPage = self.__portal.recordsPerPage
query = formData.get("query")
if query is None or query == "":
query = "*:*"
req = SearchRequest(query)
req.setParam("facet", "true")
req.setParam("rows", str(recordsPerPage))
req.setParam("facet.field", self.__portal.facetFieldList)
req.setParam("facet.sort", "true")
req.setParam("facet.limit", str(self.__portal.facetCount))
req.setParam("sort", "f_dc_title asc")
# setup facets
action = formData.get("action")
value = formData.get("value")
fq = sessionState.get("fq")
if fq is not None:
self.__pageNum = 1
req.setParam("fq", fq)
if action == "add_fq":
self.__pageNum = 1
name = formData.get("name")
print " * add_fq: %s" % value
req.addParam("fq", URLDecoder.decode(value, "UTF-8"))
elif action == "remove_fq":
self.__pageNum = 1
req.removeParam("fq", URLDecoder.decode(value, "UTF-8"))
elif action == "clear_fq":
self.__pageNum = 1
req.removeParam("fq")
elif action == "select-page":
self.__pageNum = int(value)
req.addParam("fq", 'item_type:"object"')
portalQuery = self.__portal.query
print " * portalQuery=%s" % portalQuery
if portalQuery:
req.addParam("fq", portalQuery)
self.__selected = req.getParams("fq")
sessionState.set("fq", self.__selected)
sessionState.set("pageNum", self.__pageNum)
req.setParam("start", str((self.__pageNum - 1) * recordsPerPage))
print " * search.py:", req.toString(), self.__pageNum
out = ByteArrayOutputStream()
Services.indexer.search(req, out)
self.__result = JsonConfigHelper(ByteArrayInputStream(out.toByteArray()))
if self.__result is not None:
self.__paging = Pagination(self.__pageNum,
int(self.__result.get("response/numFound")),
self.__portal.recordsPerPage)
示例2: readAsServer_0
def readAsServer_0(cls, socket):
""" generated source for method readAsServer_0 """
br = BufferedReader(InputStreamReader(socket.getInputStream()))
# The first line of the HTTP request is the request line.
requestLine = br.readLine()
if requestLine == None:
raise IOException("The HTTP request was empty.")
message = str()
if requestLine.toUpperCase().startsWith("GET "):
message = requestLine.substring(5, requestLine.lastIndexOf(' '))
message = URLDecoder.decode(message, "UTF-8")
message = message.replace(str(13), ' ')
elif requestLine.toUpperCase().startsWith("POST "):
message = readContentFromPOST(br)
elif requestLine.toUpperCase().startsWith("OPTIONS "):
# Web browsers can send an OPTIONS request in advance of sending
# real XHR requests, to discover whether they should have permission
# to send those XHR requests. We want to handle this at the network
# layer rather than sending it up to the actual player, so we write
# a blank response (which will include the headers that the browser
# is interested in) and throw an exception so the player ignores the
# rest of this request.
HttpWriter.writeAsServer(socket, "")
raise IOException("Drop this message at the network layer.")
else:
HttpWriter.writeAsServer(socket, "")
raise IOException("Unexpected request type: " + requestLine)
return message
示例3: _loadForm
def _loadForm(self):
""" Display the form and prepare the saved assessment from this assessor if exists
The uri has to be http(s)://root/portal/assess/oid
"""
uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
matches = re.match("^(.*?)/(.*?)/(.*?)$", uri)
if matches and matches.group(3):
self.oid = matches.group(3)
storedObj = self.storage.getObject(self.oid)
payloadList = storedObj.getPayloadIdList()
self.assessment = None
tfpackage = None
for pid in payloadList:
if pid.endswith(".tfpackage"):
tfpackage = pid
break
if tfpackage:
self.reviewers = self._readReviewers(storedObj, tfpackage)
else:
raise("No tfpakcage has been found.")
if payloadList.contains(self.PAYLOAD):
committeeResponses = self.getResponses(storedObj)
self.assessment = committeeResponses.get(self.assessor)
else:
self.oid = "null"
示例4: __init__
def __init__(self):
print "**** formData: ", formData.get("func")
if formData.get("func") == "open-file":
self.__openFile()
writer = response.getPrintWriter("text/plain")
writer.println("{}")
writer.close()
else:
self.__storage = Services.storage
uri = URLDecoder.decode(request.getAttribute("RequestURI"))
basePath = portalId + "/" + pageName
self.__oid = uri[len(basePath) + 1 :]
slash = self.__oid.rfind("/")
self.__pid = self.__oid[slash + 1 :]
payload = self.__storage.getPayload(self.__oid, self.__pid)
if payload is not None:
self.__mimeType = payload.contentType
else:
self.__mimeType = "application/octet-stream"
self.__metadata = JsonConfigHelper()
print " * detail.py: uri='%s' oid='%s' pid='%s' mimeType='%s'" % (
uri,
self.__oid,
self.__pid,
self.__mimeType,
)
self.__search()
示例5: __uploadMedia
def __uploadMedia(self, oid, doc, content, elem, attr):
links = doc.getElementsByTagName(elem)
for i in range(0, links.getLength()):
elem = links.item(i)
attrValue = elem.getAttribute(attr)
pid = attrValue
payload = Services.getStorage().getPayload(oid, pid)
if payload is None:
pid = URLDecoder.decode(pid, "UTF-8")
payload = Services.getStorage().getPayload(oid, pid)
if payload is not None:
#HACK to upload PDFs
contentType = payload.getContentType().replace("application/", "image/")
entry = self.__postMedia(payload.getLabel(), contentType,
payload.getInputStream())
if entry is not None:
id = entry.getId()
print " * blog.py: replacing %s with %s" % (attrValue, id)
content = content.replace('%s="%s"' % (attr, attrValue),
'%s="%s"' % (attr, id))
content = content.replace("%s='%s'" % (attr, attrValue),
"%s='%s'" % (attr, id))
else:
print " * blog.py: failed to upload %s" % pid
return content
示例6: __init__
def __init__(self):
self.__storage = Services.storage
uri = request.getAttribute("RequestURI")
basePath = portalId + "/" + pageName
self.__oid = URLDecoder.decode(uri[len(basePath)+1:])
self.__dcRdf = None
self.__metadata = JsonConfigHelper()
self.__search()
示例7: __activate__
def __activate__(self, context):
self.sessionState = context["sessionState"]
self.services = context["Services"]
self.security = context["security"]
self.request = context["request"]
self.portalId = context["portalId"]
uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
self.__relPath = "/".join(uri.split("/")[1:])
self.authentication = AuthenticationData()
self.authentication.__activate__(context)
示例8: __init__
def __init__(self):
basePath = portalId + "/" + pageName
uri = request.getAttribute("RequestURI")
print " * download.py: basePath=%s uri=%s" % (basePath, uri)
uri = uri[len(basePath) + 1 :]
if uri.find("%2F") == -1:
slash = uri.rfind("/")
else:
slash = uri.find("/")
oid = URLDecoder.decode(uri[:slash])
pid = URLDecoder.decode(uri[slash + 1 :])
print " * download.py: oid=%s pid=%s" % (oid, pid)
payload = Services.storage.getPayload(oid, pid)
filename = os.path.split(pid)[1]
mimeType = payload.contentType
if mimeType == "application/octet-stream":
response.setHeader("Content-Disposition", "attachment; filename=%s" % filename)
out = response.getOutputStream(payload.contentType)
IOUtils.copy(payload.inputStream, out)
out.close()
示例9: __init__
def __init__(self):
basePath = portalId + "/" + pageName
fullUri = URLDecoder.decode(request.getAttribute("RequestURI"))
uri = fullUri[len(basePath) + 1 :]
try:
object, payload = self.__resolve(uri)
if object == None:
response.sendRedirect(contextPath + "/" + fullUri + "/")
return
print "URI='%s' OID='%s' PID='%s'" % (uri, object.getId(), payload.getId())
except StorageException, e:
payload = None
print "Failed to get object: %s" % (str(e))
示例10: __activate__
def __activate__(self, context):
self.velocityContext = context
self.services = context["Services"]
self.request = context["request"]
self.response = context["response"]
self.contextPath = context["contextPath"]
self.formData = context["formData"]
self.page = context["page"]
self.uaActivated = False
useDownload = Boolean.parseBoolean(self.formData.get("download", "true"))
self.__isPreview = Boolean.parseBoolean(self.formData.get("preview", "false"))
self.__previewPid = None
self.__hasPid = False
uri = URLDecoder.decode(self.request.getAttribute("RequestURI"))
matches = re.match("^(.*?)/(.*?)/(?:(.*?)/)?(.*)$", uri)
if matches and matches.group(3):
oid = matches.group(3)
pid = matches.group(4)
self.__metadata = JsonConfigHelper()
self.__object = self.__getObject(oid)
self.__oid = oid
# If we have a PID
if pid:
self.__hasPid = True
if useDownload:
# Download the payload to support relative links
download = DownloadData()
download.__activate__(context)
else:
# Render the detail screen with the alternative preview
self.__readMetadata(oid)
self.__previewPid = pid
# Otherwise, render the detail screen
else:
self.__readMetadata(oid)
self.__previewPid = self.getPreview()
if self.__previewPid:
self.__previewPid = URLEncoder.encode(self.__previewPid, "UTF-8")
else:
# require trailing slash for relative paths
q = ""
if self.__isPreview:
q = "?preview=true"
self.response.sendRedirect("%s/%s/%s" % (self.contextPath, uri, q))
示例11: __getJson
def __getJson(self):
data = {}
basePath = portalId + "/" + pageName
uri = URLDecoder.decode(request.getAttribute("RequestURI"))
oid = uri[len(basePath)+1:]
payload = Services.storage.getPayload(oid, "imsmanifest.xml")
if payload is not None:
try:
from xml.etree import ElementTree as ElementTree
#xml = ElementTree()
#IOUtils.copy(payload.inputStream, out)
sb = StringBuilder()
inputStream = payload.inputStream
reader = BufferedReader(InputStreamReader(inputStream,
"UTF-8"))
while True:
line=reader.readLine()
if line is None:
break
sb.append(line).append("\n")
inputStream.close()
xmlStr = sb.toString()
xml = ElementTree.XML(xmlStr)
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")
#print resources
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
data["title"] = title
items = []
for item in organization.findall(ns+"item"):
a = item.attrib
isVisible = a.get("isvisible")
idr = a.get("identifierref")
id = resources.get(idr)
iTitle = item.find(ns+"title").text
if isVisible and id and id.endswith(".htm"):
items.append({"attributes":{"id":id}, "data":iTitle})
data["nodes"] = items
except Exception, e:
data["error"] = "Error - %s" % str(e)
print data["error"]
示例12: __init__
def __init__(self):
self.__storage = Services.storage
uri = URLDecoder.decode(request.getAttribute("RequestURI"))
basePath = portalId + "/" + pageName
self.__oid = uri[len(basePath)+1:]
slash = self.__oid.rfind("/")
self.__pid = self.__oid[slash+1:]
print " * detail.py: uri='%s' oid='%s' pid='%s'" % (uri, self.__oid, self.__pid)
if formData.get("verb") == "open":
self.__openFile()
else:
payload = self.__storage.getPayload(self.__oid, self.__pid)
if payload is not None:
self.__mimeType = payload.contentType
else:
self.__mimeType = "application/octet-stream"
self.__metadata = JsonConfigHelper()
self.__search()
示例13: __init__
def __init__(self):
self.__portal = Services.portalManager.get(portalId)
self.__result = JsonConfigHelper()
self.__pageNum = sessionState.get("pageNum", 1)
self.__selected = []
self.__storage = Services.storage
uri = URLDecoder.decode(request.getAttribute("RequestURI"))
basePath = portalId + "/" + pageName
self.__oid = uri[len(basePath)+1:]
slash = self.__oid.rfind("/")
self.__pid = self.__oid[slash+1:]
payload = self.__storage.getPayload(self.__oid, self.__pid)
if payload is not None:
self.__mimeType = payload.contentType
else:
self.__mimeType = "application/octet-stream"
self.__metadata = JsonConfigHelper()
print " * combined.py: uri='%s' oid='%s' pid='%s' mimeType='%s'" % (uri, self.__oid, self.__pid, self.__mimeType)
self.__search()
示例14: getObject
def getObject(self):
if self.__object is None:
# Grab the URL
req = self.vc("request").getAttribute("RequestURI")
uri = URLDecoder.decode(req)
# Cut everything down to the OID
basePath = self.vc("portalId") + "/" + self.vc("pageName")
oid = uri[len(basePath)+1:]
# Trim a trailing slash
if oid.endswith("/"):
oid = oid[:-1]
# Now get the object
if oid is not None:
try:
self.__object = Services.storage.getObject(oid)
return self.__object
except StorageException, e:
self.vc("log").error("Failed to retrieve object : " + e.getMessage())
return None
示例15: __init__
def __init__(self):
basePath = portalId + "/" + pageName
uri = URLDecoder.decode(request.getAttribute("RequestURI"))
uri = uri[len(basePath)+1:]
oid, pid, payload = self.__resolve(uri)
print """ * download.py: uri='%s'
oid='%s'
pid='%s'
payload='%s'""" % (uri, oid, pid, payload)
if payload is not None:
filename = os.path.split(pid)[1]
mimeType = payload.contentType
if mimeType == "application/octet-stream":
response.setHeader("Content-Disposition", "attachment; filename=%s" % filename)
out = response.getOutputStream(payload.contentType)
IOUtils.copy(payload.inputStream, out)
out.close()
else:
response.setStatus(404)
writer = response.getPrintWriter("text/plain")
writer.println("Not found: uri='%s'" % uri)
writer.close()