:type retry_request_substr_variants: list Список вхождений строк, при налиции которых в ошибке апи будет произведен повторный запрос к апи
976032
def check_err(resp, analyze_json_error_param=False, retry_request_substr_variants=None):
        
        if retry_request_substr_variants is None:
            retry_request_substr_variants = []

        # РКН блокировки вызывают ошибку SSL
        retry_request_substr_variants.append("TLSV1_ALERT_ACCESS_DENIED")

        if resp.status_code in [502, 503, 504]:
            raise RetryHttpRequestError(resp.text)

        if resp.status_code >= 400:
            rtext = resp.text
            for v_ in retry_request_substr_variants:
                if v_ in rtext:
                    raise RetryHttpRequestError(rtext)
            raise UnexpectedError("HTTP request failed: {} {}".format(resp.status_code, rtext))
        if analyze_json_error_param:
            data_ = resp.json()
            if 'error' in data_ and data_.get('error'):
                error = data_.get('error')
                full_err_ = json.dumps(error)

                if error.get("type") == "RateLimitError":
                    raise RateLimitError(error.get("message"), waiting_time=error.get("waiting_time"))

                for v_ in retry_request_substr_variants:
                    if v_ in full_err_:
                        raise RetryHttpRequestError(full_err_)
                raise ApiProxyError(full_err_)
        return resp
396973
function items2models(items, params) {
        // приводим к формату №2
        if (typeof items === 'string') {
            items = [ items ];
        }

        // приводим №2 к формату №3
        if (typeof items[0] === 'string') {
            params = params || {};
            items = normalizeItems(items, params);
        }

        var models = [];
        for (var i = 0, l = items.length; i < l; i++) {
            var item = items[i];
            // ns.request( [ ModelInstance ] )
            if (item instanceof ns.Model) {
                models.push(item);

            } else if (item.model && item.model instanceof ns.Model) {
                models.push(item.model);

            } else {
                models.push(ns.Model.get(item.id, item.params));
            }
        }

        return models;
    }
724430
def base_recherche_rapide(self, base, pattern, to_string_hook=None):
        
        Ac = self.ACCES
        if pattern == "*":
            return groups.Collection(Ac(base, i) for i in self)

        if len(pattern) >= MIN_CHAR_SEARCH:  # Needed chars.
            sub_patterns = pattern.split(" ")
            try:
                regexps = tuple(re.compile(sub_pattern, flags=re.I)
                                for sub_pattern in sub_patterns)
            except re.error:
                return groups.Collection()

            def search(string):
                for regexp in regexps:
                    if not regexp.search(string):
                        return False
                return True

            to_string_hook = to_string_hook or self._record_to_string
            return groups.Collection(Ac(base, i) for i, p in self.items() if search(to_string_hook(p)))

        return groups.Collection()
434980
function parse_BrtCellError(data, length) {
	var cell = parse_XLSBCell(data);
	var bError = data.read_shift(1);
	return [cell, bError, 'e'];
}
1305357
def ensembl_request(self, ext, headers):
        
        
        self.attempt += 1
        if self.attempt > 5:
            raise ValueError("too many attempts, figure out why its failing")
        
        response, status, requested_headers = self.open_url(self.server + ext, headers=headers)
        
        # we might end up passing too many simultaneous requests, or too many
        # requests per hour, just wait until the period is finished before
        # retrying
        if status == 429:
            if "retry-after" in requested_headers:
                time.sleep(float(requested_headers["retry-after"]))
            elif "x-ratelimit-reset" in requested_headers:
                time.sleep(int(requested_headers["x-ratelimit-reset"]))
            
            return self.ensembl_request(ext, headers)
        # retry after 30 seconds if we get service unavailable error
        elif status in [500, 503, 504]:
            time.sleep(30)
            return self.ensembl_request(ext, headers)
        elif status != 200:
            raise ValueError("Invalid Ensembl response for {}\nheaders: {}\nresponse: {}".format(\
                    self.server + ext, requested_headers, response))
        
        # sometimes ensembl returns odd data. I don't know what it is, but the
        # json interpreter can't handle it. Rather than trying to catch it,
        # simply re-request the data
        if requested_headers["content-type"] == "application/json":
            try:
                json.loads(response)
            except ValueError:
                now = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
                logging.warning("{}\t{}\t{}\t{}\t{}".format(now,
                    status, self.server + ext,
                    "cannot obtain json output"))
                return self.ensembl_request(ext, requested_headers)
        
        self.cache.cache_url_data(self.server + ext, response)
        
        return response
754760
function subUpdate (req) {
  return [ req.params.service + '/' + req.params.subresources, fp.parseNil(req.params.id), req.body ];
}
454157
def list_prefix(arg, opts, shell_opts):
    

    search_string = ''
    if type(arg) == list or type(arg) == tuple:
        search_string = ' '.join(arg)

    v = get_vrf(opts.get('vrf_rt'), default_var='default_list_vrf_rt', abort=True)

    if v.rt == 'all':
        vrf_text = 'any VRF'
        vrf_q = None
    else:
        vrf_text = vrf_format(v)
        vrf_q = {
            'operator': 'equals',
            'val1': 'vrf_rt',
            'val2': v.rt
        }
    print("Searching for prefixes in %s..." % vrf_text)

    col_def = {
            'added': { 'title': 'Added' },
            'alarm_priority': { 'title': 'Alarm Prio' },
            'authoritative_source': { 'title': 'Auth source' },
            'children': { 'title': 'Children' },
            'comment': { 'title': 'Comment' },
            'customer_id': { 'title': 'Customer ID' },
            'description': { 'title': 'Description' },
            'expires': { 'title': 'Expires' },
            'free_addresses': { 'title': 'Free addresses' },
            'monitor': { 'title': 'Monitor' },
            'last_modified': { 'title': 'Last mod' },
            'node': { 'title': 'Node' },
            'order_id': { 'title': 'Order ID' },
            'pool_name': { 'title': 'Pool name' },
            'prefix': { 'title': 'Prefix' },
            'status': { 'title': 'Status' },
            'tags': { 'title': '#' },
            'total_addresses': { 'title': 'Total addresses' },
            'type': { 'title': '' },
            'used_addresses': { 'title': 'Used addresses' },
            'vlan': { 'title': 'VLAN' },
            'vrf_rt': { 'title': 'VRF RT' },
            }
    # default columns
    columns = [ 'vrf_rt', 'prefix', 'type', 'tags', 'node', 'order_id', 'customer_id', 'description' ]

    # custom columns? prefer shell opts, then look in config file
    custom_columns = None
    if shell_opts.columns and len(shell_opts.columns) > 0:
        custom_columns = shell_opts.columns
    elif cfg.get('global', 'prefix_list_columns'):
        custom_columns = cfg.get('global', 'prefix_list_columns')

    # parse custom columns
    if custom_columns:
        # Clear out default columns, unless user whishes to append
        if custom_columns[0] != '+':
            columns = []

        # read in custom columns
        for col in list(csv.reader([custom_columns.lstrip('+') or ''], escapechar='\\'))[0]:
            col = col.strip()
            if col not in col_def:
                print("Invalid column:", col, file=sys.stderr)
                sys.exit(1)
            columns.append(col)

    offset = 0
    # small initial limit for "instant" result
    limit = 50
    prefix_str = ""
    while True:
        res = Prefix.smart_search(search_string, { 'parents_depth': -1,
            'include_neighbors': True, 'offset': offset, 'max_result': limit },
            vrf_q)

        if offset == 0: # first time in loop?
            if shell_opts.show_interpretation:
                print("Query interpretation:")
                _parse_interp_prefix(res['interpretation'])

            if res['error']:
                print("Query failed: %s" % res['error_message'])
                return

            if len(res['result']) == 0:
                print("No addresses matching '%s' found." % search_string)
                return

            # guess column width by looking at the initial result set
            for p in res['result']:
                for colname, col in col_def.items():
                    val = getattr(p, colname, '')
                    col['width'] = max(len(colname), col.get('width', 0),
                                       len(str(val)))

                # special handling of a few columns
                col_def['vrf_rt']['width'] = max(col_def['vrf_rt'].get('width', 8),
                                                 len(str(p.vrf.rt)))
                col_def['prefix']['width'] = max(col_def['prefix'].get('width', 0)-12,
                                                 p.indent * 2 + len(p.prefix)) + 12
                try:
                    col_def['pool_name']['width'] = max(col_def['pool_name'].get('width', 8),
                                                        len(str(p.pool.name)))
                except:
                    pass
            # override certain column widths
            col_def['type']['width'] = 1
            col_def['tags']['width'] = 2

            col_header_data = {}
            # build prefix formatting string
            for colname, col in [(k, col_def[k]) for k in columns]:
                prefix_str += "{%s:<%d}  " % (colname, col['width'])
                col_header_data[colname] = col['title']

            column_header = prefix_str.format(**col_header_data)
            print(column_header)
            print("".join("=" for i in range(len(column_header))))

        for p in res['result']:
            if p.display == False:
                continue

            col_data = {}
            try:
                for colname, col in col_def.items():
                    col_data[colname] = str(getattr(p, colname, None))

                # overwrite some columns due to special handling
                col_data['tags'] = '-'
                if len(p.tags) > 0:
                    col_data['tags'] = '#%d' % len(p.tags)

                try: 
                    col_data['pool_name'] = p.pool.name
                except:
                    pass

                col_data['prefix'] = "".join("  " for i in range(p.indent)) + p.display_prefix
                col_data['type'] = p.type[0].upper()
                col_data['vrf_rt'] = p.vrf.rt or '-'

                print(prefix_str.format(**col_data))

            except UnicodeEncodeError as e:
                print("\nCrazy encoding for prefix %s\n" % p.prefix, file=sys.stderr)

        if len(res['result']) < limit:
            break
        offset += limit

        # let consecutive limit be higher to tax the XML-RPC backend less
        limit = 200
