Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rewrote whole module on pure C
  • Loading branch information
bgaifullin committed Jan 29, 2017
1 parent d7feedf commit db5cb6a
Show file tree
Hide file tree
Showing 46 changed files with 4,066 additions and 1,955 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -11,4 +11,3 @@
*.pyo
*.egg*
*.so
*.c
9 changes: 6 additions & 3 deletions .travis.yml
@@ -1,9 +1,10 @@
dist: trusty
sudo: false
language: python
python:
- '2.7'
- '3.3'
- '3.4'
- '3.5'

addons:
apt:
Expand All @@ -16,6 +17,8 @@ addons:
- pkg-config

install:
- travis_retry pip install -e ".[test]"
- travis_retry pip install -r requirements-test.txt
- travis_retry pip install -e "."
- pip list

script: py.test
script: 'py.test tests'
3 changes: 1 addition & 2 deletions MANIFEST.in
@@ -1,2 +1 @@
include src/*.h
include src/xmlsec/*.pxd
include src/*
16 changes: 12 additions & 4 deletions README.md
Expand Up @@ -15,9 +15,9 @@ Check the [examples](https://github.com/mehcode/python-xmlsec/tree/master/tests/
#### Linux (Debian)

```sh
apt-get install libxml2-dev libxmlsec1-dev
apt-get install libxml2-dev libxmlsec1-dev libxmlsec1-opensssl
```

#### Linux (CentOS)

```sh
Expand Down Expand Up @@ -86,7 +86,8 @@ include the appropriate files from the libxml2 and libxmlsec1 libraries.
This will download all dependencies required for running the unit tests.

```sh
pip install -e ".[test]"
pip install -r requirements-test.txt
pip install -e "."
```

### Running the test suite
Expand All @@ -96,9 +97,16 @@ include the appropriate files from the libxml2 and libxmlsec1 libraries.
2. Run the unit tests.

```sh
py.test
py.test tests
```

## Versions of python
The following versions of python is supported
- python2.7
- python3.4
- python3.5 (required libxmlsec1 >= 1.2.18 and libxml2 >= 2.9.1)
- python3.6 (required libxmlsec1 >= 1.2.18 and libxml2 >= 2.9.1)

## License

Unless otherwise noted, all files contained within this project are liensed under the MIT opensource license. See the included file LICENSE or visit [opensource.org][] for more information.
Expand Down
2 changes: 2 additions & 0 deletions requirements-test.txt
@@ -0,0 +1,2 @@
-r requirements.txt
pytest
2 changes: 2 additions & 0 deletions requirements.txt
@@ -0,0 +1,2 @@
pkgconfig
lxml >= 3.0
142 changes: 52 additions & 90 deletions setup.py
@@ -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'),
]
)
30 changes: 30 additions & 0 deletions src/common.h
@@ -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__

0 comments on commit db5cb6a

Please sign in to comment.