Return appropriate QualysGuard API call.
486644
def format_payload(self, api_version, data):
        
        # Check if payload is for API v1 or API v2.
        if (api_version in (1, 2)):
            # Check if string type.
            if type(data) == str:
                # Convert to dictionary.
                logger.debug('Converting string to dict:\n%s' % data)
                # Remove possible starting question mark & ending ampersands.
                data = data.lstrip('?')
                data = data.rstrip('&')
                # Convert to dictionary.
                data = parse_qs(data)
                logger.debug('Converted:\n%s' % str(data))
        elif api_version in ('am', 'was', 'am2'):
            if type(data) == etree._Element:
                logger.debug('Converting lxml.builder.E to string')
                data = etree.tostring(data)
                logger.debug('Converted:\n%s' % data)
        return data
230334
def _get_results_from_api(identifiers, endpoints, api_key, api_secret):
    """"""

    if api_key is not None and api_secret is not None:
        client = housecanary.ApiClient(api_key, api_secret)
    else:
        client = housecanary.ApiClient()

    wrapper = getattr(client, endpoints[0].split('/')[0])

    if len(endpoints) > 1:
        # use component_mget to request multiple endpoints in one call
        return wrapper.component_mget(identifiers, endpoints)
    else:
        return wrapper.fetch_identifier_component(endpoints[0], identifiers)
159554
def apize_raw(url, method='GET'):
	
	def decorator(func):
		def wrapper(*args, **kwargs):
			elem = func(*args, **kwargs)

			if type(elem) is not dict:
				raise BadReturnVarType(func.__name__)

			response = send_request(url, method, 
				elem.get('data', {}),
				elem.get('args', {}),
				elem.get('params', {}),
				elem.get('headers', {}),
				elem.get('cookies', {}),
				elem.get('timeout', 8),
				elem.get('is_json', False),
				elem.get('verify_cert', True)
			)

			return response
		return wrapper

	return decorator
266161
def _gql(cls, query_string, *args, **kwds):
    """"""
    from .query import gql  # Import late to avoid circular imports.
    return gql('SELECT * FROM %s %s' % (cls._class_name(), query_string),
               *args, **kwds)
1261565
def _call(self, x, out=None):
        """"""
        if self.domain.is_real:
            return self._call_real(x, out)

        elif self.domain.is_complex:
            result_parts = [
                self._call_real(x.real, getattr(out, 'real', None)),
                self._call_real(x.imag, getattr(out, 'imag', None))]

            if out is None:
                out = self.range.element()
                out.real = result_parts[0]
                out.imag = result_parts[1]

            return out

        else:
            raise RuntimeError('bad domain {!r}'.format(self.domain))
1332870
def create_quali_api_instance(context, logger):
    
    if hasattr(context, 'reservation') and context.reservation:
        domain = context.reservation.domain
    elif hasattr(context, 'remote_reservation') and context.remote_reservation:
        domain = context.remote_reservation.domain
    else:
        domain = None
    address = context.connectivity.server_address
    token = context.connectivity.admin_auth_token
    if token:
        instance = QualiAPIHelper(address, logger, token=token, domain=domain)
    else:
        instance = QualiAPIHelper(address, logger, username='admin', password='admin', domain=domain)
    return instance
470962
def _call(self, method, *args, **kwargs):
        """"""

        assert self.session

        if not kwargs.get('verify'):
            kwargs['verify'] = self.SSL_VERIFY

        response = self.session.request(method, *args, **kwargs)
        response_json = response.text and response.json() or {}

        if response.status_code < 200 or response.status_code >= 300:
            message = response_json.get('error', response_json.get('message'))
            raise HelpScoutRemoteException(response.status_code, message)

        self.page_current = response_json.get(self.PAGE_CURRENT, 1)
        self.page_total = response_json.get(self.PAGE_TOTAL, 1)

        try:
            return response_json[self.PAGE_DATA_MULTI]
        except KeyError:
            pass

        try:
            return [response_json[self.PAGE_DATA_SINGLE]]
        except KeyError:
            pass

        return None
101540
def query_kwargs(self):
        """"""
        self._query_kwargs = query_kwargs = {}
        query = self.query
        if query: query_kwargs = self._parse_query_str(query)
        return query_kwargs
