Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Rewrote whole module on pure C
- Loading branch information
1 parent
d7feedf
commit db5cb6a
Showing
46 changed files
with
4,066 additions
and
1,955 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,3 @@ | |
*.pyo | ||
*.egg* | ||
*.so | ||
*.c |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
include src/*.h | ||
include src/xmlsec/*.pxd | ||
include src/* |
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,2 @@ | ||
-r requirements.txt | ||
pytest |
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,2 @@ | ||
pkgconfig | ||
lxml >= 3.0 |
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 |
---|---|---|
@@ -1,125 +1,87 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
# from __future__ import absolute_import, unicode_literals, division | ||
from os import path | ||
from pkgutil import get_importer | ||
from setuptools import setup, Extension | ||
from functools import wraps | ||
from __future__ import print_function | ||
|
||
import glob | ||
import os | ||
import pkgconfig | ||
from setuptools import setup | ||
from setuptools import Extension | ||
import sys | ||
|
||
def lazy(function): | ||
import lxml | ||
|
||
@wraps(function) | ||
def wrapped(*args, **kwargs): | ||
__name__ = "xmlsec" | ||
__version__ = "1.0.1" | ||
__description__ = "Python bindings for the XML Security Library" | ||
|
||
class LazyProxy(Extension): | ||
__arguments = dict() | ||
|
||
def __init__(self, function, args, kwargs): | ||
self.__arguments["function"] = function | ||
self.__arguments["args"] = args | ||
self.__arguments["kwargs"] = kwargs | ||
self.__arguments["result"] = None | ||
def is_debug(): | ||
return bool(os.getenv("PYXMLSEC_DEBUG")) | ||
|
||
def __getattr__(self, item): | ||
if self.__arguments["result"] is None: | ||
self.__arguments["result"] = self.__arguments["function"](*self.__arguments["args"], | ||
**self.__arguments["kwargs"]) | ||
|
||
return getattr(self.__arguments["result"], item) | ||
macroses = [("MODULE_NAME", __name__), ("MODULE_VERSION", __version__), ("MODULE_DOC", __description__)] | ||
cflags = ["-g", "-std=c99", "-fno-strict-aliasing", "-Wno-error=declaration-after-statement", "-Werror=implicit-function-declaration"] | ||
|
||
def __setattr__(self, name, value): | ||
if self.__arguments["result"] is None: | ||
self.__arguments["result"] = self.__arguments["function"](*self.__arguments["args"], | ||
**self.__arguments["kwargs"]) | ||
|
||
setattr(self.__arguments["result"], name, value) | ||
if is_debug(): | ||
macroses.append(("PYXMLSEC_ENABLE_DEBUG", 1)) | ||
cflags.extend(["-Wall", "-O0"]) | ||
else: | ||
cflags.extend(["-Os"]) | ||
|
||
return LazyProxy(function, args, kwargs) | ||
|
||
return wrapped | ||
config = pkgconfig.parse("xmlsec1") | ||
|
||
|
||
@lazy | ||
def make_extension(name, cython=True): | ||
from pkgconfig import parse | ||
def add_to_config(key, args): | ||
value = list(config.get(key, [])) | ||
value.extend(args) | ||
config[key] = value | ||
|
||
# Declare the crypto implementation. | ||
xmlsec_crypto = 'openssl' | ||
|
||
# Process the `pkg-config` utility and discover include and library | ||
# directories. | ||
config = {} | ||
for lib in ['libxml-2.0', 'xmlsec1-%s' % xmlsec_crypto]: | ||
config.update(parse(lib)) | ||
add_to_config('define_macros', macroses) | ||
add_to_config('include_dirs', lxml.get_include()) | ||
|
||
config['extra_compile_args'] = ['-DXMLSEC_CRYPTO_OPENSSL=1', '-DXMLSEC_NO_CRYPTO_DYNAMIC_LOADING=1'] | ||
print(config, file=sys.stderr) | ||
|
||
# List-ify config for setuptools. | ||
for key in config: | ||
config[key] = list(config[key]) | ||
|
||
if 'include_dirs' not in config: | ||
config['include_dirs'] = [] | ||
def find_sources(path): | ||
return glob.glob(os.path.join(path, "*.c")) | ||
|
||
# Add the source directories for inclusion. | ||
import lxml | ||
config['include_dirs'].insert(0, path.dirname(lxml.__file__)) | ||
config['include_dirs'].insert(0, path.join(path.dirname(lxml.__file__), 'includes')) | ||
config['include_dirs'].insert(0, 'src') | ||
|
||
# Resolve extension location from name. | ||
location = path.join('src', *name.split('.')) | ||
location += '.pyx' if cython else '.c' | ||
|
||
# Create and return the extension. | ||
return Extension(name, [location], **config) | ||
|
||
|
||
# Navigate, import, and retrieve the metadata of the project. | ||
meta = get_importer('src/xmlsec').find_module('meta').load_module('meta') | ||
|
||
_xmlsec = Extension( | ||
__name__, | ||
sources=find_sources("./src"), | ||
extra_compile_args=cflags, | ||
libraries=list(config.get('libraries', [])), | ||
library_dirs=list(config.get('library_dirs', [])), | ||
include_dirs=list(config.get('include_dirs', [])), | ||
define_macros=config['define_macros'] | ||
) | ||
|
||
setup( | ||
name='xmlsec', | ||
version=meta.version, | ||
description=meta.description, | ||
name=__name__, | ||
version=__version__, | ||
description=__description__, | ||
ext_modules=[_xmlsec], | ||
author="Ryan Leckey", | ||
author_email='support@mehcode.com', | ||
maintainer='Bulat Gaifullin', | ||
maintainer_email='gaifullinbf@gmail.com', | ||
url='https://github.com/mehcode/python-xmlsec', | ||
download_url="https://github.com/mehcode/python-xmlsec/archive/v%s.tar.gz" % __version__, | ||
license='MIT', | ||
keywords=["xmlsec"], | ||
classifiers=[ | ||
'Development Status :: 3 - Alpha', | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: System Administrators', | ||
'License :: OSI Approved :: MIT License', | ||
'Operating System :: OS Independent', | ||
'Programming Language :: Cython', | ||
'Programming Language :: C', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.3', | ||
'Programming Language :: Python :: 3.4', | ||
'Topic :: Text Processing :: Markup :: XML' | ||
], | ||
author='Ryan Leckey', | ||
author_email='support@mehcode.com', | ||
url='https://github.com/mehcode/python-xmlsec', | ||
setup_requires=[ | ||
'setuptools_cython', | ||
'pkgconfig', | ||
'lxml >= 3.0', | ||
], | ||
install_requires=[ | ||
'lxml >= 3.0', | ||
], | ||
extras_require={ | ||
'test': ['pytest'] | ||
}, | ||
package_dir={'xmlsec': 'src/xmlsec'}, | ||
packages=['xmlsec'], | ||
ext_modules=[ | ||
make_extension('xmlsec.constants'), | ||
make_extension('xmlsec.utils'), | ||
make_extension('xmlsec.tree'), | ||
make_extension('xmlsec.key'), | ||
make_extension('xmlsec.ds'), | ||
make_extension('xmlsec.enc'), | ||
make_extension('xmlsec.template'), | ||
] | ||
) |
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,30 @@ | ||
// Copyright (c) 2017 Ryan Leckey | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
#ifndef __PYXMLSEC_COMMON_H__ | ||
#define __PYXMLSEC_COMMON_H__ | ||
|
||
#include "debug.h" | ||
|
||
#ifndef MODULE_NAME | ||
#define MODULE_NAME "xmlsec" | ||
#endif | ||
|
||
#ifndef MODULE_DOC | ||
#define MODULE_DOC "The tiny python wrapper around xmlsec1 library." | ||
#endif | ||
|
||
#define JOIN(X,Y) DO_JOIN1(X,Y) | ||
#define DO_JOIN1(X,Y) DO_JOIN2(X,Y) | ||
#define DO_JOIN2(X,Y) X##Y | ||
|
||
#define DO_STRINGIFY(x) #x | ||
#define STRINGIFY(x) DO_STRINGIFY(x) | ||
|
||
#endif //__PYXMLSEC_COMMON_H__ |
Oops, something went wrong.