Example #1
0
    def _write_response(self):
        """ Generate response """
        # set HTTP response headers and XML declaration

        xmldecl = ''
        appinfo = ''

        LOGGER.info('Writing response.')

        if hasattr(self, 'soap') and self.soap:
            self._gen_soap_wrapper()

        if etree.__version__ >= '3.5.0':  # remove superfluous namespaces
            etree.cleanup_namespaces(self.response,
                                     keep_ns_prefixes=self.context.keep_ns_prefixes)

        response = etree.tostring(self.response,
                                  pretty_print=self.pretty_print,
                                  encoding='unicode')


        if (isinstance(self.kvp, dict) and 'outputformat' in self.kvp and
                (self.kvp['outputformat'] == 'application/xml' or self.kvp['outputformat'] == 'application/XML')):
            self.contenttype = self.kvp['outputformat']
            

            xmldecl = ('<?xml version="1.0" encoding="%s" standalone="no"?>'
                       '\n' % self.encoding)
            appinfo = '<!-- pycsw %s -->\n' % self.context.version

        else:  # it's json

            self.contenttype = "application/json"

            from pycsw.core.formats import fmt_json
            response = fmt_json.xml2json(response,
                                         self.context.namespaces,
                                         self.pretty_print)
        
        if isinstance(self.contenttype, bytes):
            self.contenttype = self.contenttype.decode()
        LOGGER.debug(response)
        #response = '{"csw30:SummaryRecord": {"dc:identifier123": "urn:uuid:a06af396-3105-442d-8b40-22b57a90d2f2","dc:title": "Lorem ipsum dolor sit amet","dc:type": "http://purl.org/dc/dcmitype/Image","dc:format": "image/jpeg", "": {"": ""}}}'
        s = (u'%s%s%s' % (xmldecl, appinfo, response)).encode(self.encoding)
        LOGGER.debug('Response code: %s',
                     self.context.response_codes[self.status])
        LOGGER.debug('Response:\n%s', s)
        return [self.context.response_codes[self.status], s]
Example #2
0
    def _write_response(self):
        """ Generate response """
        # set HTTP response headers and XML declaration

        xmldecl = ''
        appinfo = ''

        LOGGER.info('Writing response.')

        if hasattr(self, 'soap') and self.soap:
            self._gen_soap_wrapper()

        if etree.__version__ >= '3.5.0':  # remove superfluous namespaces
            etree.cleanup_namespaces(self.response,
                                     keep_ns_prefixes=self.context.keep_ns_prefixes)

        response = etree.tostring(self.response,
                                  pretty_print=self.pretty_print,
                                  encoding='unicode')

        if (isinstance(self.kvp, dict) and 'outputformat' in self.kvp and
                self.kvp['outputformat'] == 'application/json'):
            self.contenttype = self.kvp['outputformat']
            from pycsw.core.formats import fmt_json
            response = fmt_json.xml2json(response,
                                         self.context.namespaces,
                                         self.pretty_print)
        else:  # it's XML
            if 'outputformat' in self.kvp:
                self.contenttype = self.kvp['outputformat']
            else:
                self.contenttype = self.mimetype

            xmldecl = ('<?xml version="1.0" encoding="%s" standalone="no"?>'
                       '\n' % self.encoding)
            appinfo = '<!-- pycsw %s -->\n' % self.context.version

        if isinstance(self.contenttype, bytes):
            self.contenttype = self.contenttype.decode()

        s = (u'%s%s%s' % (xmldecl, appinfo, response)).encode(self.encoding)
        LOGGER.debug('Response code: %s',
                     self.context.response_codes[self.status])
        LOGGER.debug('Response:\n%s', s)
        return [self.context.response_codes[self.status], s]