522931
def get_listing_from_response(self, resp) -> typing.Iterable[typing.Tuple[str, dict]]:
        
        raise NotImplementedError()
960121
protected function adaptSourcesSearchPhrases()
    {
        $dataArray = [];

        //Формируем массив
        foreach ($this->data['data'] as $item) {
            $dataArray['data'][] = [
                'searchPhrase'            => $item['dimensions'][0]['name'],
                'searchEngineRoot'        => $item['dimensions'][1]['name'],
                'visits'                  => $item['metrics'][0],
                //Визиты
                'bounceRate'              => $item['metrics'][1],
                //Отказы %
                'pageDepth'               => $item['metrics'][2],
                //Глубина просмотра
                'avgVisitDurationSeconds' => date("i:s", $item['metrics'][3])
                //Время проведенное на сайте мин:сек.
            ];
        }

        //Итого и средние значения
        $dataArray['totals'] = [
            'visits'                  => $this->data['totals'][0],
            'bounceRate'              => $this->data['totals'][1],
            'pageDepth'               => $this->data['totals'][2],
            'avgVisitDurationSeconds' => date("i:s", $this->data['totals'][3]),
        ];

        $this->adaptData = $dataArray;
    }
258412
def request_error!(exception)
      case exception
      when HTTP::Request::UnsupportedSchemeError, Addressable::URI::InvalidURIError
        raise Down::InvalidUrl, exception.message
      when HTTP::ConnectionError
        raise Down::ConnectionError, exception.message
      when HTTP::TimeoutError
        raise Down::TimeoutError, exception.message
      when HTTP::Redirector::TooManyRedirectsError
        raise Down::TooManyRedirects, exception.message
      when OpenSSL::SSL::SSLError
        raise Down::SSLError, exception.message
      else
        raise exception
      end
    end
