Commit 16ebd261 authored by Mouadh Kaabachi's avatar Mouadh Kaabachi Committed by GitHub

Merge pull request #5 from abilian/xmlwitch

Xmlwitch
parents 9f3a6365 dd49e8ce
......@@ -2,11 +2,13 @@
from __future__ import absolute_import, division, print_function
import HTMLParser
import xmlwitch
import os
from datetime import datetime
from os.path import expanduser
from lxml import etree
from spyne import AnyXml, Application, ServiceBase, rpc, Fault
from spyne.const.http import HTTP_200
from spyne.error import InvalidCredentialsError
......@@ -158,11 +160,13 @@ class XmlaProviderService(ServiceBase):
if request.Command.Statement == '':
# check if command contains a query
return etree.fromstring("""
<return>
<root xmlns="urn:schemas-microsoft-com:xml-analysis:empty"/>
</return>
""")
xml = xmlwitch.Builder()
with xml['return']:
xml.root(xmlns="urn:schemas-microsoft-com:xml-analysis:empty")
return str(xml)
else:
XmlaProviderService.discover_tools.change_catalogue(
request.Properties.PropertyList.Catalog)
......@@ -171,54 +175,45 @@ class XmlaProviderService(ServiceBase):
df = executer.execute_mdx()
xmla_tools = XmlaExecuteTools(executer)
return etree.fromstring("""
<return>
<root xmlns="urn:schemas-microsoft-com:xml-analysis:mddataset"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
{0}
<OlapInfo>
<CubeInfo>
<Cube>
<CubeName>Sales</CubeName>
<LastDataUpdate
xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">{7}</LastDataUpdate>
<LastSchemaUpdate
xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">{7}</LastSchemaUpdate>
</Cube>
</CubeInfo>
<AxesInfo>
{1}
{2}
</AxesInfo>
{3}
</OlapInfo>
<Axes>
{4}
{5}
</Axes>
<CellData>
{6}
</CellData>
</root>
</return>
""".format(execute_xsd,
xmla_tools.generate_axes_info(df),
xmla_tools.generate_axes_info_slicer(df),
xmla_tools.generate_cell_info(),
xmla_tools.generate_xs0(df),
xmla_tools.generate_slicer_axis(df),
xmla_tools.generate_cell_data(df),
datetime.now().strftime('%Y-%m-%dT%H:%M:%S')).replace(
'&', '&amp;'))
# Problem:
# An XML parser returns the error “xmlParseEntityRef: noname”
#
# Cause:
# There is a stray ‘&’ (ampersand character) somewhere in the XML text eg. some text & some more text
# Solution
# .replace('&', '&amp;')
xml = xmlwitch.Builder()
with xml['return']:
with xml.root(
execute_xsd,
xmlns="urn:schemas-microsoft-com:xml-analysis:mddataset",
**{
'xmlns:xsd': 'http://www.w3.org/2001/XMLSchema',
'xmlns:xsi':
'http://www.w3.org/2001/XMLSchema-instance'
}):
with xml.OlapInfo(xmla_tools.generate_cell_info()):
with xml.CubeInfo:
with xml.Cube:
xml.CubeName('Sales')
xml.LastDataUpdate(
datetime.now().strftime(
'%Y-%m-%dT%H:%M:%S'),
xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"
)
xml.LastSchemaUpdate(
datetime.now().strftime(
'%Y-%m-%dT%H:%M:%S'),
xmlns="http://schemas.microsoft.com/analysisservices/2003/engine"
)
xml.AxesInfo(
xmla_tools.generate_axes_info(df),
xmla_tools.generate_axes_info_slicer(df))
xml.Axes(
xmla_tools.generate_xs0(df),
xmla_tools.generate_slicer_axis(df))
xml.CellData(xmla_tools.generate_cell_data(df))
html_parser = HTMLParser.HTMLParser()
xml = html_parser.unescape(str(xml)).replace('&', '&amp;')
return xml
application = Application(
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This diff is collapsed.
......@@ -5,6 +5,7 @@ spyne<3
treelib<2
SQLAlchemy
psycopg2
xmlwitch
# Test
werkzeug
......
......@@ -15,5 +15,6 @@ pytz==2017.2 # via pandas, spyne
six==1.10.0 # via python-dateutil
spyne==2.12.14
sqlalchemy==1.1.11
treelib==1.3.5
treelib==1.3.7
werkzeug==0.12.2
xmlwitch==0.3
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment