<s> import logging <EOL> import datetime <EOL> import pytest <EOL> import base64 <EOL> import time <EOL> import random <EOL> import sys <EOL> import platform <EOL> from emails . compat import to_native , is_py3 , to_unicode <EOL> logging . basicConfig ( level = logging . DEBUG ) <EOL> logger = logging . getLogger ( ) <EOL> @ pytest . fixture ( scope = '<STR_LIT>' ) <EOL> def django_email_backend ( request ) : <EOL> from django . conf import settings <EOL> logger . debug ( '<STR_LIT>' ) <EOL> settings . configure ( EMAIL_BACKEND = '<STR_LIT>' , <EOL> EMAIL_FILE_PATH = '<STR_LIT>' ) <EOL> from django . core . mail import get_connection <EOL> return get_connection ( ) <EOL> def obsfucate ( key , clear ) : <EOL> enc = [ ] <EOL> for i in range ( len ( clear ) ) : <EOL> key_c = key [ i % len ( key ) ] <EOL> enc_c = chr ( ( ord ( clear [ i ] ) + ord ( key_c ) ) % <NUM_LIT> ) <EOL> enc . append ( enc_c ) <EOL> return base64 . urlsafe_b64encode ( "<STR_LIT>" . join ( enc ) ) <EOL> def deobsfucate ( key , enc ) : <EOL> dec = [ ] <EOL> key = to_native ( key ) <EOL> enc = base64 . urlsafe_b64decode ( enc ) <EOL> for i in range ( len ( enc ) ) : <EOL> key_c = key [ i % len ( key ) ] <EOL> if is_py3 : <EOL> c1 = enc [ i ] <EOL> else : <EOL> c1 = ord ( enc [ i ] ) <EOL> dec_c = chr ( ( <NUM_LIT> + c1 - ord ( key_c ) ) % <NUM_LIT> ) <EOL> dec . append ( dec_c ) <EOL> return "<STR_LIT>" . join ( dec ) <EOL> assert <NUM_LIT:0> <EOL> class SMTPTestParams : <EOL> subject_prefix = '<STR_LIT>' <EOL> def __init__ ( self , from_email = None , to_email = None , defaults = None , ** kw ) : <EOL> params = { '<STR_LIT>' : True , '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT> } <EOL> params . update ( defaults or { } ) <EOL> params . update ( kw ) <EOL> self . params = params <EOL> pwd = params . get ( '<STR_LIT:password>' ) <EOL> if pwd and pwd . startswith ( '<STR_LIT>' ) : <EOL> user = params . get ( '<STR_LIT:user>' ) <EOL> params [ '<STR_LIT:password>' ] = deobsfucate ( user , pwd [ <NUM_LIT:3> : ] ) <EOL> self . from_email = from_email <EOL> self . to_email = to_email <EOL> def patch_message ( self , message ) : <EOL> """<STR_LIT>""" <EOL> if self . from_email : <EOL> message . mail_from = ( message . mail_from [ <NUM_LIT:0> ] , self . from_email ) <EOL> if self . to_email : <EOL> message . mail_to = self . to_email <EOL> if not to_unicode ( message . subject ) . startswith ( self . subject_prefix ) : <EOL> message . subject = "<STR_LIT:U+0020>" . join ( [ self . subject_prefix , message . subject , <EOL> '<STR_LIT>' % sys . version [ : <NUM_LIT:3> ] ] ) <EOL> message . _headers [ '<STR_LIT>' ] = datetime . datetime . utcnow ( ) . isoformat ( ) <EOL> message . _headers [ '<STR_LIT>' ] = "<STR_LIT>" % ( platform . python_version ( ) , platform . platform ( ) ) <EOL> return message <EOL> def __str__ ( self ) : <EOL> return u'<STR_LIT>' . format ( host = self . params . get ( '<STR_LIT:host>' ) , <EOL> port = self . params . get ( '<STR_LIT:port>' ) , <EOL> user = self . params . get ( '<STR_LIT:user>' , '<STR_LIT>' ) ) <EOL> def sleep ( self ) : <EOL> if '<STR_LIT>' in self . params . get ( '<STR_LIT:host>' , '<STR_LIT>' ) : <EOL> t = <NUM_LIT:2> + random . randint ( <NUM_LIT:0> , <NUM_LIT:2> ) <EOL> else : <EOL> t = <NUM_LIT:0.5> <EOL> time . sleep ( t ) <EOL> @ pytest . fixture ( scope = '<STR_LIT>' ) <EOL> def smtp_servers ( request ) : <EOL> try : <EOL> from . local_smtp_severs import SERVERS <EOL> except ImportError : <EOL> from . smtp_servers import SERVERS <EOL> return dict ( [ ( k , SMTPTestParams ( ** v ) ) for k , v in SERVERS . items ( ) ] ) </s>
