Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame^] | 1 | """ |
| 2 | MarkupSafe |
| 3 | ========== |
| 4 | |
| 5 | Implements a unicode subclass that supports HTML strings: |
| 6 | |
| 7 | >>> from markupsafe import Markup, escape |
| 8 | >>> escape("<script>alert(document.cookie);</script>") |
| 9 | Markup(u'<script>alert(document.cookie);</script>') |
| 10 | >>> tmpl = Markup("<em>%s</em>") |
| 11 | >>> tmpl % "Peter > Lustig" |
| 12 | Markup(u'<em>Peter > Lustig</em>') |
| 13 | """ |
| 14 | import sys |
| 15 | from setuptools import setup, Extension, Feature |
| 16 | from distutils.command.build_ext import build_ext |
| 17 | from distutils.errors import CCompilerError, DistutilsExecError, \ |
| 18 | DistutilsPlatformError |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 19 | |
| 20 | |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame^] | 21 | # fail safe compilation shamelessly stolen from the simplejson |
| 22 | # setup.py file. Original author: Bob Ippolito |
| 23 | |
| 24 | |
| 25 | speedups = Feature( |
| 26 | 'optional C speed-enhancement module', |
| 27 | standard=True, |
| 28 | ext_modules = [ |
| 29 | Extension('markupsafe._speedups', ['markupsafe/_speedups.c']), |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 30 | ], |
Armin Ronacher | 115ba37 | 2010-06-22 19:21:32 +0200 | [diff] [blame] | 31 | ) |
Armin Ronacher | 5bda522 | 2010-06-22 19:33:18 +0200 | [diff] [blame^] | 32 | |
| 33 | ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError) |
| 34 | if sys.platform == 'win32' and sys.version_info > (2, 6): |
| 35 | # 2.6's distutils.msvc9compiler can raise an IOError when failing to |
| 36 | # find the compiler |
| 37 | ext_errors += (IOError,) |
| 38 | |
| 39 | |
| 40 | class BuildFailed(Exception): |
| 41 | pass |
| 42 | |
| 43 | |
| 44 | class ve_build_ext(build_ext): |
| 45 | """This class allows C extension building to fail.""" |
| 46 | |
| 47 | def run(self): |
| 48 | try: |
| 49 | build_ext.run(self) |
| 50 | except DistutilsPlatformError, x: |
| 51 | raise BuildFailed() |
| 52 | |
| 53 | def build_extension(self, ext): |
| 54 | try: |
| 55 | build_ext.build_extension(self, ext) |
| 56 | except ext_errors, x: |
| 57 | raise BuildFailed() |
| 58 | |
| 59 | |
| 60 | def run_setup(with_binary): |
| 61 | features = {} |
| 62 | if with_binary: |
| 63 | features['speedups'] = speedups |
| 64 | setup( |
| 65 | name='MarkupSafe', |
| 66 | version='0.9', |
| 67 | url='http://dev.pocoo.org/', |
| 68 | license='BSD', |
| 69 | author='Armin Ronacher', |
| 70 | author_email='armin.ronacher@active-4.com', |
| 71 | description='Implements a XML/HTML/XHTML Markup safe string for Python', |
| 72 | long_description=__doc__, |
| 73 | zip_safe=False, |
| 74 | classifiers=[ |
| 75 | 'Development Status :: 5 - Production/Stable', |
| 76 | 'Environment :: Web Environment', |
| 77 | 'Intended Audience :: Developers', |
| 78 | 'License :: OSI Approved :: BSD License', |
| 79 | 'Operating System :: OS Independent', |
| 80 | 'Programming Language :: Python', |
| 81 | 'Programming Language :: Python :: 3', |
| 82 | 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', |
| 83 | 'Topic :: Software Development :: Libraries :: Python Modules', |
| 84 | 'Topic :: Text Processing :: Markup :: HTML' |
| 85 | ], |
| 86 | packages=['markupsafe'], |
| 87 | include_package_data=True, |
| 88 | cmdclass={'build_ext': ve_build_ext}, |
| 89 | features=features |
| 90 | ) |
| 91 | |
| 92 | |
| 93 | try: |
| 94 | run_setup(True) |
| 95 | except BuildFailed: |
| 96 | LINE = '=' * 74 |
| 97 | BUILD_EXT_WARNING = 'WARNING: The C extension could not be compiled, speedups are not enabled.' |
| 98 | |
| 99 | print LINE |
| 100 | print BUILD_EXT_WARNING |
| 101 | print 'Failure information, if any, is above.' |
| 102 | print 'Retrying the build without the C extension now.' |
| 103 | print |
| 104 | |
| 105 | run_setup(False) |
| 106 | |
| 107 | print LINE |
| 108 | print BUILD_EXT_WARNING |
| 109 | print 'Plain-Python installation succeeded.' |
| 110 | print LINE |