def prepare_export(self, command):
     """
     :param command: DAL command for export
     :return:
     """
     builder = HttpPostBuilder(command, self._dalHttpFactory)
     builder.build()
 def prepare_upload(self, command, uploadable):
     """
     :param command: POST command for the DAL
     :return:
     """
     builder = HttpPostBuilder(command, self._dalHttpFactory)
     builder.build_for_upload(self._writeToken, uploadable)
 def prepare_POST_query(self, command):
     """
     :param command: POST command for DAL
     :return:
     """
     builder = HttpPostBuilder(command, self._dalHttpFactory)
     builder.build_for_update(self._writeToken)
 def perpare_GET_query(self, command):
     """
     :param command: GET command for DAL
     :return:
     """
     builder = HttpPostBuilder(command, self._dalHttpFactory)
     builder.build()
    def login_internal(self, username, password, usingOAuth2, oAuth2Token=None, redirectUrl=None):
        """
        :param username: System username
        :param password: System password
        :param usingOAuth2: Boolean as to whether to use google oAuth2 instead of system login
        :param oAuth2Token: Tokean for oAuth2 login, is selected
        :return:
        """
        # If there no URL we can conitnue?
        if self._loginURL is None:
            raise DALResponseException("Login URL is None")

        # Can ignore the hashing if using oAuth2 to login
        cmd = None;
        url = None;
        if not usingOAuth2:
            cmd = "login/" + username + "/" + self._expire
            url = self._loginURL + "/" + cmd

            # Perform hashing!
            rand = str(self._dalUtil.create_random_number())
            signature = self._dalUtil.create_sha1_hash(hashkey=password, hashable=username)
            signature = self._dalUtil.create_sha1_hash(hashkey=signature, hashable=rand)
            signature = self._dalUtil.create_sha1_hash(hashkey=signature, hashable=url)
        else:
            cmd = "oauth2google"
            url = self._loginURL + "/" + cmd

        httpPostBuilder = HttpPostBuilder(self._dalHttpFactory, url)

        if self._debug > 0:
            print "Attempting login to: " + self._loginURL
            print "Using cmd: " + url
            print "Hash: " + signature + "\n"

        request = httpPostBuilder.set_respone_type(self._responseType)
        request = request.add_parameter("rand_num", rand) \
            .add_parameter("url", url) \
            .add_parameter("ctype", self._responseType.value)
        if not usingOAuth2:
            request.add_parameter("signature", signature)
        else:
            request.add_parameter("access_token", oAuth2Token) \
            .add_parameter("redirect_url", redirectUrl)

        request = request.build()

        # Actually performing the Http command
        rsp = None
        content = None
        try:
            rsp = self._opener.open(request.request)
            content = rsp.read()
        except urllib2.HTTPError, e:
            self.build_DALResponse(e.readlines(), e.getcode())
    def perform_query_internal(self, command, postTrue, postParams=None, fileContentTypeTuple=None, dont_include=None):
        """
        :param command: Command for DAL
        :return: Returns DALResponse for the command
        """
        cmd = self._loginURL + "/" + command

        if not self._responseType.isXML() and not dont_include:
            cmd += "?ctype=" + self._responseType.value

        prep = HttpPostBuilder(self._dalHttpFactory, cmd) \
        .set_respone_type(self._responseType) \

        data = None
        if not fileContentTypeTuple is None and not postParams is None:
            data = fileContentTypeTuple[1]

            postParams['Content-type'] = fileContentTypeTuple[0]
            postParams['Content-length'] = len(data)

        if not postParams is None and len(postParams) > 0:
            for key in postParams.keys():
                val = postParams[key]
                prep = prep.add_parameter(key, val)

        if postTrue and not fileContentTypeTuple is None:
            # Building for a POST with an upload file
            req = prep.build_for_upload(self._writeToken, data)

        elif postTrue:
            # Building for a POST
            req = prep.build_for_update(self._writeToken)
        else:
            # Building for a GET
            req = prep.build()

        if self._debug > 0:
            print "Performing Query: " + cmd

        # Actually performing the Http command
        rsp = None
        try:
            rsp = self._opener.open(req.request)
            content = rsp.read()
        except urllib2.HTTPError, e:
            content = e.readlines()
            return self.build_DALResponse(content, e.getcode())