<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> import pprint <EOL> import logging <EOL> from salt . ext . six . moves . urllib . parse import urlencode as _urlencode <EOL> import salt . returners <EOL> import salt . utils . pushover <EOL> from salt . exceptions import SaltInvocationError <EOL> log = logging . getLogger ( __name__ ) <EOL> __virtualname__ = '<STR_LIT>' <EOL> def _get_options ( ret = None ) : <EOL> '''<STR_LIT>''' <EOL> defaults = { '<STR_LIT>' : '<STR_LIT:0>' } <EOL> attrs = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:user>' : '<STR_LIT:user>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT:title>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> profile_attr = '<STR_LIT>' <EOL> profile_attrs = { '<STR_LIT:user>' : '<STR_LIT:user>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT:title>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> _options = salt . returners . get_returner_options ( __virtualname__ , <EOL> ret , <EOL> attrs , <EOL> profile_attr = profile_attr , <EOL> profile_attrs = profile_attrs , <EOL> __salt__ = __salt__ , <EOL> __opts__ = __opts__ , <EOL> defaults = defaults ) <EOL> return _options <EOL> def __virtual__ ( ) : <EOL> '''<STR_LIT>''' <EOL> return __virtualname__ <EOL> def _post_message ( user , <EOL> device , <EOL> message , <EOL> title , <EOL> priority , <EOL> expire , <EOL> retry , <EOL> sound , <EOL> api_version = <NUM_LIT:1> , <EOL> token = None ) : <EOL> '''<STR_LIT>''' <EOL> user_validate = salt . utils . pushover . validate_user ( user , device , token ) <EOL> if not user_validate [ '<STR_LIT:result>' ] : <EOL> return user_validate <EOL> parameters = dict ( ) <EOL> parameters [ '<STR_LIT:user>' ] = user <EOL> parameters [ '<STR_LIT>' ] = device <EOL> parameters [ '<STR_LIT>' ] = token <EOL> parameters [ '<STR_LIT:title>' ] = title <EOL> parameters [ '<STR_LIT>' ] = priority <EOL> parameters [ '<STR_LIT>' ] = expire <EOL> parameters [ '<STR_LIT>' ] = retry <EOL> parameters [ '<STR_LIT:message>' ] = message <EOL> if sound : <EOL> sound_validate = salt . utils . pushover . validate_sound ( sound , token ) <EOL> if sound_validate [ '<STR_LIT>' ] : <EOL> parameters [ '<STR_LIT>' ] = sound <EOL> result = salt . utils . pushover . query ( function = '<STR_LIT:message>' , <EOL> method = '<STR_LIT:POST>' , <EOL> header_dict = { '<STR_LIT:Content-Type>' : '<STR_LIT>' } , <EOL> data = _urlencode ( parameters ) , <EOL> opts = __opts__ ) <EOL> return result <EOL> def returner ( ret ) : <EOL> '''<STR_LIT>''' <EOL> _options = _get_options ( ret ) <EOL> user = _options . get ( '<STR_LIT:user>' ) <EOL> device = _options . get ( '<STR_LIT>' ) <EOL> token = _options . get ( '<STR_LIT>' ) <EOL> title = _options . get ( '<STR_LIT:title>' ) <EOL> priority = _options . get ( '<STR_LIT>' ) <EOL> expire = _options . get ( '<STR_LIT>' ) <EOL> retry = _options . get ( '<STR_LIT>' ) <EOL> sound = _options . get ( '<STR_LIT>' ) <EOL> if not token : <EOL> raise SaltInvocationError ( '<STR_LIT>' ) <EOL> if not user : <EOL> raise SaltInvocationError ( '<STR_LIT>' ) <EOL> if priority and priority == <NUM_LIT:2> : <EOL> if not expire and not retry : <EOL> raise SaltInvocationError ( '<STR_LIT>' ) <EOL> message = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) . format ( <EOL> ret . get ( '<STR_LIT:id>' ) , <EOL> ret . get ( '<STR_LIT>' ) , <EOL> ret . get ( '<STR_LIT>' ) , <EOL> ret . get ( '<STR_LIT>' ) , <EOL> pprint . pformat ( ret . get ( '<STR_LIT>' ) ) ) <EOL> result = _post_message ( user = user , <EOL> device = device , <EOL> message = message , <EOL> title = title , <EOL> priority = priority , <EOL> expire = expire , <EOL> retry = retry , <EOL> sound = sound , <EOL> token = token ) <EOL> log . debug ( '<STR_LIT>' . format ( result ) ) <EOL> if not result [ '<STR_LIT>' ] : <EOL> log . info ( '<STR_LIT>' . format ( result [ '<STR_LIT:message>' ] ) ) <EOL> return </s>
