How to use get_default_provider method in localstack

Best Python code snippet using localstack_python

user.py

Source:user.py Github

copy

Full Screen

...165 logger.debug("Creating User Profile for %s" % instance)166# Instantiate the hooks:167post_save.connect(get_or_create_user_profile, sender=AtmosphereUser)168# USER METHODS HERE169def get_default_provider(username):170 """171 Return default provider given172 """173 try:174 from core.models.group import get_user_group175 from core.models.provider import Provider176 group = get_user_group(username)177 provider_ids = group.current_identities.values_list(178 'provider',179 flat=True)180 provider = Provider.objects.filter(181 id__in=provider_ids,182 type__name="OpenStack")183 if provider:184 logger.debug("get_default_provider selected a new "185 "Provider for %s: %s" % (username, provider))186 provider = provider[0]187 else:188 logger.error("get_default_provider could not find a new "189 "Provider for %s" % (username,))190 return None191 return provider192 except Exception as e:193 logger.exception("get_default_provider encountered an error "194 "for %s" % (username,))195 return None196def get_default_identity(username, provider=None):197 """198 Return the default identity given to the user-group for provider.199 """200 try:201 from core.models.group import get_user_group202 group = get_user_group(username)203 if not group or not group.current_identities.all().count():204 logger.info("Cannot find the group for user: %s" % username)205 return None206 identities = group.current_identities.all()207 if provider:208 if provider.is_active():209 identities = identities.filter(provider=provider)210 return identities[0]211 else:212 logger.error("Provider provided for "213 "get_default_identity is inactive.")214 raise "Inactive Provider provided for get_default_identity "215 else:216 default_provider = get_default_provider(username)217 default_identity = group.current_identities.filter(218 provider=default_provider)219 if not default_identity:220 logger.error("User %s has no identities on Provider %s" % (username, default_provider))221 raise Exception("No Identities on Provider %s for %s" % (default_provider, username))222 # Passing223 default_identity = default_identity[0]224 logger.debug(225 "default_identity set to %s " %226 default_identity)227 return default_identity228 except Exception as e:229 logger.exception(e)230 return None...

Full Screen

Full Screen

beaver.py

Source:beaver.py Github

copy

Full Screen

