예제 #1
0
    def __resolve_wordlist_name(self, wordlist):
        """
        Looking for the world list in this order:
        1 - In the internal database and.
        2 - Looking in the plugin directory
        3 - Looking the wordlist in the file system.

        If Wordlist not found, raise WordlistNotFound exception.

        :param wordlist: wordlist name
        :type wordlist: str

        :return: a file descriptor.
        :rtype: open()

        :raises: WordlistNotFound, TypeError, ValueError
        """
        if not wordlist:
            raise ValueError("Wordlist name can't be an empty value")
        if not isinstance(wordlist, basestring):
            raise TypeError("Expected 'str' got '%s'." % type(wordlist))

        m_return = None

        # For avoid user errors, library accept also, wordlists starting as:
        # wordlist/....
        if "wordlist" in wordlist:
            wordlist = "/".join(wordlist.split("/")[1:])

        try:
            m_return = open(self.__store[wordlist], "rU")
        except KeyError:  # Wordlist is not in the internal database
            # Exits the file
            try:
                if LocalFile.exists(wordlist):
                    if not LocalFile.isfile(wordlist):
                        raise TypeError("Wordlist '%s' is not a file." %
                                        wordlist)

                    m_return = LocalFile.open(wordlist, "rU")

            except ValueError:  # Wordlist is out of the plugin path

                # Looking the wordlist in the file system, assuming that the
                # worllist name is an absolute path.
                if exists(wordlist):
                    if not isfile(wordlist):
                        raise TypeError("Wordlist '%s' is not a file." %
                                        wordlist)

                    m_return = open(wordlist, "rU")

                else:
                    raise WordlistNotFound(
                        "Wordlist file '%s' does not exist." % wordlist)

        return m_return
예제 #2
0
    def __get_wordlist_descriptor(self, wordlist):
        """
        Looking for the world list in this order:
        1 - In the internal database and.
        2 - Looking in the plugin directory
        3 - Looking the wordlist in the file system.

        If Wordlist not found, raise WordlistNotFound exception.

        :param wordlist: wordlist name
        :type wordlist: basestring

        :return: a file descriptor.
        :rtype: open()

        :raises: WordlistNotFound, TypeError, ValueError, IOError
        """
        if not isinstance(wordlist, basestring):
            raise TypeError("Expected 'str' got '%s'." % type(wordlist))

        # For avoid user errors, library accept also, wordlists starting as:
        # wordlist/....
        if wordlist.startswith("wordlist"):
            wordlist = "/".join(wordlist.split("/")[1:])

        if not wordlist:
            raise ValueError("Wordlist name can't be an empty value")

        try:
            return open(self.__store[wordlist], "rU")
        except KeyError:  # Wordlist is not in the internal database

            # Can open from plugin wordlists?
            internal = True
            try:
                if LocalFile.exists(wordlist):
                    if not LocalFile.isfile(wordlist):
                        internal = False

                    return LocalFile.open(wordlist, "rU")
                else:
                    internal = False
            except ValueError:
                internal = False

            if not internal:
                # Looking the wordlist in the file system, assuming that the
                # wordlist name is an absolute path.
                if exists(wordlist):
                    if not isfile(wordlist):
                        raise WordlistNotFound("Wordlist '%s' is not a file." %
                                               wordlist)

                    return open(wordlist, "rU")
                else:
                    raise WordlistNotFound(
                        "Wordlist file '%s' does not exist." % wordlist)
예제 #3
0
    def __get_wordlist_descriptor(self, wordlist):
        """
        Looking for the world list in this order:
        1 - In the internal database and.
        2 - Looking in the plugin directory
        3 - Looking the wordlist in the file system.

        If Wordlist not found, raise WordlistNotFound exception.

        :param wordlist: wordlist name
        :type wordlist: basestring

        :return: a file descriptor.
        :rtype: open()

        :raises: WordlistNotFound, TypeError, ValueError, IOError
        """
        if not isinstance(wordlist, basestring):
            raise TypeError("Expected 'str' got '%s'." % type(wordlist))

        # For avoid user errors, library accept also, wordlists starting as:
        # wordlist/....
        if wordlist.startswith("wordlist"):
            wordlist = "/".join(wordlist.split("/")[1:])

        if not wordlist:
            raise ValueError("Wordlist name can't be an empty value")

        try:
            return open(self.__store[wordlist], "rU")
        except KeyError:  # Wordlist is not in the internal database

            # Can open from plugin wordlists?
            internal = True
            try:
                if LocalFile.exists(wordlist):
                    if not LocalFile.isfile(wordlist):
                        internal = False

                    return LocalFile.open(wordlist, "rU")
                else:
                    internal = False
            except ValueError:
                internal = False

            if not internal:
                # Looking the wordlist in the file system, assuming that the
                # wordlist name is an absolute path.
                if exists(wordlist):
                    if not isfile(wordlist):
                        raise WordlistNotFound("Wordlist '%s' is not a file." % wordlist)

                    return open(wordlist, "rU")
                else:
                    raise WordlistNotFound("Wordlist file '%s' does not exist." % wordlist)
예제 #4
0
    def __resolve_wordlist_name(self, wordlist):
        """
        Looking for the world list in this order:
        1 - In the internal database and.
        2 - Looking in the plugin directory
        3 - Looking the wordlist in the file system.

        If Wordlist not found, raise WordlistNotFound exception.

        :param wordlist: wordlist name
        :type wordlist: str

        :return: a file descriptor.
        :rtype: open()

        :raises: WordlistNotFound, TypeError, ValueError
        """
        if not wordlist:
            raise ValueError("Wordlist name can't be an empty value")
        if not isinstance(wordlist, basestring):
            raise TypeError("Expected 'str' got '%s'." % type(wordlist))

        m_return = None

        # For avoid user errors, library accept also, wordlists starting as:
        # wordlist/....
        if "wordlist" in wordlist:
            wordlist = "/".join(wordlist.split("/")[1:])

        try:
            m_return = open(self.__store[wordlist], "rU")
        except KeyError: # Wordlist is not in the internal database
            # Exits the file
            try:
                if LocalFile.exists(wordlist):
                    if not LocalFile.isfile(wordlist):
                        raise TypeError("Wordlist '%s' is not a file." % wordlist)

                    m_return = LocalFile.open(wordlist, "rU")

            except ValueError: # Wordlist is out of the plugin path

                # Looking the wordlist in the file system, assuming that the
                # worllist name is an absolute path.
                if exists(wordlist):
                    if not isfile(wordlist):
                        raise TypeError("Wordlist '%s' is not a file." % wordlist)

                    m_return = open(wordlist, "rU")

                else:
                    raise WordlistNotFound("Wordlist file '%s' does not exist." % wordlist)

        return m_return