Beispiel #1
0
 def protocol(self, value):
     if validations.isURI(value):
         p = value.split("://")[0]
         if p in ["file"]:
             self._protocol = p
         else:
             raise ValueError(
                 "The provided URI does not represent a path to a file. The path should start with 'file://'."
             )
Beispiel #2
0
def analyseExtensionFromURI(
    uri,
    quiet=False,
    analysisPath=utils.getConfigPath()["appPathDataAnalysis"],
    downloadPath=utils.getConfigPath()["appPathDataFiles"],
    tmpPath=tempfile.gettempdir()):
    """
    Main function for Neto Analyser.

    Performs an analysis of a URI extension provided using the command line.

    Params:
    -------
        uri: The parameter options received from the command line.
        quiet: A boolean that defines whether to print an output.
        analysisPath: The folder where the anbalysis will be stored.
        downloadPath: The folder where the downloaded extension will be stored.
        tmpPath: The folder where unzipped files will be created.

    Returns:
    --------
        An Extension object.
    """
    if validations.isURI(uri):
        try:
            u = HTTPResource(uri)
            data = u.download()
            if data:
                # The name of the extension is formed by:
                #   <source>_<hashed_uri>_<extension_name>
                # Not that the hash is not the hash of the whole extension
                if uri.split("/")[-1] != "":
                    fileName = uri.split("/")[-1]
                else:
                    fileName = "Manual_" + md5.calculateHash(u.uri)
                filePath = os.path.join(downloadPath, fileName)
                if not quiet:
                    print("[*]\tRemote file is being stored as {}…".format(
                        filePath))
                with open(filePath, "wb") as oF:
                    oF.write(data)
        except ConnectionError as e:
            print(
                "[X]\tSomething happened when trying to download the resource. Have we been banned?\n"
                + str(e))
            return
    else:
        # If it is not a URI, assume that is a local path
        filePath = uri

    return analyseExtensionFromFile(filePath,
                                    tmpPath=tmpPath,
                                    analysisPath=outputPath,
                                    quiet=quiet)
Beispiel #3
0
    def protocol(self, value):
        """
        Sets the protocol

        Args:
        -----
            value: A string representing a URI.

        Raises:
        -------
            ValueError: If the value is not a well formed URI.
        """
        if validations.isURI(value):
            self._protocol = value.split("://")[0]
Beispiel #4
0
    def uri(self, value):
        """
        Sets the URI value

        It also calls the appropiate setter to get the appropriate protocol.

        Args:
        -----
            value: A string representing a URI.

        Raises:
        -------
            TypeError: Whenever the value provided is not a string.
            ValueError: If the value is not  a well formed URI.
        """
        if validations.isURI(value):
            self._uri = value
            # We call the protocol setter
            self.protocol = value
Beispiel #5
0
Datei: http.py Projekt: mmg1/neto
    def protocol(self, value):
        """
        Sets the value for the protocol.

        Args:
        -----
            value: a string representing the URI.

        Raises:
        -------
            ValueError: if the value is not a valid URI and if it is not a HTTP or HTTPS one.
        """
        if validations.isURI(value):
            p = value.split("://")[0]
            if p in ["http", "https"]:
                self._protocol = p
            else:
                raise ValueError(
                    "The provided URI (" + value +
                    ") does not represent a HTTP or HTTPS protocol.")