buildframework/helium/external/python/lib/2.5/docutils-0.5-py2.5.egg/docutils/writers/pep_html/__init__.py
changeset 179 d8ac696cc51f
parent 1 be27ed110b50
child 180 e02a83d4c571
child 592 3215c239276a
equal deleted inserted replaced
1:be27ed110b50 179:d8ac696cc51f
     1 # $Id: __init__.py 4564 2006-05-21 20:44:42Z wiemann $
       
     2 # Author: David Goodger <goodger@python.org>
       
     3 # Copyright: This module has been placed in the public domain.
       
     4 
       
     5 """
       
     6 PEP HTML Writer.
       
     7 """
       
     8 
       
     9 __docformat__ = 'reStructuredText'
       
    10 
       
    11 
       
    12 import sys
       
    13 import os
       
    14 import os.path
       
    15 import codecs
       
    16 import docutils
       
    17 from docutils import frontend, nodes, utils, writers
       
    18 from docutils.writers import html4css1
       
    19 
       
    20 
       
    21 class Writer(html4css1.Writer):
       
    22 
       
    23     default_stylesheet = 'pep.css'
       
    24 
       
    25     default_stylesheet_path = utils.relative_path(
       
    26         os.path.join(os.getcwd(), 'dummy'),
       
    27         os.path.join(os.path.dirname(__file__), default_stylesheet))
       
    28 
       
    29     default_template = 'template.txt'
       
    30 
       
    31     default_template_path = utils.relative_path(
       
    32         os.path.join(os.getcwd(), 'dummy'),
       
    33         os.path.join(os.path.dirname(__file__), default_template))
       
    34 
       
    35     settings_spec = html4css1.Writer.settings_spec + (
       
    36         'PEP/HTML-Specific Options',
       
    37         'For the PEP/HTML writer, the default value for the --stylesheet-path '
       
    38         'option is "%s", and the default value for --template is "%s". '
       
    39         'See HTML-Specific Options above.'
       
    40         % (default_stylesheet_path, default_template_path),
       
    41         (('Python\'s home URL.  Default is "http://www.python.org".',
       
    42           ['--python-home'],
       
    43           {'default': 'http://www.python.org', 'metavar': '<URL>'}),
       
    44          ('Home URL prefix for PEPs.  Default is "." (current directory).',
       
    45           ['--pep-home'],
       
    46           {'default': '.', 'metavar': '<URL>'}),
       
    47          # For testing.
       
    48          (frontend.SUPPRESS_HELP,
       
    49           ['--no-random'],
       
    50           {'action': 'store_true', 'validator': frontend.validate_boolean}),))
       
    51 
       
    52     settings_default_overrides = {'stylesheet_path': default_stylesheet_path,
       
    53                                   'template': default_template_path,}
       
    54 
       
    55     relative_path_settings = (html4css1.Writer.relative_path_settings
       
    56                               + ('template',))
       
    57 
       
    58     config_section = 'pep_html writer'
       
    59     config_section_dependencies = ('writers', 'html4css1 writer')
       
    60 
       
    61     def __init__(self):
       
    62         html4css1.Writer.__init__(self)
       
    63         self.translator_class = HTMLTranslator
       
    64 
       
    65     def interpolation_dict(self):
       
    66         subs = html4css1.Writer.interpolation_dict(self)
       
    67         settings = self.document.settings
       
    68         pyhome = settings.python_home
       
    69         subs['pyhome'] = pyhome
       
    70         subs['pephome'] = settings.pep_home
       
    71         if pyhome == '..':
       
    72             subs['pepindex'] = '.'
       
    73         else:
       
    74             subs['pepindex'] = pyhome + '/dev/peps'
       
    75         index = self.document.first_child_matching_class(nodes.field_list)
       
    76         header = self.document[index]
       
    77         self.pepnum = header[0][1].astext()
       
    78         subs['pep'] = self.pepnum
       
    79         if settings.no_random:
       
    80             subs['banner'] = 0
       
    81         else:
       
    82             import random
       
    83             subs['banner'] = random.randrange(64)
       
    84         try:
       
    85             subs['pepnum'] = '%04i' % int(self.pepnum)
       
    86         except ValueError:
       
    87             subs['pepnum'] = pepnum
       
    88         self.title = header[1][1].astext()
       
    89         subs['title'] = self.title
       
    90         subs['body'] = ''.join(
       
    91             self.body_pre_docinfo + self.docinfo + self.body)
       
    92         return subs
       
    93 
       
    94     def assemble_parts(self):
       
    95         html4css1.Writer.assemble_parts(self)
       
    96         self.parts['title'] = [self.title]
       
    97         self.parts['pepnum'] = self.pepnum
       
    98 
       
    99 
       
   100 class HTMLTranslator(html4css1.HTMLTranslator):
       
   101 
       
   102     def depart_field_list(self, node):
       
   103         html4css1.HTMLTranslator.depart_field_list(self, node)
       
   104         if 'rfc2822' in node['classes']:
       
   105              self.body.append('<hr />\n')