Example #1
0
 def testSpace(self):
     defaults = dict(year=(1980, 'doc'),
                     month=('june', 'doc'),
                     day=(24, 'doc'))
     raw = 'year=the year I was born'
     known, _ = common.parse_settings(defaults, raw)
     self.assertEqual(known['year'], 'the year I was born')
Example #2
0
    def createToken(self, info, parent):

        cmd = (info['command'], info['subcommand'])
        settings = info['settings']

        # Handle filename and None subcommand
        match = self.FILENAME_RE.search(
            info['subcommand']) if info['subcommand'] else None
        if match:
            cmd = (info['command'], match.group('ext'))
        elif info['subcommand'] and info['subcommand'].startswith('http'):
            cmd = (info['command'], None)
        elif info['subcommand'] and '=' in info['subcommand']:
            #settings += ' ' + info['subcommand']
            settings = info['subcommand'] + ' ' + settings
            cmd = (info['command'], None)

        # Locate the command object to call
        try:
            obj = self.translator.__EXTENSION_COMMANDS__[cmd]
        except KeyError:
            try:
                obj = self.translator.__EXTENSION_COMMANDS__[(cmd[0], '*')]
            except KeyError:
                msg = "The following command combination is unknown: '{} {}'."
                raise common.exceptions.TokenizeException(msg.format(*cmd))

        # Build the token
        if obj.PARSE_SETTINGS:
            settings, _ = common.parse_settings(obj.defaultSettings(),
                                                settings)
            obj.setSettings(settings)
        token = obj.createToken(info, parent)
        return token
Example #3
0
    def createToken(self, info, parent):

        cmd = (info['command'], info['subcommand'])
        settings = info['settings']

        # Handle filename and None subcommand
        match = self.FILENAME_RE.search(info['subcommand']) if info['subcommand'] else None
        if match:
            cmd = (info['command'], match.group('ext'))
        elif info['subcommand'] and info['subcommand'].startswith('http'):
            cmd = (info['command'], None)
        elif info['subcommand'] and '=' in info['subcommand']:
            #settings += ' ' + info['subcommand']
            settings = info['subcommand'] + ' ' + settings
            cmd = (info['command'], None)

        # Locate the command object to call
        try:
            obj = self.translator.__EXTENSION_COMMANDS__[cmd]
        except KeyError:
            try:
                obj = self.translator.__EXTENSION_COMMANDS__[(cmd[0], '*')]
            except KeyError:
                msg = "The following command combination is unknown: '{} {}'."
                raise common.exceptions.TokenizeException(msg.format(*cmd))

        # Build the token
        if obj.PARSE_SETTINGS:
            settings, _ = common.parse_settings(obj.defaultSettings(), settings)
            obj.setSettings(settings)
        token = obj.createToken(info, parent)
        return token
Example #4
0
    def __call__(self, parent, info, page):
        """
        MooseDocs internal method, this should not be called, please use the createToken method.

        The lexer system within MooseDocs expects a function this method allows this class to act
        as a function.

        Inputs:
            info[LexerInformation]: Object containing the lexer information object.
            parent[tokens.Token]: The parent node in the AST for the token being created.
        """
        # Disable inactive extensions, the "is not None" allows this method to work when
        # components are added outside of an extension, which is needed for testing
        if (self.extension is not None) and (not self.extension.active):
            tokens.DisabledToken(parent, string=info[0])
            return parent

        # Define the settings
        defaults = self.defaultSettings()
        if self.PARSE_SETTINGS and ('settings' in info):
            self.__settings, _ = parse_settings(defaults, info['settings'])
        else:
            self.__settings = {k: v[0] for k, v in defaults.iteritems()}

        # Call user method and reset settings
        token = self.createToken(parent, info, page)
        self.__settings = None
        return token
