Best Python code snippet using localstack_python
caffe2parrots
Source:caffe2parrots  
...58                self._net_dict['params'].append(59                            {'id': k.strip('@'), 'learning-policy': v }60                    )61    @staticmethod62    def _parse_blob(blob):63        flat_data = np.array(blob.data)64        sp = list(blob.shape.dim)65        if len(sp) == 0:66            sp = [blob.num, blob.channels, blob.height, blob.width]67        shaped_data = flat_data.reshape(sp)68        return shaped_data69    @staticmethod70    def _parse_filer(filler, param=None):71        lr = param['lr_mult'] if param and 'lr_mult' in param else 172        decay = param['decay_mult'] if param and 'decay_mult' in param else 173        if filler.type == "xavier":74            return {"init": "xavier()", "lr_mult":lr, "decay_mult":decay}75        elif filler.type == "gaussian":76            return {"init": "gauss({})".format(filler.std), "lr_mult":lr, "decay_mult":decay}77        elif filler.type == "constant":78            return {"init": "fill({})".format(filler.value), "lr_mult":lr, "decay_mult":decay}79        else:80            raise NotImplemented81    def _layer2dict(self, layer, version):82        attr_dict = {}83        params = []84        weight_params = []85        fillers = []86        for field, value in layer.ListFields():87            if field.name == 'top':88                tops = [v.replace('-', '_').replace('/', '_') for v in value]89            elif field.name == 'name':90                layer_name = str(value).replace('-', '_').replace('/', '_')91            elif field.name == 'bottom':92                bottoms = [v.replace('-', '_').replace('/', '_') for v in value]93            elif field.name == 'include':94                if value[0].phase == 1 and op == 'Data':95                    print 'found 1 testing data layer'96                    return None, dict(), dict(), False97            elif field.name == 'type':98                if version == 2:99                    op = value100                else:101                    raise NotImplemented102            elif field.name == 'param':103                params = [{k.name: v for k, v in x.ListFields()} for x in value]104            elif field.name == 'loss_weight':105                pass106            else:107                # other params108                try:109                    for f, v in value.ListFields():110                        if 'filler' in f.name:111                          continue112                        elif f.name == 'pool':113                          attr_dict['mode'] = 'max' if v == 0 else 'ave'114                        else:115                          attr_dict[f.name] = v116                    ## get filler options117                    fillers = filter(lambda x: 'filler' in x[0].name, value.ListFields())118                except:119                    print field.name, value120                    raise121        expr_temp = '{top} = {op}({input}{params})'122        if op == 'BN' and len(params) <= 2:123            # special treatment for BN's params124            params.append({})125        if op == 'Data':126            return tops, dict(), dict(), True127        else:128            # attach weights129            if layer.name in self._weight_dict:130                blobs = self._weight_dict[layer.name].blobs131            else:132                blobs = []133            blob_dict = {}134            init_dict = {}135            if len(params) == 0:136                param_str = ''137            else:138                param_str_list = []139                for i, p in enumerate(params):140                    if 'name' in p:141                        param_str_list.append('@' + p['name'].replace('/', '_'))142                    else:143                        param_str_list.append('@{}_{}'.format(layer_name, i))144                    if i < len(blobs):145                        blob_dict[param_str_list[i]] = self._parse_blob(blobs[i])146                        if op == 'BN' and i == 2:147                            # concatenate the mean and std into a single param148                            blob_dict[param_str_list[i]] = np.concatenate((self._parse_blob(blobs[i]).ravel(), self._parse_blob(blobs[i+1]).ravel()))149                    if i < len(fillers):150                        init_dict[param_str_list[i]] = self._parse_filer(fillers[i][1], p)151                param_str = ', ' + ','.join(param_str_list)152            expr = expr_temp.format(top=','.join(tops), input=','.join(bottoms), op=op,153                                    params=param_str)154            out_dict = {155                'id': layer_name,156                'expr': expr,157            }158            if len(attr_dict) > 0:159                out_dict['attrs'] = attr_dict160            return out_dict, blob_dict, init_dict, False161    @property162    def text_form(self):...xpass
Source:xpass  
...65        else:66            line = line.lstrip()67            parts = line.split("=")68            keychains[-1]["attributes"][parts[0]] = parts[1]69    def _parse_blob(content):70        return content[1:-1]71    def _parse_timedate(content):72        content = content.split("  ")[-1][1:-6]73        timedate = time.strptime(content, "%Y%m%d%H%M%S")74        return time.strftime("%Y-%m-%d %H:%M:%S", timedate)75    data = []76    for keychain in keychains:77        account = keychain.get("attributes", {}).get('"acct"<blob>', "")78        if _parse_blob(account) != LOGIN:79            continue80        if _parse_blob(keychain["attributes"]['"desc"<blob>']) != DESC:81            continue82        name = _parse_blob(keychain["attributes"]['"svce"<blob>'])83        mtime = _parse_timedate(keychain["attributes"]['"mdat"<timedate>'])84        data.append([name, mtime])85    print(tabulate(data, headers=["Name", "Date Modified"]))86@cli.command87def list():88    commands = [89        "security",90        "dump-keychain",91    ]92    proc = run_command(commands, capture_output=True)93    format_security_output(proc)94@cli.command95@click.argument("name")96def find(name):...parse_md_supplement.py
Source:parse_md_supplement.py  
...13def parse_markdown_supplement(data, filename):14    """Parse a supplemental markdown file. Returns a dict. """15    # Possible top-level headings:16    possible_h1s = ['description', 'jsonpayload', 'property_details', 'action_details']17    parsed = _parse_blob(data, marker='#--', filename=filename, limit_headings=possible_h1s)18    if parsed.get('property_details'):19        parsed['property_details'] = _parse_blob(parsed['property_details'], filename=filename, marker="##--")20    if parsed.get('action_details'):21        parsed['action_details'] = _parse_blob(parsed['action_details'], filename=filename, marker="##--")22    return parsed23def _parse_blob(blob, marker='#--', filename=None, limit_headings=None):24    marker_len = len(marker)25    text = []26    current_item = None27    parsed = {}28    # First pass: split into chunks by main heading:29    for raw_line in blob.splitlines():30        line = raw_line.strip('\r\n') # Keep other whitespace31        if line.startswith(marker):32            if current_item:33                current_content = '\n'.join(text)34                parsed[current_item] = current_content.strip()35            text = []36            next_item = line[marker_len:].strip()37            if limit_headings and next_item not in limit_headings:...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!!
