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
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
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
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
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) try: response['Last-Modified'] = getFormatLastModified(headers['LAST-MODIFIED']) except: pass for h in HEADS: if headers.has_key(h): response['VAMDC-'+h] = '%s'%headers[h] if headers.has_key('LAST-MODIFIED'): response['Last-Modified'] = '%s'%headers['LAST-MODIFIED'] return response
def __init__(self, *args, **kwargs): "Set keys to upper for initial dict" CaselessDict.__init__(self, *args, **kwargs) self['VEVENT'] = Event self['VTODO'] = Todo self['VJOURNAL'] = Journal self['VFREEBUSY'] = FreeBusy self['VTIMEZONE'] = Timezone self['VALARM'] = Alarm self['VCALENDAR'] = Calendar
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 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): if headers[h]: response['VAMDC-'+h] = '%s'%headers[h] return response
def __init__(self, *args, **kwargs): "Set keys to upper for initial dict" CaselessDict.__init__(self, *args, **kwargs) self['binary'] = vBinary self['boolean'] = vBoolean self['cal-address'] = vCalAddress self['date'] = vDDDTypes self['date-time'] = vDDDTypes self['duration'] = vDDDTypes self['float'] = vFloat self['integer'] = vInt self['period'] = vPeriod self['recur'] = vRecur self['text'] = vText self['time'] = vTime self['uri'] = vUri self['utc-offset'] = vUTCOffset self['geo'] = vGeo self['inline'] = vInline
def __init__(self, data): try: data = CaselessDict(dict(data)) self.lang = lower(data['LANG']) self.query = data['QUERY'] self.format = lower(data['FORMAT']) self.isvalid = True except Exception, e: self.isvalid = False LOG(str(e))
def __init__(self, request): self.HTTPmethod = request.method self.isvalid = True self.errormsg = '' try: self.request = CaselessDict(dict(request.GET or request.POST)) except Exception, e: self.isvalid = False self.errormsg = 'Could not read argument dict: %s' % e log.error(self.errormsg)
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): 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
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
def __init__(self, *args, **kwargs): CaselessDict.__init__(self, *args, **kwargs) self.params = Parameters()
def __init__(self, *args, **kwargs): "Set keys to upper for initial dict" CaselessDict.__init__(self, *args, **kwargs) # set parameters here for properties that use non-default values self.subcomponents = [] # Components can be nested.
oracleSqlComment = "--" + restOfLine selectStmt.ignore(oracleSqlComment) return selectStmt SQL = setupSQLparser() ############ SQL PARSER FINISHED; SOME HELPER THINGS BELOW from django.db.models import Q, F from django.conf import settings from importlib import import_module DICTS = import_module(settings.NODEPKG + '.dictionaries') from caselessdict import CaselessDict RESTRICTABLES = CaselessDict(DICTS.RESTRICTABLES) from types import TupleType, FunctionType from django.db.models.query_utils import Q as QType from string import strip import logging log = logging.getLogger('vamdc.tap.sql') # Q-objects for always True / False QTrue = Q(pk=F('pk')) QFalse = ~QTrue OPTRANS= { # transfer SQL operators to django-style '<': '__lt', '>': '__gt', '=': '__exact',
def getEntryFromString(s): parser = bibtex.Parser() try: parser.parse_stream(StringIO(s)) key, entry = parser.data.entries.items()[0] except: bib = parser.parse_stream(StringIO(DUMMY)) key, entry = parser.data.entries.items()[0] return entry TYPE2CATEGORY=CaselessDict({\ 'article':'journal', 'book':'book', 'techreport':'report', 'misc':'private communication', 'inproceedings':'proceedings', }) 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>'
from django.utils.unittest import TestCase except ImportError: from django.test import TestCase try: from django.utils import unittest except ImportError: import unittest from django.test.client import Client from django.utils.importlib import import_module from vamdctap import generators, views # node-specific from django.conf import settings from caselessdict import CaselessDict DICTS = import_module(settings.NODEPKG + ".dictionaries") RETURNABLES = CaselessDict(DICTS.RETURNABLES) try: NODEID = RETURNABLES['NodeID'] except: NODEID = RETURNABLES["TempNodeID"] from nodes.ExampleNode.node import queryfunc if not hasattr(settings, "EXAMPLENODE") or not settings.EXAMPLENODE: print "Error: The NodeSoftware unit tests must be run from nodes/ExampleNode." sys.exit() #------------------------------------------------------------ # Testing of sending TAP queries and their response #------------------------------------------------------------ #
from importlib import import_module from django.utils.http import http_date if settings.LOG_CENTRALLY: try: import requests as librequests except: log.critical( 'settings.LOG_CENTRALLY is set but requests package is missing!') QUERYFUNC = import_module(settings.NODEPKG + '.queryfunc') DICTS = import_module(settings.NODEPKG + '.dictionaries') # import helper modules that reside in the same directory from caselessdict import CaselessDict NODEID = CaselessDict(DICTS.RETURNABLES)['NodeID'] from generators import * from sqlparse import SQL REQUESTABLES = map(lower, [\ 'AtomStates', 'Atoms', 'Collisions', 'Environments', 'Functions', 'Methods', 'MoleculeBasisStates', 'MoleculeQuantumNumbers', 'MoleculeStates', 'Molecules', 'NonRadiativeTransitions',
def getEntryFromString(s): parser = bibtex.Parser() try: parser.parse_stream(StringIO(s)) key, entry = parser.data.entries.items()[0] except Exception: parser.parse_stream(StringIO(DUMMY)) key, entry = parser.data.entries.items()[0] return entry TYPE2CATEGORY=CaselessDict({\ 'article':'journal', 'book':'book', 'techreport':'report', 'misc':'private communication', 'inproceedings':'proceedings', 'phdthesis':'thesis', 'unpublished':'private communication' }) 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)