コード例 #1
0
ファイル: rss.py プロジェクト: seecr/meresco-components
    def handleRequest(self, RequestURI='', **kwargs):
        yield httputils.okRss
        yield """<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel>"""
        try:
            Scheme, Netloc, Path, Query, Fragment = urlsplit(RequestURI)
            arguments = parse_qs(Query)
            sortKeys = arguments.get('sortKeys', [self._sortKeys])[0]
            sortBy, sortDescending = None, None
            if sortKeys:
                sortBy, ignored, sortDescending = sortKeys.split(',')
                sortDescending = sortDescending == '1'

            maximumRecords = int(arguments.get('maximumRecords', [self._maximumRecords])[0])
            query = arguments.get('query', [''])[0]
            filters = arguments.get('filter', [])
            startRecord = 1

            if not query and not self._antiUnaryClause:
                raise SruMandatoryParameterNotSuppliedException("query")
            webquery = WebQuery(query, antiUnaryClause=self._antiUnaryClause)
            for filter in filters:
                if not ':' in filter:
                    raise BadRequestException('Invalid filter: %s' % filter)
                field,term = filter.split(':', 1)
                webquery.addFilter(field, term)

            ast = webquery.ast
        except (SruMandatoryParameterNotSuppliedException, BadRequestException, CQLParseException), e:
            yield '<title>ERROR %s</title>' % xmlEscape(self._title)
            yield '<link>%s</link>' % xmlEscape(self._link)
            yield "<description>An error occurred '%s'</description>" % xmlEscape(str(e))
            yield """</channel></rss>"""
            raise StopIteration()
コード例 #2
0
    def echoedExtraRequestData(self, sruArguments, **kwargs):
        requestedTerms = [
            singleRequest
            for request in sruArguments.get('x-term-drilldown', [])
            for singleRequest in request.split(',') if singleRequest.strip()
        ]
        if requestedTerms:
            outputFormat = sruArguments.get('x-drilldown-format',
                                            [self._defaultFormat])[0]
            if outputFormat == FORMAT_OLD_XML:
                yield _DRILLDOWN_HEADER % _DRILLDOWN_XSD_2007
                yield "<dd:term-drilldown>%s</dd:term-drilldown>" % xmlEscape(
                    ','.join(requestedTerms))
                yield DRILLDOWN_FOOTER
                return

            yield _DRILLDOWN_HEADER % _DRILLDOWN_XSD_2013
            yield '<dd:request>'
            for term in requestedTerms:
                yield "<dd:x-term-drilldown>%s</dd:x-term-drilldown>" % xmlEscape(
                    term)
            if 'x-drilldown-format' in sruArguments:
                yield "<dd:x-drilldown-format>%s</dd:x-drilldown-format>" % xmlEscape(
                    outputFormat)
            yield '</dd:request>'
            yield DRILLDOWN_FOOTER
コード例 #3
0
ファイル: oaiutils.py プロジェクト: seecr/meresco-oai
def oaiRequestArgs(arguments, requestUrl, **httpkwargs):
    url = xmlEscape(requestUrl)
    args = ' '.join([
        '%s="%s"' % (xmlEscape(k), xmlEscape(v[0]).replace('"', '&quot;'))
        for k, v in sorted(arguments.items())
    ])
    yield REQUEST % locals()
コード例 #4
0
ファイル: snapshot.py プロジェクト: mgijax/iphone_server
    def diffs(self, f1, f2):
	# foreach pair of records
	for idVal, r1, r2 in mergeIter(f1, f2, all=True):
	    r1 = r1 and self.convertZeros(r1) or None
	    r2 = r2 and self.convertZeros(r2) or None
	    # try each comparison
	    for cmpr in self.cmprs:
		try:
		    # report any diffs
		    for d in cmpr.diffs(r1, r2):
			d['id'] = idVal
			d['type'] = self.typ
			if d.get('subject',None) is None:
			    d['subject'] = self.labeler.get(self.stype, idVal, self.sformat)
			    if d['subject'] is None:
				logging.warn("No label found for: "+idVal)
				d['subject'] = '???'
			d['label'] = xmlEscape(d['subject']) + ' [' + idVal + ']'
			d['updateMessage'] = xmlEscape(d['updateMessage'] % d)
			d['pubDate'] = self.pubDate
			yield d
		except:
		    print "ERROR!"
		    print "comparator=",str(cmpr)
		    print "r1=",r1
		    print "r2=",r2
		    raise
コード例 #5
0
class Srw(Observable):
    def __init__(self, defaultRecordSchema=None, defaultRecordPacking=None):
        Observable.__init__(self)
        self._defaultRecordSchema = defaultRecordSchema
        self._defaultRecordPacking = defaultRecordPacking

    def handleRequest(self, Body='', **kwargs):
        try:
            arguments = self._soapXmlToArguments(Body)
            if not 'recordPacking' in arguments and self._defaultRecordPacking:
                arguments['recordPacking'] = [self._defaultRecordPacking]
            if not 'recordSchema' in arguments and self._defaultRecordSchema:
                arguments['recordSchema'] = [self._defaultRecordSchema]

        except SoapException, e:
            yield httputils.serverErrorXml
            yield SOAP % e.asSoap()
            raise StopIteration()

        yield httputils.okXml

        try:
            operation, arguments = self.call._parseArguments(arguments)
            self._srwSpecificValidation(operation, arguments)
            sruArgs, queryArgs = self.call.parseSruArgs(arguments)
        except SruException, e:
            yield SOAP % DIAGNOSTICS % (e.code, xmlEscape(
                e.details), xmlEscape(e.message))
            raise StopIteration()