1035935
def get_oncall(self, **kwargs):
        """"""

        endpoint = '/'.join((self.endpoint, self.id, 'users'))

        return self.request('GET', endpoint=endpoint, query_params=kwargs)
645970
def coerce(cls, arg):
        """"""
        try:
            return cls(arg).value
        except (ValueError, TypeError):
            raise InvalidParameterDatatype("%s coerce error" % (cls.__name__,))
501986
def _q(self, number, precision='.00001'):
        """"""
        if np.isinf(number):
            return np.nan
        else:
            return D(D(number).quantize(D(precision)))
661018
def qual_name(self) -> QualName:
        """"""
        p, s, loc = self._key.partition(":")
        return (loc, p) if s else (p, self.namespace)
755552
def GetQualifier(self, *args, **kwargs):
        

        qualname = args[0] if args else kwargs['QualifierName']
        try:
            qual = self.qualifiers[self.default_namespace][qualname]
        except KeyError:
            if self.conn is None:
                raise CIMError(
                    CIM_ERR_NOT_FOUND, qualname, conn_id=self.conn_id)
            qual = self.conn.GetQualifier(*args, **kwargs)
        return qual
824459
def kwargs(self):
        """"""
        kwargs = dict(self.query_kwargs)
        kwargs.update(self.body_kwargs)

        return kwargs
820704
def get(cls):
        
        apikey = cls.__api_key or cls.__api_key_env_var

        if apikey:
            return apikey
        else:
            raise APIKeyMissingError("API key not set")
912496
def _qsturng(p, r, v):
    """"""
##    print 'q',p
    # r is interpolated through the q to y here we only need to
    # account for when p and/or v are not found in the table.
    global A, p_keys, v_keys

    if p < .1 or p > .999:
        raise ValueError('p must be between .1 and .999')

    if p < .9:
        if v < 2:
            raise ValueError('v must be > 2 when p < .9')
    else:
        if v < 1:
            raise ValueError('v must be > 1 when p >= .9')

    # The easy case. A tabled value is requested.
    #numpy 1.4.1: TypeError: unhashable type: 'numpy.ndarray' :
    p = float(p)
    if isinstance(v, np.ndarray):
        v = v.item()
    if (p,v) in A:
        y = _func(A[(p,v)], p, r, v) + 1.

    elif p not in p_keys and v not in v_keys+([],[1])[p>=.90]:
        # find the 3 closest v values
        v0, v1, v2 = _select_vs(v, p)

        # find the 3 closest p values
        p0, p1, p2 = _select_ps(p)

        # calculate r0, r1, and r2
        r0_sq = _interpolate_p(p, r, v0)**2
        r1_sq = _interpolate_p(p, r, v1)**2
        r2_sq = _interpolate_p(p, r, v2)**2

        # transform v
        v_, v0_, v1_, v2_ = 1./v, 1./v0, 1./v1, 1./v2

        # calculate derivatives for quadratic interpolation
        d2 = 2.*((r2_sq-r1_sq)/(v2_-v1_) - \
                 (r0_sq-r1_sq)/(v0_-v1_)) / (v2_-v0_)
        if (v2_ + v0_) >= (v1_ + v1_):
            d1 = (r2_sq-r1_sq) / (v2_-v1_) - 0.5*d2*(v2_-v1_)
        else:
            d1 = (r1_sq-r0_sq) / (v1_-v0_) + 0.5*d2*(v1_-v0_)
        d0 = r1_sq

        # calculate y
        y = math.sqrt((d2/2.)*(v_-v1_)**2. + d1*(v_-v1_)+ d0)

    elif v not in v_keys+([],[1])[p>=.90]:
        y = _interpolate_v(p, r, v)

    elif p not in p_keys:
        y = _interpolate_p(p, r, v)

    return math.sqrt(2) * -y * \
           scipy.stats.t.isf((1. + p) / 2., max(v, 1e38))
758727
def basic_query(returns):
    """"""
    return compose(
        reusable,
        map_send(parse_request),
        map_yield(prepare_params, snug.prefix_adder(API_PREFIX)),
        map_return(loads(returns)),
        oneyield,
    )