<s> __version__ = '<STR_LIT>' <EOL> __author__ = "<STR_LIT>" <EOL> __date__ = '<STR_LIT>' <EOL> __url__ = '<STR_LIT>' <EOL> __copyright__ = "<STR_LIT>" <EOL> try : <EOL> from email . mime . base import MIMEBase <EOL> except ImportError as e : <EOL> from email import MIMEBase <EOL> from httplib import HTTPConnection <EOL> from urllib import urlencode <EOL> import sys <EOL> if sys . version_info [ <NUM_LIT:0> ] < <NUM_LIT:3> : <EOL> from urllib2 import Request , urlopen , HTTPError , URLError <EOL> else : <EOL> from urllib . request import Request , urlopen <EOL> from urllib . error import HTTPError , URLError <EOL> from http . client import HTTPConnection <EOL> from urllib . parse import urlencode <EOL> import collections <EOL> from contextlib import closing <EOL> try : <EOL> import simplejson as json <EOL> except ImportError : <EOL> try : <EOL> from django . utils import simplejson as json <EOL> except ImportError : <EOL> import json <EOL> class PMJSONEncoder ( json . JSONEncoder ) : <EOL> def default ( self , o ) : <EOL> if hasattr ( o , '<STR_LIT>' ) : <EOL> return unicode ( o ) <EOL> return super ( PMJSONEncoder , self ) . default ( o ) <EOL> __POSTMARK_URL__ = '<STR_LIT>' <EOL> class PMMail ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> self . __api_key = None <EOL> self . __sender = None <EOL> self . __reply_to = None <EOL> self . __to = None <EOL> self . __cc = None <EOL> self . __bcc = None <EOL> self . __subject = None <EOL> self . __tag = None <EOL> self . __html_body = None <EOL> self . __text_body = None <EOL> self . __track_opens = False <EOL> self . __custom_headers = { } <EOL> self . __attachments = [ ] <EOL> self . __message_id = None <EOL> acceptable_keys = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:to>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> for key in kwargs : <EOL> if key in acceptable_keys : <EOL> if key == '<STR_LIT>' : <EOL> setattr ( self , '<STR_LIT>' , kwargs [ key ] ) <EOL> else : <EOL> setattr ( self , '<STR_LIT>' % key , kwargs [ key ] ) <EOL> self . __user_agent = '<STR_LIT>' % ( '<STR_LIT:_>' . join ( [ str ( var ) for var in sys . version_info ] ) , __version__ ) <EOL> try : <EOL> from django import VERSION <EOL> from django . conf import settings as django_settings <EOL> self . __user_agent = '<STR_LIT>' % ( self . __user_agent , '<STR_LIT:_>' . join ( [ str ( var ) for var in VERSION ] ) ) <EOL> if not self . __api_key and hasattr ( django_settings , '<STR_LIT>' ) : <EOL> self . __api_key = django_settings . POSTMARK_API_KEY <EOL> if not self . __sender and hasattr ( django_settings , '<STR_LIT>' ) : <EOL> self . __sender = django_settings . POSTMARK_SENDER <EOL> if not self . __track_opens and hasattr ( django_settings , '<STR_LIT>' ) : <EOL> self . __track_opens = django_settings . POSTMARK_TRACK_OPENS <EOL> except ImportError : <EOL> pass <EOL> def _set_custom_headers ( self , value ) : <EOL> '''<STR_LIT>''' <EOL> if value is None : <EOL> setattr ( self , '<STR_LIT>' , { } ) <EOL> elif isinstance ( value , dict ) : <EOL> setattr ( self , '<STR_LIT>' , value ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> def _set_attachments ( self , value ) : <EOL> '''<STR_LIT>''' <EOL> if value is None : <EOL> setattr ( self , '<STR_LIT>' , [ ] ) <EOL> elif isinstance ( value , list ) : <EOL> setattr ( self , '<STR_LIT>' , value ) <EOL> else : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> api_key = property ( <EOL> lambda self : self . __api_key , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> sender = property ( <EOL> lambda self : self . __sender , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> reply_to = property ( <EOL> lambda self : self . __reply_to , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> to = property ( <EOL> lambda self : self . __to , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> cc = property ( <EOL> lambda self : self . __cc , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> bcc = property ( <EOL> lambda self : self . __bcc , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> subject = property ( <EOL> lambda self : self . __subject , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> tag = property ( <EOL> lambda self : self . __tag , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> html_body = property ( <EOL> lambda self : self . __html_body , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> text_body = property ( <EOL> lambda self : self . __text_body , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> track_opens = property ( <EOL> lambda self : self . __track_opens , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> custom_headers = property ( <EOL> lambda self : self . __custom_headers , <EOL> _set_custom_headers , <EOL> lambda self : setattr ( self , '<STR_LIT>' , { } ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> attachments = property ( <EOL> lambda self : self . __attachments , <EOL> _set_attachments , <EOL> lambda self : setattr ( self , '<STR_LIT>' , [ ] ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> message_id = property ( <EOL> lambda self : self . __message_id , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> recipient = property ( <EOL> lambda self : self . __to , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> def _check_values ( self ) : <EOL> '''<STR_LIT>''' <EOL> if not self . __api_key : <EOL> raise PMMailMissingValueException ( '<STR_LIT>' ) <EOL> elif not self . __sender : <EOL> raise PMMailMissingValueException ( '<STR_LIT>' ) <EOL> elif not self . __to : <EOL> raise PMMailMissingValueException ( '<STR_LIT>' ) <EOL> elif not self . __subject : <EOL> raise PMMailMissingValueException ( '<STR_LIT>' ) <EOL> elif not self . __html_body and not self . __text_body : <EOL> raise PMMailMissingValueException ( '<STR_LIT>' ) <EOL> if self . __track_opens and not self . __html_body : <EOL> print ( '<STR_LIT>' ) <EOL> def to_json_message ( self ) : <EOL> json_message = { <EOL> '<STR_LIT>' : self . __sender , <EOL> '<STR_LIT>' : self . __to , <EOL> '<STR_LIT>' : self . __subject , <EOL> } <EOL> if self . __reply_to : <EOL> json_message [ '<STR_LIT>' ] = self . __reply_to <EOL> if self . __cc : <EOL> json_message [ '<STR_LIT>' ] = self . __cc <EOL> if self . __bcc : <EOL> json_message [ '<STR_LIT>' ] = self . __bcc <EOL> if self . __tag : <EOL> json_message [ '<STR_LIT>' ] = self . __tag <EOL> if self . __html_body : <EOL> json_message [ '<STR_LIT>' ] = self . __html_body <EOL> if self . __text_body : <EOL> json_message [ '<STR_LIT>' ] = self . __text_body <EOL> if self . __track_opens : <EOL> json_message [ '<STR_LIT>' ] = True <EOL> if len ( self . __custom_headers ) > <NUM_LIT:0> : <EOL> cust_headers = [ ] <EOL> for key , value in self . __custom_headers . items ( ) : <EOL> cust_headers . append ( { <EOL> '<STR_LIT:Name>' : key , <EOL> '<STR_LIT>' : value <EOL> } ) <EOL> json_message [ '<STR_LIT>' ] = cust_headers <EOL> if len ( self . __attachments ) > <NUM_LIT:0> : <EOL> attachments = [ ] <EOL> for attachment in self . __attachments : <EOL> if isinstance ( attachment , tuple ) : <EOL> attachments . append ( { <EOL> "<STR_LIT:Name>" : attachment [ <NUM_LIT:0> ] , <EOL> "<STR_LIT>" : attachment [ <NUM_LIT:1> ] , <EOL> "<STR_LIT>" : attachment [ <NUM_LIT:2> ] , <EOL> } ) <EOL> elif isinstance ( attachment , MIMEBase ) : <EOL> attachments . append ( { <EOL> "<STR_LIT:Name>" : attachment . get_filename ( ) , <EOL> "<STR_LIT>" : attachment . get_payload ( ) , <EOL> "<STR_LIT>" : attachment . get_content_type ( ) , <EOL> } ) <EOL> json_message [ '<STR_LIT>' ] = attachments <EOL> return json_message <EOL> def send ( self , test = None ) : <EOL> '''<STR_LIT>''' <EOL> self . _check_values ( ) <EOL> json_message = self . to_json_message ( ) <EOL> if test is None : <EOL> try : <EOL> from django . conf import settings as django_settings <EOL> test = getattr ( django_settings , "<STR_LIT>" , None ) <EOL> except ImportError : <EOL> pass <EOL> if test : <EOL> print ( '<STR_LIT>' % json . dumps ( json_message , cls = PMJSONEncoder ) ) <EOL> return <EOL> req = Request ( <EOL> __POSTMARK_URL__ + '<STR_LIT:email>' , <EOL> json . dumps ( json_message , cls = PMJSONEncoder ) . encode ( '<STR_LIT:utf8>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : self . __api_key , <EOL> '<STR_LIT>' : self . __user_agent <EOL> } <EOL> ) <EOL> try : <EOL> result = urlopen ( req ) <EOL> jsontxt = result . read ( ) . decode ( ) <EOL> result . close ( ) <EOL> if result . code == <NUM_LIT:200> : <EOL> self . message_id = json . loads ( jsontxt ) . get ( '<STR_LIT>' , None ) <EOL> return True <EOL> else : <EOL> raise PMMailSendException ( '<STR_LIT>' % ( result . code , result . msg ) ) <EOL> except HTTPError as err : <EOL> if err . code == <NUM_LIT> : <EOL> raise PMMailUnauthorizedException ( '<STR_LIT>' , err ) <EOL> elif err . code == <NUM_LIT> : <EOL> try : <EOL> jsontxt = err . read ( ) . decode ( ) <EOL> jsonobj = json . loads ( jsontxt ) <EOL> desc = jsonobj [ '<STR_LIT>' ] <EOL> error_code = jsonobj [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> raise PMMailUnprocessableEntityException ( '<STR_LIT>' ) <EOL> if error_code == <NUM_LIT> : <EOL> raise PMMailInactiveRecipientException ( '<STR_LIT>' ) <EOL> raise PMMailUnprocessableEntityException ( '<STR_LIT>' % desc ) <EOL> elif err . code == <NUM_LIT> : <EOL> raise PMMailServerErrorException ( '<STR_LIT>' , err ) <EOL> except URLError as err : <EOL> if hasattr ( err , '<STR_LIT>' ) : <EOL> raise PMMailURLException ( '<STR_LIT>' % err . reason , err ) <EOL> elif hasattr ( err , '<STR_LIT:code>' ) : <EOL> raise PMMailURLException ( '<STR_LIT>' % err . code , err ) <EOL> else : <EOL> raise PMMailURLException ( '<STR_LIT>' , err ) <EOL> def _chunks ( l , n ) : <EOL> return ( l [ i : i + n ] for i in range ( <NUM_LIT:0> , len ( l ) , n ) ) <EOL> class PMBatchMail ( object ) : <EOL> MAX_MESSAGES = <NUM_LIT> <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . __api_key = None <EOL> self . __messages = [ ] <EOL> acceptable_keys = ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> for key in kwargs : <EOL> if key in acceptable_keys : <EOL> setattr ( self , '<STR_LIT>' % key , kwargs [ key ] ) <EOL> self . __user_agent = '<STR_LIT>' % ( '<STR_LIT:_>' . join ( [ str ( var ) for var in sys . version_info ] ) , __version__ ) <EOL> try : <EOL> from django import VERSION <EOL> from django . conf import settings as django_settings <EOL> self . __user_agent = '<STR_LIT>' % ( self . __user_agent , '<STR_LIT:_>' . join ( [ str ( var ) for var in VERSION ] ) ) <EOL> if not self . __api_key and hasattr ( django_settings , '<STR_LIT>' ) : <EOL> self . __api_key = django_settings . POSTMARK_API_KEY <EOL> except ImportError : <EOL> pass <EOL> api_key = property ( <EOL> lambda self : self . __api_key , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> messages = property ( <EOL> lambda self : self . __messages , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> def add_message ( self , message ) : <EOL> '''<STR_LIT>''' <EOL> self . __messages . append ( message ) <EOL> def remove_message ( self , message ) : <EOL> '''<STR_LIT>''' <EOL> if message in self . __messages : <EOL> self . __messages . remove ( message ) <EOL> def _check_values ( self ) : <EOL> '''<STR_LIT>''' <EOL> for message in self . __messages : <EOL> message . _check_values ( ) <EOL> def send ( self , test = None ) : <EOL> inactive_recipient = False <EOL> self . _check_values ( ) <EOL> if test is None : <EOL> try : <EOL> from django . conf import settings as django_settings <EOL> test = getattr ( django_settings , "<STR_LIT>" , None ) <EOL> except ImportError : <EOL> pass <EOL> for messages in _chunks ( self . messages , PMBatchMail . MAX_MESSAGES ) : <EOL> json_message = [ ] <EOL> for message in messages : <EOL> json_message . append ( message . to_json_message ( ) ) <EOL> req = Request ( <EOL> __POSTMARK_URL__ + '<STR_LIT>' , <EOL> json . dumps ( json_message , cls = PMJSONEncoder ) . encode ( '<STR_LIT:utf8>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : self . __api_key , <EOL> '<STR_LIT>' : self . __user_agent <EOL> } <EOL> ) <EOL> if test : <EOL> print ( '<STR_LIT>' % json . dumps ( json_message , cls = PMJSONEncoder ) ) <EOL> continue <EOL> try : <EOL> result = urlopen ( req ) <EOL> jsontxt = result . read ( ) . decode ( ) <EOL> result . close ( ) <EOL> if result . code == <NUM_LIT:200> : <EOL> results = json . loads ( jsontxt ) <EOL> for i , res in enumerate ( results ) : <EOL> self . __messages [ i ] . message_id = res . get ( "<STR_LIT>" , None ) <EOL> else : <EOL> raise PMMailSendException ( '<STR_LIT>' % ( result . code , result . msg ) ) <EOL> except HTTPError as err : <EOL> if err . code == <NUM_LIT> : <EOL> raise PMMailUnauthorizedException ( '<STR_LIT>' , err ) <EOL> elif err . code == <NUM_LIT> : <EOL> try : <EOL> jsontxt = err . read ( ) . decode ( ) <EOL> jsonobj = json . loads ( jsontxt ) <EOL> desc = jsonobj [ '<STR_LIT>' ] <EOL> error_code = jsonobj [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> raise PMMailUnprocessableEntityException ( '<STR_LIT>' ) <EOL> if error_code == <NUM_LIT> : <EOL> inactive_recipient = True <EOL> continue <EOL> raise PMMailUnprocessableEntityException ( '<STR_LIT>' % desc ) <EOL> elif err . code == <NUM_LIT> : <EOL> raise PMMailServerErrorException ( '<STR_LIT>' , err ) <EOL> except URLError as err : <EOL> if hasattr ( err , '<STR_LIT>' ) : <EOL> raise PMMailURLException ( '<STR_LIT>' % err . reason , err ) <EOL> elif hasattr ( err , '<STR_LIT:code>' ) : <EOL> raise PMMailURLException ( '<STR_LIT>' % err . code , err ) <EOL> else : <EOL> raise PMMailURLException ( '<STR_LIT>' , err ) <EOL> if inactive_recipient : <EOL> raise PMMailInactiveRecipientException ( '<STR_LIT>' ) <EOL> return True <EOL> class PMBounceManager ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> self . __api_key = None <EOL> acceptable_keys = ( <EOL> '<STR_LIT>' , <EOL> ) <EOL> for key in kwargs : <EOL> if key in acceptable_keys : <EOL> setattr ( self , '<STR_LIT>' % key , kwargs [ key ] ) <EOL> self . __user_agent = '<STR_LIT>' % ( '<STR_LIT:_>' . join ( [ str ( var ) for var in sys . version_info ] ) , __version__ ) <EOL> try : <EOL> from django import VERSION <EOL> from django . conf import settings as django_settings <EOL> if not self . __api_key and hasattr ( django_settings , '<STR_LIT>' ) : <EOL> self . __api_key = django_settings . POSTMARK_API_KEY <EOL> self . __user_agent = '<STR_LIT>' % ( self . __user_agent , '<STR_LIT:_>' . join ( [ str ( var ) for var in VERSION ] ) ) <EOL> except ImportError : <EOL> pass <EOL> def _check_values ( self ) : <EOL> '''<STR_LIT>''' <EOL> if not self . __api_key : <EOL> raise PMMailMissingValueException ( '<STR_LIT>' ) <EOL> api_key = property ( <EOL> lambda self : self . __api_key , <EOL> lambda self , value : setattr ( self , '<STR_LIT>' , value ) , <EOL> lambda self : setattr ( self , '<STR_LIT>' , None ) , <EOL> '''<STR_LIT>''' <EOL> ) <EOL> def delivery_stats ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . _check_values ( ) <EOL> req = Request ( <EOL> __POSTMARK_URL__ + '<STR_LIT>' , <EOL> None , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : self . __api_key , <EOL> '<STR_LIT>' : self . __user_agent <EOL> } <EOL> ) <EOL> try : <EOL> result = urlopen ( req ) <EOL> with closing ( result ) : <EOL> if result . code == <NUM_LIT:200> : <EOL> return json . loads ( result . read ( ) ) <EOL> else : <EOL> raise PMMailSendException ( '<STR_LIT>' % ( result . code , result . msg ) ) <EOL> except HTTPError as err : <EOL> return err <EOL> def get_all ( self , inactive = '<STR_LIT>' , email_filter = '<STR_LIT>' , tag = '<STR_LIT>' , count = <NUM_LIT> , offset = <NUM_LIT:0> ) : <EOL> '''<STR_LIT>''' <EOL> self . _check_values ( ) <EOL> params = '<STR_LIT>' + inactive + '<STR_LIT>' + email_filter + '<STR_LIT>' + tag <EOL> params += '<STR_LIT>' + str ( count ) + '<STR_LIT>' + str ( offset ) <EOL> req = Request ( <EOL> __POSTMARK_URL__ + '<STR_LIT>' + params , <EOL> None , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : self . __api_key , <EOL> '<STR_LIT>' : self . __user_agent <EOL> } <EOL> ) <EOL> try : <EOL> result = urlopen ( req ) <EOL> with closing ( result ) : <EOL> if result . code == <NUM_LIT:200> : <EOL> return json . loads ( result . read ( ) ) <EOL> else : <EOL> raise PMMailSendException ( '<STR_LIT>' % ( result . code , result . msg ) ) <EOL> except HTTPError as err : <EOL> return err <EOL> def get_single ( self , bounce_id ) : <EOL> '''<STR_LIT>''' <EOL> self . _check_values ( ) <EOL> req = Request ( <EOL> __POSTMARK_URL__ + '<STR_LIT>' + str ( bounce_id ) , <EOL> None , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : self . __api_key , <EOL> '<STR_LIT>' : self . __user_agent <EOL> } <EOL> ) <EOL> try : <EOL> result = urlopen ( req ) <EOL> with closing ( result ) : <EOL> if result . code == <NUM_LIT:200> : <EOL> return json . loads ( result . read ( ) ) <EOL> else : <EOL> raise PMMailSendException ( '<STR_LIT>' % ( result . code , result . msg ) ) <EOL> except HTTPError as err : <EOL> return err <EOL> def get_dump ( self , bounce_id ) : <EOL> '''<STR_LIT>''' <EOL> self . _check_values ( ) <EOL> req_url = __POSTMARK_URL__ + '<STR_LIT>' + str ( bounce_id ) + '<STR_LIT>' <EOL> req = Request ( <EOL> req_url , <EOL> None , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : self . __api_key , <EOL> '<STR_LIT>' : self . __user_agent <EOL> } <EOL> ) <EOL> try : <EOL> print ( '<STR_LIT>' ) <EOL> result = urlopen ( req ) <EOL> with closing ( result ) : <EOL> if result . code == <NUM_LIT:200> : <EOL> return json . loads ( result . read ( ) ) <EOL> else : <EOL> raise PMMailSendException ( '<STR_LIT>' % ( result . code , result . msg ) ) <EOL> except HTTPError as err : <EOL> return err <EOL> def get_tags ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . _check_values ( ) <EOL> req = Request ( <EOL> __POSTMARK_URL__ + '<STR_LIT>' , <EOL> None , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : self . __api_key , <EOL> '<STR_LIT>' : self . __user_agent <EOL> } <EOL> ) <EOL> try : <EOL> result = urlopen ( req ) <EOL> with closing ( result ) : <EOL> if result . code == <NUM_LIT:200> : <EOL> return json . loads ( result . read ( ) ) <EOL> else : <EOL> raise PMMailSendException ( '<STR_LIT>' % ( result . code , result . msg ) ) <EOL> except HTTPError as err : <EOL> return err <EOL> def activate ( self , bounce_id ) : <EOL> '''<STR_LIT>''' <EOL> self . _check_values ( ) <EOL> req_url = '<STR_LIT>' + str ( bounce_id ) + '<STR_LIT>' <EOL> h1 = HTTPConnection ( '<STR_LIT>' ) <EOL> dta = urlencode ( { "<STR_LIT:data>" : "<STR_LIT:blank>" } ) . encode ( '<STR_LIT:utf8>' ) <EOL> req = h1 . request ( '<STR_LIT>' , <EOL> req_url , <EOL> dta , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT:Content-Type>' : '<STR_LIT:application/json>' , <EOL> '<STR_LIT>' : self . __api_key , <EOL> '<STR_LIT>' : self . __user_agent <EOL> } <EOL> ) <EOL> r = h1 . getresponse ( ) <EOL> return json . loads ( r . read ( ) ) <EOL> class PMMailMissingValueException ( Exception ) : <EOL> def __init__ ( self , value ) : <EOL> self . parameter = value <EOL> def __str__ ( self ) : <EOL> return repr ( self . parameter ) <EOL> class PMMailSendException ( Exception ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , value , inner_exception = None ) : <EOL> self . parameter = value <EOL> self . inner_exception = inner_exception <EOL> def __str__ ( self ) : <EOL> return repr ( self . parameter ) <EOL> class PMMailUnauthorizedException ( PMMailSendException ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> class PMMailUnprocessableEntityException ( PMMailSendException ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> class PMMailServerErrorException ( PMMailSendException ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> class PMMailURLException ( PMMailSendException ) : <EOL> '''<STR_LIT>''' <EOL> pass <EOL> class PMMailInactiveRecipientException ( PMMailSendException ) : <EOL> '''<STR_LIT>''' <EOL> pass </s>
