def get(self, domain): app.logger.info('apiDomainInfo [%s]' % domain) d = db.get('cache-%s' % domain) if d is None: o = Domain(domain, cfg.domainPath) if o.found: d = o.asDict() db.set('cache-%s' % domain, json.dumps(d)) else: d = None else: d = json.loads(d) if d is None: return { "domain": domain, "result": "Domain is not being tracked" }, 404 else: return d, 200
def make_zone(name: str, info: Domain) -> dict: return { "name": name, "type": "CNAME", "content": info["cname"], "proxied": info.get("cloudflare", False), }
def mip_solve(network, x, radius=None, problem_type='min_dist', lp_norm='l_inf', box_bounds=None, force_radius=False, bound_fxn='full_lp', timeout=None): """ Computes the decision problem for MIP : - first computes the LP for each neuron to get pre-relu actviations - then loops through all logits to compute decisions """ dom = Domain(x.numel(), x) if box_bounds is not None: dom.set_original_hyperbox_bound(*box_bounds) else: dom.set_original_hyperbox_bound(0.0, 1.0) assert problem_type in ['decision_problem', 'min_dist'] if (problem_type == 'decision_problem') or (force_radius is True): assert radius is not None dom.set_upper_bound(radius, lp_norm) # Build domain and shrink if only doing a decision problem start = time.time() if bound_fxn == 'full_lp': pre_relu_bounds = full_lp.compute_full_lp_bounds(network, dom, compute_logit_bounds=True) print("COMPUTED FULL-LP BOUNDS IN %.03f seconds" % (time.time() - start)) if bound_fxn == 'ia': # assert bound_fxn == 'ia' pre_relu_bounds = network.compute_interval_bounds(dom, compute_logit_bounds=True) print("COMPUTED IA BOUNDS IN %.03f seconds" % (time.time() - start)) true_label = network(x).max(1)[1].item() num_logits = network(x).numel() solved_models = [] model = build_mip_model(network, x, dom, pre_relu_bounds, true_label, problem_type, radius, lp_norm, timeout=timeout) model.optimize() if model.Status == 3: print("INFEASIBLE!") return model
def post(self, request, *args, **kwargs): try: # Get payload from request body_unicode = request.body.decode('utf-8') body = json.loads(body_unicode) utterance = body.get('utterance') data = Domain.analyze_utterance(utterance) res = Response(data) return JsonResponse(res.response, json_dumps_params={'ensure_ascii': True}) except: # TODO: Error handling return HttpResponse('Error occurred!')
def handleDomain(): app.logger.info('handleInfo [%s]' % request.method) owner = False authed_domain = None authed, indieauth_id = checkAuth() app.logger.info('[%s] [%s]' % (authed, indieauth_id)) arg_domain = request.args.get('domain') app.logger.info('args["domain"] %s' % arg_domain) if authed: authed_url = urlparse(indieauth_id) authed_domain = authed_url.netloc if arg_domain is None: arg_domain = authed_domain owner = arg_domain == authed_domain if arg_domain is not None: app.logger.info('%s %s %s %s' % (arg_domain, cfg.dataPath, cfg.domainPath, cfg.domains)) # domainList = Domains(cfg.dataPath, cfg.domainPath, cfg.domains) # if arg_domain not in domainList: # domainList[arg_domain] = Domain(arg_domain, cfg.domainPath) # domain = domainList[arg_domain] domain = Domain(arg_domain, cfg.domainPath) status = domainStatus(domain) found = domain.found if not found and owner: domain.store() found = True else: found = False templateContext = {} if found: form = DomainForm(domain=domain.domain, excluded=domain.excluded) if authed and owner and request.method == 'POST': app.logger.info('domain post') if form.validate(): domain.excluded = form.excluded.data domain.claimed = True domain.store() return redirect('/domain') else: flash('all fields are required') if not owner: if domain.excluded: templateContext['caption'] = 'Domain is being excluded by request of owner.' else: if domain.claimed: templateContext['caption'] = 'Domain is being included.' else: templateContext['caption'] = 'Domain has not been claimed.' else: templateContext['caption'] = '' templateContext['title'] = 'Domain Information' templateContext['form'] = form templateContext['authed'] = authed templateContext['authed_domain'] = authed_domain templateContext['authed_url'] = indieauth_id templateContext['owner'] = owner templateContext['domain'] = domain.domain templateContext['domain_url'] = domain.url templateContext['from_uri'] = '/domain?domain=%s' % domain.domain if domain.ts is None: templateContext['domain_polled'] = '' templateContext['domain_polled_ts'] = 'n/a' else: templateContext['domain_polled'] = time.strftime('%Y-%m-%d %H:%M:%S', domain.ts) templateContext['domain_polled_ts'] = time.strftime('%Y-%m-%d %H:%M:%S', domain.ts) return render_template('domain.jinja', **templateContext) else: form = DomainNotFoundForm(domain=arg_domain) templateContext['title'] = 'Domain not found' templateContext['form'] = form templateContext['domain'] = arg_domain templateContext['authed'] = authed templateContext['authed_domain'] = authed_domain templateContext['authed_url'] = indieauth_id templateContext['domain_url'] = '' if arg_domain is None: templateContext['message'] = 'You must be logged in or specify include a domain parameter to search for' templateContext['from_uri'] = '' else: templateContext['message'] = 'Unable to find any information about %s' % arg_domain templateContext['from_uri'] = '/domain' return render_template('domain-not-found.jinja', **templateContext)
def __init__( self, did, vmap ): Domain.__init__(self, did) self.vmap = vmap
def __init__( self, did ): Domain.__init__(self, did)