Example #3
0
    def _write_response(self):
        """ Generate response """
        # set HTTP response headers and XML declaration

        xmldecl = ''
        appinfo = ''

        LOGGER.info('Writing response.')

        if hasattr(self, 'soap') and self.soap:
            self._gen_soap_wrapper()

        if etree.__version__ >= '3.5.0':  # remove superfluous namespaces
            etree.cleanup_namespaces(self.response,
                                     keep_ns_prefixes=self.context.keep_ns_prefixes)

        response = etree.tostring(self.response,
                                  pretty_print=self.pretty_print,
                                  encoding='unicode')

        if (isinstance(self.kvp, dict) and 'outputformat' in self.kvp and
                self.kvp['outputformat'] == 'application/json'):
            self.contenttype = self.kvp['outputformat']
            from pycsw.core.formats import fmt_json
            response = fmt_json.xml2json(response,
                                         self.context.namespaces,
                                         self.pretty_print)
        else:  # it's XML
            if 'outputformat' in self.kvp:
                self.contenttype = self.kvp['outputformat']
            else:
                self.contenttype = self.mimetype

            xmldecl = ('<?xml version="1.0" encoding="%s" standalone="no"?>'
                       '\n' % self.encoding)
            appinfo = '<!-- pycsw %s -->\n' % self.context.version

        if isinstance(self.contenttype, bytes):
            self.contenttype = self.contenttype.decode()

        s = (u'%s%s%s' % (xmldecl, appinfo, response)).encode(self.encoding)
        LOGGER.debug('Response code: %s',
                     self.context.response_codes[self.status])
        LOGGER.debug('Response:\n%s', s)
        return [self.context.response_codes[self.status], s]
    def _write_response(self):
        """ Generate response """
        # set HTTP response headers and XML declaration

        xmldecl = ''
        appinfo = ''

        LOGGER.info('Writing response.')

        #import webbrowser

        # neuer code für unsere API html anzeigen zu können TAN
        #if self.response == 'a':
            #print('ja')
            
            #new = 2 # open in a new tab, if possible

            #url = "'/usr/lib/python3.5/site-packages/pycsw/test.html'"
            #webbrowser.open(url,new=new)
            #open('/usr/lib/python3.5/site-packages/pycsw/test.html')
            #print('nein')

        if hasattr(self, 'soap') and self.soap:
            self._gen_soap_wrapper()

        if etree.__version__ >= '3.5.0':  # remove superfluous namespaces
            etree.cleanup_namespaces(self.response,
                                     keep_ns_prefixes=self.context.keep_ns_prefixes)

        response = etree.tostring(self.response,
                                  pretty_print=self.pretty_print,
                                  encoding='unicode')

        # Funktion wird aufgerufen um xml in json umzuwandeln, wenn es in der url angegeben ist 
        if (isinstance(self.kvp, dict) and 'outputformat' in self.kvp and
                self.kvp['outputformat'] == 'application/json'):
            self.contenttype = self.kvp['outputformat']
            from pycsw.core.formats import fmt_json
            response = fmt_json.xml2json(response,
                                         self.context.namespaces,
                                         self.pretty_print)
        
        # new requests for the similarities should be always in json format (@author: Anika Graupner)
        elif (isinstance(self.kvp, dict) and 'request' in self.kvp and
                self.kvp['request'] == 'GetSimilarRecords'):
            
                if (isinstance(self.kvp, dict) and 'outputformat' in self.kvp and
                    self.kvp['outputformat'] == 'application/xml'):
                        if 'outputformat' in self.kvp:
                            self.contenttype = self.kvp['outputformat']
                        else:
                            self.contenttype = self.mimetype

                        xmldecl = ('<?xml version="1.0" encoding="%s" standalone="no"?>'
                                '\n' % self.encoding)
                        appinfo = '<!-- pycsw %s -->\n' % self.context.version 

                else:
                    self.contenttype = self.kvp['request']
                    from pycsw.core.formats import fmt_json
                    response = fmt_json.xml2json(response,
                                                self.context.namespaces,
                                                self.pretty_print)
                                                
        
        elif (isinstance(self.kvp, dict) and 'request' in self.kvp and
                self.kvp['request'] == 'GetSimilarityBBox'):
            
                if (isinstance(self.kvp, dict) and 'outputformat' in self.kvp and
                    self.kvp['outputformat'] == 'application/xml'):
                        if 'outputformat' in self.kvp:
                            self.contenttype = self.kvp['outputformat']
                        else:
                            self.contenttype = self.mimetype

                        xmldecl = ('<?xml version="1.0" encoding="%s" standalone="no"?>'
                                '\n' % self.encoding)
                        appinfo = '<!-- pycsw %s -->\n' % self.context.version 

                else:
                    self.contenttype = self.kvp['request']
                    from pycsw.core.formats import fmt_json
                    response = fmt_json.xml2json(response,
                                                self.context.namespaces,
                                                self.pretty_print)                                        

        else:  # it's XML
            if 'outputformat' in self.kvp:
                self.contenttype = self.kvp['outputformat']
            else:
                self.contenttype = self.mimetype

            xmldecl = ('<?xml version="1.0" encoding="%s" standalone="no"?>'
                       '\n' % self.encoding)
            appinfo = '<!-- pycsw %s -->\n' % self.context.version

        if isinstance(self.contenttype, bytes):
            self.contenttype = self.contenttype.decode()

        s = (u'%s%s%s' % (xmldecl, appinfo, response)).encode(self.encoding)
        LOGGER.debug('Response code: %s',
                     self.context.response_codes[self.status])
        LOGGER.debug('Response:\n%s', s)
        return [self.context.response_codes[self.status], s]