コード例 #6
0
ファイル: srw.py プロジェクト: seecr/meresco-components
    def handleRequest(self, Body=b'', **kwargs):
        try:
            arguments = self._soapXmlToArguments(Body)
            if not 'recordPacking' in arguments and self._defaultRecordPacking:
                arguments['recordPacking'] = [self._defaultRecordPacking]
            if not 'recordSchema' in arguments and self._defaultRecordSchema:
                arguments['recordSchema'] = [self._defaultRecordSchema]

        except SoapException as e:
            yield httputils.serverErrorXml
            yield SOAP % e.asSoap()
            return

        yield httputils.okXml

        try:
            operation, arguments = self.call._parseArguments(arguments)
            self._srwSpecificValidation(operation, arguments)
            sruArgs, queryArgs = self.call.parseSruArgs(arguments)
        except SruException as e:
            yield SOAP % DIAGNOSTICS % (e.code, xmlEscape(e.details), xmlEscape(e.message))
            return

        try:
            yield SOAP_HEADER
            yield self.all.searchRetrieve(sruArguments=sruArgs, **queryArgs)
            yield SOAP_FOOTER
        except Exception as e:
            yield "Unexpected Exception:\n"
            yield str(e)
            raise e
コード例 #7
0
 def echoedExtraRequestData(self, sruArguments, **kwargs):
     if 'x-suggestionsQuery' not in sruArguments:
         return
     yield '<suggestions xmlns="http://meresco.org/namespace/suggestions">\n'
     yield '<query>%s</query>' % xmlEscape(sruArguments['x-suggestionsQuery'][0])
     yield '<count>%s</count>' % self._getCount(sruArguments)
     yield '<field>%s</field>' % xmlEscape(self._getField(sruArguments))
     yield '</suggestions>'
コード例 #8
0
 def _writeDiagnostics(self, diagnostics):
     if not diagnostics:
         return
     yield '<srw:diagnostics>'
     for code, message, details in diagnostics:
         yield self._createDiagnostic(uri=code,
                                      message=xmlEscape(message),
                                      details=xmlEscape(details))
     yield '</srw:diagnostics>'
コード例 #9
0
 def _writeResult(self, recordSchema=None, recordPacking=None, hit=None, version=None, **kwargs):
     yield '<srw:record>'
     yield '<srw:recordSchema>%s</srw:recordSchema>' % xmlEscape(recordSchema)
     yield '<srw:recordPacking>%s</srw:recordPacking>' % xmlEscape(recordPacking)
     if version == "1.2":
         yield '<srw:recordIdentifier>%s</srw:recordIdentifier>' % xmlEscape(hit.id)
     yield self._writeRecordData(recordSchema=recordSchema, recordPacking=recordPacking, recordId=hit.id)
     yield self._writeExtraRecordData(recordPacking=recordPacking, hit=hit, **kwargs)
     yield '</srw:record>'
コード例 #10
0
 def _writeResult(self, recordSchema=None, recordPacking=None, hit=None, version=None, **kwargs):
     yield '<srw:record>'
     yield '<srw:recordSchema>%s</srw:recordSchema>' % xmlEscape(recordSchema)
     yield '<srw:recordPacking>%s</srw:recordPacking>' % xmlEscape(recordPacking)
     if version == "1.2":
         yield '<srw:recordIdentifier>%s</srw:recordIdentifier>' % xmlEscape(hit.id)
     yield self._writeRecordData(recordSchema=recordSchema, recordPacking=recordPacking, recordId=hit.id)
     yield self._writeExtraRecordData(recordPacking=recordPacking, hit=hit, **kwargs)
     yield '</srw:record>'
コード例 #11
0
 def _createOutput(self, anUpload):
     if not self._target.oaiEnvelope:
         return anUpload.record
     envelopedata = {
         "identifier": xmlEscape(anUpload.recordIdentifier),
         "metadataPrefix": xmlEscape(str(anUpload.repository.metadataPrefix)),
         "baseurl": xmlEscape(str(anUpload.repository.baseurl)),
         "responseDate": self.tznow(),
         "recordData": lxmltostring(anUpload.record),
     }
     return parse(StringIO(OAI_ENVELOPE % envelopedata), XMLParser(ns_clean=True)).getroot()
コード例 #12
0
 def createRecord(self, dataDictionary):
     try:
         link = self._linkTemplate % dict(((k, urlQuote(v)) for k,v in dataDictionary.items()))
     except KeyError:
         link = ''
     rssData = {
         'link': xmlEscape(link),
         'description': xmlEscape(dataDictionary.get('description', '')),
         'title': xmlEscape(dataDictionary.get('title', ''))
     }
     return str(RSS_TEMPLATE % rssData)
コード例 #13
0
 def echoedExtraRequestData(self, sruArguments, **kwargs):
     if 'x-suggestionsQuery' not in sruArguments:
         return
     yield '<suggestions xmlns="http://meresco.org/namespace/suggestions">\n'
     yield '<query>%s</query>' % xmlEscape(
         sruArguments['x-suggestionsQuery'][0])
     yield '<count>%s</count>' % self._getCount(sruArguments)
     yield '<field>%s</field>' % xmlEscape(self._getField(sruArguments))
     suggestMode = self._getSuggestMode(sruArguments)
     if suggestMode:
         yield '<mode>%s</mode>' % xmlEscape(suggestMode)
     yield '</suggestions>'
コード例 #14
0
    def handleRequest(self, RequestURI='', **kwargs):
        yield httputils.okRss
        yield """<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel>"""

        try:
            Scheme, Netloc, Path, Query, Fragment = urlsplit(RequestURI)
            arguments = parse_qs(Query)
            sortKeys = arguments.get('sortKeys', [self._sortKeys])[0]
            sortBy, sortDescending = None, None
            if sortKeys:
                sortBy, ignored, sortDescending = sortKeys.split(',')
                sortDescending = sortDescending == '0'

            # Set Language:
            prefLanguage = arguments.get('preflang', [self._supportedLanguages[0]])[0]
            # This might be German:-(  Not anymore :-)
            prefLanguage = prefLanguage if prefLanguage.lower() in self._supportedLanguages else self._supportedLanguages[0]

            # Get max records, from request or get default
            maximumRecords = int(arguments.get('maximumRecords', [self._maximumRecords])[0])
            maximumRecords = maximumRecords if maximumRecords <= self._max_maximumRecords else int(self._max_maximumRecords) # Check if requested max does not exceed our max...

            #set startrecord: we support rss paging...
            startRecord = int(arguments.get('startRecord', [self._startRecord])[0])
            
            #set querylabel:
            querylabel = arguments.get('querylabel', [self._title.get(prefLanguage)])[0]

            #get userquery:
            query = arguments.get('query', [''])[0]
            filters = arguments.get('filter', [])
            # startRecord = 1

            if not query and not self._antiUnaryClause:
                raise SruMandatoryParameterNotSuppliedException("query")

            webquery = WebQuery(query, antiUnaryClause=self._antiUnaryClause)
            for filter in filters:
                if not ':' in filter:
                    raise BadRequestException('Invalid filter: %s' % filter)
                field,term = filter.split(':', 1)
                webquery.addFilter(field, term)

            ast = webquery.ast

        except (SruMandatoryParameterNotSuppliedException, BadRequestException, CQLParseException), e:
            yield '<title>ERROR %s</title>' % xmlEscape(self._title)
            # yield '<link>%s</link>' % xmlEscape(self._link)
            yield '<link>%s</link>' % xmlEscape(self._link.get(prefLanguage))
            yield "<description>An error occurred '%s'</description>" % xmlEscape(str(e))
            yield """</channel></rss>"""
            raise StopIteration()
