def addHeaders(headers,response):
    HEADS=['COUNT-SOURCES',
           'COUNT-ATOMS',
           'COUNT-MOLECULES',
           'COUNT-SPECIES',
           'COUNT-STATES',
           'COUNT-COLLISIONS',
           'COUNT-RADIATIVE',
           'COUNT-NONRADIATIVE',
           'TRUNCATED',
           'APPROX-SIZE']

    headers = CaselessDict(headers)

    for h in HEADS:
        if headers.has_key(h):
            response['VAMDC-'+h] = '%s'%headers[h]

    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
Exemple #2
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']

    headers = CaselessDict(headers)

    headlist_asString=''
    for h in HEADS:
        if headers.has_key(h):
            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
Exemple #3
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'
    ]

    headers = CaselessDict(headers)

    headlist_asString = ''
    for h in HEADS:
        if headers.has_key(h):
            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
Exemple #4
0
def addHeaders(headers, response):
    HEADS = [
        'COUNT-SOURCES', 'COUNT-ATOMS', 'COUNT-MOLECULES', 'COUNT-SPECIES',
        'COUNT-STATES', 'COUNT-COLLISIONS', 'COUNT-RADIATIVE',
        'COUNT-NONRADIATIVE', 'TRUNCATED', 'APPROX-SIZE'
    ]

    headers = CaselessDict(headers)

    for h in HEADS:
        if headers.has_key(h):
            response['VAMDC-' + h] = '%s' % headers[h]

    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
Exemple #5
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 = map(strip, name)
        name = map(strip, name, ['{}'] * len(name))
        xml += '<Author><Name>%s</Name></Author>' % ' '.join(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
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 = map(strip,name)
        name = map(strip,name,['{}']*len(name))
        xml += '<Author><Name>%s</Name></Author>'%' '.join(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
Exemple #7
0
def BibTeX2XML(bibtexstring):
    e = getEntryFromString(bibtexstring)
    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 = map(strip,name)
        name = map(strip,name,['{}']*len(name))
        xml += '<Author><Name>%s</Name></Author>'%' '.join(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')
    if pages:
        if '-' in pages:
            p1,p2 = pages.split('-')
        else:
            p1, p2 = pages, ''
    else: 
        p1,p2 = '',''

    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
Exemple #8
0
def BibTeX2XML(bibtexstring):
    e = getEntryFromString(bibtexstring)
    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 = map(strip, name)
        name = map(strip, name, ['{}'] * len(name))
        xml += '<Author><Name>%s</Name></Author>' % ' '.join(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')
    if pages:
        if '-' in pages:
            p1, p2 = pages.split('-')
        else:
            p1, p2 = pages, ''
    else:
        p1, p2 = '', ''

    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