-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into docs/examples
- Loading branch information
Showing
13 changed files
with
139 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from os import getenv | ||
from pubnub.pubnub import PubNub | ||
from pubnub.pnconfiguration import PNConfiguration | ||
from pubnub.crypto import AesCbcCryptoModule | ||
|
||
config = PNConfiguration() | ||
config.publish_key = getenv('PUBLISH_KEY', 'demo') | ||
config.subscribe_key = getenv('SUBSCRIBE_KEY', 'demo') | ||
config.cipher_key = getenv('CIPHER_KEY', 'my_cipher_key') | ||
config.uuid = 'example-python' | ||
config.crypto_module = AesCbcCryptoModule(config) | ||
|
||
pubnub = PubNub(config) | ||
|
||
message = 'Plaintext_message' | ||
if config.cipher_key and not config.crypto_module: | ||
message = f'cryptodome({type(config.crypto)})' | ||
if config.crypto_module: | ||
message = f'crypto_module({type(config.crypto_module)})' | ||
|
||
pubnub.publish().channel('example').message(message).sync() | ||
print(f'published: {message}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
from os import getenv | ||
from pubnub.pubnub import PubNub | ||
from pubnub.pnconfiguration import PNConfiguration | ||
|
||
config = PNConfiguration() | ||
config.publish_key = getenv('PUBLISH_KEY', 'demo') | ||
config.subscribe_key = getenv('SUBSCRIBE_KEY', 'demo') | ||
config.cipher_key = getenv('CIPHER_KEY', 'my_cipher_key') | ||
config.uuid = 'example' | ||
config.cipher_key = "my_cipher_key" | ||
pubnub = PubNub(config) | ||
|
||
messages = pubnub.fetch_messages().channels('example').count(30).decrypt_messages().sync() | ||
for msg in messages.result.channels['example']: | ||
print(msg.message, f' !! Error during decryption: {msg.error}' if msg.error else '') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import asyncio | ||
|
||
from os import getenv | ||
from pubnub.callbacks import SubscribeCallback | ||
from pubnub.crypto import AesCbcCryptoModule | ||
from pubnub.pnconfiguration import PNConfiguration | ||
from pubnub.pubnub_asyncio import PubNubAsyncio | ||
|
||
config = PNConfiguration() | ||
config.publish_key = getenv('PUBLISH_KEY', 'demo') | ||
config.subscribe_key = getenv('SUBSCRIBE_KEY', 'demo') | ||
config.cipher_key = getenv('CIPHER_KEY', 'my_cipher_key') | ||
config.crypto_module = AesCbcCryptoModule(config) | ||
config.uuid = 'example-python' | ||
config.enable_subscribe = True | ||
|
||
pubnub = PubNubAsyncio(config) | ||
|
||
|
||
class PrinterCallback(SubscribeCallback): | ||
def status(self, pubnub, status): | ||
print(status.category.name) | ||
|
||
def message(self, pubnub, message): | ||
print(message.message) | ||
|
||
|
||
async def main(): | ||
pubnub.add_listener(PrinterCallback()) | ||
pubnub.subscribe().channels("example").execute() | ||
|
||
await asyncio.sleep(500) | ||
|
||
|
||
loop = asyncio.get_event_loop() | ||
loop.run_until_complete(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters