예제 #1
0
def addHeaders(headers, request, response):
    HEADS = [
        'COUNT-SOURCES', 'COUNT-ATOMS', 'COUNT-MOLECULES', 'COUNT-SPECIES',
        'COUNT-STATES', 'COUNT-COLLISIONS', 'COUNT-RADIATIVE',
        'COUNT-NONRADIATIVE', 'TRUNCATED', 'APPROX-SIZE', 'REQUEST-TOKEN'
    ]

    headers = CaselessDict(headers)

    headlist_asString = ''
    for h in HEADS:
        if h in headers:
            response['VAMDC-' + h] = '%s' % headers[h]
            headlist_asString += 'VAMDC-' + h + ', '

    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Expose-Headers'] = headlist_asString[:-2]

    lastmod = headers.get('LAST-MODIFIED')
    if not lastmod and hasattr(settings, 'LAST_MODIFIED'):
        lastmod = settings.LAST_MODIFIED

    if isinstance(lastmod, datetime.date):
        response['Last-Modified'] = getFormatLastModified(lastmod)
    elif isinstance(lastmod, str):
        response['Last-Modified'] = lastmod
    else:
        pass

    return response
예제 #2
0
    def test_request_headers(self):
        headers = {'User-Agent': 'me', 'X-HeyBoy': 'HeyGirl'}
        resp = self.session.get('http://myapp.local/headers', headers=headers)
        resp.raise_for_status()

        # Turn this into a case-insensitive dictionary to make it easier to
        # compare.
        from requests.utils import CaseInsensitiveDict
        resp_headers = CaseInsensitiveDict(resp.json()['headers'])

        for h_key, h_value in headers.items():
            assert resp_headers.get(h_key) == h_value
예제 #3
0
def BibTeX2XML(bibtexstring, key=None):
    """
    Derives an XSAMS source element from the given BibTeX and returns the XML text.
    The ID of the Source is set in the form B(node)-(key) where (node) is replaced
    by the ID string for this node and (key) is replaced by the unique key for this
    Source. If the key argument is given, this value is used for the key; otherwise,
    a key is generated from the BibTeX content.
    """
    e = getEntryFromString(bibtexstring)
    if key:
        xml = u'<Source sourceID="B%s-%s">\n<Authors>\n' % (NODEID, key)
    else:
        xml = u'<Source sourceID="B%s-%s">\n<Authors>\n' % (NODEID, e.key)
    for a in e.persons['author']:
        name = a.first() + a.middle() + a.last() + a.lineage()
        name = [n.strip().strip('{}') for n in name]
        name = ' '.join(name)
        xml += '<Author><Name>%s</Name></Author>' % name
    xml += '\n</Authors>'

    category = TYPE2CATEGORY.get(e.type)

    f = CaselessDict(e.fields)
    url = f.get('bdsk-url-1')
    title = f.get('title', "").strip().strip('{}')
    sourcename = f.get('journal', 'unknown')
    doi = f.get('doi', "")
    year = f.get('year', "")
    volume = f.get('volume', "")
    pages = f.get('pages', "")
    p1, p2 = '', ''
    pages = re.findall(r'[0-9][0-9]*', pages)
    if pages:
        p1 = pages[0]
        if len(pages) > 1:
            p2 = pages[-1]

    xml += """<Title>%s</Title>
<Category>%s</Category>
<Year>%s</Year>
<SourceName>%s</SourceName>
<Volume>%s</Volume>
<PageBegin>%s</PageBegin>
<PageEnd>%s</PageEnd>
<UniformResourceIdentifier>%s</UniformResourceIdentifier>
<DigitalObjectIdentifier>%s</DigitalObjectIdentifier>
""" % (title, category, year or 2222, sourcename, volume, p1, p2, url, doi)

    xml += '<BibTeX>%s</BibTeX></Source>' % quoteattr(bibtexstring)[1:-1]

    return xml
예제 #4
0
파일: views.py 프로젝트: ivh/VAMDC-VALD
def addHeaders(headers,request,response):
    HEADS=['COUNT-SOURCES',
           'COUNT-ATOMS',
           'COUNT-MOLECULES',
           'COUNT-SPECIES',
           'COUNT-STATES',
           'COUNT-COLLISIONS',
           'COUNT-RADIATIVE',
           'COUNT-NONRADIATIVE',
           'TRUNCATED',
           'APPROX-SIZE',
           'REQUEST-TOKEN']

    headers = CaselessDict(headers)

    headlist_asString=''
    for h in HEADS:
        if h in headers:
            response['VAMDC-'+h] = '%s'%headers[h]
            headlist_asString += 'VAMDC-'+h+', '

    response['Access-Control-Allow-Origin'] = '*'
    response['Access-Control-Expose-Headers'] = headlist_asString[:-2]

    lastmod = headers.get('LAST-MODIFIED')
    if not lastmod and hasattr(settings,'LAST_MODIFIED'):
        lastmod=settings.LAST_MODIFIED

    if isinstance(lastmod,datetime.date):
        response['Last-Modified'] = getFormatLastModified(lastmod)
    elif isinstance(lastmod,str):
        response['Last-Modified'] = lastmod
    else:
        pass

    return response