In some case you want the url to be based on server_name/server_port and not http_host, now you can get what you want.
This commit is contained in:
parent
77e5a407a5
commit
e401cf25e2
@ -154,16 +154,19 @@ def extract(environ, empty=False, err=False):
|
||||
return formdata
|
||||
|
||||
|
||||
def geturl(environ, query=True, path=True):
|
||||
def geturl(environ, query=True, path=True, use_server_name=False):
|
||||
"""Rebuilds a request URL (from PEP 333).
|
||||
You may want to chose to use the environment variables
|
||||
server_name and server_port instead of http_host in some case.
|
||||
The parameter use_server_name allows you to chose.
|
||||
|
||||
:param query: Is QUERY_STRING included in URI (default: True)
|
||||
:param path: Is path included in URI (default: True)
|
||||
:param use_server_name: If SERVER_NAME/_HOST should be used instead of
|
||||
HTTP_HOST
|
||||
"""
|
||||
url = [environ['wsgi.url_scheme'] + '://']
|
||||
if environ.get('SERVER_NAME'):
|
||||
url.append(environ['HTTP_HOST'])
|
||||
else:
|
||||
if use_server_name:
|
||||
url.append(environ['SERVER_NAME'])
|
||||
if environ['wsgi.url_scheme'] == 'https':
|
||||
if environ['SERVER_PORT'] != '443':
|
||||
@ -171,6 +174,8 @@ def geturl(environ, query=True, path=True):
|
||||
else:
|
||||
if environ['SERVER_PORT'] != '80':
|
||||
url.append(':' + environ['SERVER_PORT'])
|
||||
else:
|
||||
url.append(environ['HTTP_HOST'])
|
||||
if path:
|
||||
url.append(getpath(environ))
|
||||
if query and environ.get('QUERY_STRING'):
|
||||
|
68
tools/mdexport_test.py
Executable file
68
tools/mdexport_test.py
Executable file
@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
|
||||
from saml2 import saml
|
||||
from saml2 import md
|
||||
from saml2.extension import mdui
|
||||
from saml2.extension import idpdisc
|
||||
from saml2.extension import dri
|
||||
from saml2.extension import mdattr
|
||||
from saml2.extension import ui
|
||||
from saml2.extension import shibmd
|
||||
import xmldsig
|
||||
import xmlenc
|
||||
|
||||
from saml2.mdstore import MetaDataFile, MetaDataExtern
|
||||
|
||||
__author__ = 'rolandh'
|
||||
|
||||
"""
|
||||
A script that imports and verifies metadata and then dumps it in a basic
|
||||
dictionary format.
|
||||
"""
|
||||
|
||||
|
||||
ONTS = {
|
||||
saml.NAMESPACE: saml,
|
||||
mdui.NAMESPACE: mdui,
|
||||
mdattr.NAMESPACE: mdattr,
|
||||
dri.NAMESPACE: dri,
|
||||
ui.NAMESPACE: ui,
|
||||
idpdisc.NAMESPACE: idpdisc,
|
||||
md.NAMESPACE: md,
|
||||
xmldsig.NAMESPACE: xmldsig,
|
||||
xmlenc.NAMESPACE: xmlenc,
|
||||
shibmd.NAMESPACE: shibmd
|
||||
}
|
||||
|
||||
MDIMPORT = {
|
||||
"swamid": {
|
||||
"url": "https://kalmar2.org/simplesaml/module.php/aggregator/?id=kalmarcentral2&set=saml2",
|
||||
"cert": "kalmar2.pem",
|
||||
"type": "external"
|
||||
},
|
||||
"incommon": {
|
||||
"file": "InCommon-metadata.xml",
|
||||
"type": "local"
|
||||
},
|
||||
"test": {
|
||||
"file": "mdtest.xml",
|
||||
"type": "local"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
item = MDIMPORT[sys.argv[1]]
|
||||
|
||||
metad = None
|
||||
|
||||
if item["type"] == "local":
|
||||
metad = MetaDataFile(sys.argv[1], ONTS.values(), item["file"])
|
||||
elif item["type"] == "external":
|
||||
metad = MetaDataExtern(sys.argv[1], ONTS.values(),
|
||||
item["url"], "/opt/local/bin/xmlsec1", item["cert"])
|
||||
|
||||
if metad:
|
||||
metad.load()
|
||||
print metad.dumps()
|
||||
|
@ -1,10 +1,11 @@
|
||||
#!/usr/bin/env python
|
||||
import sys
|
||||
import time
|
||||
from saml2.attribute_converter import ac_factory
|
||||
from saml2.mdstore import MetaDataMD, MetaDataFile
|
||||
|
||||
__author__ = 'rolandh'
|
||||
|
||||
from saml2.mdie import from_dict
|
||||
|
||||
import xmldsig
|
||||
import xmlenc
|
||||
from saml2 import md
|
||||
@ -27,7 +28,20 @@ ONTS = {
|
||||
xmldsig.NAMESPACE: xmldsig,
|
||||
}
|
||||
|
||||
_dict = eval(open(sys.argv[1]).read())
|
||||
res = from_dict(_dict, ONTS)
|
||||
start = time.time()
|
||||
for i in range(1, 10):
|
||||
mdmd = MetaDataMD(ONTS, ac_factory("../tests/attributemaps"), "swamid2.md")
|
||||
mdmd.load()
|
||||
|
||||
print res
|
||||
_ = mdmd.keys()
|
||||
|
||||
print time.time() - start
|
||||
|
||||
start = time.time()
|
||||
for i in range(1, 10):
|
||||
mdf = MetaDataFile(ONTS.values(), ac_factory("../tests/attributemaps"),
|
||||
"../tests/swamid-2.0.xml")
|
||||
mdf.load()
|
||||
_ = mdf.keys()
|
||||
|
||||
print time.time() - start
|
||||
|
Loading…
Reference in New Issue
Block a user