Example #5
0
    def __call__(self, parent, info, page):
        """
        MooseDocs internal method, this should not be called, please use the createToken method.

        The lexer system within MooseDocs expects a function this method allows this class to act
        as a function.

        Inputs:
            info[LexerInformation]: Object containing the lexer information object.
            parent[tokens.Token]: The parent node in the AST for the token being created.
        """
        # Disable inactive extensions, the "is not None" allows this method to work when
        # components are added outside of an extension, which is needed for testing
        if (self.extension is not None) and (not self.extension.active):
            tokens.DisabledToken(parent, string=info[0])
            return parent

        # Define the settings
        defaults = self.defaultSettings()
        if self.PARSE_SETTINGS and ('settings' in info):
            self.__settings, _ = parse_settings(defaults, info['settings'])
        else:
            self.__settings = {k:v[0] for k, v in defaults.iteritems()}

        # Call user method and reset settings
        token = self.createToken(parent, info, page)
        self.__settings = None
        return token
Example #6
0
    def testChangeException(self):
        defaults = dict(year=(1980, 'doc'))
        raw = 'year=2003 month=june'
        with self.assertRaises(exceptions.MooseDocsException) as e:
            known, unknown = common.parse_settings(defaults, raw)

        self.assertIn("The following key, value settings are unknown:", e.exception.message)
        self.assertIn("month", e.exception.message)
Example #7
0
 def testUnknown(self):
     defaults = dict(year=(1980, 'doc'))
     raw = 'year=2003 month=june'
     known, unknown = common.parse_settings(defaults, raw, error_on_unknown=False)
     self.assertEqual(known['year'], 2003)
     self.assertNotIn('month', known)
     self.assertIn('month', unknown)
     self.assertEqual(unknown['month'], 'june')
Example #8
0
 def testBasic(self):
     defaults = dict(year=(1980, 'doc'), month=('june', 'doc'), day=(24, 'doc'))
     raw = 'year=2003'
     known, unknown = common.parse_settings(defaults, raw)
     self.assertEqual(known['year'], 2003)
     self.assertEqual(known['month'], 'june')
     self.assertEqual(known['day'], 24)
     self.assertEqual(unknown, dict())
Example #9
0
    def testChangeException(self):
        defaults = dict(year=(1980, 'doc'))
        raw = 'year=2003 month=june'
        with self.assertRaises(KeyError) as e:
            known, unknown = common.parse_settings(defaults, raw, exc=KeyError)

        self.assertIn("The following key, value settings are unknown:",
                      e.exception.message)
        self.assertIn("month", e.exception.message)
    def testUnknownException(self):
        defaults = dict(year=(1980, 'doc'))
        raw = 'year=2003 month=june'
        with self.assertRaises(exceptions.MooseDocsException) as e:
            known, unknown = common.parse_settings(defaults, raw)

        self.assertIn("The following key, value settings are unknown:",
                      e.exception.message)
        self.assertIn("month", e.exception.message)
Example #11
0
 def testUnknown(self):
     defaults = dict(year=(1980, 'doc'))
     raw = 'year=2003 month=june'
     known, unknown = common.parse_settings(defaults,
                                            raw,
                                            error_on_unknown=False)
     self.assertEqual(known['year'], 2003)
     self.assertNotIn('month', known)
     self.assertIn('month', unknown)
     self.assertEqual(unknown['month'], 'june')
Example #12
0
 def testBasic(self):
     defaults = dict(year=(1980, 'doc'),
                     month=('june', 'doc'),
                     day=(24, 'doc'))
     raw = 'year=2003'
     known, unknown = common.parse_settings(defaults, raw)
     self.assertEqual(known['year'], 2003)
     self.assertEqual(known['month'], 'june')
     self.assertEqual(known['day'], 24)
     self.assertEqual(unknown, dict())
Example #13
0
    def createToken(self, parent, info, page):

        cmd = (info['command'], info['subcommand'])
        settings = info['settings']

        # Handle filename and None subcommand
        match = self.FILENAME_RE.search(
            info['subcommand']) if info['subcommand'] else None
        if match:
            cmd = (info['command'], match.group('ext'))
        elif info['subcommand'] and info['subcommand'].startswith('http'):
            cmd = (info['command'], None)
        elif info['subcommand'] and '=' in info['subcommand']:
            settings = info['subcommand'] + ' ' + settings
            cmd = (info['command'], None)

        # Locate the command object to call
        try:
            obj = CommandExtension.EXTENSION_COMMANDS[cmd]
        except KeyError:
            try:
                obj = CommandExtension.EXTENSION_COMMANDS[(cmd[0], '*')]
            except KeyError:
                msg = "The following command combination is unknown: '{} {}'."
                raise common.exceptions.MooseDocsException(msg.format(*cmd))

        if not obj.extension.active:
            if isinstance(self, InlineCommand):
                tokens.DisabledToken(parent, tag='span', string=info[0])
            tokens.DisabledToken(parent, tag='p', string=info[0])
            return parent

        # Build the token
        if obj.PARSE_SETTINGS:
            settings, _ = common.parse_settings(obj.defaultSettings(),
                                                settings)
            obj.setSettings(settings)
        token = obj.createToken(parent, info, page)
        return token
