示例#1
0
 def getZone(self, con, name, current):
     cur = self._dbh.execute(con, 'SELECT id FROM domains WHERE name=%s',
                             name)
     result = cur.fetchall()
     if len(result) != 1:
         raise ICore.NotFoundError("Could not locate zone in the database")
     return utils.proxy(I.ZonePrx, current, "DNS-Zone", str(result[0][0]))
示例#2
0
 def getZones(self, con, current):
     cur = self._dbh.execute(con, 'SELECT id FROM domains')
     result = [
         utils.proxy(I.ZonePrx, current, "DNS-Zone", str(x[0]))
         for x in cur.fetchall()
     ]
     return result
示例#3
0
 def createZone(self, con, name, soar, current):
     self._dbh.execute(con,
                       'INSERT INTO domains (name, type) VALUES (%s, %s)',
                       name, 'NATIVE')
     # we'll need id later to create proxy
     cur = self._dbh.execute(con, 'SELECT id FROM domains WHERE name=%s',
                             name)
     result = cur.fetchall()
     if len(result) != 1:
         raise ICore.DBError("Zone creation failed"
                             "Could not locate zone in the database")
     n = str(result[0][0])
     cur = self._dbh.execute(
         con, "INSERT INTO records (domain_id, name, type, content)"
         "VALUES (%s, %s, 'SOA', %s)", n, name, utils.soar2str(soar))
     if cur.rowcount != 1:
         raise ICore.DBError("Zone creation failed",
                             "Failed to add SOA Record.")
     con.commit()
     return utils.proxy(I.ZonePrx, current, "DNS-Zone", n)
示例#4
0
    slopes = rises / runs
    
    runs = [25] + list(runs) + [25]
    slopes = [slopes[0]] + list(slopes) + [slopes[-1]]
    
    intercept = quantiles[0] - runs[0] * slopes[0]
    poly = [intercept]
    for slope, run in zip(slopes, runs):
        start = poly[-1] + slope
        stop = poly[-1] + run * slope
        poly.extend(np.linspace(start, stop, num=run))
    
    return poly


proxied = proxy('distribution')

class RandomVariable(np.ndarray):
    # cf. http://docs.scipy.org/doc/numpy-1.10.1/user/basics.subclassing.html
    # for details on subclassing an ndarray
    def __new__(cls, distribution):
        sample = distribution.rvs(N)
        obj = sample.view(cls)
        obj.distribution = distribution
        return obj

    @proxied
    def rvs(self, n):
        return np.random.choice(self, size=n, replace=True)

    @vectorize
示例#5
0
文件: api.py 项目: Lobos/wordstore
def get_xml(url):
    resp = make_response(proxy(url).replace('\n', ''))
    resp.mimetype = 'text/xml'
    return resp