def __init__(self,
                 model=None,
                 modelserver=None,
                 user=None,
                 password=None,
                 app=None,
                 description="",
                 debug=0,
                 ca_certs_file="ca_certs/ca.pem"):
        if modelserver == None:
            raise ValueError, "modelserver is None"
        if ':' in modelserver:
            self.modelserver, self.modelport = modelserver.split(":")
        else:
            self.modelserver = modelserver
            self.modelport = 2005  # default port for personis server
        self.modelname = model
        self.user = user
        self.password = password
        self.app = app
        self.description = description
        self.debug = debug
        self.key = None
        self.ca_certs_file = ca_certs_file
        if self.app == None:
            self.auth = user + ":" + password
            self.authType = "user"
        else:
            self.authType = "app"
            try:
                self.key = Personis_base.import_app_key(app)
            except Personis_exceptions.KeyFileNotFoundError:
                self.key = Personis_base.generate_app_key(self.app)
                fingerprint = Personis_base.generate_app_fingerprint(self.key)
                AppRequestAuth(model=self.modelname,
                               modelserver=self.modelserver,
                               app=self.app,
                               key=self.key.publickey().exportKey(),
                               description=self.description)
                message = "Authorisation has been requested for app " + self.app + " to access model " + self.model + " on server " + self.modelserver + ".\n"
                message += "Key fingerprint: %s\n" % (fingerprint)
                raise Personis_exceptions.AuthRequestedError(message)

        ok = False
        try:
            command = "access"
            args = {'modelname': self.modelname}
            if self.app != None:
                self.auth = self.app + ":" + Personis_base.generate_app_signature(
                    self.app, self.key)
                args['authType'] = 'app'
            else:
                args['authType'] = 'user'
            args['auth'] = self.auth
            if self.debug != 0:
                print "jsondocall:", self.modelserver, self.modelport, self.ca_certs_file, self.modelname, self.authType, self.auth

            ok = jsoncall.do_call(self.modelserver, self.modelport,
                                  self.ca_certs_file, command, args)
            if self.debug != 0:
                print "---------------------- result returned", ok
        except:
            if debug > 0:
                traceback.print_exc()
            raise
            raise ValueError, "cannot access model '%s', server '%s'" % (
                self.modelname, self.modelserver)
        if not ok:
            raise ValueError, "server '%s' cannot access model '%s'" % (
                self.modelserver, self.modelname)
                         'ask': True,
                         'tell': False
                     })
except Exception as e:
    print "setpermission failed with exception : %s\n" % (e)

print ">>>> Try to access the model as an unregistered app"
try:
    app_um = Personis.Access(model="Alice",
                             app="MyHealth",
                             description="My Health Manager")
except Exception as e:
    print "App access failed with exception: %s\n" % (e)

print ">>>> Authorise the app"
key = Personis_base.import_app_key("MyHealth")
fp = Personis_base.generate_app_fingerprint(key)
um.registerapp(app="MyHealth", desc="My Health Manager", fingerprint=fp)
print ">>>> List the registered apps (should be one):"
apps = um.listapps()
print apps

print ">>>> Set some permissions for the 'MyHealth' app"
um.setpermission(context=["Personal"],
                 app="MyHealth",
                 permissions={
                     'ask': False,
                     'tell': False
                 })

print ">>>> Show the permissions:"
print apps

print ">>>> Try and set permissions on an unregistered app:"
try:
	um.setpermission(context=["Personal"], app="MyHealth", permissions={'ask':True, 'tell':False})
except Exception as e:
	print "setpermission failed with exception : %s\n" % (e)

print ">>>> Try to access the model as an unregistered app"
try:
    app_um = Personis.Access(model="Alice",  app="MyHealth", description="My Health Manager")
except Exception as e:
    print "App access failed with exception: %s\n" % (e)

print ">>>> Authorise the app"
key = Personis_base.import_app_key("MyHealth")
fp = Personis_base.generate_app_fingerprint(key)
um.registerapp(app="MyHealth", desc="My Health Manager", fingerprint=fp)
print ">>>> List the registered apps (should be one):"
apps = um.listapps()
print apps

print ">>>> Set some permissions for the 'MyHealth' app"
um.setpermission(context=["Personal"], app="MyHealth", permissions={'ask':False, 'tell':False})

print ">>>> Show the permissions:"
perms = um.getpermission(context=["Personal"], app="MyHealth")
print "MyHealth:", perms

print ">>>> Try getting permissions for an unregistered app:"
try: