Georg Brandl avatar Georg Brandl committed 1e645ac Merge

Merge heads.

Comments (0)

Files changed (6)

email/MANIFEST.in

+include README
+include CHANGES.*
+=========================
+ sphinxcontrib-email
+=========================
+
+This package contains sphinxcontrb.email, an email obfuscator for
+Sphinx-based documentation.
+
+
+Installation
+============
+
+1. ``pip install sphinxcontrib-email``
+
+Configuration
+=============
+
+1. Add ``'sphinxcontrib.email'`` to the ``extensions`` list in ``conf.py``.
+
+  ::
+
+    extensions = [ 'sphinxcontrib.email' ]
+
+
+Usage
+=====
+
+To obfuscate an email address use something like::
+
+    :email:`Name Surname <user@myplace.org>`
+    :email:`Name Surname (user@myplace.org)`
+
+Renders as "Name Surname" with the appropriate mailto link.
+
+    :email:`user@myplace.org`
+
+Renders as "user@myplace.org" with the appropriate mailto link
+
+History
+=======
+
+0.1
+  First public release.
+
+[egg_info]
+#tag_build = dev
+#tag_date = true
+
+[aliases]
+release = egg_info -RDb '' register bdist_egg sdist upload
+# -*- coding: utf-8 -*-
+
+from setuptools import setup, find_packages
+
+f = open('README', 'r')
+try:
+    long_desc = f.read()
+finally:
+    f.close()
+    
+requires = ['Sphinx>=0.6']
+
+setup(
+    name='sphinxcontrib-email',
+    version='0.1',
+    url='http://bitbucket.org/birkenfeld/sphinx-contrib',
+    download_url='http://pypi.python.org/pypi/sphinxcontrib-email',
+    license='BSD',
+    author='Kevin Teague',
+    author_email='kevin@bud.ca',
+    description='Sphinx email obfuscation extension',
+    long_description=long_desc,
+    zip_safe=False,
+    classifiers=[
+        'Development Status :: 3 - Alpha',
+        'Environment :: Console',
+        'Environment :: Web Environment',
+        'Intended Audience :: Developers',
+        'License :: OSI Approved :: BSD License',
+        'Operating System :: OS Independent',
+        'Programming Language :: Python',
+        'Topic :: Documentation',
+        'Topic :: Utilities',
+    ],
+    platforms='any',
+    packages=find_packages(),
+    include_package_data=True,
+    install_requires=requires,
+    namespace_packages=['sphinxcontrib'],
+)

email/sphinxcontrib/__init__.py

+# -*- coding: utf-8 -*-
+"""
+    sphinxcontrib
+    ~~~~~~~~~~~~~
+
+    This package is a namespace package that contains all extensions
+    distributed in the ``sphinx-contrib`` distribution.
+
+    :copyright: Copyright 2007-2009 by the Sphinx team, see AUTHORS.
+    :license: BSD, see LICENSE for details.
+"""
+
+__import__('pkg_resources').declare_namespace(__name__)
+

email/sphinxcontrib/email.py

+# E-mail obfuscation role for Sphinx.
+
+from docutils import nodes
+
+# The obfuscation code was taken from
+#
+#   http://pypi.python.org/pypi/bud.nospam
+#
+# and was was released by Kevin Teague <kevin at bud ca> under
+# a BSD license.
+
+import re
+import string
+
+rot_13_trans = string.maketrans(
+    'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
+    'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm'
+)
+
+def rot_13_encrypt(line):
+    """Rotate 13 encryption.
+
+    """
+    line = line.translate(rot_13_trans)
+    line = re.sub('(?=[\\"])', r'\\', line)
+    line = re.sub('\n', r'\n', line)
+    line = re.sub('@', r'\\100', line)
+    line = re.sub('\.', r'\\056', line)
+    line = re.sub('/', r'\\057', line)
+    return line
+
+def js_obfuscated_text(text):
+    """ROT 13 encryption with embedded in Javascript code to decrypt
+    in the browser.
+
+    """
+    return """<script type="text/javascript">document.write(
+              "%s".replace(/[a-zA-Z]/g,
+              function(c){
+                return String.fromCharCode(
+                (c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);}));
+                </script>""" % rot_13_encrypt(text)
+
+def js_obfuscated_mailto(email, displayname=None):
+    """ROT 13 encryption within an Anchor tag w/ a mailto: attribute
+
+    """
+    if not displayname:
+        displayname = email
+    return js_obfuscated_text("""<a href="mailto:%s">%s</a>""" % (
+        email, displayname
+    ))
+
+# -- end bud.nospam
+
+def email_role(typ, rawtext, text, lineno, inliner, options={}, content=[]):
+    """
+    Role to obfuscate e-mail addresses.
+    """
+    print 123456789, text, '\n\n'
+    text = text.decode('utf-8').encode('utf-8')
+    # Handle addresses of the form "Name <name@domain.org>"
+    if '<' in text and '>' in text:
+        name, email = text.split('<')
+        email = email.split('>')[0]
+    elif '(' in text and ')' in text:
+        name, email = text.split('(')
+        email = email.split(')')[0]
+    else:
+        name = text
+        email = name
+
+    obfuscated = js_obfuscated_mailto(email, displayname=name)
+    node = nodes.raw('', obfuscated, format='html')
+    return [node], []
+
+def setup(app):
+    app.add_role('email', email_role)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.