Python docutils.utils.split_escaped_whitespace() Examples

The following are 22 code examples of docutils.utils.split_escaped_whitespace(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module docutils.utils , or try the search function .
Example #1
Source File: states.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 6 votes vote down vote up
def parse_target(self, block, block_text, lineno):
        """
        Determine the type of reference of a target.

        :Return: A 2-tuple, one of:

            - 'refname' and the indirect reference name
            - 'refuri' and the URI
            - 'malformed' and a system_message node
        """
        if block and block[-1].strip()[-1:] == '_': # possible indirect target
            reference = ' '.join([line.strip() for line in block])
            refname = self.is_reference(reference)
            if refname:
                return 'refname', refname
        ref_parts = split_escaped_whitespace(' '.join(block))
        reference = ' '.join(''.join(unescape(part).split())
                             for part in ref_parts)
        return 'refuri', reference 
Example #2
Source File: states.py    From aws-builders-fair-projects with Apache License 2.0 6 votes vote down vote up
def parse_target(self, block, block_text, lineno):
        """
        Determine the type of reference of a target.

        :Return: A 2-tuple, one of:

            - 'refname' and the indirect reference name
            - 'refuri' and the URI
            - 'malformed' and a system_message node
        """
        if block and block[-1].strip()[-1:] == '_': # possible indirect target
            reference = ' '.join([line.strip() for line in block])
            refname = self.is_reference(reference)
            if refname:
                return 'refname', refname
        ref_parts = split_escaped_whitespace(' '.join(block))
        reference = ' '.join(''.join(unescape(part).split())
                             for part in ref_parts)
        return 'refuri', reference 
Example #3
Source File: states.py    From aws-extender with MIT License 6 votes vote down vote up
def parse_target(self, block, block_text, lineno):
        """
        Determine the type of reference of a target.

        :Return: A 2-tuple, one of:

            - 'refname' and the indirect reference name
            - 'refuri' and the URI
            - 'malformed' and a system_message node
        """
        if block and block[-1].strip()[-1:] == '_': # possible indirect target
            reference = ' '.join([line.strip() for line in block])
            refname = self.is_reference(reference)
            if refname:
                return 'refname', refname
        ref_parts = split_escaped_whitespace(' '.join(block))
        reference = ' '.join(''.join(unescape(part).split())
                             for part in ref_parts)
        return 'refuri', reference 
Example #4
Source File: states.py    From blackmamba with MIT License 6 votes vote down vote up
def parse_target(self, block, block_text, lineno):
        """
        Determine the type of reference of a target.

        :Return: A 2-tuple, one of:

            - 'refname' and the indirect reference name
            - 'refuri' and the URI
            - 'malformed' and a system_message node
        """
        if block and block[-1].strip()[-1:] == '_': # possible indirect target
            reference = ' '.join([line.strip() for line in block])
            refname = self.is_reference(reference)
            if refname:
                return 'refname', refname
        ref_parts = split_escaped_whitespace(' '.join(block))
        reference = ' '.join(''.join(unescape(part).split())
                             for part in ref_parts)
        return 'refuri', reference 
Example #5
Source File: states.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 6 votes vote down vote up
def parse_target(self, block, block_text, lineno):
        """
        Determine the type of reference of a target.

        :Return: A 2-tuple, one of:

            - 'refname' and the indirect reference name
            - 'refuri' and the URI
            - 'malformed' and a system_message node
        """
        if block and block[-1].strip()[-1:] == '_': # possible indirect target
            reference = ' '.join([line.strip() for line in block])
            refname = self.is_reference(reference)
            if refname:
                return 'refname', refname
        ref_parts = split_escaped_whitespace(' '.join(block))
        reference = ' '.join(''.join(unescape(part).split())
                             for part in ref_parts)
        return 'refuri', reference 
Example #6
Source File: states.py    From bash-lambda-layer with MIT License 6 votes vote down vote up
def parse_target(self, block, block_text, lineno):
        """
        Determine the type of reference of a target.

        :Return: A 2-tuple, one of:

            - 'refname' and the indirect reference name
            - 'refuri' and the URI
            - 'malformed' and a system_message node
        """
        if block and block[-1].strip()[-1:] == '_': # possible indirect target
            reference = ' '.join([line.strip() for line in block])
            refname = self.is_reference(reference)
            if refname:
                return 'refname', refname
        ref_parts = split_escaped_whitespace(' '.join(block))
        reference = ' '.join(''.join(unescape(part).split())
                             for part in ref_parts)
        return 'refuri', reference 
Example #7
Source File: states.py    From deepWordBug with Apache License 2.0 6 votes vote down vote up
def parse_target(self, block, block_text, lineno):
        """
        Determine the type of reference of a target.

        :Return: A 2-tuple, one of:

            - 'refname' and the indirect reference name
            - 'refuri' and the URI
            - 'malformed' and a system_message node
        """
        if block and block[-1].strip()[-1:] == '_': # possible indirect target
            reference = ' '.join([line.strip() for line in block])
            refname = self.is_reference(reference)
            if refname:
                return 'refname', refname
        ref_parts = split_escaped_whitespace(' '.join(block))
        reference = ' '.join(''.join(unescape(part).split())
                             for part in ref_parts)
        return 'refuri', reference 
Example #8
Source File: __init__.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 5 votes vote down vote up
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri 
Example #9
Source File: __init__.py    From aws-builders-fair-projects with Apache License 2.0 5 votes vote down vote up
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri 
Example #10
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri 
Example #11
Source File: __init__.py    From deepWordBug with Apache License 2.0 5 votes vote down vote up
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri 
Example #12
Source File: __init__.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 5 votes vote down vote up
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri 
Example #13
Source File: __init__.py    From blackmamba with MIT License 5 votes vote down vote up
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri 
Example #14
Source File: __init__.py    From aws-extender with MIT License 5 votes vote down vote up
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri 
Example #15
Source File: __init__.py    From bash-lambda-layer with MIT License 5 votes vote down vote up
def uri(argument):
    """
    Return the URI argument with unescaped whitespace removed.
    (Directive option conversion function.)

    Raise ``ValueError`` if no argument is found.
    """
    if argument is None:
        raise ValueError('argument required but none supplied')
    else:
        parts = split_escaped_whitespace(escape2null(argument))
        uri = ' '.join(''.join(unescape(part).split()) for part in parts)
        return uri 
Example #16
Source File: states.py    From deepWordBug with Apache License 2.0 4 votes vote down vote up
def phrase_ref(self, before, after, rawsource, escaped, text):
        match = self.patterns.embedded_link.search(escaped)
        if match: # embedded <URI> or <alias_>
            text = unescape(escaped[:match.start(0)])
            aliastext = match.group(2)
            underscore_escaped = aliastext.endswith('\x00_')
            aliastext = unescape(aliastext)
            if aliastext.endswith('_') and not (underscore_escaped
                                        or self.patterns.uri.match(aliastext)):
                aliastype = 'name'
                alias = normalize_name(aliastext[:-1])
                target = nodes.target(match.group(1), refname=alias)
                target.indirect_reference_name = aliastext[:-1]
            else:
                aliastype = 'uri'
                alias_parts = split_escaped_whitespace(match.group(2))
                alias = ' '.join(''.join(unescape(part).split())
                                 for part in alias_parts)
                alias = self.adjust_uri(alias)
                if alias.endswith(r'\_'):
                    alias = alias[:-2] + '_'
                target = nodes.target(match.group(1), refuri=alias)
                target.referenced = 1
            if not aliastext:
                raise ApplicationError('problem with embedded link: %r'
                                       % aliastext)
            if not text:
                text = alias
        else:
            target = None

        refname = normalize_name(text)
        reference = nodes.reference(rawsource, text,
                                    name=whitespace_normalize_name(text))
        node_list = [reference]

        if rawsource[-2:] == '__':
            if  target and (aliastype == 'name'):
                reference['refname'] = alias
                self.document.note_refname(reference)
                # self.document.note_indirect_target(target) # required?
            elif target and (aliastype == 'uri'):
                reference['refuri'] = alias
            else:
                reference['anonymous'] = 1
        else:
            if target:
                target['names'].append(refname)
                if aliastype == 'name':
                    reference['refname'] = alias
                    self.document.note_indirect_target(target)
                    self.document.note_refname(reference)
                else:
                    reference['refuri'] = alias
                    self.document.note_explicit_target(target, self.parent)
                # target.note_referenced_by(name=refname)
                node_list.append(target)
            else:
                reference['refname'] = refname
                self.document.note_refname(reference)
        return before, node_list, after, [] 
Example #17
Source File: states.py    From aws-extender with MIT License 4 votes vote down vote up
def phrase_ref(self, before, after, rawsource, escaped, text):
        match = self.patterns.embedded_link.search(escaped)
        if match: # embedded <URI> or <alias_>
            text = unescape(escaped[:match.start(0)])
            aliastext = match.group(2)
            underscore_escaped = aliastext.endswith('\x00_')
            aliastext = unescape(aliastext)
            if aliastext.endswith('_') and not (underscore_escaped
                                        or self.patterns.uri.match(aliastext)):
                aliastype = 'name'
                alias = normalize_name(aliastext[:-1])
                target = nodes.target(match.group(1), refname=alias)
                target.indirect_reference_name = aliastext[:-1]
            else:
                aliastype = 'uri'
                alias_parts = split_escaped_whitespace(match.group(2))
                alias = ' '.join(''.join(unescape(part).split())
                                 for part in alias_parts)
                alias = self.adjust_uri(alias)
                if alias.endswith(r'\_'):
                    alias = alias[:-2] + '_'
                target = nodes.target(match.group(1), refuri=alias)
                target.referenced = 1
            if not aliastext:
                raise ApplicationError('problem with embedded link: %r'
                                       % aliastext)
            if not text:
                text = alias
        else:
            target = None

        refname = normalize_name(text)
        reference = nodes.reference(rawsource, text,
                                    name=whitespace_normalize_name(text))
        node_list = [reference]

        if rawsource[-2:] == '__':
            if  target and (aliastype == 'name'):
                reference['refname'] = alias
                self.document.note_refname(reference)
                # self.document.note_indirect_target(target) # required?
            elif target and (aliastype == 'uri'):
                reference['refuri'] = alias
            else:
                reference['anonymous'] = 1
        else:
            if target:
                target['names'].append(refname)
                if aliastype == 'name':
                    reference['refname'] = alias
                    self.document.note_indirect_target(target)
                    self.document.note_refname(reference)
                else:
                    reference['refuri'] = alias
                    self.document.note_explicit_target(target, self.parent)
                # target.note_referenced_by(name=refname)
                node_list.append(target)
            else:
                reference['refname'] = refname
                self.document.note_refname(reference)
        return before, node_list, after, [] 
Example #18
Source File: states.py    From blackmamba with MIT License 4 votes vote down vote up
def phrase_ref(self, before, after, rawsource, escaped, text):
        match = self.patterns.embedded_link.search(escaped)
        if match: # embedded <URI> or <alias_>
            text = unescape(escaped[:match.start(0)])
            aliastext = match.group(2)
            underscore_escaped = aliastext.endswith('\x00_')
            aliastext = unescape(aliastext)
            if aliastext.endswith('_') and not (underscore_escaped
                                        or self.patterns.uri.match(aliastext)):
                aliastype = 'name'
                alias = normalize_name(aliastext[:-1])
                target = nodes.target(match.group(1), refname=alias)
                target.indirect_reference_name = aliastext[:-1]
            else:
                aliastype = 'uri'
                alias_parts = split_escaped_whitespace(match.group(2))
                alias = ' '.join(''.join(unescape(part).split())
                                 for part in alias_parts)
                alias = self.adjust_uri(alias)
                if alias.endswith(r'\_'):
                    alias = alias[:-2] + '_'
                target = nodes.target(match.group(1), refuri=alias)
                target.referenced = 1
            if not aliastext:
                raise ApplicationError('problem with embedded link: %r'
                                       % aliastext)
            if not text:
                text = alias
        else:
            target = None

        refname = normalize_name(text)
        reference = nodes.reference(rawsource, text,
                                    name=whitespace_normalize_name(text))
        node_list = [reference]

        if rawsource[-2:] == '__':
            if  target and (aliastype == 'name'):
                reference['refname'] = alias
                self.document.note_refname(reference)
                # self.document.note_indirect_target(target) # required?
            elif target and (aliastype == 'uri'):
                reference['refuri'] = alias
            else:
                reference['anonymous'] = 1
        else:
            if target:
                target['names'].append(refname)
                if aliastype == 'name':
                    reference['refname'] = alias
                    self.document.note_indirect_target(target)
                    self.document.note_refname(reference)
                else:
                    reference['refuri'] = alias
                    self.document.note_explicit_target(target, self.parent)
                # target.note_referenced_by(name=refname)
                node_list.append(target)
            else:
                reference['refname'] = refname
                self.document.note_refname(reference)
        return before, node_list, after, [] 
Example #19
Source File: states.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 4 votes vote down vote up
def phrase_ref(self, before, after, rawsource, escaped, text):
        match = self.patterns.embedded_link.search(escaped)
        if match: # embedded <URI> or <alias_>
            text = unescape(escaped[:match.start(0)])
            aliastext = match.group(2)
            underscore_escaped = aliastext.endswith('\x00_')
            aliastext = unescape(aliastext)
            if aliastext.endswith('_') and not (underscore_escaped
                                        or self.patterns.uri.match(aliastext)):
                aliastype = 'name'
                alias = normalize_name(aliastext[:-1])
                target = nodes.target(match.group(1), refname=alias)
                target.indirect_reference_name = aliastext[:-1]
            else:
                aliastype = 'uri'
                alias_parts = split_escaped_whitespace(match.group(2))
                alias = ' '.join(''.join(unescape(part).split())
                                 for part in alias_parts)
                alias = self.adjust_uri(alias)
                if alias.endswith(r'\_'):
                    alias = alias[:-2] + '_'
                target = nodes.target(match.group(1), refuri=alias)
                target.referenced = 1
            if not aliastext:
                raise ApplicationError('problem with embedded link: %r'
                                       % aliastext)
            if not text:
                text = alias
        else:
            target = None

        refname = normalize_name(text)
        reference = nodes.reference(rawsource, text,
                                    name=whitespace_normalize_name(text))
        node_list = [reference]

        if rawsource[-2:] == '__':
            if  target and (aliastype == 'name'):
                reference['refname'] = alias
                self.document.note_refname(reference)
                # self.document.note_indirect_target(target) # required?
            elif target and (aliastype == 'uri'):
                reference['refuri'] = alias
            else:
                reference['anonymous'] = 1
        else:
            if target:
                target['names'].append(refname)
                if aliastype == 'name':
                    reference['refname'] = alias
                    self.document.note_indirect_target(target)
                    self.document.note_refname(reference)
                else:
                    reference['refuri'] = alias
                    self.document.note_explicit_target(target, self.parent)
                # target.note_referenced_by(name=refname)
                node_list.append(target)
            else:
                reference['refname'] = refname
                self.document.note_refname(reference)
        return before, node_list, after, [] 
Example #20
Source File: states.py    From AWS-Transit-Gateway-Demo-MultiAccount with MIT License 4 votes vote down vote up
def phrase_ref(self, before, after, rawsource, escaped, text):
        match = self.patterns.embedded_link.search(escaped)
        if match: # embedded <URI> or <alias_>
            text = unescape(escaped[:match.start(0)])
            aliastext = match.group(2)
            underscore_escaped = aliastext.endswith('\x00_')
            aliastext = unescape(aliastext)
            if aliastext.endswith('_') and not (underscore_escaped
                                        or self.patterns.uri.match(aliastext)):
                aliastype = 'name'
                alias = normalize_name(aliastext[:-1])
                target = nodes.target(match.group(1), refname=alias)
                target.indirect_reference_name = aliastext[:-1]
            else:
                aliastype = 'uri'
                alias_parts = split_escaped_whitespace(match.group(2))
                alias = ' '.join(''.join(unescape(part).split())
                                 for part in alias_parts)
                alias = self.adjust_uri(alias)
                if alias.endswith(r'\_'):
                    alias = alias[:-2] + '_'
                target = nodes.target(match.group(1), refuri=alias)
                target.referenced = 1
            if not aliastext:
                raise ApplicationError('problem with embedded link: %r'
                                       % aliastext)
            if not text:
                text = alias
        else:
            target = None

        refname = normalize_name(text)
        reference = nodes.reference(rawsource, text,
                                    name=whitespace_normalize_name(text))
        node_list = [reference]

        if rawsource[-2:] == '__':
            if  target and (aliastype == 'name'):
                reference['refname'] = alias
                self.document.note_refname(reference)
                # self.document.note_indirect_target(target) # required?
            elif target and (aliastype == 'uri'):
                reference['refuri'] = alias
            else:
                reference['anonymous'] = 1
        else:
            if target:
                target['names'].append(refname)
                if aliastype == 'name':
                    reference['refname'] = alias
                    self.document.note_indirect_target(target)
                    self.document.note_refname(reference)
                else:
                    reference['refuri'] = alias
                    self.document.note_explicit_target(target, self.parent)
                # target.note_referenced_by(name=refname)
                node_list.append(target)
            else:
                reference['refname'] = refname
                self.document.note_refname(reference)
        return before, node_list, after, [] 
Example #21
Source File: states.py    From bash-lambda-layer with MIT License 4 votes vote down vote up
def phrase_ref(self, before, after, rawsource, escaped, text):
        match = self.patterns.embedded_link.search(escaped)
        if match: # embedded <URI> or <alias_>
            text = unescape(escaped[:match.start(0)])
            aliastext = match.group(2)
            underscore_escaped = aliastext.endswith('\x00_')
            aliastext = unescape(aliastext)
            if aliastext.endswith('_') and not (underscore_escaped
                                        or self.patterns.uri.match(aliastext)):
                aliastype = 'name'
                alias = normalize_name(aliastext[:-1])
                target = nodes.target(match.group(1), refname=alias)
                target.indirect_reference_name = aliastext[:-1]
            else:
                aliastype = 'uri'
                alias_parts = split_escaped_whitespace(match.group(2))
                alias = ' '.join(''.join(unescape(part).split())
                                 for part in alias_parts)
                alias = self.adjust_uri(alias)
                if alias.endswith(r'\_'):
                    alias = alias[:-2] + '_'
                target = nodes.target(match.group(1), refuri=alias)
                target.referenced = 1
            if not aliastext:
                raise ApplicationError('problem with embedded link: %r'
                                       % aliastext)
            if not text:
                text = alias
        else:
            target = None

        refname = normalize_name(text)
        reference = nodes.reference(rawsource, text,
                                    name=whitespace_normalize_name(text))
        node_list = [reference]

        if rawsource[-2:] == '__':
            if  target and (aliastype == 'name'):
                reference['refname'] = alias
                self.document.note_refname(reference)
                # self.document.note_indirect_target(target) # required?
            elif target and (aliastype == 'uri'):
                reference['refuri'] = alias
            else:
                reference['anonymous'] = 1
        else:
            if target:
                target['names'].append(refname)
                if aliastype == 'name':
                    reference['refname'] = alias
                    self.document.note_indirect_target(target)
                    self.document.note_refname(reference)
                else:
                    reference['refuri'] = alias
                    self.document.note_explicit_target(target, self.parent)
                # target.note_referenced_by(name=refname)
                node_list.append(target)
            else:
                reference['refname'] = refname
                self.document.note_refname(reference)
        return before, node_list, after, [] 
Example #22
Source File: states.py    From cadquery-freecad-module with GNU Lesser General Public License v3.0 4 votes vote down vote up
def phrase_ref(self, before, after, rawsource, escaped, text):
        match = self.patterns.embedded_link.search(escaped)
        if match: # embedded <URI> or <alias_>
            text = unescape(escaped[:match.start(0)])
            aliastext = match.group(2)
            underscore_escaped = aliastext.endswith('\x00_')
            aliastext = unescape(aliastext)
            if aliastext.endswith('_') and not (underscore_escaped
                                        or self.patterns.uri.match(aliastext)):
                aliastype = 'name'
                alias = normalize_name(aliastext[:-1])
                target = nodes.target(match.group(1), refname=alias)
                target.indirect_reference_name = aliastext[:-1]
            else:
                aliastype = 'uri'
                alias_parts = split_escaped_whitespace(match.group(2))
                alias = ' '.join(''.join(unescape(part).split())
                                 for part in alias_parts)
                alias = self.adjust_uri(alias)
                if alias.endswith(r'\_'):
                    alias = alias[:-2] + '_'
                target = nodes.target(match.group(1), refuri=alias)
                target.referenced = 1
            if not aliastext:
                raise ApplicationError('problem with embedded link: %r'
                                       % aliastext)
            if not text:
                text = alias
        else:
            target = None

        refname = normalize_name(text)
        reference = nodes.reference(rawsource, text,
                                    name=whitespace_normalize_name(text))
        node_list = [reference]

        if rawsource[-2:] == '__':
            if  target and (aliastype == 'name'):
                reference['refname'] = alias
                self.document.note_refname(reference)
                # self.document.note_indirect_target(target) # required?
            elif target and (aliastype == 'uri'):
                reference['refuri'] = alias
            else:
                reference['anonymous'] = 1
        else:
            if target:
                target['names'].append(refname)
                if aliastype == 'name':
                    reference['refname'] = alias
                    self.document.note_indirect_target(target)
                    self.document.note_refname(reference)
                else:
                    reference['refuri'] = alias
                    self.document.note_explicit_target(target, self.parent)
                # target.note_referenced_by(name=refname)
                node_list.append(target)
            else:
                reference['refname'] = refname
                self.document.note_refname(reference)
        return before, node_list, after, []