<s> import logging <EOL> from django . conf import settings <EOL> from django . template . loader import render_to_string <EOL> from Crypto . PublicKey import RSA <EOL> from Crypto . Hash import SHA256 <EOL> from Crypto . Signature import PKCS1_PSS <EOL> from django . templatetags . i18n import language_name <EOL> from dimagi . utils . decorators . memoized import memoized <EOL> from corehq . apps . hqwebapp . forms import BulkUploadForm <EOL> from corehq . apps . hqwebapp . tasks import send_html_email_async <EOL> from corehq . apps . users . models import WebUser <EOL> logger = logging . getLogger ( __name__ ) <EOL> @ memoized <EOL> def get_hq_private_key ( ) : <EOL> if settings . HQ_PRIVATE_KEY : <EOL> return RSA . importKey ( settings . HQ_PRIVATE_KEY ) <EOL> raise Exception ( '<STR_LIT>' ) <EOL> def sign ( message ) : <EOL> """<STR_LIT>""" <EOL> private_key = get_hq_private_key ( ) <EOL> sha256_hash = SHA256 . new ( message ) <EOL> signature = PKCS1_PSS . new ( private_key ) . sign ( sha256_hash ) <EOL> return signature <EOL> def send_confirmation_email ( invitation ) : <EOL> invited_user = invitation . email <EOL> subject = '<STR_LIT>' % invited_user <EOL> recipient = WebUser . get_by_user_id ( invitation . invited_by ) . get_email ( ) <EOL> context = { <EOL> '<STR_LIT>' : invited_user , <EOL> } <EOL> html_content = render_to_string ( '<STR_LIT>' , <EOL> context ) <EOL> text_content = render_to_string ( '<STR_LIT>' , <EOL> context ) <EOL> send_html_email_async . delay ( subject , recipient , html_content , <EOL> text_content = text_content ) <EOL> def get_bulk_upload_form ( context , context_key = "<STR_LIT>" ) : <EOL> return BulkUploadForm ( <EOL> context [ context_key ] [ '<STR_LIT>' ] , <EOL> context [ context_key ] . get ( '<STR_LIT:action>' ) , <EOL> context_key + "<STR_LIT>" <EOL> ) <EOL> def csrf_inline ( request ) : <EOL> """<STR_LIT>""" <EOL> from django . template import Template , RequestContext <EOL> node = "<STR_LIT>" <EOL> return Template ( node ) . render ( RequestContext ( request ) ) <EOL> def aliased_language_name ( lang_code ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return language_name ( lang_code ) <EOL> except KeyError : <EOL> for code , name in settings . LANGUAGES : <EOL> if code == lang_code : <EOL> return name <EOL> raise KeyError ( '<STR_LIT>' % lang_code ) </s>