Example #14
0
    def __call__(self, info, parent):
        """
        MooseDocs internal method, this should not be called, please use the createToken method.

        The lexer system within MooseDocs expects a function this method allows this class to act
        as a function.

        Inputs:
            info[LexerInformation]: Object containing the lexer information object.
            parent[tokens.Token]: The parent node in the AST for the token being created.
        """

        # Define the settings
        defaults = self.defaultSettings()
        if self.PARSE_SETTINGS and ('settings' in info):
            self.__settings, _ = parse_settings(defaults, info['settings'])
        else:
            self.__settings = {k: v[0] for k, v in defaults.iteritems()}

        # Call user method and reset settings
        token = self.createToken(info, parent)
        self.__settings = None
        return token
Example #15
0
    def __call__(self, info, parent):
        """
        MooseDocs internal method, this should not be called, please use the createToken method.

        The lexer system within MooseDocs expects a function this method allows this class to act
        as a function.

        Inputs:
            info[LexerInformation]: Object containing the lexer information object.
            parent[tokens.Token]: The parent node in the AST for the token being created.
        """

        # Define the settings
        defaults = self.defaultSettings()
        if self.PARSE_SETTINGS and ('settings' in info):
            self.__settings, _ = parse_settings(defaults, info['settings'])
        else:
            self.__settings = {k:v[0] for k, v in defaults.iteritems()}

        # Call user method and reset settings
        token = self.createToken(info, parent)
        self.__settings = None
        return token
Example #16
0
    def createToken(self, parent, info, page):

        cmd = (info['command'], info['subcommand'])
        settings = info['settings']

        # Handle filename and None subcommand
        match = self.FILENAME_RE.search(info['subcommand']) if info['subcommand'] else None
        if match:
            cmd = (info['command'], match.group('ext'))
        elif info['subcommand'] and info['subcommand'].startswith('http'):
            cmd = (info['command'], None)
        elif info['subcommand'] and '=' in info['subcommand']:
            settings = info['subcommand'] + ' ' + settings
            cmd = (info['command'], None)

        # Locate the command object to call
        try:
            obj = CommandExtension.EXTENSION_COMMANDS[cmd]
        except KeyError:
            try:
                obj = CommandExtension.EXTENSION_COMMANDS[(cmd[0], '*')]
            except KeyError:
                msg = "The following command combination is unknown: '{} {}'."
                raise common.exceptions.MooseDocsException(msg.format(*cmd))

        if not obj.extension.active:
            if isinstance(self, InlineCommand):
                tokens.DisabledToken(parent, tag='span', string=info[0])
            tokens.DisabledToken(parent, tag='p', string=info[0])
            return parent

        # Build the token
        if obj.PARSE_SETTINGS:
            settings, _ = common.parse_settings(obj.defaultSettings(), settings)
            obj.setSettings(settings)
        token = obj.createToken(parent, info, page)
        return token
Example #17
0
 def testFloat(self):
     defaults = dict(year=(1980, 'doc'))
     raw = 'year=2003'
     known, _ = common.parse_settings(defaults, raw)
     self.assertIsInstance(known['year'], float)
Example #18
0
 def testSpace(self):
     defaults = dict(year=(1980, 'doc'), month=('june', 'doc'), day=(24, 'doc'))
     raw = 'year=the year I was born'
     known, _ = common.parse_settings(defaults, raw)
     self.assertEqual(known['year'], 'the year I was born')
Example #19
0
 def testFloat(self):
     defaults = dict(year=(1980, 'doc'))
     raw = 'year=2003'
     known, _ = common.parse_settings(defaults, raw)
     self.assertIsInstance(known['year'], float)