77import json
88import os
99import time
10+ import logging
1011
1112try :
1213 from urllib .parse import urlparse
@@ -164,7 +165,7 @@ def __init__(self, subscription_info, requests_session=None,
164165
165166 def verb (self , msg , * args , ** kwargs ):
166167 if self .verbose :
167- print (msg .format (* args , ** kwargs ))
168+ logging . info (msg .format (* args , ** kwargs ))
168169
169170 def _repad (self , data ):
170171 """Add base64 padding to the end of a string, if required"""
@@ -198,6 +199,7 @@ def encode(self, data, content_encoding="aes128gcm"):
198199 if content_encoding == "aesgcm" :
199200 self .verb ("Generating salt for aesgcm..." )
200201 salt = os .urandom (16 )
202+ logging .debug ("Salt: {}" .format (salt ))
201203 # The server key is an ephemeral ECDH key used only for this
202204 # transaction
203205 server_key = ec .generate_private_key (ec .SECP256R1 , default_backend ())
@@ -442,7 +444,7 @@ def webpush(subscription_info,
442444 vapid_headers = None
443445 if vapid_claims :
444446 if verbose :
445- print ("Generating VAPID headers..." )
447+ logging . info ("Generating VAPID headers..." )
446448 if not vapid_claims .get ('aud' ):
447449 url = urlparse (subscription_info .get ('endpoint' ))
448450 aud = "{}://{}" .format (url .scheme , url .netloc )
@@ -454,24 +456,31 @@ def webpush(subscription_info,
454456 # encryption lives for 12 hours
455457 vapid_claims ['exp' ] = int (time .time ()) + (12 * 60 * 60 )
456458 if verbose :
457- print ("Setting VAPID expry to {}..." .format (
459+ logging . info ("Setting VAPID expry to {}..." .format (
458460 vapid_claims ['exp' ]))
459461 if not vapid_private_key :
460462 raise WebPushException ("VAPID dict missing 'private_key'" )
461463 if isinstance (vapid_private_key , Vapid01 ):
464+ if verbose :
465+ logging .info ("Looks like we already have a valid VAPID key" )
462466 vv = vapid_private_key
463467 elif os .path .isfile (vapid_private_key ):
464468 # Presume that key from file is handled correctly by
465469 # py_vapid.
470+ if verbose :
471+ logging .info (
472+ "Reading VAPID key from file {}" .format (vapid_private_key ))
466473 vv = Vapid .from_file (
467474 private_key_file = vapid_private_key ) # pragma no cover
468475 else :
476+ if verbose :
477+ logging .info ("Reading VAPID key from arguments" )
469478 vv = Vapid .from_string (private_key = vapid_private_key )
470479 if verbose :
471- print ("\t claims: {}" .format (vapid_claims ))
480+ logging . info ("\t claims: {}" .format (vapid_claims ))
472481 vapid_headers = vv .sign (vapid_claims )
473482 if verbose :
474- print ("\t headers: {}" .format (vapid_headers ))
483+ logging . info ("\t headers: {}" .format (vapid_headers ))
475484 headers .update (vapid_headers )
476485
477486 response = WebPusher (
0 commit comments