コード例 #1
0
ファイル: misc.py プロジェクト: Tank-D/Shards
def unicode_directive(name, arguments, options, content, lineno,
                      content_offset, block_text, state, state_machine):
    r"""
    Convert Unicode character codes (numbers) to characters.  Codes may be
    decimal numbers, hexadecimal numbers (prefixed by ``0x``, ``x``, ``\x``,
    ``U+``, ``u``, or ``\u``; e.g. ``U+262E``), or XML-style numeric character
    entities (e.g. ``☮``).  Text following ".." is a comment and is
    ignored.  Spaces are ignored, and any other text remains as-is.
    """
    if not isinstance(state, states.SubstitutionDef):
        error = state_machine.reporter.error(
            'Invalid context: the "%s" directive can only be used within a '
            'substitution definition.' % (name),
            nodes.literal_block(block_text, block_text), line=lineno)
        return [error]
    substitution_definition = state_machine.node
    if options.has_key('trim'):
        substitution_definition.attributes['ltrim'] = 1
        substitution_definition.attributes['rtrim'] = 1
    if options.has_key('ltrim'):
        substitution_definition.attributes['ltrim'] = 1
    if options.has_key('rtrim'):
        substitution_definition.attributes['rtrim'] = 1
    codes = unicode_comment_pattern.split(arguments[0])[0].split()
    element = nodes.Element()
    for code in codes:
        try:
            decoded = directives.unicode_code(code)
        except ValueError, err:
            error = state_machine.reporter.error(
                'Invalid character code: %s\n%s: %s'
                % (code, err.__class__.__name__, err),
                nodes.literal_block(block_text, block_text), line=lineno)
            return [error]
        element += nodes.Text(decoded)
コード例 #2
0
 def run(self):
     if not isinstance(self.state, states.SubstitutionDef):
         raise self.error(
             'Invalid context: the "%s" directive can only be used within '
             "a substitution definition." % self.name
         )
     substitution_definition = self.state_machine.node
     if "trim" in self.options:
         substitution_definition.attributes["ltrim"] = 1
         substitution_definition.attributes["rtrim"] = 1
     if "ltrim" in self.options:
         substitution_definition.attributes["ltrim"] = 1
     if "rtrim" in self.options:
         substitution_definition.attributes["rtrim"] = 1
     codes = self.comment_pattern.split(self.arguments[0])[0].split()
     element = nodes.Element()
     for code in codes:
         try:
             decoded = directives.unicode_code(code)
         except ValueError as error:
             raise self.error(
                 u"Invalid character code: %s\n%s" % (code, ErrorString(error))
             )
         element += nodes.Text(decoded)
     return element.children
コード例 #3
0
ファイル: misc.py プロジェクト: greghicks01/selenium
def unicode_directive(name, arguments, options, content, lineno,
                      content_offset, block_text, state, state_machine):
    r"""
    Convert Unicode character codes (numbers) to characters.  Codes may be
    decimal numbers, hexadecimal numbers (prefixed by ``0x``, ``x``, ``\x``,
    ``U+``, ``u``, or ``\u``; e.g. ``U+262E``), or XML-style numeric character
    entities (e.g. ``☮``).  Text following ".." is a comment and is
    ignored.  Spaces are ignored, and any other text remains as-is.
    """
    if not isinstance(state, states.SubstitutionDef):
        error = state_machine.reporter.error(
            'Invalid context: the "%s" directive can only be used within a '
            'substitution definition.' % (name),
            nodes.literal_block(block_text, block_text), line=lineno)
        return [error]
    substitution_definition = state_machine.node
    if options.has_key('trim'):
        substitution_definition.attributes['ltrim'] = 1
        substitution_definition.attributes['rtrim'] = 1
    if options.has_key('ltrim'):
        substitution_definition.attributes['ltrim'] = 1
    if options.has_key('rtrim'):
        substitution_definition.attributes['rtrim'] = 1
    codes = unicode_comment_pattern.split(arguments[0])[0].split()
    element = nodes.Element()
    for code in codes:
        try:
            decoded = directives.unicode_code(code)
        except ValueError, err:
            error = state_machine.reporter.error(
                'Invalid character code: %s\n%s: %s'
                % (code, err.__class__.__name__, err),
                nodes.literal_block(block_text, block_text), line=lineno)
            return [error]
        element += nodes.Text(decoded)
コード例 #4
0
ファイル: misc.py プロジェクト: srid/debris
 def run(self):
     if not isinstance(self.state, states.SubstitutionDef):
         raise self.error(
             'Invalid context: the "%s" directive can only be used within ' "a substitution definition." % self.name
         )
     substitution_definition = self.state_machine.node
     if self.options.has_key("trim"):
         substitution_definition.attributes["ltrim"] = 1
         substitution_definition.attributes["rtrim"] = 1
     if self.options.has_key("ltrim"):
         substitution_definition.attributes["ltrim"] = 1
     if self.options.has_key("rtrim"):
         substitution_definition.attributes["rtrim"] = 1
     codes = self.comment_pattern.split(self.arguments[0])[0].split()
     element = nodes.Element()
     for code in codes:
         try:
             decoded = directives.unicode_code(code)
         except ValueError, err:
             raise self.error("Invalid character code: %s\n%s: %s" % (code, err.__class__.__name__, err))
         element += nodes.Text(decoded)
コード例 #5
0
ファイル: misc.py プロジェクト: cheeryguo/TinyApp
 def run(self):
     if not isinstance(self.state, states.SubstitutionDef):
         raise self.error(
             'Invalid context: the "%s" directive can only be used within '
             'a substitution definition.' % self.name)
     substitution_definition = self.state_machine.node
     if 'trim' in self.options:
         substitution_definition.attributes['ltrim'] = 1
         substitution_definition.attributes['rtrim'] = 1
     if 'ltrim' in self.options:
         substitution_definition.attributes['ltrim'] = 1
     if 'rtrim' in self.options:
         substitution_definition.attributes['rtrim'] = 1
     codes = self.comment_pattern.split(self.arguments[0])[0].split()
     element = nodes.Element()
     for code in codes:
         try:
             decoded = directives.unicode_code(code)
         except ValueError, error:
             raise self.error(u'Invalid character code: %s\n%s'
                 % (code, ErrorString(error)))
         element += nodes.Text(decoded)
コード例 #6
0
 def run(self):
     if not isinstance(self.state, states.SubstitutionDef):
         raise self.error(
             'Invalid context: the "%s" directive can only be used within '
             'a substitution definition.' % self.name)
     substitution_definition = self.state_machine.node
     if 'trim' in self.options:
         substitution_definition.attributes['ltrim'] = 1
         substitution_definition.attributes['rtrim'] = 1
     if 'ltrim' in self.options:
         substitution_definition.attributes['ltrim'] = 1
     if 'rtrim' in self.options:
         substitution_definition.attributes['rtrim'] = 1
     codes = self.comment_pattern.split(self.arguments[0])[0].split()
     element = nodes.Element()
     for code in codes:
         try:
             decoded = directives.unicode_code(code)
         except ValueError, error:
             raise self.error(u'Invalid character code: %s\n%s' %
                              (code, ErrorString(error)))
         element += nodes.Text(utils.unescape(decoded), decoded)