-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initial TAP-like implementation. #6
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# LSST Data Management System | ||
# Copyright 2016 AURA/LSST. | ||
# | ||
# This product includes software developed by the | ||
# LSST Project (http://www.lsst.org/). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the LSST License Statement and | ||
# the GNU General Public License along with this program. If not, | ||
# see <http://www.lsstcorp.org/LegalNotices/>. | ||
|
||
""" | ||
This module is intended to help us introspect DBAPI cursor | ||
metadata and rows to determine field types for a given result set. | ||
""" | ||
|
||
from base64 import b64encode | ||
|
||
import MySQLdb | ||
from MySQLdb.constants.FLAG import BINARY | ||
|
||
|
||
class MySQLFieldHelper: | ||
def __init__(self, description, flags, value): | ||
""" | ||
Helper class to define a column, get it's type for conversion, and convert types if needed. | ||
This class works on a best-effort basis. It's not guaranteed to be 100% correct. | ||
@param flags: Flags from MySQLdb.constants.FLAGS | ||
@param value: An example value type to help with inferring how to convert | ||
""" | ||
self.datatype = None | ||
self.xtype = None | ||
self.converter = None | ||
self.name = description[0] | ||
|
||
type_code = description[1] | ||
scale = description[5] | ||
|
||
if type_code in MySQLdb.NUMBER: | ||
# Use python types first, fallback on float otherwise (e.g. NoneType) | ||
if isinstance(value, int): | ||
self.datatype = "int" | ||
else: | ||
# If there's a scale, use double, otherwise assume long | ||
self.datatype = "double" if scale else "long" | ||
|
||
# Check datetime and date | ||
if type_code in MySQLdb.DATETIME: | ||
self.datatype = "text" | ||
self.xtype = "timestamp" | ||
self.converter = lambda x: x.isoformat() | ||
if type_code in MySQLdb.DATE: | ||
self.datatype = "text" | ||
self.xtype = "date" | ||
self.converter = lambda x: x.isoformat() | ||
|
||
# Check if this is binary data and potentially unsafe for JSON | ||
if not self.datatype and flags & BINARY and type_code not in MySQLdb.TIME: | ||
# This needs to be checked BEFORE the next type check | ||
self.datatype = "binary" | ||
self.converter = b64encode | ||
elif isinstance(value, str): | ||
self.datatype = "text" | ||
|
||
if not self.datatype: | ||
# Just return a string and make sure to convert it to string if we don't know about | ||
# this type. This may include datetime.time | ||
self.datatype = "text" | ||
self.converter = str | ||
|
||
def check_value(self, value): | ||
""" | ||
Check the value returned from the DBAPI. | ||
@param value: | ||
@return: The value itself, or a stringified version if it needs to be stringified. | ||
""" | ||
if self.converter and value: | ||
return self.converter(value) | ||
return value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{%- macro xml_attribute(meta, name) -%} | ||
{%- set value = meta.get(name) -%}{%- if value %} {{ name }}="{{ value }}"{%- endif -%} | ||
{%- endmacro -%} | ||
|
||
<?xml version="1.0"?> | ||
<VOTABLE version="1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://www.ivoa.net/xml/VOTable/v1.3"> | ||
<RESOURCE> | ||
{%- set table = result["table"] %} | ||
<TABLE> | ||
{% for element in table["metadata"]["elements"] -%} | ||
{%- set is_array = element["datatype"] in mappings -%} | ||
{%- set xtype = element.get("xtype") -%} | ||
{%- set datatype = mappings.get(element["datatype"], element["datatype"]) -%} | ||
<FIELD name="{{ element["name"] }}" datatype="{{ datatype }}" | ||
{%- if is_array %} arraysize="*"{%- endif -%} | ||
{%- if xtype %} xtype="{{ xtype }}"{%- endif -%}/> | ||
{%- endfor %} | ||
<DATA> | ||
<TABLEDATA> | ||
{%- for row in table["data"] %} | ||
<TR>{%- for column in row -%} | ||
{%- set field = table["metadata"]["elements"][loop.index0] -%} | ||
{%- set b64 = field["datatype"] == "binary" -%} | ||
<TD {%- if b64 %} encoding="base64"{%- endif -%}>{{ column }}</TD>{%- endfor -%} | ||
</TR> | ||
{%- endfor -%} | ||
</TABLEDATA> | ||
</DATA> | ||
</TABLE> | ||
</RESOURCE> | ||
</VOTABLE> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With all of these function name changes (getRoot -> application_root, etc.) I don't see any changes to the client code as part of this ticket. Are there any users of this service yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the function names are inconsequential, I was just trying to do some PEP8 cleanup. The reason why they are inconsequential is because the decorator above the name,
@app.route
, registers the function at import time to the Flask framework. The Flask framework handles incoming HTTP requests, finds out routes match (/db
in this case), and dispatches to the method. So Flask, in effect, is the only client to these methods and it doesn't really care about the method name (except for debugging purposes)However, the HTTP route did, in fact, change. SUI is the main consumer of the HTTP interface and they've been notified. The routes changed to more closely adhere to the guidelines in the TAP interface.