<s> '''<STR_LIT>''' <EOL> from __future__ import absolute_import <EOL> from contextlib import contextmanager <EOL> import logging <EOL> from salt . pillar . sql_base import SqlBaseExtPillar <EOL> log = logging . getLogger ( __name__ ) <EOL> try : <EOL> from pysqlcipher import dbapi2 as sqlcipher <EOL> HAS_SQLCIPHER = True <EOL> except ImportError : <EOL> HAS_SQLCIPHER = False <EOL> def __virtual__ ( ) : <EOL> if not HAS_SQLCIPHER : <EOL> return False <EOL> return True <EOL> class SQLCipherExtPillar ( SqlBaseExtPillar ) : <EOL> '''<STR_LIT>''' <EOL> @ classmethod <EOL> def _db_name ( cls ) : <EOL> return '<STR_LIT>' <EOL> def _get_options ( self ) : <EOL> '''<STR_LIT>''' <EOL> defaults = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> _options = { } <EOL> _opts = __opts__ . get ( '<STR_LIT>' , { } ) <EOL> for attr in defaults : <EOL> if attr not in _opts : <EOL> log . debug ( '<STR_LIT>' , attr ) <EOL> _options [ attr ] = defaults [ attr ] <EOL> continue <EOL> _options [ attr ] = _opts [ attr ] <EOL> return _options <EOL> @ contextmanager <EOL> def _get_cursor ( self ) : <EOL> '''<STR_LIT>''' <EOL> _options = self . _get_options ( ) <EOL> conn = sqlcipher . connect ( _options . get ( '<STR_LIT>' ) , <EOL> timeout = float ( _options . get ( '<STR_LIT>' ) ) ) <EOL> conn . execute ( '<STR_LIT>' . format ( _options . get ( '<STR_LIT>' ) ) ) <EOL> cursor = conn . cursor ( ) <EOL> try : <EOL> yield cursor <EOL> except sqlcipher . Error as err : <EOL> log . exception ( '<STR_LIT>' , err . args ) <EOL> finally : <EOL> conn . close ( ) <EOL> def ext_pillar ( minion_id , <EOL> pillar , <EOL> * args , <EOL> ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return SQLCipherExtPillar ( ) . fetch ( minion_id , pillar , * args , ** kwargs ) </s>