コード例 #15
0
 def _createOutput(self, anUpload):
     if not self._target.oaiEnvelope:
         return anUpload.record
     envelopedata = {
         'identifier': xmlEscape(anUpload.recordIdentifier),
         'metadataPrefix':
         xmlEscape(str(anUpload.repository.metadataPrefix)),
         'baseurl': xmlEscape(str(anUpload.repository.baseurl)),
         'responseDate': self.tznow(),
         'recordData': lxmltostring(anUpload.record)
     }
     return parse(StringIO(OAI_ENVELOPE % envelopedata),
                  XMLParser(ns_clean=True)).getroot()
コード例 #16
0
    def send(self, anUpload):
        anId = anUpload.id
        self._logLine('UPLOAD.SEND', 'START', id = anId)

        recordData = '<document xmlns="http://meresco.org/namespace/harvester/document">%s</document>' % ''.join(
                ['<part name="%s">%s</part>' % (xmlEscape(partName), xmlEscape(partValue)) for partName, partValue in anUpload.parts.items()])

        action = "replace"
        recordIdentifier= xmlEscape(anId)
        recordPacking = 'xml'
        recordSchema = xmlEscape(partName)
        self._sendData(anId, recordUpdate % locals())
        self._logLine('UPLOAD.SEND', 'END', id = anId)
コード例 #17
0
    def handleRequest(self, arguments, **kwargs):
        yield httputils.okXml

        yield XML_HEADER
        try:
            operation, arguments = self._parseArguments(arguments)
            operationMethod = self._explain
            if operation == 'searchRetrieve':
                operationMethod = self._searchRetrieve
            yield operationMethod(arguments, **kwargs)
        except SruException, e:
            additionalDiagnosticDetails = compose(self.all.additionalDiagnosticDetails())
            details = ' - '.join([e.details] + list(additionalDiagnosticDetails))
            yield DIAGNOSTICS % (e.code, xmlEscape(details), xmlEscape(e.message))
            raise StopIteration()
コード例 #18
0
    def _writeExtraRecordData(self, sruArguments=None, recordPacking=None, hit=None, **kwargs):
        generator = compose(self.all.extraRecordData(hit=hit))

        started = False
        for data in generator:
            if not started:
                yield '<srw:extraRecordData>'
                started = True
            yield data

        for schema in sruArguments.get('x-recordSchema', []):
            if not started:
                yield '<srw:extraRecordData>'
                started = True
            if not self._extraRecordDataNewStyle:
                yield self._writeOldStyleExtraRecordData(schema, recordPacking, hit.id)
                continue
            yield '<srw:record>'
            yield '<srw:recordSchema>%s</srw:recordSchema>' % xmlEscape(schema)
            yield '<srw:recordPacking>%s</srw:recordPacking>' % recordPacking
            yield '<srw:recordData>'
            yield self._catchErrors(self._yieldData(identifier=hit.id, recordSchema=schema, recordPacking=recordPacking), schema, hit.id)
            yield '</srw:recordData>'
            yield '</srw:record>'
        if started:
            yield '</srw:extraRecordData>'
コード例 #19
0
    def _writeExtraRecordData(self, sruArguments=None, recordPacking=None, hit=None, **kwargs):
        generator = compose(self.all.extraRecordData(hit=hit))

        started = False
        for data in generator:
            if not started:
                yield '<srw:extraRecordData>'
                started = True
            yield data

        for schema in sruArguments.get('x-recordSchema', []):
            if not started:
                yield '<srw:extraRecordData>'
                started = True
            if not self._extraRecordDataNewStyle:
                yield self._writeOldStyleExtraRecordData(schema, recordPacking, hit.id)
                continue
            yield '<srw:record>'
            yield '<srw:recordSchema>%s</srw:recordSchema>' % xmlEscape(schema)
            yield '<srw:recordPacking>%s</srw:recordPacking>' % recordPacking
            yield '<srw:recordData>'
            yield self._catchErrors(self._yieldData(identifier=hit.id, recordSchema=schema, recordPacking=recordPacking), schema, hit.id)
            yield '</srw:recordData>'
            yield '</srw:record>'
        if started:
            yield '</srw:extraRecordData>'
コード例 #20
0
 def _writeOldStyleExtraRecordData(self, schema, recordPacking, recordId):
     yield '<recordData recordSchema="%s">' % xmlEscape(schema)
     yield self._catchErrors(
         self._yieldData(identifier=recordId,
                         recordSchema=schema,
                         recordPacking=recordPacking), schema, recordId)
     yield '</recordData>'
コード例 #21
0
    def oaiRecordHeader(self, record, **kwargs):
        isDeletedStr = ' status="deleted"' if record.isDeleted else ''
        datestamp = record.getDatestamp(
            preciseDatestamp=self._preciseDatestamp)
        identifier = record.identifier.encode('utf-8')

        #########
        str_genre = ''  # Get 'genre' from normalized short format: We cannot tell from the identifier.
        try:
            data = yield self.any.retrieveData(identifier=record.identifier,
                                               name="knaw_short")
            genre = findall("<genre>(.+?)</genre>", data)
            if len(genre) >= 1: str_genre = genre[0]
            if not str_genre in CERIF_GENRE_MAPPING.keys():
                str_genre = "publication"
            # if str_genre == 'research': # Might be a Funding... <type_nl>Financieringsprogramma</type_nl>
            #     metadata = yield self.any.retrieveData(identifier=record.identifier, name="metadata")
            #     if len(findall("<type_nl>Financieringsprogramma</type_nl>", metadata)) >= 1: str_genre = "funding"
        except IOError:
            pass
        if self._repository:
            identifier = self._repository.prefixIdentifier(
                identifier, CERIF_GENRE_MAPPING.get(str_genre, ''))
########
        yield '<header%s>' % isDeletedStr
        yield '<identifier>%s</identifier>' % xmlEscape(identifier)
        yield '<datestamp>%s</datestamp>' % datestamp
        yield self._getSetSpecs(record)
        yield '</header>'
コード例 #22
0
ファイル: graph.py プロジェクト: idkwim/sonare
    def _formatHex(self, hexstring):
        '''Add spaces between hex chars, format nicely as HTML'''

        assert len(hexstring) % 2 == 0
        hexWithSpaces = ' '.join(hexstring[i:i + 2]
                                 for i in xrange(0, len(hexstring), 2))
        return xmlEscape(hexWithSpaces)
コード例 #23
0
 def result():
     yield '<doc:document xmlns:doc="http://meresco.org/namespace/harvester/document">'
     for subpart, data in resultparts:
         yield '<doc:part name="%s">' % xmlEscape(subpart)
         yield data
         yield '</doc:part>'
     yield '</doc:document>'
コード例 #24
0
 def _writeDiagnostics(self, diagnostics):
     if not diagnostics:
         return
     yield '<srw:diagnostics>'
     for code, message, details in diagnostics:
         yield self._createDiagnostic(uri=code, message=xmlEscape(message), details=xmlEscape(details))
     yield '</srw:diagnostics>'
コード例 #25
0
 def _extraResponseDataTryExcept(self, **kwargs):
     try:
         yield self.all.extraResponseData(**kwargs)
     except Exception, e:
         print_exc()
         yield self._createDiagnostic(uri=GENERAL_SYSTEM_ERROR[0],
                                      message=GENERAL_SYSTEM_ERROR[1],
                                      details=xmlEscape(str(e)))
コード例 #26
0
 def add(self, identifier, data, **kwargs):
     yield self._upload(
         SRURECORDUPDATE_TEMPLATE % {
             b'recordIdentifier':
             bytes(xmlEscape(identifier), encoding="utf-8"),
             b'recordData':
             data if type(data) is bytes else bytes(data, encoding="utf-8")
         })
コード例 #27
0
 def delete(self, anUpload):
     self._logDelete(anUpload.id)
     action = "delete"
     recordIdentifier = xmlEscape(anUpload.id)
     recordPacking = 'xml'
     recordSchema = 'ignored'
     recordData = '<ignored/>'
     self._sendData(anUpload.id, recordUpdate % locals())
コード例 #28
0
    def listMetadataFormats(self, arguments, **httpkwargs):
        responseDate = zuluTime()
        verb = arguments.get('verb', [None])[0]
        if not verb == 'ListMetadataFormats':
            return

        try:
            validatedArguments = self._validateArguments(arguments)
            metadataFormats = self.call.getAllMetadataFormats()
            if 'identifier' in validatedArguments:
                identifier = validatedArguments['identifier']
                if self._repository:
                    identifier = self._repository.unprefixIdentifier(
                        identifier)
                record = self.call.getRecord(identifier=identifier)
                if record is None:
                    raise OaiException('idDoesNotExist')
                metadataFormats = [(prefix, xsd, ns)
                                   for prefix, xsd, ns in metadataFormats
                                   if prefix in record.prefixes]
            displayedMetadataFormats = sorted(metadataFormats)
        except OaiException as e:
            yield oaiError(
                e.statusCode,
                e.additionalMessage,
                arguments,
                requestUrl=self._repository.requestUrl(**httpkwargs),
                **httpkwargs)
            return

        yield oaiHeader(self, responseDate)
        yield oaiRequestArgs(
            arguments,
            requestUrl=self._repository.requestUrl(**httpkwargs),
            **httpkwargs)
        yield '<%s>' % verb
        for metadataPrefix, schema, metadataNamespace in displayedMetadataFormats:
            yield '<metadataFormat>'
            yield '<metadataPrefix>%s</metadataPrefix>' % xmlEscape(
                metadataPrefix)
            yield '<schema>%s</schema>' % xmlEscape(schema)
            yield '<metadataNamespace>%s</metadataNamespace>' % xmlEscape(
                metadataNamespace)
            yield '</metadataFormat>'
        yield '</%s>' % verb
        yield oaiFooter()
コード例 #29
0
 def result():
     yield b'<doc:document xmlns:doc="http://meresco.org/namespace/harvester/document">'
     for subpart, data in resultparts:
         yield b'<doc:part name="%b">' % bytes(xmlEscape(subpart),
                                               encoding='utf-8')
         yield data
         yield b'</doc:part>'
     yield b'</doc:document>'
コード例 #30
0
 def delete(self, anUpload):
     self._logDelete(anUpload.id)
     action = "delete"
     recordIdentifier = xmlEscape(anUpload.id)
     recordPacking = 'xml'
     recordSchema = 'ignored'
     recordData = '<ignored/>'
     self._sendData(anUpload.id, recordUpdate % locals())
コード例 #31
0
ファイル: graph.py プロジェクト: blaquee/sonare
    def _formatHex(self, hexstring):
        '''Add spaces between hex chars, format nicely as HTML'''

        assert len(hexstring) % 2 == 0
        hexWithSpaces = ' '.join(
            hexstring[i:i+2]
            for i in xrange(0, len(hexstring), 2))
        return xmlEscape(hexWithSpaces)
コード例 #32
0
 def _yieldData(self, identifier=None, recordSchema=None, recordPacking=None):
     data = yield self.any.retrieveData(identifier=identifier, name=recordSchema)
     if recordPacking == 'xml':
         yield data
     elif recordPacking == 'string':
         yield xmlEscape(data)
     else:
         raise Exception("Unknown Record Packing: %s" % recordPacking)
