Beispiel #1
0
    def to_string(self):
        empty_line = ' ' * len(self.string)

        def to_hex(x):
            if isinstance(x, int):
                return str(x) if x < 10 else chr(55 + x)
            return x

        def meaning(result):
            mmap = {
                'episodeNumber': 'E',
                'season': 'S',
                'extension': 'e',
                'format': 'f',
                'language': 'l',
                'country': 'C',
                'videoCodec': 'v',
                'audioCodec': 'a',
                'website': 'w',
                'container': 'c',
                'series': 'T',
                'title': 't',
                'date': 'd',
                'year': 'y',
                'releaseGroup': 'r',
                'screenSize': 's'
            }

            if result is None:
                return ' '

            for prop, l in mmap.items():
                if prop in result:
                    return l

            return 'x'

        lines = [empty_line] * (self.depth + 2)  # +2: remaining, meaning
        lines[-2] = self.string

        for node in self.nodes():
            if node == self:
                continue

            idx = node.node_idx
            depth = len(idx) - 1
            if idx:
                lines[depth] = str_fill(lines[depth], node.span,
                                        to_hex(idx[-1]))
            if node.guess:
                lines[-2] = str_fill(lines[-2], node.span, '_')
                lines[-1] = str_fill(lines[-1], node.span, meaning(node.guess))

        lines.append(self.string)

        return '\n'.join(lines)
Beispiel #2
0
    def to_string(self):
        empty_line = ' ' * len(self.string)

        def to_hex(x):
            if isinstance(x, int):
                return str(x) if x < 10 else chr(55 + x)
            return x

        def meaning(result):
            mmap = {'episodeNumber': 'E',
                    'season': 'S',
                    'extension': 'e',
                    'format': 'f',
                    'language': 'l',
                    'country': 'C',
                    'videoCodec': 'v',
                    'audioCodec': 'a',
                    'website': 'w',
                    'container': 'c',
                    'series': 'T',
                    'title': 't',
                    'date': 'd',
                    'year': 'y',
                    'releaseGroup': 'r',
                    'screenSize': 's'
                    }

            if result is None:
                return ' '

            for prop, l in mmap.items():
                if prop in result:
                    return l

            return 'x'

        lines = [empty_line] * (self.depth + 2)  # +2: remaining, meaning
        lines[-2] = self.string

        for node in self.nodes():
            if node == self:
                continue

            idx = node.node_idx
            depth = len(idx) - 1
            if idx:
                lines[depth] = str_fill(lines[depth], node.span,
                                        to_hex(idx[-1]))
            if node.guess:
                lines[-2] = str_fill(lines[-2], node.span, '_')
                lines[-1] = str_fill(lines[-1], node.span, meaning(node.guess))

        lines.append(self.string)

        return '\n'.join(lines)
Beispiel #3
0
    def to_string(self):
        empty_line = " " * len(self.string)

        def to_hex(x):
            if isinstance(x, int):
                return str(x) if x < 10 else chr(55 + x)
            return x

        def meaning(result):
            mmap = {
                "episodeNumber": "E",
                "season": "S",
                "extension": "e",
                "format": "f",
                "language": "l",
                "country": "C",
                "videoCodec": "v",
                "audioCodec": "a",
                "website": "w",
                "container": "c",
                "series": "T",
                "title": "t",
                "date": "d",
                "year": "y",
                "releaseGroup": "r",
                "screenSize": "s",
            }

            if result is None:
                return " "

            for prop, l in mmap.items():
                if prop in result:
                    return l

            return "x"

        lines = [empty_line] * (self.depth + 2)  # +2: remaining, meaning
        lines[-2] = self.string

        for node in self.nodes():
            if node == self:
                continue

            idx = node.node_idx
            depth = len(idx) - 1
            if idx:
                lines[depth] = str_fill(lines[depth], node.span, to_hex(idx[-1]))
            if node.guess:
                lines[-2] = str_fill(lines[-2], node.span, "_")
                lines[-1] = str_fill(lines[-1], node.span, meaning(node.guess))

        lines.append(self.string)

        return "\n".join(lines)
Beispiel #4
0
    def test_camel(self):
        self.assertEqual("", from_camel(""))

        self.assertEqual("Hello world", str_replace("Hello World", 6, 'w'))
        self.assertEqual("Hello *****", str_fill("Hello World", (6, 11), '*'))

        self.assertTrue("This is camel", from_camel("ThisIsCamel"))

        self.assertEqual('camel case', from_camel('camelCase'))
        self.assertEqual('A case', from_camel('ACase'))
        self.assertEqual('MiXedCaSe is not camel case', from_camel('MiXedCaSe is not camelCase'))

        self.assertEqual("This is camel cased title", from_camel("ThisIsCamelCasedTitle"))
        self.assertEqual("This is camel CASED title", from_camel("ThisIsCamelCASEDTitle"))

        self.assertEqual("These are camel CASED title", from_camel("TheseAreCamelCASEDTitle"))

        self.assertEqual("Give a camel case string", from_camel("GiveACamelCaseString"))

        self.assertEqual("Death TO camel case", from_camel("DeathTOCamelCase"))
        self.assertEqual("But i like java too:)", from_camel("ButILikeJavaToo:)"))

        self.assertEqual("Beatdown french DVD rip.mkv", from_camel("BeatdownFrenchDVDRip.mkv"))
        self.assertEqual("DO NOTHING ON UPPER CASE", from_camel("DO NOTHING ON UPPER CASE"))

        self.assertFalse(is_camel("this_is_not_camel"))
        self.assertTrue(is_camel("ThisIsCamel"))

        self.assertEqual("Dark.City.(1998).DC.BDRIP.720p.DTS.X264-CHD.mkv", from_camel("Dark.City.(1998).DC.BDRIP.720p.DTS.X264-CHD.mkv"))
        self.assertFalse(is_camel("Dark.City.(1998).DC.BDRIP.720p.DTS.X264-CHD.mkv"))

        self.assertEqual("A2LiNE", from_camel("A2LiNE"))
Beispiel #5
0
    def test_camel(self):
        assert "" == from_camel("")

        assert "Hello world" == str_replace("Hello World", 6, 'w')
        assert "Hello *****" == str_fill("Hello World", (6, 11), '*')

        assert "This is camel" == from_camel("ThisIsCamel")

        assert 'camel case' == from_camel('camelCase')
        assert 'A case' == from_camel('ACase')
        assert 'MiXedCaSe is not camel case' == from_camel('MiXedCaSe is not camelCase')

        assert "This is camel cased title" == from_camel("ThisIsCamelCasedTitle")
        assert "This is camel CASED title" == from_camel("ThisIsCamelCASEDTitle")

        assert "These are camel CASED title" == from_camel("TheseAreCamelCASEDTitle")

        assert "Give a camel case string" == from_camel("GiveACamelCaseString")

        assert "Death TO camel case" == from_camel("DeathTOCamelCase")
        assert "But i like java too:)" == from_camel("ButILikeJavaToo:)")

        assert "Beatdown french DVD rip.mkv" == from_camel("BeatdownFrenchDVDRip.mkv")
        assert "DO NOTHING ON UPPER CASE" == from_camel("DO NOTHING ON UPPER CASE")

        assert not is_camel("this_is_not_camel")
        assert is_camel("ThisIsCamel")

        assert "Dark.City.(1998).DC.BDRIP.720p.DTS.X264-CHD.mkv" == \
               from_camel("Dark.City.(1998).DC.BDRIP.720p.DTS.X264-CHD.mkv")
        assert not is_camel("Dark.City.(1998).DC.BDRIP.720p.DTS.X264-CHD.mkv")

        assert "A2LiNE" == from_camel("A2LiNE")
Beispiel #6
0
    def test_camel(self):
        assert "" == from_camel("")

        assert "Hello world" == str_replace("Hello World", 6, 'w')
        assert "Hello *****" == str_fill("Hello World", (6, 11), '*')

        assert "This is camel" == from_camel("ThisIsCamel")

        assert 'camel case' == from_camel('camelCase')
        assert 'A case' == from_camel('ACase')
        assert 'MiXedCaSe is not camel case' == from_camel(
            'MiXedCaSe is not camelCase')

        assert "This is camel cased title" == from_camel(
            "ThisIsCamelCasedTitle")
        assert "This is camel CASED title" == from_camel(
            "ThisIsCamelCASEDTitle")

        assert "These are camel CASED title" == from_camel(
            "TheseAreCamelCASEDTitle")

        assert "Give a camel case string" == from_camel("GiveACamelCaseString")

        assert "Death TO camel case" == from_camel("DeathTOCamelCase")
        assert "But i like java too:)" == from_camel("ButILikeJavaToo:)")

        assert "Beatdown french DVD rip.mkv" == from_camel(
            "BeatdownFrenchDVDRip.mkv")
        assert "DO NOTHING ON UPPER CASE" == from_camel(
            "DO NOTHING ON UPPER CASE")

        assert not is_camel("this_is_not_camel")
        assert is_camel("ThisIsCamel")

        assert "Dark.City.(1998).DC.BDRIP.720p.DTS.X264-CHD.mkv" == \
               from_camel("Dark.City.(1998).DC.BDRIP.720p.DTS.X264-CHD.mkv")
        assert not is_camel("Dark.City.(1998).DC.BDRIP.720p.DTS.X264-CHD.mkv")

        assert "A2LiNE" == from_camel("A2LiNE")
Beispiel #7
0
    def to_string(self):
        """Return a readable string representation of this tree.

        The result is a multi-line string, where the lines are:
         - line 1 -> N-2: each line contains the nodes at the given depth in the tree
         - line N-2: original string where all the found groups have been blanked
         - line N-1: type of property that has been found
         - line N: the original string, which you can use a reference.
        """
        empty_line = ' ' * len(self.string)

        def to_hex(x):
            if isinstance(x, int):
                return str(x) if x < 10 else chr(55 + x)
            return x

        def meaning(result):
            mmap = {
                'episodeNumber': 'E',
                'season': 'S',
                'extension': 'e',
                'format': 'f',
                'language': 'l',
                'country': 'C',
                'videoCodec': 'v',
                'videoProfile': 'v',
                'audioCodec': 'a',
                'audioProfile': 'a',
                'audioChannels': 'a',
                'website': 'w',
                'container': 'c',
                'series': 'T',
                'title': 't',
                'date': 'd',
                'year': 'y',
                'releaseGroup': 'r',
                'screenSize': 's',
                'other': 'o'
            }

            if result is None:
                return ' '

            for prop, l in mmap.items():
                if prop in result:
                    return l

            return 'x'

        lines = [empty_line] * (self.depth + 2)  # +2: remaining, meaning
        lines[-2] = self.string

        for node in self.nodes():
            if node == self:
                continue

            idx = node.node_idx
            depth = len(idx) - 1
            if idx:
                lines[depth] = str_fill(lines[depth], node.span,
                                        to_hex(idx[-1]))
            if node.guess:
                lines[-2] = str_fill(lines[-2], node.span, '_')
                lines[-1] = str_fill(lines[-1], node.span, meaning(node.guess))

        lines.append(self.string)

        return '\n'.join(l.rstrip() for l in lines)
Beispiel #8
0
    def to_string(self):
        """Return a readable string representation of this tree.

        The result is a multi-line string, where the lines are:
         - line 1 -> N-2: each line contains the nodes at the given depth in the tree
         - line N-2: original string where all the found groups have been blanked
         - line N-1: type of property that has been found
         - line N: the original string, which you can use a reference.
        """
        empty_line = ' ' * len(self.string)

        def to_hex(x):
            if isinstance(x, int):
                return str(x) if x < 10 else chr(55 + x)
            return x

        def meaning(result):
            mmap = {'episodeNumber': 'E',
                    'season': 'S',
                    'extension': 'e',
                    'format': 'f',
                    'language': 'l',
                    'country': 'C',
                    'videoCodec': 'v',
                    'videoProfile': 'v',
                    'audioCodec': 'a',
                    'audioProfile': 'a',
                    'audioChannels': 'a',
                    'website': 'w',
                    'container': 'c',
                    'series': 'T',
                    'title': 't',
                    'date': 'd',
                    'year': 'y',
                    'releaseGroup': 'r',
                    'screenSize': 's',
                    'other': 'o'
                    }

            if result is None:
                return ' '

            for prop, l in mmap.items():
                if prop in result:
                    return l

            return 'x'

        lines = [empty_line] * (self.depth + 2)  # +2: remaining, meaning
        lines[-2] = self.string

        for node in self.nodes():
            if node == self:
                continue

            idx = node.node_idx
            depth = len(idx) - 1
            if idx:
                lines[depth] = str_fill(lines[depth], node.span,
                                        to_hex(idx[-1]))
            if node.guess:
                lines[-2] = str_fill(lines[-2], node.span, '_')
                lines[-1] = str_fill(lines[-1], node.span, meaning(node.guess))

        lines.append(self.string)

        return '\n'.join(l.rstrip() for l in lines)