Best Python code snippet using localstack_python
__init__.py
Source:__init__.py
...10 assert ret is not None11 return ret12def msgpack_decode(content: bytes):13 return msgpack.unpackb(content, raw=False)14def _inner(it):15 return getattr(it, "_inner", None)16DEFAULT_SERVER_URL = etebase_python.Client.get_default_server_url()17def random_bytes(size: int):18 return bytes(etebase_python.Utils.randombytes(size))19def pretty_fingerprint(content):20 return etebase_python.Utils.pretty_fingerprint(content)21class Base64Url:22 @classmethod23 def from_base64(cls, value):24 return bytes(Utils.from_base64(value))25 to_base64 = Utils.to_base6426class Client:27 def __init__(self, client_name, server_url=DEFAULT_SERVER_URL):28 self._inner = etebase_python.Client.new(client_name, server_url)29 @property30 def server_url(self) -> str:31 raise RuntimeError("This property has no getter!")32 @server_url.setter33 def server_url(self, value: str):34 self._inner.set_server_url(value)35class User:36 def __init__(self, username: str, email: str):37 self._inner = etebase_python.User(username, email)38 @property39 def username(self) -> str:40 return self._inner.get_username()41 @username.setter42 def username(self, value: str):43 self._inner.set_username(value)44 @property45 def email(self) -> str:46 return self._inner.get_email()47 @email.setter48 def email(self, value: str):49 self._inner.set_email(value)50class Account:51 def __init__(self, inner: etebase_python.Account):52 self._inner = inner53 @classmethod54 def is_etebase_server(cls, client: Client):55 return etebase_python.Account.is_etebase_server(client._inner)56 @classmethod57 def login(cls, client: Client, username: str, password: str):58 return cls(etebase_python.Account.login(client._inner, username, password))59 @classmethod60 def login_key(cls, client: Client, username: str, key: bytes):61 return cls(etebase_python.Account.login_key(client._inner, username, key))62 @classmethod63 def signup(cls, client: Client, user: User, password: str):64 return cls(etebase_python.Account.signup(client._inner, user._inner, password))65 @classmethod66 def signup_key(cls, client: Client, user: User, key: bytes):67 return cls(etebase_python.Account.signup_key(client._inner, user._inner, key))68 def fetch_token(self):69 self._inner.fetch_token()70 def force_server_url(self, api_base: str):71 self._inner.force_server_url(api_base)72 def change_password(self, password: str):73 self._inner.change_password(password)74 def logout(self):75 self._inner.logout()76 def get_collection_manager(self):77 return CollectionManager(self._inner.get_collection_manager())78 def get_invitation_manager(self):79 return CollectionInvitationManager(self._inner.get_invitation_manager())80 def save(self, encryption_key: t.Optional[bytes]):81 return self._inner.save(encryption_key)82 @classmethod83 def restore(cls, client: Client, account_data_stored: str, encryption_key: t.Optional[bytes]):84 return cls(etebase_python.Account.restore(client._inner, account_data_stored, encryption_key))85class RemovedCollection:86 def __init__(self, inner: etebase_python.RemovedCollection):87 self._inner = inner88 @property89 def uid(self):90 return self._inner.get_uid()91class CollectionListResponse:92 def __init__(self, inner: etebase_python.CollectionListResponse):93 self._inner = inner94 @cached_property95 def stoken(self):96 return self._inner.get_stoken()97 @property98 def data(self):99 return map(lambda x: Collection(x), self._inner.get_data())100 @cached_property101 def done(self):102 return self._inner.is_done()103 @property104 def removed_memberships(self):105 return map(lambda x: RemovedCollection(x), self._inner.get_removed_memberships())106class ItemListResponse:107 def __init__(self, inner: etebase_python.ItemListResponse):108 self._inner = inner109 @cached_property110 def stoken(self):111 return self._inner.get_stoken()112 @property113 def data(self):114 return map(lambda x: Item(x), self._inner.get_data())115 @cached_property116 def done(self):117 return self._inner.is_done()118class ItemRevisionsListResponse:119 def __init__(self, inner: etebase_python.ItemRevisionsListResponse):120 self._inner = inner121 @cached_property122 def iterator(self):123 return self._inner.get_iterator()124 @property125 def data(self):126 return map(lambda x: Item(x), self._inner.get_data())127 @cached_property128 def done(self):129 return self._inner.is_done()130class FetchOptions:131 def __init__(self):132 self._inner = etebase_python.FetchOptions()133 def limit(self, value: int):134 self._inner.limit(value)135 return self136 def prefetch(self, value: PrefetchOption):137 self._inner.prefetch(value)138 return self139 def with_collection(self, value: bool):140 self._inner.with_collection(value)141 return self142 def iterator(self, value: t.Optional[str]):143 self._inner.iterator(value)144 return self145 def stoken(self, value: t.Optional[str]):146 self._inner.stoken(value)147 return self148def _verify_col_meta(meta: t.Dict):149 if "name" not in meta:150 raise RuntimeError("Collection meta must have a name field")151 return meta152class CollectionManager:153 def __init__(self, inner: etebase_python.CollectionManager):154 self._inner = inner155 def fetch(self, col_uid: str, fetch_options: t.Optional[FetchOptions]=None):156 return Collection(self._inner.fetch(col_uid, _inner(fetch_options)))157 def create(self, col_type: str, meta: t.Dict, content: bytes):158 meta_packed = msgpack_encode(_verify_col_meta(meta))159 return self.create_raw(col_type, meta_packed, content)160 def create_raw(self, col_type: str, meta: bytes, content: bytes):161 return Collection(self._inner.create_raw(col_type, meta, content))162 def get_item_manager(self, col: "Collection"):163 return ItemManager(self._inner.get_item_manager(col._inner))164 def list(self, col_type: t.Union[str, t.List[str]], fetch_options: t.Optional[FetchOptions]=None):165 if isinstance(col_type, str):166 return CollectionListResponse(self._inner.list(col_type, _inner(fetch_options)))167 else:168 return CollectionListResponse(self._inner.list_multi(list(col_type), _inner(fetch_options)))169 def upload(self, collection: "Collection", fetch_options: t.Optional[FetchOptions]=None):170 self._inner.upload(collection._inner, _inner(fetch_options))171 def transaction(self, collection: "Collection", fetch_options: t.Optional[FetchOptions]=None):172 self._inner.transaction(collection._inner, _inner(fetch_options))173 def cache_load(self, cached: bytes):174 return Collection(self._inner.cache_load(cached))175 def cache_save(self, collection: "Collection", with_content: bool=True):176 if with_content:177 return bytes(self._inner.cache_save_with_content(collection._inner))178 else:179 return bytes(self._inner.cache_save(collection._inner))180 def get_member_manager(self, collection: "Collection"):181 return CollectionMemberManager(self._inner.get_member_manager(collection._inner))182class ItemManager:183 def __init__(self, inner: etebase_python.ItemManager):184 self._inner = inner185 def fetch(self, col_uid, fetch_options: t.Optional[FetchOptions]=None):186 return Item(self._inner.fetch(col_uid, _inner(fetch_options)))187 def create(self, meta: t.Dict, content: bytes):188 meta_packed = msgpack_encode(meta)189 return self.create_raw(meta_packed, content)190 def create_raw(self, meta: bytes, content: bytes):191 return Item(self._inner.create_raw(meta, content))192 def list(self, fetch_options: t.Optional[FetchOptions]=None):193 return ItemListResponse(self._inner.list(_inner(fetch_options)))194 def item_revisions(self, item: "Item", fetch_options: t.Optional[FetchOptions]=None):195 return ItemRevisionsListResponse(self._inner.item_revisions(item._inner, _inner(fetch_options)))196 def fetch_updates(self, items: t.List["Item"], fetch_options: t.Optional[FetchOptions]=None):197 items_inner = list(map(lambda x: x._inner, items))198 return ItemListResponse(self._inner.fetch_updates(items_inner, _inner(fetch_options)))199 def fetch_multi(self, items_uids: t.List[str], fetch_options: t.Optional[FetchOptions]=None):200 return ItemListResponse(self._inner.fetch_multi(items_uids, _inner(fetch_options)))201 def batch(self, items: t.List["Item"], deps: t.List["Item"]=None, fetch_options: t.Optional[FetchOptions]=None):202 items_inner = list(map(lambda x: x._inner, items))203 deps_inner = list(map(lambda x: x._inner, deps)) if deps is not None else None204 self._inner.batch(items_inner, deps_inner, _inner(fetch_options))205 def transaction(self, items: t.List["Item"], deps: t.List["Item"]=None, fetch_options: t.Optional[FetchOptions]=None):206 items_inner = list(map(lambda x: x._inner, items))207 deps_inner = list(map(lambda x: x._inner, deps)) if deps is not None else None208 self._inner.transaction(items_inner, deps_inner, _inner(fetch_options))209 def download_content(self, item: "Item"):210 self._inner.download_content(item._inner)211 def upload_content(self, item: "Item"):212 self._inner.upload_content(item._inner)213 def cache_load(self, cached: bytes):214 return Item(self._inner.cache_load(cached))215 def cache_save(self, item: "Item", with_content: bool=True):216 if with_content:217 return bytes(self._inner.cache_save_with_content(item._inner))218 else:219 return bytes(self._inner.cache_save(item._inner))220class Collection:221 def __init__(self, inner: etebase_python.Collection):222 self._inner = inner223 def verify(self):224 return self._inner.verify()225 @cached_property226 def meta(self):227 return msgpack_decode(bytes(self._inner.get_meta_raw()))228 @meta.setter229 def meta(self, value: t.Any):230 self.__class__.meta.fget.cache_clear()231 self.__class__.meta_raw.fget.cache_clear()232 value = msgpack_encode(_verify_col_meta(value))233 self._inner.set_meta_raw(value)234 @cached_property235 def meta_raw(self):236 return self._inner.get_meta_raw()237 @meta_raw.setter238 def meta_raw(self, value: bytes):239 self.__class__.meta.fget.cache_clear()240 self.__class__.meta_raw.fget.cache_clear()241 self._inner.set_meta_raw(value)242 @cached_property243 def content(self):244 return bytes(self._inner.get_content())245 @content.setter246 def content(self, value: bytes):247 self.__class__.content.fget.cache_clear()248 self._inner.set_content(value)249 def delete(self):250 self._inner.delete()251 @property252 def deleted(self):253 return self._inner.is_deleted()254 @property255 def uid(self):256 return self._inner.get_uid()257 @property258 def etag(self):259 return self._inner.get_etag()260 @property261 def stoken(self):262 return self._inner.get_stoken()263 @property264 def access_level(self):265 return self._inner.get_access_level()266 @property267 def item(self):268 return Item(self._inner.get_item())269 @cached_property270 def collection_type(self):271 return self._inner.get_collection_type()272class Item:273 def __init__(self, inner: etebase_python.Item):274 self._inner = inner275 def verify(self):276 return self._inner.verify()277 @cached_property278 def meta(self):279 return msgpack_decode(bytes(self._inner.get_meta_raw()))280 @meta.setter281 def meta(self, value: t.Any):282 self.__class__.meta.fget.cache_clear()283 self.__class__.meta_raw.fget.cache_clear()284 value = msgpack_encode(value)285 self._inner.set_meta_raw(value)286 @cached_property287 def meta_raw(self):288 return self._inner.get_meta_raw()289 @meta_raw.setter290 def meta_raw(self, value: bytes):291 self.__class__.meta.fget.cache_clear()292 self.__class__.meta_raw.fget.cache_clear()293 self._inner.set_meta_raw(value)294 @cached_property295 def content(self):296 return bytes(self._inner.get_content())297 @content.setter298 def content(self, value: bytes):299 self.__class__.content.fget.cache_clear()300 self._inner.set_content(value)301 def delete(self):302 self._inner.delete()303 @property304 def deleted(self):305 return self._inner.is_deleted()306 @property307 def missing_content(self):308 return self._inner.is_missing_content()309 @property310 def uid(self):311 return self._inner.get_uid()312 @property313 def etag(self):314 return self._inner.get_etag()315class UserProfile:316 def __init__(self, inner: etebase_python.UserProfile):317 self._inner = inner318 @property319 def pubkey(self):320 return bytes(self._inner.get_pubkey())321class InvitationListResponse:322 def __init__(self, inner: etebase_python.InvitationListResponse):323 self._inner = inner324 @cached_property325 def iterator(self):326 return self._inner.get_iterator()327 @property328 def data(self):329 return map(lambda x: SignedInvitation(x), self._inner.get_data())330 @cached_property331 def done(self):332 return self._inner.is_done()333class CollectionInvitationManager:334 def __init__(self, inner: etebase_python.CollectionInvitationManager):335 self._inner = inner336 def list_incoming(self, fetch_options: t.Optional[FetchOptions]=None):337 return InvitationListResponse(self._inner.list_incoming(_inner(fetch_options)))338 def list_outgoing(self, fetch_options: t.Optional[FetchOptions]=None):339 return InvitationListResponse(self._inner.list_outgoing(_inner(fetch_options)))340 def accept(self, signed_invitation: "SignedInvitation"):341 self._inner.accept(signed_invitation._inner)342 def reject(self, signed_invitation: "SignedInvitation"):343 self._inner.reject(signed_invitation._inner)344 def fetch_user_profile(self, username: str):345 return UserProfile(self._inner.fetch_user_profile(username))346 def invite(self, collection: Collection, username: str, pubkey: bytes, access_level: "CollectionAccessLevel"):347 self._inner.invite(collection._inner, username, pubkey, access_level)348 def disinvite(self, signed_invitation: "SignedInvitation"):349 self._inner.disinvite(signed_invitation._inner)350 @property351 def pubkey(self):352 return self._inner.get_pubkey()353class SignedInvitation:354 def __init__(self, inner: etebase_python.SignedInvitation):355 self._inner = inner356 @property357 def uid(self):358 return self._inner.get_uid()359 @property360 def username(self):361 return self._inner.get_username()362 @property363 def collection(self):364 return self._inner.get_collection()365 @property366 def access_level(self):367 return self._inner.get_access_level()368 @property369 def from_username(self):370 return self._inner.get_username()371 @property372 def from_pubkey(self):373 return bytes(self._inner.get_from_pubkey())374class CollectionMember:375 def __init__(self, inner: etebase_python.CollectionMember):376 self._inner = inner377 @property378 def username(self):379 return self._inner.get_username()380 @property381 def access_level(self):382 return self._inner.get_access_level()383class MemberListResponse:384 def __init__(self, inner: etebase_python.MemberListResponse):385 self._inner = inner386 @cached_property387 def iterator(self):388 return self._inner.get_iterator()389 @property390 def data(self):391 return map(lambda x: CollectionMember(x), self._inner.get_data())392 @cached_property393 def done(self):394 return self._inner.is_done()395class CollectionMemberManager:396 def __init__(self, inner: etebase_python.CollectionMemberManager):397 self._inner = inner398 def list(self, fetch_options: t.Optional[FetchOptions]=None):399 return MemberListResponse(self._inner.list(_inner(fetch_options)))400 def remove(self, username: str):401 self._inner.remove(username)402 def leave(self):403 self._inner.leave()404 def modify_access_level(self, username: str, access_level: CollectionAccessLevel):...
scad.py
Source:scad.py
1def cylinder(h, r1, r2=0, fn=40):2 def _inner(indent=0):3 nonlocal h4 nonlocal r15 nonlocal r26 if r2 == 0:7 r2 = r18 return ' ' * indent + f'cylinder(h={h}, r1={r1}, r2={r2}, $fn={fn});'9 return _inner10def cube(x, y, z):11 def _inner(indent=0):12 nonlocal x13 nonlocal y14 nonlocal z15 return ' ' * indent + f'cube([{x:.4f}, {y:.4f}, {z:.4f}]);'16 return _inner17def __iterate_children(children, indent):18 text = '{\n'19 for child in children:20 text += f'{child(indent + 1)}\n'21 text += ' ' * indent + '}'22 return text23def hull(children):24 def _inner(indent=0):25 nonlocal children26 text = ' ' * indent + 'hull()'27 return text + ' ' + __iterate_children(children, indent)28 return _inner29def union(children):30 def _inner(indent=0):31 nonlocal children32 text = ' ' * indent + 'union()'33 return text + ' ' + __iterate_children(children, indent)34 return _inner35def translate(x, y, z, children):36 def _inner(indent=0):37 nonlocal x38 nonlocal y39 nonlocal z40 nonlocal children41 text = ' ' * indent + f'translate([{x:.4f}, {y:.4f}, {z:.4f}])'42 return text + ' ' + __iterate_children(children, indent)43 return _inner44def rotate(x, y, z, children):45 def _inner(indent=0):46 nonlocal x47 nonlocal y48 nonlocal z49 nonlocal children50 text = ' ' * indent + f'rotate([{x:.4f}, {y:.4f}, {z:.4f}])'51 return text + ' ' + __iterate_children(children, indent)52 return _inner53def chamfered_cylinder(h, r, chamfer=0.5):54 def _inner(indent=0):55 nonlocal h56 nonlocal r57 nonlocal chamfer58 return union([59 cylinder(h - chamfer, r),60 translate(0, 0, h - chamfer, [61 cylinder(chamfer, r1=r, r2=r - chamfer)62 ])63 ])(indent)...
indexed_container.py
Source:indexed_container.py
1from collections.abc import Mapping, Sequence2class MappingWrapper:3 def __init__(self, mapping):4 self._inner = mapping5 def __iter__(self):6 return ((k, v) for k, v in self._inner.items())7 def __getitem__(self, loc):8 return self._inner[loc]9 def values(self):10 return (v for v in self._inner.values())11 def locs(self):12 return (k for k in self._inner.keys())13class SequenceWrapper:14 def __init__(self, sequence):15 self._inner = sequence16 def __iter__(self):17 return ((i, e) for i, e in enumerate(self._inner))18 def __getitem__(self, loc):19 return self._inner[loc]20 def values(self):21 return (e for e in self._inner)22 def locs(self):23 return (i for i in range(len(self._inner)))24class IndexedContainer(object):25 def __init__(self, container):26 self._inner = _wrap(container)27 def __getattribute__(self, attr_name):28 inner = object.__getattribute__(self, "_inner")29 if attr_name in inner.locs():30 item = inner[attr_name]31 try:32 return object.__class__(self)(item)33 except ValueError as _ve:34 return item35 raise AttributeError36 def __getitem__(self, loc):37 return self._get_inner_val(loc)38def _wrap(container):39 if isinstance(container, Mapping):40 return MappingWrapper(container)41 elif isinstance(container, Sequence):42 return SequenceWrapper(container)43 raise ValueError44def _get_wrapped_inner_val(loc):45 return IndexedContainer(self._get_inner_val(loc))46def _get_inner_val(loc):...
test_elasticsearch_util.py
Source:test_elasticsearch_util.py
...3 dataset_name = "Project Baseline"4 assert "project_baseline" == elasticsearch_util.convert_to_index_name(5 dataset_name)6def test_range_to_number():7 def _inner(range_str, expected_number):8 actual_number = elasticsearch_util.range_to_number(range_str)9 assert expected_number == actual_number10 _inner('0.1-0.2', 0.1)11 _inner('1', 1)12 _inner('10-20', 10)13 _inner('1.0M-1.9M', 1000000)14 _inner('10M-20M', 10000000)15 _inner('-20--10', -20)16 _inner('-10-0', -10)17def test_number_to_range():18 def _inner(interval_start, interval, expected_range):19 actual_range = elasticsearch_util.number_to_range(20 interval_start, interval)21 assert expected_range == actual_range22 _inner(.1, .1, '0.1-0.2')23 _inner(1, 1, '1')24 _inner(10, 10, '10-19')25 _inner(1000000, 1000000, '1.0M-1.9M')26 _inner(10000000, 10000000, '10M-19M')...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!