def __init__(self, url, username=None, password=None, token=None,
                 generate_token=False, expiration=60, ago_login=False):
        """If a username/password is provided, AUTH and AUTH_DIGEST
           authentication will be handled automatically. If using
           token based authentication, either
                1. Pass a token in the token argument
                2. Set generate_token to True for generateToken-style auth
                3. Set ago_login for ArcGIS online-style auth"""
        if username is not None and password is not None:
            self._pwdmgr.add_password(None,
                                      url,
                                      username,
                                      password)
        url_ = list(compat.urlsplit(url))
        if not url_[2].endswith('/'):
            url_[2] += "/"
        if token is not None:
            self.__token__ = token
        elif ago_login and generate_token:
            raise ValueError("Only one authentication method of ago_login or "
                             "generate_token may be set")
        elif ago_login:
            new_url = compat.urlunsplit(url_)
            agologin = AGOLoginToken(url, username, password)
            self.__token__ = agologin.token
        elif generate_token:
            new_url = compat.urlunsplit(url_)
            gentoken = GenerateToken(url, username, password, expiration)
            self._referer = gentoken._referer
            self.__token__ = gentoken.token
        super(Catalog, self).__init__(url_)
        # Basically a Folder, but do some really, really rudimentary sanity
        # checking (look for folders/services, make sure format is JSON) so we
        # can verify this URL behaves like a Folder -- catch errors early 
        # before any other manipulations go on.
        assert 'folders' in self._json_struct, "No folders in catalog root"
        assert 'services' in self._json_struct, "No services in catalog root"
dataset/ETHPy150Open jasonbot/arcrest/arcrest/server.py/Catalog.__init__/original