Best Python code snippet using localstack_python
__init__.py
Source:__init__.py  
...85    ###########################################################################################################86    # Authentication87    ###########################################################################################################88    def build_oauth_url(self, state, end_other_sessions=False):89        if self.api_client.is_v1():90            raise Exception()91        else:92            return intralinks.authenticators.v2.authentication.build_oauth_url(self.api_client, state, end_other_sessions)93    def validate_oauth_code(self, code):94        if self.api_client.is_v1():95            raise Exception()96        else:97            return intralinks.authenticators.v2.authentication.validate_oauth_code(self.api_client, code)98    def login(self, email, password, end_other_sessions=False, secure_id_callback=None):99        if self.api_client.is_v1():100            try:101                intralinks.authenticators.v1.authentication.login(self.api_client, email, password)102            except intralinks.authenticators.v1.authentication.AlreadyLoggedInException as e:103                if end_other_sessions:104                    intralinks.authenticators.v1.authentication.special_login(self.api_client, self.api_client.session.email, self.api_client.session.password, secure_id=None, end_other_sessions=True)105                else:106                    raise e1107            except intralinks.authenticators.v1.authentication.SecureIdRequiredException as e:108                if secure_id_callback:109                    secure_id = secure_id_callback()110                    intralinks.authenticators.v1.authentication.special_login(self.api_client, self.api_client.session.email, self.api_client.session.password, secure_id=secure_id, end_other_sessions=end_other_sessions)111            intralinks.authenticators.v1.authentication.get_flags(self.api_client)112        else:113            intralinks.authenticators.v2.authentication.login(self.api_client, email, password, end_other_sessions)114    115    def logout(self):116        if self.api_client.is_v1():117            return intralinks.authenticators.v1.authentication.logout(self.api_client)118        else:119            return intralinks.authenticators.v2.authentication.logout(self.api_client)120    ###########################################################################################################121    # User Accounts122    ###########################################################################################################123    def get_user_account(self, email, exchange=None):124        exchange_id = self._get_id(exchange)125        if self.api_client.is_v1() or self.use_v1:126            return intralinks.functions.v1.user_accounts.get_user_account(self.api_client, email, exchange_id)127        else:128            return self._retry(lambda: intralinks.functions.v2.user_accounts.get_user_account(self.api_client, email, exchange_id))129    def create_user_account(self, email, first_name, last_name, organization, phone, language):130        if self.api_client.is_v1() or self.use_v1:131            return intralinks.functions.v1.user_accounts.create_user_account(self.api_client, email, first_name, last_name, organization, phone, language)132        else:133            return intralinks.functions.v2.user_accounts.create_user_account(self.api_client, email, first_name, last_name, organization, phone, language)134    ###########################################################################################################135    # Exchanges136    ###########################################################################################################137    def get_exchanges(self, user=None, is_manager=None):138        user_id = self._get_id(user, 'userId')139        if self.api_client.is_v1() or self.use_v1:140            return intralinks.functions.v1.exchanges.get_exchanges(self.api_client, user_id=user_id, is_manager=is_manager)141        else:142            return self._retry(lambda: intralinks.functions.v2.exchanges.get_exchanges(self.api_client, user_id=user_id, is_manager=is_manager))143    def get_exchange(self, exchange):144        exchange_id = self._get_id(exchange)145        if self.api_client.is_v1() or self.use_v1:146            return intralinks.functions.v1.exchanges.get_exchange(self.api_client, exchange_id)147        else:148            return self._retry(lambda: intralinks.functions.v2.exchanges.get_exchange(self.api_client, exchange_id))149    150    def get_exchange_settings(self, exchange):151        exchange_id = self._get_id(exchange)152        if self.api_client.is_v1() or self.use_v1:153            return intralinks.functions.v1.exchanges.get_exchange_settings(self.api_client, exchange_id)154        else:155            raise Exception()156    def create_exchange(self, exchange, suppress_welcome_alert=True, update_param=True):157        if self.api_client.is_v1() or self.use_v1:158            result = intralinks.functions.v1.exchanges.create_exchange(self.api_client, exchange, suppress_welcome_alert)159        else:160            result = intralinks.functions.v2.exchanges.create_exchange(self.api_client, exchange, suppress_welcome_alert)161        if update_param:162            exchange = entity_to_dict(exchange)163            exchange.update(result)164            exchange['id'] = exchange.pop('workspaceId')165            return exchange166        else:167            return result168    169    def update_exchange(self, exchange, is_phase_updated=False):170        if self.api_client.is_v1() or self.use_v1:171            intralinks.functions.v1.exchanges.update_exchange(self.api_client, exchange, is_phase_updated)172        else:173            intralinks.functions.v2.exchanges.update_exchange(self.api_client, exchange, is_phase_updated)174        175        return exchange176    177    ###########################################################################################################178    # Splash179    ###########################################################################################################180    def get_splash(self, exchange):181        exchange_id = self._get_id(exchange)182        if self.api_client.is_v1() or self.use_v1:183            return intralinks.functions.v1.splashes.get_splash(self.api_client, exchange_id)184        else:185            return self._retry(lambda: intralinks.functions.v2.splashes.get_splash(self.api_client, exchange_id))186    187    def download_splash_image(self, exchange, path_without_extension):188        exchange_id = self._get_id(exchange)189        return intralinks.functions.v1.splashes.download_splash_image(self.api_client, exchange_id, path_without_extension)190    191    def enter_exchange(self, exchange, accept_splash=None):192        exchange_id = self._get_id(exchange)193        if self.api_client.is_v1() or self.use_v1:194            return intralinks.functions.v1.splashes.enter_exchange(self.api_client, exchange_id, accept_splash=accept_splash)195        else:196            return intralinks.functions.v2.splashes.enter_exchange(self.api_client, exchange_id, accept_splash=accept_splash)197    198    ###########################################################################################################199    # Folders200    ###########################################################################################################201    def get_folders(self, exchange):202        exchange_id = self._get_id(exchange)203        if self.api_client.is_v1() or self.use_v1:204            return intralinks.functions.v1.folders.get_folders(self.api_client, exchange_id)  205        else:  206            return self._retry(lambda: intralinks.functions.v2.folders.get_folders(self.api_client, exchange_id))207    208    def create_folder(self, exchange, folder, update_param=True):209        exchange_id = self._get_id(exchange)210        if self.api_client.is_v1() or self.use_v1:211            result = intralinks.functions.v1.folders.create_folder(self.api_client, exchange_id, folder)212        else:213            result = intralinks.functions.v2.folders.create_folder(self.api_client, exchange_id, folder)214        return self._update_param(folder, result, update_param)215    def create_folders(self, exchange, folders, update_param=True):216        exchange_id = self._get_id(exchange)217        result = None218        if self.api_client.is_v1() or self.use_v1:219            result = intralinks.functions.v1.folders.create_folders(self.api_client, exchange_id, folders)220        else:221            result = intralinks.functions.v2.folders.create_folders(self.api_client, exchange_id, folders)222        return self._update_param_as_list(folders, result, update_param)223    def update_folder(self, exchange, folder, update_param=True):224        exchange_id = self._get_id(exchange)225        if self.api_client.is_v1() or self.use_v1:226            result = intralinks.functions.v1.folders.update_folder(self.api_client, exchange_id, folder)227        else:228            result = intralinks.functions.v2.folders.update_folder(self.api_client, exchange_id, folder)229        230        return self._update_param(folder, result, update_param) 231    def delete_folder(self, exchange, folder):232        exchange_id = self._get_id(exchange)233        if self.api_client.is_v1() or self.use_v1:234            return intralinks.functions.v1.folders.delete_folder(self.api_client, exchange_id, folder)235        else:236            return intralinks.functions.v2.folders.delete_folder(self.api_client, exchange_id, folder)237    def delete_folders(self, exchange, folders):238        exchange_id = self._get_id(exchange)239        if self.api_client.is_v1() or self.use_v1:240            return intralinks.functions.v1.folders.delete_folders(self.api_client, exchange_id, folders)241        else:242            results = []243            for folder in folders:244                results.append(intralinks.functions.v2.folders.delete_folder(self.api_client, exchange_id, folder))245            return results246    ###########################################################################################################247    # Documents & Files248    ###########################################################################################################249    def get_documents(self, exchange):250        exchange_id = self._get_id(exchange)251        if self.api_client.is_v1() or self.use_v1:252            return intralinks.functions.v1.documents.get_documents(self.api_client, exchange_id)253        else:254            return self._retry(lambda: intralinks.functions.v2.documents.get_documents(self.api_client, exchange_id))255        256    def create_document(self, exchange, document, file=None, batch_id=None, update_param=True):257        exchange_id = self._get_id(exchange)258        if self.api_client.is_v1() or self.use_v1:259            result = intralinks.functions.v1.documents.create_document(self.api_client, exchange_id, document, file=file, batch_id=batch_id)260        else:261            result = intralinks.functions.v2.documents.create_document(self.api_client, exchange_id, document, batch_id=batch_id)262        263        return self._update_param(document, result, update_param)264    def create_documents(self, exchange, documents, batch_id=None):265        exchange_id = self._get_id(exchange)266        if self.api_client.is_v1() or self.use_v1:267            return intralinks.functions.v1.documents.create_documents(self.api_client, exchange_id, documents, batch_id)268        else:269            return intralinks.functions.v2.documents.create_documents(self.api_client, exchange_id, documents, batch_id)270    def download_file(self, exchange, document, file_path):271        exchange_id = self._get_id(exchange)272        document_id = self._get_id(document)273        if self.api_client.is_v1() or self.use_v1:274            raise Exception()275        else:276            return intralinks.functions.v2.documents.download_file(self.api_client, exchange_id, document_id, file_path)277    def upload_file(self, exchange, document, version, file_path):278        exchange_id = self._get_id(exchange)279        document_id = self._get_id(document)280        if self.api_client.is_v1() or self.use_v1:281            raise Exception()282        else:283            return intralinks.functions.v2.documents.upload_file(self.api_client, exchange_id, document_id, version, file_path)284    def update_document(self, exchange, document, update_param=True):285        exchange_id = self._get_id(exchange)286        if self.api_client.is_v1() or self.use_v1:287            result = intralinks.functions.v1.documents.update_document(self.api_client, exchange_id, document)288        else:289            result = intralinks.functions.v2.documents.update_document(self.api_client, exchange_id, document)290        291        return self._update_param(document, result, update_param)292    def delete_document(self, exchange, document):293        exchange_id = self._get_id(exchange)294        if self.api_client.is_v1() or self.use_v1:295            return intralinks.functions.v1.documents.delete_document(self.api_client, exchange_id, document)296        else:297            return intralinks.functions.v2.documents.delete_document(self.api_client, exchange_id, document)298    def delete_documents(self, exchange, documents):299        exchange_id = self._get_id(exchange)300        if self.api_client.is_v1() or self.use_v1:301            return intralinks.functions.v1.documents.delete_documents(self.api_client, exchange_id, documents)302        else:303            return intralinks.functions.v2.documents.delete_documents(self.api_client, exchange_id, documents)304    305    ###########################################################################################################306    # Exchange Members307    ###########################################################################################################308    def get_exchange_members(self, exchange):309        exchange_id = self._get_id(exchange)310        if self.api_client.is_v1() or self.use_v1:311            return intralinks.functions.v1.exchange_members.get_exchange_members(self.api_client, exchange_id)312        else:313            return self._retry(lambda: intralinks.functions.v2.exchange_members.get_exchange_members(self.api_client, exchange_id))314    def get_removed_exchange_members(self, exchange):315        exchange_id = self._get_id(exchange)316        return intralinks.functions.v1.exchange_members.get_removed_exchange_members(self.api_client, exchange_id)317    def create_exchange_member(self, exchange, exchange_member, alert=None, update_param=True):318        exchange_id = self._get_id(exchange)319        if self.api_client.is_v1() or self.use_v1:320            result = intralinks.functions.v1.exchange_members.create_exchange_member(self.api_client, exchange_id, exchange_member)321        else:322            result = intralinks.functions.v2.exchange_members.create_exchange_member(self.api_client, exchange_id, exchange_member, alert)323        324        if update_param:325            if isinstance(exchange_member, tuple):326                exchange_member = entity_to_dict(exchange_member)327            328            user = exchange_member.pop('user')329            if isinstance(user, tuple):330                user = entity_to_dict(user)331            332            exchange_member.update(user)333            exchange_member['emailId'] = result.pop('email')334            exchange_member.update(result)335            return exchange_member336        else:337            return result338    def update_exchange_member(self, exchange, exchange_member, update_param=True):339        exchange_id = self._get_id(exchange)340        if self.api_client.is_v1() or self.use_v1:341            result = intralinks.functions.v1.exchange_members.update_exchange_member(self.api_client, exchange_id, exchange_member)342        else:343            result = intralinks.functions.v2.exchange_members.update_exchange_member(self.api_client, exchange_id, exchange_member)344        345        return self._update_param(exchange_member, result, update_param)346    def delete_exchange_member(self, exchange, exchange_member):347        exchange_id = self._get_id(exchange)348        id = exchange_member['id']349        version = exchange_member['version']350        if self.api_client.is_v1() or self.use_v1:351            return intralinks.functions.v1.exchange_members.delete_exchange_member(self.api_client, exchange_id, id, version)352        else:353            return intralinks.functions.v2.exchange_members.delete_exchange_member(self.api_client, exchange_id, id, version)354    def delete_exchange_members(self, exchange, exchange_members):355        exchange_id = self._get_id(exchange)356        if self.api_client.is_v1() or self.use_v1:357            return intralinks.functions.v1.exchange_members.delete_exchange_members(self.api_client, exchange_id, exchange_members)358        else:359            raise Exception()360    ###########################################################################################################361    # Groups362    ###########################################################################################################363    def get_groups(self, exchange):364        exchange_id = self._get_id(exchange)365        if self.api_client.is_v1() or self.use_v1:366            return intralinks.functions.v1.groups.get_groups(self.api_client, exchange_id)367        else:368            return self._retry(lambda: intralinks.functions.v2.groups.get_groups(self.api_client, exchange_id))369    370    def get_groups_and_members(self, exchange):371        exchange_id = self._get_id(exchange)372        if self.api_client.is_v1() or self.use_v1:373            return intralinks.functions.v1.groups.get_groups_and_members(self.api_client, exchange_id)374        else:375            return self._retry(lambda: intralinks.functions.v2.groups.get_groups_and_members(self.api_client, exchange_id))376    377    def create_group(self, exchange, group, update_param=True):378        exchange_id = self._get_id(exchange)379        if self.api_client.is_v1() or self.use_v1:380            result = intralinks.functions.v1.groups.create_group(self.api_client, exchange_id, group)381        else:382            result = intralinks.functions.v2.groups.create_group(self.api_client, exchange_id, group)383        384        return self._update_param(group, result, update_param)385    def update_group(self, exchange, group, remove_group_members=None, add_group_members=None, update_param=True):386        exchange_id = self._get_id(exchange)387        if self.api_client.is_v1() or self.use_v1:388            result = intralinks.functions.v1.groups.update_group(self.api_client, exchange_id, group, remove_group_members=remove_group_members, add_group_members=add_group_members)389        else:390            result = intralinks.functions.v2.groups.update_group(self.api_client, exchange_id, group, remove_group_members=remove_group_members, add_group_members=add_group_members)391        392        return self._update_param(group, result, update_param) 393    def delete_group(self, exchange, group, remove_users=False):394        exchange_id = self._get_id(exchange)395        id = group['id']396        version = group['version']397        if self.api_client.is_v1() or self.use_v1:398            return intralinks.functions.v1.groups.delete_group(self.api_client, exchange_id, id, version, remove_users)399        else:400            return intralinks.functions.v2.groups.delete_group(self.api_client, exchange_id, id, version, remove_users)401    def delete_groups(self, exchange, groups, remove_users=False):402        exchange_id = self._get_id(exchange)403        results = []404        for group_sublist in intralinks.utils.data.chunks(groups, intralinks.functions.validations.GROUP_MAX_ENTITY_COUNT_DELETE):405            if self.api_client.is_v1() or self.use_v1:406                result = intralinks.functions.v1.groups.delete_groups(self.api_client, exchange_id, group_sublist, remove_users)407            else:408                result = intralinks.functions.v2.groups.delete_groups(self.api_client, exchange_id, group_sublist, remove_users)409            410            results.append(result)411        412        return results413    ###########################################################################################################414    # Group Members415    ###########################################################################################################416    def add_member_to_group(self, exchange, group, exchange_member):417        exchange_id = self._get_id(exchange)418        group_id = self._get_id(group)419        exchange_member_id = self._get_id(exchange_member)420        if self.api_client.is_v1() or self.use_v1:421            return intralinks.functions.v1.groups.add_member_to_group(self.api_client, exchange_id, group_id, exchange_member_id)422        else:423            return intralinks.functions.v2.groups.create_group_member(self.api_client, exchange_id, group_id, exchange_member_id)424    425    def add_member_from_group(self, exchange, group, exchange_member):426        exchange_id = self._get_id(exchange)427        group_id = self._get_id(group)428        exchange_member_id = self._get_id(exchange_member)429        if self.api_client.is_v1() or self.use_v1:430            return intralinks.functions.v1.groups.remove_member_from_group(self.api_client, exchange_id, group_id, exchange_member_id)431        else:432            return intralinks.functions.v2.groups.create_group_member(self.api_client, exchange_id, group_id, exchange_member_id)433    ###########################################################################################################434    # Bulk Upload435    ###########################################################################################################436    def get_bulk_uploads(self, exchange):437        exchange_id = self._get_id(exchange)438        if self.api_client.is_v1() or self.use_v1:439            raise Exception()440        else:441            return self._retry(lambda: intralinks.functions.v2.batches.get_batches(self.api_client, exchange_id, operation_type='Bulk Upload'))442    443    def get_bulk_upload_items(self, exchange, bulk_upload_id):444        exchange_id = self._get_id(exchange)445        if self.api_client.is_v1() or self.use_v1:446            raise Exception()447        else:448            return self._retry(lambda: intralinks.functions.v2.batches.get_batch_items(self.api_client, exchange_id, bulk_upload_id))449    450    def get_permissions(self, exchange, document):451        exchange_id = self._get_id(exchange)452        document_id = self._get_id(document)453        if self.api_client.is_v1() or self.use_v1:454            raise Exception()455        else:456            return self._retry(lambda: intralinks.functions.v2.permissions.get_permissions(self.api_client, exchange_id, document_id))457    458    def get_access_statuses(self, exchange, document):459        exchange_id = self._get_id(exchange)460        document_id = self._get_id(document)461        if self.api_client.is_v1() or self.use_v1:462            return intralinks.functions.v1.documents.get_access_statuses(self.api_client, exchange_id, document_id)463        else:464            return self._retry(lambda: intralinks.functions.v2.documents.get_access_statuses(self.api_client, exchange_id, document_id))465    466    def get_custom_alerts(self, resource_type, resource_id, alert_type, alert_locale=None):467        return intralinks.functions.v1.custom_alerts.get_custom_alerts(self.api_client, resource_type, resource_id, alert_type, alert_locale)468    469    def get_field_definitions(self, exchange):470        exchange_id = self._get_id(exchange)471        if self.api_client.is_v1() or self.use_v1:472            return intralinks.functions.v1.fields.get_field_definitions(self.api_client, exchange_id)473        else:474            return self._retry(lambda: intralinks.functions.v2.fields.get_field_definitions(self.api_client, exchange_id))475def new_client(base_url, session_token=None):476    config = intralinks.api.v2.Config(477        base_url478    )479    session = intralinks.api.v2.Session(480        session_token481    )482    api_client = intralinks.api.ApiClient(config, session)...ZigZagIterator.py
Source:ZigZagIterator.py  
1"""2Given two 1d vectors, implement an iterator to return their elements alternately.3Example:4Input:5v1 = [1,2]6v2 = [3,4,5,6] 7Output: [1,3,2,4,5,6]8Explanation: By calling next repeatedly until hasNext returns false, 9             the order of elements returned by next should be: [1,3,2,4,5,6].10Follow up: What if you are given k 1d vectors? How well can your code be extended to such cases?11Clarification for the follow up question:12The "Zigzag" order is not clearly defined and is ambiguous for k > 2 cases. If "Zigzag" does not look right to you, replace "Zigzag" with "Cyclic". For example:13Input:14[1,2,3]15[4,5,6,7]16[8,9]17Output: [1,4,8,2,5,9,3,6,7].18"""19class ZigzagIterator(object):20    def __init__(self, v1, v2):21        """22        Initialize your data structure here.23        :type v1: List[int]24        :type v2: List[int]25        """26        self.v1 = collections.deque(v1)27        self.v2 = collections.deque(v2)28        self.is_v1 = True29        30    def next(self):31        """32        :rtype: int33        """34        val = None35        if self.is_v1:36            if len(self.v1) > 0:37                val = self.v1.popleft()38            else:39                val = self.v2.popleft()40        else:41            if len(self.v2) > 0:42                val = self.v2.popleft()43            else:44                val = self.v1.popleft()45        46        self.is_v1 = not self.is_v147        return val48                49        50    def hasNext(self):51        """52        :rtype: bool53        """54        if len(self.v1) == 0 and len(self.v2) == 0:55            return False56        else:57            return True58        59# Your ZigzagIterator object will be instantiated and called as such:60# i, v = ZigzagIterator(v1, v2), []...rhythmic_pattern.py
Source:rhythmic_pattern.py  
1import ast2class RhythmicPattern:3    def __init__(self, pattern, frequency, is_v1):4        # Converts a string in the format of a list to an actual list object5        self.pattern = pattern6        self.frequency = frequency7        if type(self.pattern) is list:8            self.length = len(self.pattern)9            self.beats = _get_beats_length(str(pattern))10        else:11            self.pattern = len(ast.literal_eval(self.pattern))12            self.beats = _get_beats_length(pattern)13        self.is_v1 = is_v114    def __str__(self):15        return f"Pattern: {self.pattern} \nFrequency: {self.frequency} \nLength: {self.length} \nBeats: {self.beats}\nIs V1: {self.is_v1}\n"16def _get_beats_length(pattern):17    length = 018    to_count = True19    # counts the length of each bar within the combined pattern20    for char in pattern:21        if char == '(':22            to_count = False23        # if its a digit, then check if to_count is true (to_count will be false if its a rest's beat)24        if char.isdigit() and to_count:25            length += 126        elif char.isdigit() and not to_count:27            to_count = True...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!!