コード例 #33
0
    def changePasswordForm(self,
                           session,
                           path,
                           arguments,
                           user=None,
                           lang=None,
                           onlyNewPassword=False,
                           **kwargs):
        lang = lang or self._lang
        formValues = session.get('BasicHtmlLoginForm.formValues',
                                 {}) if session else {}
        yield """<div id="login-change-password-form">\n"""
        if not USER in session:
            yield '<p class="error">Please login to change password.</p>\n</div>'
            return
        if 'errorMessage' in formValues:
            yield '    <p class="error">%s</p>\n' % xmlEscape(
                formValues['errorMessage'])

        formUrl = path
        if arguments:
            formUrl += "?" + urlencode(arguments, doseq=True)

        username = session[USER].name if user is None else (
            user if isinstance(user, basestring) else user.name)
        values = dict(
            action=quoteattr(join(self._action, 'changepassword')),
            formUrl=quoteattr(formUrl),
            returnUrl=quoteattr(kwargs.get('returnUrl', path)),
            username=quoteattr(username),
            lblOldPassword=getLabel(lang, "changepasswordForm",
                                    "old-password"),
            lblNewPassword=getLabel(lang, "changepasswordForm",
                                    "new-password"),
            lblNewPasswordRepeat=getLabel(lang, "changepasswordForm",
                                          "new-password-repeat"),
            lblChange=getLabel(lang, "changepasswordForm", "change"),
        )

        yield """<form method="POST" name="changePassword" action=%(action)s>
        <input type="hidden" name="formUrl" value=%(formUrl)s/>
        <input type="hidden" name="returnUrl" value=%(returnUrl)s/>
        <input type="hidden" name="username" value=%(username)s/>
        <dl>
            """ % values
        if not onlyNewPassword:
            yield """<dt>%(lblOldPassword)s</dt>
            <dd><input type="password" name="oldPassword"/></dd>""" % values
        yield """
            <dt>%(lblNewPassword)s</dt>
            <dd><input type="password" name="newPassword"/></dd>
            <dt>%(lblNewPasswordRepeat)s</dt>
            <dd><input type="password" name="retypedPassword"/></dd>
            <dd class="submit"><input type="submit" value="%(lblChange)s"/></dd>
        </dl>
    </form>
</div>""" % values
        session.pop('BasicHtmlLoginForm.formValues', None)
コード例 #34
0
    def echoedExtraRequestData(self, sruArguments, **kwargs):
        requestedTerms = [singleRequest for request in sruArguments.get('x-term-drilldown',[]) for singleRequest in request.split(',') if singleRequest.strip()]
        if requestedTerms:
            outputFormat = sruArguments.get('x-drilldown-format', [self._defaultFormat])[0]
            if outputFormat == FORMAT_OLD_XML:
                yield _DRILLDOWN_HEADER % _DRILLDOWN_XSD_2007
                yield "<dd:term-drilldown>%s</dd:term-drilldown>" % xmlEscape(','.join(requestedTerms))
                yield DRILLDOWN_FOOTER
                return

            yield _DRILLDOWN_HEADER % _DRILLDOWN_XSD_2013
            yield '<dd:request>'
            for term in requestedTerms:
                yield "<dd:x-term-drilldown>%s</dd:x-term-drilldown>" % xmlEscape(term)
            if 'x-drilldown-format' in sruArguments:
                yield "<dd:x-drilldown-format>%s</dd:x-drilldown-format>" % xmlEscape(outputFormat)
            yield '</dd:request>'
            yield DRILLDOWN_FOOTER
コード例 #35
0
    def handleRequest(self, arguments, **kwargs):
        yield httputils.okXml

        yield XML_HEADER
        try:
            operation, arguments = self._parseArguments(arguments)
            operationMethod = self._explain
            if operation == 'searchRetrieve':
                operationMethod = self._searchRetrieve
            yield operationMethod(arguments, **kwargs)
        except SruException, e:
            additionalDiagnosticDetails = compose(
                self.all.additionalDiagnosticDetails())
            details = ' - '.join([e.details] +
                                 list(additionalDiagnosticDetails))
            yield DIAGNOSTICS % (e.code, xmlEscape(details),
                                 xmlEscape(e.message))
            raise StopIteration()
コード例 #36
0
 def formatFailure(buff, kind, name, msg):
     buff.write(
         '  <testcase status="run" time="0" classname="{}" name="{}">\n'.
         format(kind, name))
     fixedMsg = xmlEscape(msg).replace('"', '&quot;')
     buff.write(
         '    <failure message="{}" type=""><![CDATA[{}]]></failure>\n'.
         format(fixedMsg, msg))
     buff.write('  </testcase>\n')
コード例 #37
0
 def delete(self, identifier):
     body = """<ucp:updateRequest xmlns:ucp="info:lc/xmlns/update-v1">
         <srw:version xmlns:srw="http://www.loc.gov/zing/srw/">1.0</srw:version>
         <ucp:action>info:srw/action/1/delete</ucp:action>
         <ucp:recordIdentifier>%s</ucp:recordIdentifier>
     </ucp:updateRequest>""" % xmlEscape(identifier)
     response = self._send(body)
     self.checkResponse(response)
     yield
コード例 #38
0
 def _getSetSpecs(self, record):
     if record.sets:
         deletedSets = set()
         if self._deleteInSetsSupport:
             deletedSets = record.deletedSets
         return ''.join('<setSpec{1}>{0}</setSpec>'.format(
                 xmlEscape(setSpec),
                 ' status="deleted"' if setSpec in deletedSets else ''
             ) for setSpec in sorted(record.sets))
     return ''
コード例 #39
0
 def __init__(self, text, caption):
     figures.Figure.__init__(self, 0, 0, caption)
     descrStyle = ParagraphStyle('description',
                             fontName='Courier',
                             fontSize=8,
                             leading=9.6)
     textStyle = B
     self.text = text
     self.left = Paragraph(xmlEscape(text), descrStyle)
     self.right = Paragraph(text, B)
コード例 #40
0
    def newUserForm(self, session, path, lang=None, extraFields="", **kwargs):
        lang = lang or self._lang
        formValues = session.get('BasicHtmlLoginForm.newUserFormValues',
                                 {}) if session else {}
        yield """<div id="login-new-user-form">\n"""
        if not USER in session:
            yield '<p class="error">Please login to add new users.</p>\n</div>'
            return
        if 'errorMessage' in formValues:
            yield '    <p class="error">%s</p>\n' % xmlEscape(
                formValues['errorMessage'])
        if 'successMessage' in formValues:
            yield '    <p class="success">%s</p>\n' % xmlEscape(
                formValues['successMessage'])

        values = dict(username=quoteattr(formValues.get('username', '')),
                      action=quoteattr(join(self._action, 'newUser')),
                      formUrl=quoteattr(path),
                      returnUrl=quoteattr(kwargs.get('returnUrl', path)),
                      lblUsername=getLabel(lang, 'newuserForm', 'username'),
                      lblPassword=getLabel(lang, 'newuserForm', 'password'),
                      lblPasswordRepeat=getLabel(lang, 'newuserForm',
                                                 'password-repeat'),
                      lblCreate=getLabel(lang, 'newuserForm', 'create'),
                      extraFields=extraFields)

        yield """
    <form method="POST" name="newUser" action=%(action)s>
        <input type="hidden" name="formUrl" value=%(formUrl)s/>
        <input type="hidden" name="returnUrl" value=%(returnUrl)s/>
        <dl>
            <dt>%(lblUsername)s</dt>
            <dd><input type="text" name="username" value=%(username)s/></dd>
            <dt>%(lblPassword)s</dt>
            <dd><input type="password" name="password"/></dd>
            <dt>%(lblPasswordRepeat)s</dt>
            <dd><input type="password" name="retypedPassword"/></dd>
            %(extraFields)s
            <dd class="submit"><input type="submit" value="%(lblCreate)s"/></dd>
        </dl>
    </form>
</div>""" % values
        session.pop('BasicHtmlLoginForm.newUserFormValues', None)
コード例 #41
0
 def __init__(self, text, caption):
     figures.Figure.__init__(self, 0, 0, caption)
     descrStyle = ParagraphStyle('description',
                                 fontName='Courier',
                                 fontSize=8,
                                 leading=9.6)
     textStyle = B
     self.text = text
     self.left = Paragraph(xmlEscape(text), descrStyle)
     self.right = Paragraph(text, B)
コード例 #42
0
ファイル: oairecord.py プロジェクト: seecr/meresco-oai
 def _getSetSpecs(self, record):
     if record.sets:
         deletedSets = set()
         if self._deleteInSetsSupport:
             deletedSets = record.deletedSets
         return ''.join('<setSpec{1}>{0}</setSpec>'.format(
                 xmlEscape(setSpec),
                 ' status="deleted"' if setSpec in deletedSets else ''
             ) for setSpec in sorted(record.sets))
     return ''
コード例 #43
0
 def _writeEchoedSearchRetrieveRequest(self, sruArguments, **kwargs):
     yield '<srw:echoedSearchRetrieveRequest>'
     for paramSets in ECHOED_PARAMETER_NAMES, self._extraXParameters:
         for parameterName in paramSets:
             value = sruArguments.get(parameterName, [])
             for v in (value if isinstance(value, list) else [value]):
                 aValue = xmlEscape(str(v))
                 yield '<srw:%(parameterName)s>%(aValue)s</srw:%(parameterName)s>' % locals()
     for chunk in decorate('<srw:extraRequestData>', compose(self.all.echoedExtraRequestData(sruArguments=sruArguments, **kwargs)), '</srw:extraRequestData>'):
         yield chunk
     yield '</srw:echoedSearchRetrieveRequest>'
コード例 #44
0
 def oaiRecordHeader(self, record, **kwargs):
     isDeletedStr = ' status="deleted"' if record.isDeleted else ''
     datestamp = record.getDatestamp(preciseDatestamp=self._preciseDatestamp)
     identifier = record.identifier.encode('utf-8')
     if self._repository:
         identifier = self._repository.prefixIdentifier(identifier)
     yield '<header%s>' % isDeletedStr
     yield '<identifier>%s</identifier>' % xmlEscape(identifier)
     yield '<datestamp>%s</datestamp>' % datestamp
     yield self._getSetSpecs(record)
     yield '</header>'
コード例 #45
0
    def send(self, anUpload):
        anId = anUpload.id
        self._logLine('UPLOAD.SEND', 'START', id=anId)

        partsItems = list(anUpload.parts.items())
        recordData = '<document xmlns="http://meresco.org/namespace/harvester/document">%s</document>' % ''.join(
            [
                '<part name="%s">%s</part>' %
                (xmlEscape(partName), xmlEscape(partValue))
                for partName, partValue in partsItems
            ])

        action = "replace"
        recordIdentifier = xmlEscape(anId)
        recordPacking = 'xml'

        partName, _ = partsItems[-1]
        recordSchema = xmlEscape(partName)
        self._sendData(anId, recordUpdate % locals())
        self._logLine('UPLOAD.SEND', 'END', id=anId)
コード例 #46
0
ファイル: loggerrss.py プロジェクト: DANS-KNAW/gmh-meresco
    def handleRequest(self, RequestURI='', **kwargs):
        yield httputils.okRss
        yield """<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"><channel>"""
        try:
            Scheme, Netloc, Path, Query, Fragment = urlsplit(RequestURI)
            arguments = parse_qs(Query)
            maximumRecords = int(
                arguments.get('maximumRecords', [self._maximumRecords])[0])
            rId = arguments.get('repositoryId', [''])[0]  #['']
            if rId == '' or not rId:
                raise BadRequestException('Invalid repositoryId parameter.')

        except (SruMandatoryParameterNotSuppliedException, BadRequestException,
                CQLParseException), e:
            yield '<title>ERROR %s</title>' % xmlEscape(self._title)
            yield '<link>%s</link>' % xmlEscape(self._link)
            yield "<description>An error occurred '%s'</description>" % xmlEscape(
                str(e))
            yield """</channel></rss>"""
            raise StopIteration()