1362128
def _get_query_parts(self, query_str, search_options=None):
        

        if search_options is None:
            search_options = {}

        if query_str is None:
            raise NipapValueError("'query_string' must not be None")

        # find query parts
        query_str_parts = []
        try:
            for part in shlex.split(query_str.encode('utf-8')):
                query_str_parts.append({ 'string': part.decode('utf-8') })
        except ValueError as exc:
            if unicode(exc) == 'No closing quotation':
                raise NipapValueError(unicode(exc))
            raise exc

        # Handle empty search.
        # We need something to iterate over, but shlex.split() returns
        # zero-element list for an empty string, so we have to append one
        # manually
        if len(query_str_parts) == 0:
            query_str_parts.append({ 'string': '' })

        return query_str_parts
68603
def collapse_substrings(variant_sequences):
    
    if len(variant_sequences) <= 1:
        # if we don't have at least two VariantSequences then just
        # return your input
        return variant_sequences

    # dictionary mapping VariantSequence objects to lists of reads
    # they absorb from substring VariantSequences
    extra_reads_from_substrings = defaultdict(set)
    result_list = []
    # sort by longest to shortest total length
    for short_variant_sequence in sorted(
            variant_sequences,
            key=lambda seq: -len(seq)):
        found_superstring = False
        for long_variant_sequence in result_list:
            found_superstring = long_variant_sequence.contains(short_variant_sequence)
            if found_superstring:
                extra_reads_from_substrings[long_variant_sequence].update(
                    short_variant_sequence.reads)
        if not found_superstring:
            result_list.append(short_variant_sequence)
    # add to each VariantSequence the reads it absorbed from dropped substrings
    # and then return
    return [
        variant_sequence.add_reads(
            extra_reads_from_substrings[variant_sequence])
        for variant_sequence in result_list
    ]
104699
def helpful_error_list_get(lst, index):
    
    try:
        return lst[index]
    except IndexError:
        raise IndexError('Tried to access %r, length is only %r' % (index, len(lst)))
1298567
def list_prefix(self):
        

        # fetch attributes from request.json
        attr = XhrController.extract_prefix_attr(request.json)

        try:
            prefixes = Prefix.list(attr)
        except NipapError, e:
            return json.dumps({'error': 1, 'message': e.args, 'type': type(e).__name__})

        return json.dumps(prefixes, cls=NipapJSONEncoder)
853671
def rl_quotes(x):
    
    
    patterns = (
        # открывающие кавычки ставятся обычно вплотную к слову слева
        # а закрывающие -- вплотную справа
        # открывающие русские кавычки-ёлочки
        (re.compile(r'((?:^|\s))(")((?u))', re.UNICODE), u'\\1\xab\\3'),
        # закрывающие русские кавычки-ёлочки
        (re.compile(r'(\S)(")((?u))', re.UNICODE), u'\\1\xbb\\3'),
        # открывающие кавычки-лапки, вместо одинарных кавычек
        (re.compile(r'((?:^|\s))(\')((?u))', re.UNICODE), u'\\1\u201c\\3'),
        # закрывающие кавычки-лапки
	(re.compile(r'(\S)(\')((?u))', re.UNICODE), u'\\1\u201d\\3'),
    )
    return _sub_patterns(patterns, x)
932292
def _raise_redirect_exceptions(response):
    
    if response.status_code not in [301, 302, 307]:
        return None
    new_url = urljoin(response.url, response.headers['location'])
    if 'reddits/search' in new_url:  # Handle non-existent subreddit
        subreddit = new_url.rsplit('=', 1)[1]
        raise InvalidSubreddit('`{0}` is not a valid subreddit'
                               .format(subreddit))
    elif not RE_REDIRECT.search(response.url):
        raise RedirectException(response.url, new_url)
    return new_url
4496
def subst_src_suffixes(self, env):
        
        memo_key = id(env)
        try:
            memo_dict = self._memo['subst_src_suffixes']
        except KeyError:
            memo_dict = {}
            self._memo['subst_src_suffixes'] = memo_dict
        else:
            try:
                return memo_dict[memo_key]
            except KeyError:
                pass
        suffixes = [env.subst(x) for x in self.src_suffix]
        memo_dict[memo_key] = suffixes
        return suffixes