# pylint: disable=missing-module-docstring
#
# Copyright (c) 2008--2016 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public License,
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
# implied, including the implied warranties of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
# along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
#
# Red Hat trademarks are not licensed under GPLv2. No permission is
# granted to use or replicate Red Hat trademarks that are incorporated
# in this software or its documentation.
#

#
# Package uploading tool
#

from rhnpush import connection


# pylint: disable-next=missing-class-docstring
class PackageUpload(connection.PackageUpload):
    user_agent = "rhnpush"

    def set_session(self, session_string):
        # pylint: disable-next=consider-using-f-string
        self.headers["%s-%s" % (self.header_prefix, "Auth-Session")] = session_string

    def set_force(self, force):
        if force:
            force = 1
        else:
            force = 0
        # pylint: disable-next=consider-using-f-string
        self.headers["%s-%s" % (self.header_prefix, "Force")] = str(force)

    def set_null_org(self, null_org):
        if null_org:
            # pylint: disable-next=consider-using-f-string
            self.headers["%s-%s" % (self.header_prefix, "Null-Org")] = "1"

    def set_timeout(self, timeout):
        self.connection.set_timeout(timeout)


class PingPackageUpload(connection.PackageUpload):
    user_agent = "rhnpush-ping"

    def ping(self):
        self.send_http("GET")
        # return the header info as well to check for capabilities.
        return self._response.status, self._response.reason, self._response.msg