コード例 #47
0
 def oaiRecordHeader(self, record, **kwargs):
     isDeletedStr = ' status="deleted"' if record.isDeleted else ''
     datestamp = record.getDatestamp(preciseDatestamp=self._preciseDatestamp)
     identifier = record.identifier
     if self._repository:
         identifier = self._repository.prefixIdentifier(identifier)
     yield '<header%s>' % isDeletedStr
     yield '<identifier>%s</identifier>' % xmlEscape(identifier)
     yield '<datestamp>%s</datestamp>' % datestamp
     yield self._getSetSpecs(record)
     yield '</header>'
コード例 #48
0
 def _writeEchoedSearchRetrieveRequest(self, sruArguments, **kwargs):
     yield '<srw:echoedSearchRetrieveRequest>'
     for paramSets in ECHOED_PARAMETER_NAMES, self._extraXParameters:
         for parameterName in paramSets:
             value = sruArguments.get(parameterName, [])
             for v in (value if isinstance(value, list) else [value]):
                 aValue = xmlEscape(str(v))
                 yield '<srw:%(parameterName)s>%(aValue)s</srw:%(parameterName)s>' % locals()
     for chunk in decorate('<srw:extraRequestData>', compose(self.all.echoedExtraRequestData(sruArguments=sruArguments, **kwargs)), '</srw:extraRequestData>'):
         yield chunk
     yield '</srw:echoedSearchRetrieveRequest>'
コード例 #49
0
    def newUserForm(self, session, path, lang=None, extraFields="", **kwargs):
        lang = lang or self._lang
        formValues = session.get('BasicHtmlLoginForm.newUserFormValues', {}) if session else {}
        yield """<div id="login-new-user-form">\n"""
        if not USER in session:
            yield '<p class="error">Please login to add new users.</p>\n</div>'
            return
        if 'errorMessage' in formValues:
            yield '    <p class="error">%s</p>\n' % xmlEscape(formValues['errorMessage'])
        if 'successMessage' in formValues:
            yield '    <p class="success">%s</p>\n' % xmlEscape(formValues['successMessage'])

        values = dict(
            username=quoteattr(formValues.get('username', '')),
            action=quoteattr(join(self._action, 'newUser')),
            formUrl=quoteattr(path),
            returnUrl=quoteattr(kwargs.get('returnUrl', path)),
            lblUsername=getLabel(lang, 'newuserForm', 'username'),
            lblPassword=getLabel(lang, 'newuserForm', 'password'),
            lblPasswordRepeat=getLabel(lang, 'newuserForm', 'password-repeat'),
            lblCreate=getLabel(lang, 'newuserForm', 'create'),
            extraFields=extraFields
        )

        yield """
    <form method="POST" name="newUser" action=%(action)s>
        <input type="hidden" name="formUrl" value=%(formUrl)s/>
        <input type="hidden" name="returnUrl" value=%(returnUrl)s/>
        <dl>
            <dt>%(lblUsername)s</dt>
            <dd><input type="text" name="username" value=%(username)s/></dd>
            <dt>%(lblPassword)s</dt>
            <dd><input type="password" name="password"/></dd>
            <dt>%(lblPasswordRepeat)s</dt>
            <dd><input type="password" name="retypedPassword"/></dd>
            %(extraFields)s
            <dd class="submit"><input type="submit" value="%(lblCreate)s"/></dd>
        </dl>
    </form>
</div>""" % values
        session.pop('BasicHtmlLoginForm.newUserFormValues', None)
コード例 #50
0
    def test0(self):
        """Test story with TOC and a cascaded header hierarchy.

        The story should contain exactly one table of contents that is
        immediatly followed by a list of of cascaded levels of header
        lines, each nested one level deeper than the previous one.

        Features to be visually confirmed by a human being are:

            1. TOC lines are indented in multiples of 1 cm.
            2. Wrapped TOC lines continue with additional 0.5 cm indentation.
            3. Only entries of every second level has links
            ...
        """

        maxLevels = 12

        # Create styles to be used for document headers
        # on differnet levels.
        headerLevelStyles = []
        for i in range(maxLevels):
            headerLevelStyles.append(makeHeaderStyle(i))

        # Create styles to be used for TOC entry lines
        # for headers on differnet levels.
        tocLevelStyles = []
        d, e = tableofcontents.delta, tableofcontents.epsilon
        for i in range(maxLevels):
            tocLevelStyles.append(makeTocHeaderStyle(i, d, e))

        # Build story.
        story = []
        styleSheet = getSampleStyleSheet()
        bt = styleSheet['BodyText']

        description = '<font color=red>%s</font>' % self.test0.__doc__
        story.append(XPreformatted(description, bt))

        toc = tableofcontents.TableOfContents()
        toc.levelStyles = tocLevelStyles
        story.append(toc)

        for i in range(maxLevels):
            story.append(Paragraph('HEADER, LEVEL %d' % i,
                                   headerLevelStyles[i]))
            #now put some body stuff in.
            txt = xmlEscape(randomtext.randomText(randomtext.PYTHON, 5))
            para = Paragraph(txt, makeBodyStyle())
            story.append(para)

        path = outputfile('test_platypus_toc.pdf')
        doc = MyDocTemplate(path)
        doc.multiBuild(story)
コード例 #51
0
 def _termDrilldown(self, drilldownData, format):
     if format == FORMAT_XML:
         self._dd_item = self._dd_item_new
         for facet in drilldownData:
             yield self._dd_navigator(facet['fieldname'], facet['terms'])
     elif format == FORMAT_JSON:
         yield "<dd:json>%s</dd:json>" % xmlEscape(dumps(drilldownData, indent=4))
     elif format == FORMAT_OLD_XML:
         self._dd_item = self._dd_item_old
         for facet in drilldownData:
             yield self._dd_navigator(facet['fieldname'], facet['terms'])
     else:
         raise ValueError("Expected x-drilldown-format to be one of: %s" % str([FORMAT_XML, FORMAT_JSON]))
