当前位置: 首页>>代码示例>>Python>>正文


Python Pubnub.grant方法代码示例

本文整理汇总了Python中pubnub.Pubnub.grant方法的典型用法代码示例。如果您正苦于以下问题:Python Pubnub.grant方法的具体用法?Python Pubnub.grant怎么用?Python Pubnub.grant使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pubnub.Pubnub的用法示例。


在下文中一共展示了Pubnub.grant方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Pubnub

# 需要导入模块: from pubnub import Pubnub [as 别名]
# 或者: from pubnub.Pubnub import grant [as 别名]
# We'll also implement a CLIENT called client, who is an arbitrary hardware device member of the network

# Please swap out the default 'pam' demo keys with your own PAM-enabled keys

# init server object
server = Pubnub(publish_key="pam", subscribe_key="pam", secret_key="pam", auth_key=server_auth_token, uuid=server_uuid)

# init client object
client = Pubnub(publish_key="pam", subscribe_key="pam", auth_key=client_auth_token, uuid=client_uuid)

# To access a Presence channel with PAM, its format is CHANNELNAME-pnpres

# Grant permission to server auth keys
# grant r/w to public, and r/w public Presence (public-pnpres)

print(server.grant(channel=channel_public, auth_key=server_auth_token, read=True, write=True))
print(server.grant(channel=channel_public + '-pnpres', auth_key=server_auth_token, read=True, write=True))

# Grant permission to client auth keys
# grant r/w to public, and w-only access to public Presence (public-pnpres)
print(server.grant(channel=channel_public, auth_key=client_auth_token, read=True, write=False))
print(server.grant(channel=channel_public + '-pnpres', auth_key=client_auth_token, read=False, write=False))

# Now, we'll run it to watch it work as advertised...

# Define some simple callabcks for the Server and Client

def _server_message_callback(message, channel):
	print("Server heard: " + json.dumps(message))

def _client_message_callback(message, channel):
开发者ID:jlitzinger-kinestral,项目名称:python,代码行数:33,代码来源:demo.py

示例2: len

# 需要导入模块: from pubnub import Pubnub [as 别名]
# 或者: from pubnub.Pubnub import grant [as 别名]
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False

# -----------------------------------------------------------------------
# Initiate Pubnub State
# -----------------------------------------------------------------------
pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key,
                secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on, auth_key="abcd")
channel = 'hello_world'


def callback(message):
    print(message)

print(pubnub.revoke(channel_group='dev:abcd', auth_key="abcd"))
print(pubnub.audit(channel_group="dev:abcd"))
print(pubnub.grant(channel_group='dev:abcd', read=True, write=True, manage=True, auth_key="abcd"))
print(pubnub.channel_group_list_namespaces())
print(pubnub.channel_group_list_groups(namespace='aaa'))
print(pubnub.channel_group_list_groups(namespace='foo'))
print(pubnub.channel_group_list_channels(channel_group='dev:abcd'))
print(pubnub.channel_group_add_channel(channel_group='dev:abcd', channel="hi"))
print(pubnub.channel_group_list_channels(channel_group='dev:abcd'))
print(pubnub.channel_group_remove_channel(channel_group='dev:abcd', channel="hi"))
print(pubnub.channel_group_list_channels(channel_group='dev:abcd'))


pubnub.revoke(channel_group='dev:abcd', auth_key="abcd", callback=callback, error=callback)
pubnub.audit(channel_group="dev:abcd", callback=callback, error=callback)
pubnub.grant(channel_group='dev:abcd', read=True, write=True, manage=True, auth_key="abcd", callback=callback, error=callback)
pubnub.channel_group_list_namespaces(callback=callback, error=callback)
pubnub.channel_group_list_groups(namespace='aaa', callback=callback, error=callback)
开发者ID:FahadMonir,项目名称:python,代码行数:33,代码来源:cr.py

示例3: ConfigParser

# 需要导入模块: from pubnub import Pubnub [as 别名]
# 或者: from pubnub.Pubnub import grant [as 别名]
cfg = ConfigParser()
cfg.read('creds.cfg')
mongo_uri = cfg.get('mongo', 'MONGO_URI')
db_name = cfg.get('mongo', 'DB_NAME')
publish = cfg.get('pubnub', 'PUBNUB_PUBLISH_KEY')
subscribe = cfg.get('pubnub', 'PUBNUB_SUBSCRIBE_KEY')
secret = cfg.get('pubnub', 'PUBNUB_SECRET_KEY')
auth = cfg.get('pubnub', 'PUBNUB_AUTH_KEY')
channel_grp = cfg.get('pubnub', 'PUBNUB_CHANNEL_GRP')
# database instance
client = MongoClient(mongo_uri)
db = client[db_name]
# pubnub instance
pubnub = Pubnub(publish_key=publish, subscribe_key=subscribe,
                secret_key=secret, auth_key=auth)
pubnub.grant(channel_group=channel_grp, auth_key=auth, write=True)
# operators
compare = {'<' : operator.lt, '>' : operator.gt}

def connect_grows():
    """Get all of the grows from the database

    Parameters
    ----------
    db : pymongo.database.Database
        The database instance; assuming the URI is in `creds.cfg`

    Returns
    -------
    grows : pymongo.cursor.Cursor
        Iterable
开发者ID:hydrobase,项目名称:iot,代码行数:33,代码来源:state.py

示例4: len

# 需要导入模块: from pubnub import Pubnub [as 别名]
# 或者: from pubnub.Pubnub import grant [as 别名]
import sys
from pubnub import Pubnub

publish_key = len(sys.argv) > 1 and sys.argv[1] or "pam"
subscribe_key = len(sys.argv) > 2 and sys.argv[2] or "pam"
secret_key = len(sys.argv) > 3 and sys.argv[3] or "pam"
cipher_key = len(sys.argv) > 4 and sys.argv[4] or ""
ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False

## -----------------------------------------------------------------------
## Initiate Pubnub State
## -----------------------------------------------------------------------
pubnub = Pubnub(
    publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on
)
channel = "hello_world"
authkey = "abcd"

# Synchronous usage
print pubnub.grant(channel, authkey, True, True)

# Asynchronous usage


def callback(message):
    print (message)


pubnub.grant(channel, authkey, True, True, callback=callback, error=callback)
开发者ID:jlitzinger-kinestral,项目名称:python,代码行数:31,代码来源:grant.py

示例5: int

# 需要导入模块: from pubnub import Pubnub [as 别名]
# 或者: from pubnub.Pubnub import grant [as 别名]
		
		# insert in display
		logging.basicConfig(filename='hydrobase_display.log',level=logging.INFO)
		logging.info(message_array)
		db.display.insert_many(message_array)

		# insert in data db if last entry was more than 4 hpurs back
		if int(time_diff.seconds) >= 14400:
			logging.basicConfig(filename='hydrobase_data.log',level=logging.INFO)
			logging.info(message_array)
			db.data.insert_many(message_array)
		

if __name__ == '__main__':

	client = MongoClient('mongodb://admin:[email protected]:11268/analytics-hydrobase')
	db = client['analytics-hydrobase']

	#initialize the pubnub instance
	pubnub = Pubnub(publish_key='pub-c-93c6c384-e1a0-412f-87cf-e626aaab6a00', \
		subscribe_key='sub-c-8ec9d89e-e4aa-11e5-a4f2-0619f8945a4f', secret_key='sec-c-YzQyMTU3NmYtMDNhMS00MzM5LTg3MTgtZjA2N2U0N2IyNGY3', \
		auth_key='40ed6434-1991-4f7a-8034-20a072abde43')

	# Grant read, write and manage permissions to the pubnub instance that we initialized
	pubnub.grant(channel_group='hydrobase', auth_key='40ed6434-1991-4f7a-8034-20a072abde43',\
	 read=True, write=True, manage=True, ttl=0, callback=_callback, error=_error)

	# Subscribe to the channel group 'hydrobase' that contains the channels for all users to get the data 
	# coming in from different devices and put that into the DB
	pubnub.subscribe_group(channel_groups='hydrobase', \
		callback=sub_callback, error=_error)
开发者ID:binnie869,项目名称:app,代码行数:33,代码来源:db_writer.py


注:本文中的pubnub.Pubnub.grant方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。