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
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
def __init__(self,request): if 'X_REQUEST_METHOD' in request.META: # workaround for mod_wsgi self.XRequestMethod = request.META['X_REQUEST_METHOD'] self.HTTPmethod = request.method self.isvalid = True self.errormsg = '' self.token = request.token try: self.request=CaselessDict(dict(request.GET or request.POST)) except Exception as e: self.isvalid = False self.errormsg = 'Could not read argument dict: %s'%e log.error(self.errormsg) if self.isvalid: self.validate() self.fullurl = getBaseURL(request) + 'sync?' + request.META.get('QUERY_STRING')
from django.conf import settings from importlib import import_module from django.utils.http import http_date from requests.utils import CaseInsensitiveDict as CaselessDict if settings.QUERY_STORE_ACTIVE: try: import requests as librequests except: log.critical('settings.QUERY_STORE_ACTIVE is True 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 NODEID = CaselessDict(DICTS.RETURNABLES)['NodeID'] from .generators import * from .sqlparse import SQL REQUESTABLES = [req.lower() for req in [\ 'AtomStates', 'Atoms', 'Collisions', 'Environments', 'Functions', 'Methods', 'MoleculeBasisStates', 'MoleculeQuantumNumbers', 'MoleculeStates', 'Molecules', 'NonRadiativeTransitions',
# -*- coding: utf-8 -*- from requests.utils import CaseInsensitiveDict as CaselessDict from vamdctap.unitconv import * from methane.node.MyFunctions import * RESTRICTABLES = CaselessDict({\ 'RadTransWavenumber':'wavenumber', 'RadTransWavelength':('wavenumber',invcm2Angstr), 'RadTransProbabilityA':'einstein', 'RadTransProbabilityLineStrength':'intensity', 'MoleculeChemicalName':checkChemicalName, 'Inchi':'isotopeid__inchi', 'InchiKey':'inchikey', 'MoleculeStoichiometricFormula':checkStoichiometricFormula, 'upper.StateEnergy':'upstateid__position', 'lower.StateEnergy':'lowstateid__position', 'StateEnergy':'lowstateid__position', 'EnvironmentTemperature' : checkEnvironmentTemperature, }) RETURNABLES = CaselessDict({\ 'NodeID':'ICB-CH4', 'XSAMSVersion' : u'1.0', 'SourceID':'Source.sourceid', 'SourceAuthorName':'Source.extractRisVal("AU")', 'SourceCategory':'Source.extractRisVal("TY")', 'SourceName':'Source.extractRisVal("JO")',
RETURNABLES = CaselessDict({\ 'NodeID':'GSMA-SMPO', 'SourceID':'Source.SourceID', 'SourceAuthorName':'Source.authorlist()', 'SourceCategory':'Source.SourceCategory', 'SourcePageBegin':'Source.SourcePageBegin', 'SourcePageEnd':'Source.SourcePageEnd', 'SourceName':'Source.SourceName', 'SourceTitle':'Source.SourceTitle', 'SourceURI':'Source.SourceURI', 'SourceVolume':'Source.SourceVolume', 'SourceYear':'Source.SourceYear', ########################################################################### 'MethodID': 'Method.id', 'MethodCategory': 'Method.category', 'MethodDescription': 'Method.description', 'FunctionID': 'Function.id', 'FunctionName': 'Function.name', 'FunctionComputerLanguage': 'Function.clang', 'FunctionExpression': 'Function.expr', 'FunctionDescription': 'Function.descr', 'FunctionYName': 'Function.yname', 'FunctionYUnits': 'Function.yunits', 'FunctionYDescription': 'Function.ydescr', 'FunctionArgumentName': 'FunctionArgument.name', 'FunctionArgumentUnits': 'FunctionArgument.units', 'FunctionArgumentDescription': 'FunctionArgument.descr', 'FunctionArgumentLowerLimit': 'FunctionArgument.low', 'FunctionArgumentUpperLimit': 'FunctionArgument.up', 'FunctionParameterName': 'FunctionParameter.name', 'FunctionParameterUnits': 'FunctionParameter.units', 'FunctionParameterDescription': 'FunctionParameter.descr', 'EnvironmentID': 'Environment.id', 'EnvironmentTemperature': 'Environment.temperature', 'EnvironmentTemperatureUnit': 'K', 'EnvironmentTotalPressure': 'Environment.pressure', 'EnvironmentTotalPressureUnit': 'atm', 'EnvironmentSpeciesName': 'EnvSpecies.name', 'EnvironmentSpeciesMoleFraction': 'EnvSpecies.fraction', #'EnvironmentSpeciesRef': 'NONE', ########################################################################### 'RadTransWavenumber':'RadTran.wn', 'RadTransWavenumberUnit':'1/cm', 'RadTransWavenumberRef':'RadTran.ref_wn', 'RadTransWavenumberComment':'', 'RadTransWavenumberMethod':'', 'RadTransWavenumberAccuracy':'RadTran.dwn', 'RadTransWavenumberAccuracyType':'statistical', 'RadTransWavenumberAccuracyRelative':'1', 'RadTransWavenumberAccuracyStatisticalRelative':'RadTran.dwn', 'RadTransEnergy':'RadTran.elow', 'RadTransEnergyUnit':'1/cm', 'RadTransEnergyRef':'RadTran.ref_e', 'RadTransEnergyComment':'Lower state energy', 'RadTransProbabilityLineStrength':'RadTran.s', 'RadTransProbabilityLineStrengthUnit':'1/cm2/atm', 'RadTransProbabilityLineStrengthRef':'RadTran.ref_s', 'RadTransProbabilityLineStrengthMethod':'', 'RadTransProbabilityLineStrengthAccuracy':'RadTran.dint', 'RadTransProbabilityLineStrengthAccuracyType':'statistical', 'RadTransProbabilityLineStrengthAccuracyRelative':'1', 'RadTransProbabilityLineStrengthAccuracyStatisticalRelative':'RadTran.dint', 'RadTransProbabilityA':'RadTran.ae', 'RadTransProbabilityAUnit':'1/s', #'RadTransBroadeningPressureLineshapeParameterName':'SelfBroadening', #'RadTransBroadeningPressureLineshapeParameter':'RadTran.hwhms', #'RadTransBroadeningPressureLineshapeParameterUnit':'1/cm', #'RadTransBroadeningPressureLineshapeParameterRef':'', #'RadTransBroadeningPressureLineshapeParameterComment':'', #'RadTransBroadeningPressureLineshapeParameterMethod':'', 'RadTransFrequency':'', 'RadTransFrequencyUnit':'', 'RadTransFrequencyRef':'', 'RadTransFrequencyComment':'', 'RadTransFinalStateRef':'RadTran.getStateRefUp()', 'RadTransInitialStateRef':'RadTran.getStateRefLow()', 'RadTransID':'RadTran.getTranId()', ####################################################################### 'MoleculeChemicalName':'Ozone', 'MoleculeStoichiometricFormula':'O3', 'MoleculeOrdinaryStructuralFormula':'Molecule.formula', 'MoleculeSpeciesID':'Molecule.nnn', 'MoleculeInChI':'Molecule.inchi', 'MoleculeInChIKey':'Molecule.inchikey', 'MoleculeStateID':'MoleculeState.id', 'MoleculeStateEnergy':'MoleculeState.vl_energy', 'MoleculeStateEnergyOrigin':'MoleculeState.src', 'MoleculeStateEnergyUnit':'1/cm', 'MoleculeStateEnergyRef':'MoleculeState.ref_e', 'MoleculeStateEnergyComment':'MoleculeState.src', 'MoleculeStateEnergyMethod':'', #'MoleculeStateEnergyAccuracy':'0.01', 'MoleculeMolecularWeight':'Molecule.mass', 'MoleculeMolecularWeightUnit':'au', 'MoleculeMolecularWeightRef':'Molecule.ref_mass', 'MoleculePartitionFunctionT':'Molecule.pft', 'MoleculePartitionFunction':'Molecule.pfv', 'MoleculeIonCharge':'0' })
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 requests.utils import CaseInsensitiveDict as CaselessDict RESTRICTABLES = CaselessDict(DICTS.RESTRICTABLES) from django.db.models.query_utils import Q as QType 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', '<=': '__lte', '>=': '__gte',
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 requests.utils import CaseInsensitiveDict as 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 #------------------------------------------------------------ #
def getEntryFromString(s): parser = bibtex.Parser() try: parser.parse_stream(StringIO(s)) key, entry = parser.data.entries.items()[0] except Exception as e: log.warn('BibTex parsing failed: %s' % e) 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)