コード例 #52
0
 def extraResponseData(self, drilldownData, sruArguments, **kwargs):
     if drilldownData is None:
         return
     outputFormat = sruArguments.get('x-drilldown-format', [self._defaultFormat])[0]
     drilldownHeader = _DRILLDOWN_HEADER % (_DRILLDOWN_XSD_2007 if outputFormat == FORMAT_OLD_XML else _DRILLDOWN_XSD_2013)
     try:
         yield decorate(drilldownHeader, self._termDrilldown(drilldownData, format=outputFormat), DRILLDOWN_FOOTER)
     except Exception, e:
         print_exc()
         yield drilldownHeader + "<dd:term-drilldown>"
         yield generalSystemError(xmlEscape(e.args[0]))
         yield "</dd:term-drilldown>" + DRILLDOWN_FOOTER
         return
コード例 #53
0
ファイル: preppy.py プロジェクト: AndyKovv/hostel
def uStdQuote(s):
    if not isinstance(s,strTypes):
        if s is None: return u'' #we usually don't want output
        cnv = getattr(s,_ucvn,None)
        if not cnv:
            cnv = getattr(s,_bcvn,None)
        s = cnv() if cnv else unicodeT(s)
    if isinstance(s,_safeBase):
        if isinstance(s,SafeString):
            s = s.decode('utf8')
        return s
    elif not isinstance(s,unicodeT):
        s = s.decode('utf8')
    return xmlEscape(s)
コード例 #54
0
 def _dd_navigator(self, fieldname, terms):
     try:
         firstTerm = terms[0]
         yield '<dd:navigator name=%s>' % quoteattr(fieldname)
         yield self._dd_item(firstTerm)
         for term in terms[1:]:
             yield self._dd_item(term)
         yield '</dd:navigator>'
     except IndexError:
         yield '<dd:navigator name=%s/>' % quoteattr(fieldname)
         return
     except Exception, e:
         print_exc()
         yield generalSystemError(xmlEscape(str(e)))
         return
コード例 #55
0
    def userList(self, session, path, userLink=None, **kwargs):
        yield """<div id="login-user-list">\n"""
        if not USER in session:
            yield '<p class="error">Please login to show user list.</p>\n</div>'
            return
        sessionUser = session[USER]
        if sessionUser.canEdit():
            yield """<script type="text/javascript">
function deleteUser(username) {
    if (confirm("Are you sure?")) {
        document.removeUser.username.value = username;
        document.removeUser.submit();
    }
}
            </script>"""
            yield """<form name="removeUser" method="POST" action=%s>
            <input type="hidden" name="formUrl" value=%s/>
            <input type="hidden" name="username"/>""" % (
                    quoteattr(join(self._action, 'remove')),
                    quoteattr(path),
                )
            yield '</form>\n'
        yield '<ul>\n'
        for user in sorted(self._listUsers(), key=lambda u:u.title()):
            yield '<li>'
            if userLink:
                yield '<a href="%s?user=%s">%s</a>' % (userLink, xmlEscape(user.name), xmlEscape(user.title()))
            else:
                yield xmlEscape(user.title())
            if sessionUser.name != user.name and (
                    sessionUser.canEdit(user.name)
                ):
                yield """ <a href="javascript:deleteUser('%s');">delete</a>""" % user.name
            yield '</li>\n'
        yield '</ul>\n'
        yield '</div>\n'
コード例 #56
0
    def extraResponseData(self, response, sruArguments, **kwargs):
        if not hasattr(response, 'suggestions'):
            return
        sortedSuggestions = sorted(response.suggestions.items())
        if not sortedSuggestions:
            return

        yield '<suggestions xmlns="http://meresco.org/namespace/suggestions">\n'
        shortest = min([len(suggestions) for word, suggestions in sortedSuggestions])
        for i in range(shortest):
            suggestionWords = unicode(sruArguments['x-suggestionsQuery'][0]).split()
            for word, suggestions in reversed(sortedSuggestions):
                replaceWord = suggestions[i]
                suggestionWords[suggestionWords.index(word)] = replaceWord
            yield "<suggestion>%s</suggestion>\n" % xmlEscape(' '.join(suggestionWords))
        yield '</suggestions>\n'
コード例 #57
0
    def changePasswordForm(self, session, path, arguments, user=None, lang=None, onlyNewPassword=False, **kwargs):
        lang = lang or self._lang
        formValues = session.get('BasicHtmlLoginForm.formValues', {}) if session else {}
        yield """<div id="login-change-password-form">\n"""
        if not USER in session:
            yield '<p class="error">Please login to change password.</p>\n</div>'
            return
        if 'errorMessage' in formValues:
            yield '    <p class="error">%s</p>\n' % xmlEscape(formValues['errorMessage'])

        formUrl = path
        if arguments:
            formUrl += "?" + urlencode(arguments, doseq=True)

        username = session[USER].name if user is None else (user if isinstance(user, basestring) else user.name)
        values = dict(
            action=quoteattr(join(self._action, 'changepassword')),
            formUrl=quoteattr(formUrl),
            returnUrl=quoteattr(kwargs.get('returnUrl', path)),
            username=quoteattr(username),
            lblOldPassword=getLabel(lang, "changepasswordForm", "old-password"),
            lblNewPassword=getLabel(lang, "changepasswordForm", "new-password"),
            lblNewPasswordRepeat=getLabel(lang, "changepasswordForm", "new-password-repeat"),
            lblChange=getLabel(lang, "changepasswordForm", "change"),
        )

        yield """<form method="POST" name="changePassword" action=%(action)s>
        <input type="hidden" name="formUrl" value=%(formUrl)s/>
        <input type="hidden" name="returnUrl" value=%(returnUrl)s/>
        <input type="hidden" name="username" value=%(username)s/>
        <dl>
            """ % values
        if not onlyNewPassword:
            yield """<dt>%(lblOldPassword)s</dt>
            <dd><input type="password" name="oldPassword"/></dd>""" % values
        yield """
            <dt>%(lblNewPassword)s</dt>
            <dd><input type="password" name="newPassword"/></dd>
            <dt>%(lblNewPasswordRepeat)s</dt>
            <dd><input type="password" name="retypedPassword"/></dd>
            <dd class="submit"><input type="submit" value="%(lblChange)s"/></dd>
        </dl>
    </form>
</div>""" % values
        session.pop('BasicHtmlLoginForm.formValues', None)