...21# "conv2d",22# "conv_transpose1d",23# "conv_transpose2d",24# }25# provider = crypten.mpc.get_default_provider()26# a, b, c = provider.generate_additive_triple(27# x.size(), y.size(), op, device=x.device, *args, **kwargs28# )29# # Vectorized reveal to reduce rounds of communication30# from .arithmetic import ArithmeticSharedTensor31# eps_del = ArithmeticSharedTensor.reveal_batch([x - a, y - b])32# epsilon = eps_del[0]33# delta = eps_del[1]34# # z = c + (a * delta) + (epsilon * b) + epsilon * delta35# c._tensor += getattr(torch, op)(epsilon, b._tensor, *args, **kwargs)36# c._tensor += getattr(torch, op)(a._tensor, delta, *args, **kwargs)37# c += getattr(torch, op)(epsilon, delta, *args, **kwargs)38# return c39# def mul(x, y):40# return __beaver_protocol("mul", x, y)41# def matmul(x, y):42# return __beaver_protocol("matmul", x, y)43# def conv1d(x, y, **kwargs):44# return __beaver_protocol("conv1d", x, y, **kwargs)45# def conv2d(x, y, **kwargs):46# return __beaver_protocol("conv2d", x, y, **kwargs)47# def conv_transpose1d(x, y, **kwargs):48# return __beaver_protocol("conv_transpose1d", x, y, **kwargs)49# def conv_transpose2d(x, y, **kwargs):50# return __beaver_protocol("conv_transpose2d", x, y, **kwargs)51# def square(x):52# """Computes the square of `x` for additively secret-shared tensor `x`53# 1. Obtain uniformly random sharings [r] and [r2] = [r * r]54# 2. Additively hide [x] with appropriately sized [r]55# 3. Open ([epsilon] = [x] - [r])56# 4. Return z = [r2] + 2 * epsilon * [r] + epsilon ** 257# """58# provider = crypten.mpc.get_default_provider()59# r, r2 = provider.square(x.size(), device=x.device)60# epsilon = (x - r).reveal()61# return r2 + 2 * r * epsilon + epsilon * epsilon62# def wraps(x):63# """Privately computes the number of wraparounds for a set a shares64# To do so, we note that:65# [theta_x] = theta_z + [beta_xr] - [theta_r] - [eta_xr]66# Where [theta_i] is the wraps for a variable i67# [beta_ij] is the differential wraps for variables i and j68# [eta_ij] is the plaintext wraps for variables i and j69# Note: Since [eta_xr] = 0 with probability 1 - |x| / Q for modulus Q, we70# can make the assumption that [eta_xr] = 0 with high probability.71# """72# provider = crypten.mpc.get_default_provider()73# r, theta_r = provider.wrap_rng(x.size(), device=x.device)74# beta_xr = theta_r.clone()75# beta_xr._tensor = count_wraps([x._tensor, r._tensor])76# z = x + r77# theta_z = comm.get().gather(z._tensor, 0)78# theta_x = beta_xr - theta_r79# # TODO: Incorporate eta_xr80# if x.rank == 0:81# theta_z = count_wraps(theta_z)82# theta_x._tensor += theta_z83# return theta_x84# def AND(x, y):85# """86# Performs Beaver protocol for binary secret-shared tensors x and y87# 1. Obtain uniformly random sharings [a],[b] and [c] = [a & b]88# 2. XOR hide [x] and [y] with appropriately sized [a] and [b]89# 3. Open ([epsilon] = [x] ^ [a]) and ([delta] = [y] ^ [b])90# 4. Return [c] ^ (epsilon & [b]) ^ ([a] & delta) ^ (epsilon & delta)91# """92# from .binary import BinarySharedTensor93# provider = crypten.mpc.get_default_provider()94# a, b, c = provider.generate_binary_triple(x.size(), y.size(), device=x.device)95# # Stack to vectorize reveal96# eps_del = BinarySharedTensor.reveal_batch([x ^ a, y ^ b])97# epsilon = eps_del[0]98# delta = eps_del[1]99# return (b & epsilon) ^ (a & delta) ^ (epsilon & delta) ^ c100# def B2A_single_bit(xB):101# """Converts a single-bit BinarySharedTensor xB into an102# ArithmeticSharedTensor. This is done by:103# 1. Generate ArithmeticSharedTensor [rA] and BinarySharedTensor =rB= with104# a common 1-bit value r.105# 2. Hide xB with rB and open xB ^ rB106# 3. If xB ^ rB = 0, then return [rA], otherwise return 1 - [rA]107# Note: This is an arithmetic xor of a single bit.108# """109# if comm.get().get_world_size() < 2:110# from .arithmetic import ArithmeticSharedTensor111# return ArithmeticSharedTensor(xB._tensor, precision=0, src=0)112# provider = crypten.mpc.get_default_provider()113# rA, rB = provider.B2A_rng(xB.size(), device=xB.device)114 115# #xB.share = xB.share.long()116# z = (xB ^ rB).reveal()117# rA = rA * (1 - 2 * z) + z...

Full Screen

Full Screen

web3.py

Source:web3.py Github

copy

Full Screen

1from web3 import Web32from config import Web3ProviderConfig3def get_default_provider():4 """5 :return: default HTTPProvider (endpoint url from config.py)6 """7 return Web3.HTTPProvider(8 Web3ProviderConfig.endpoint_url,9 request_kwargs={10 'timeout': Web3ProviderConfig.timeout11 }12 )13def get_web3(provider=None, default_account=None):14 """15 Returns web3 instance for backend interacting with block chain network. If not setting provider parameter, bring16 configuration from config.py.17 """18 web3 = Web3(provider) if provider else Web3(get_default_provider())19 if default_account is None and web3.eth.accounts:20 default_account = web3.eth.accounts[0]21 web3.eth.defaultAccount = default_account...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful