text_prompt stringlengths 157 13.1k | code_prompt stringlengths 7 19.8k ⌀ |
|---|---|
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def plantloopfieldlists(data):
"""return the plantloopfield list""" |
objkey = 'plantloop'.upper()
numobjects = len(data.dt[objkey])
return [[
'Name',
'Plant Side Inlet Node Name',
'Plant Side Outlet Node Name',
'Plant Side Branch List Name',
'Demand Side Inlet Node Name',
'Demand Side Outlet Node Name',
'Demand Side Br... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def plantloopfields(data, commdct):
"""get plantloop fields to diagram it""" |
fieldlists = plantloopfieldlists(data)
objkey = 'plantloop'.upper()
return extractfields(data, commdct, objkey, fieldlists) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def branchlist2branches(data, commdct, branchlist):
"""get branches from the branchlist""" |
objkey = 'BranchList'.upper()
theobjects = data.dt[objkey]
fieldlists = []
objnames = [obj[1] for obj in theobjects]
for theobject in theobjects:
fieldlists.append(list(range(2, len(theobject))))
blists = extractfields(data, commdct, objkey, fieldlists)
thebranches = [branches for n... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def branch_inlet_outlet(data, commdct, branchname):
"""return the inlet and outlet of a branch""" |
objkey = 'Branch'.upper()
theobjects = data.dt[objkey]
theobject = [obj for obj in theobjects if obj[1] == branchname]
theobject = theobject[0]
inletindex = 6
outletindex = len(theobject) - 2
return [theobject[inletindex], theobject[outletindex]] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def splittermixerfieldlists(data, commdct, objkey):
"""docstring for splittermixerfieldlists""" |
objkey = objkey.upper()
objindex = data.dtls.index(objkey)
objcomms = commdct[objindex]
theobjects = data.dt[objkey]
fieldlists = []
for theobject in theobjects:
fieldlist = list(range(1, len(theobject)))
fieldlists.append(fieldlist)
return fieldlists |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def splitterfields(data, commdct):
"""get splitter fields to diagram it""" |
objkey = "Connector:Splitter".upper()
fieldlists = splittermixerfieldlists(data, commdct, objkey)
return extractfields(data, commdct, objkey, fieldlists) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def mixerfields(data, commdct):
"""get mixer fields to diagram it""" |
objkey = "Connector:Mixer".upper()
fieldlists = splittermixerfieldlists(data, commdct, objkey)
return extractfields(data, commdct, objkey, fieldlists) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def objectcount(data, key):
"""return the count of objects of key""" |
objkey = key.upper()
return len(data.dt[objkey]) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getfieldindex(data, commdct, objkey, fname):
"""given objkey and fieldname, return its index""" |
objindex = data.dtls.index(objkey)
objcomm = commdct[objindex]
for i_index, item in enumerate(objcomm):
try:
if item['field'] == [fname]:
break
except KeyError as err:
pass
return i_index |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getadistus(data, commdct):
"""docstring for fname""" |
objkey = "ZoneHVAC:AirDistributionUnit".upper()
objindex = data.dtls.index(objkey)
objcomm = commdct[objindex]
adistutypefield = "Air Terminal Object Type"
ifield = getfieldindex(data, commdct, objkey, adistutypefield)
adistus = objcomm[ifield]['key']
return adistus |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def makeadistu_inlets(data, commdct):
"""make the dict adistu_inlets""" |
adistus = getadistus(data, commdct)
# assume that the inlet node has the words "Air Inlet Node Name"
airinletnode = "Air Inlet Node Name"
adistu_inlets = {}
for adistu in adistus:
objkey = adistu.upper()
objindex = data.dtls.index(objkey)
objcomm = commdct[objindex]
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def folder2ver(folder):
"""get the version number from the E+ install folder""" |
ver = folder.split('EnergyPlus')[-1]
ver = ver[1:]
splitapp = ver.split('-')
ver = '.'.join(splitapp)
return ver |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def nocomment(astr, com='!'):
""" just like the comment in python. removes any text after the phrase 'com' """ |
alist = astr.splitlines()
for i in range(len(alist)):
element = alist[i]
pnt = element.find(com)
if pnt != -1:
alist[i] = element[:pnt]
return '\n'.join(alist) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def idf2txt(txt):
"""convert the idf text to a simple text""" |
astr = nocomment(txt)
objs = astr.split(';')
objs = [obj.split(',') for obj in objs]
objs = [[line.strip() for line in obj] for obj in objs]
objs = [[_tofloat(line) for line in obj] for obj in objs]
objs = [tuple(obj) for obj in objs]
objs.sort()
lst = []
for obj in objs:
f... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def iddversiontuple(afile):
"""given the idd file or filehandle, return the version handle""" |
def versiontuple(vers):
"""version tuple"""
return tuple([int(num) for num in vers.split(".")])
try:
fhandle = open(afile, 'rb')
except TypeError:
fhandle = afile
line1 = fhandle.readline()
try:
line1 = line1.decode('ISO-8859-2')
except AttributeError:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def makeabunch(commdct, obj, obj_i):
"""make a bunch from the object""" |
objidd = commdct[obj_i]
objfields = [comm.get('field') for comm in commdct[obj_i]]
objfields[0] = ['key']
objfields = [field[0] for field in objfields]
obj_fields = [bunchhelpers.makefieldname(field) for field in objfields]
bobj = EpBunch(obj, obj_fields, objidd)
return bobj |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def convertfields_old(key_comm, obj, inblock=None):
"""convert the float and interger fields""" |
convinidd = ConvInIDD()
typefunc = dict(integer=convinidd.integer, real=convinidd.real)
types = []
for comm in key_comm:
types.append(comm.get('type', [None])[0])
convs = [typefunc.get(typ, convinidd.no_type) for typ in types]
try:
inblock = list(inblock)
except TypeError as... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def convertafield(field_comm, field_val, field_iddname):
"""convert field based on field info in IDD""" |
convinidd = ConvInIDD()
field_typ = field_comm.get('type', [None])[0]
conv = convinidd.conv_dict().get(field_typ, convinidd.no_type)
return conv(field_val, field_iddname) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def convertfields(key_comm, obj, inblock=None):
"""convert based on float, integer, and A1, N1""" |
# f_ stands for field_
convinidd = ConvInIDD()
if not inblock:
inblock = ['does not start with N'] * len(obj)
for i, (f_comm, f_val, f_iddname) in enumerate(zip(key_comm, obj, inblock)):
if i == 0:
# inblock[0] is the iddobject key. No conversion here
pass
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def convertallfields(data, commdct, block=None):
"""docstring for convertallfields""" |
# import pdbdb; pdb.set_trace()
for key in list(data.dt.keys()):
objs = data.dt[key]
for i, obj in enumerate(objs):
key_i = data.dtls.index(key)
key_comm = commdct[key_i]
try:
inblock = block[key_i]
except TypeError as e:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def addfunctions(dtls, bunchdt):
"""add functions to the objects""" |
snames = [
"BuildingSurface:Detailed",
"Wall:Detailed",
"RoofCeiling:Detailed",
"Floor:Detailed",
"FenestrationSurface:Detailed",
"Shading:Site:Detailed",
"Shading:Building:Detailed",
"Shading:Zone:Detailed", ]
for sname in snames:
if snam... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def conv_dict(self):
"""dictionary of conversion""" |
return dict(integer=self.integer, real=self.real, no_type=self.no_type) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getanymentions(idf, anidfobject):
"""Find out if idjobject is mentioned an any object anywhere""" |
name = anidfobject.obj[1]
foundobjs = []
keys = idfobjectkeys(idf)
idfkeyobjects = [idf.idfobjects[key.upper()] for key in keys]
for idfobjects in idfkeyobjects:
for idfobject in idfobjects:
if name.upper() in [item.upper()
for item in idfobj... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getobject_use_prevfield(idf, idfobject, fieldname):
"""field=object_name, prev_field=object_type. Return the object""" |
if not fieldname.endswith("Name"):
return None
# test if prevfieldname ends with "Object_Type"
fdnames = idfobject.fieldnames
ifieldname = fdnames.index(fieldname)
prevfdname = fdnames[ifieldname - 1]
if not prevfdname.endswith("Object_Type"):
return None
objkey = idfobject[... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getidfkeyswithnodes():
"""return a list of keys of idfobjects that hve 'None Name' fields""" |
idf = IDF(StringIO(""))
keys = idfobjectkeys(idf)
keysfieldnames = ((key, idf.newidfobject(key.upper()).fieldnames)
for key in keys)
keysnodefdnames = ((key, (name for name in fdnames
if (name.endswith('Node_Name'))))
for k... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getobjectswithnode(idf, nodekeys, nodename):
"""return all objects that mention this node name""" |
keys = nodekeys
# TODO getidfkeyswithnodes needs to be done only once. take out of here
listofidfobjects = (idf.idfobjects[key.upper()]
for key in keys if idf.idfobjects[key.upper()])
idfobjects = [idfobj
for idfobjs in listofidfobjects
for... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getidfobjectlist(idf):
"""return a list of all idfobjects in idf""" |
idfobjects = idf.idfobjects
# idfobjlst = [idfobjects[key] for key in idfobjects if idfobjects[key]]
idfobjlst = [idfobjects[key] for key in idf.model.dtls if idfobjects[key]]
# `for key in idf.model.dtls` maintains the order
# `for key in idfobjects` does not have order
idfobjlst = i... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def copyidfintoidf(toidf, fromidf):
"""copy fromidf completely into toidf""" |
idfobjlst = getidfobjectlist(fromidf)
for idfobj in idfobjlst:
toidf.copyidfobject(idfobj) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def autosize_fieldname(idfobject):
"""return autsizeable field names in idfobject""" |
# undocumented stuff in this code
return [fname for (fname, dct) in zip(idfobject.objls,
idfobject['objidd'])
if 'autosizable' in dct] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def idd2group(fhandle):
"""wrapper for iddtxt2groups""" |
try:
txt = fhandle.read()
return iddtxt2groups(txt)
except AttributeError as e:
txt = open(fhandle, 'r').read()
return iddtxt2groups(txt) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def idd2grouplist(fhandle):
"""wrapper for iddtxt2grouplist""" |
try:
txt = fhandle.read()
return iddtxt2grouplist(txt)
except AttributeError as e:
txt = open(fhandle, 'r').read()
return iddtxt2grouplist(txt) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def iddtxt2groups(txt):
"""extract the groups from the idd file""" |
try:
txt = txt.decode('ISO-8859-2')
except AttributeError as e:
pass # for python 3
txt = nocomment(txt, '!')
txt = txt.replace("\\group", "!-group") # retains group in next line
txt = nocomment(txt, '\\') # remove all other idd info
lines = txt.splitlines()
lines = [line.st... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def iddtxt2grouplist(txt):
"""return a list of group names the list in the same order as the idf objects in idd file """ |
def makenone(astr):
if astr == 'None':
return None
else:
return astr
txt = nocomment(txt, '!')
txt = txt.replace("\\group", "!-group") # retains group in next line
txt = nocomment(txt, '\\') # remove all other idd info
lines = txt.splitlines()
lines = [l... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def group2commlst(commlst, glist):
"""add group info to commlst""" |
for (gname, objname), commitem in zip(glist, commlst):
newitem1 = "group %s" % (gname, )
newitem2 = "idfobj %s" % (objname, )
commitem[0].insert(0, newitem1)
commitem[0].insert(1, newitem2)
return commlst |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def group2commdct(commdct, glist):
"""add group info tocomdct""" |
for (gname, objname), commitem in zip(glist, commdct):
commitem[0]['group'] = gname
commitem[0]['idfobj'] = objname
return commdct |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def flattencopy(lst):
"""flatten and return a copy of the list indefficient on large lists""" |
# modified from
# http://stackoverflow.com/questions/2158395/flatten-an-irregular-list-of-lists-in-python
thelist = copy.deepcopy(lst)
list_is_nested = True
while list_is_nested: # outer loop
keepchecking = False
atemp = []
for element in thelist: # inner loop
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def makepipecomponent(idf, pname):
"""make a pipe component generate inlet outlet names""" |
apipe = idf.newidfobject("Pipe:Adiabatic".upper(), Name=pname)
apipe.Inlet_Node_Name = "%s_inlet" % (pname,)
apipe.Outlet_Node_Name = "%s_outlet" % (pname,)
return apipe |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def makeductcomponent(idf, dname):
"""make a duct component generate inlet outlet names""" |
aduct = idf.newidfobject("duct".upper(), Name=dname)
aduct.Inlet_Node_Name = "%s_inlet" % (dname,)
aduct.Outlet_Node_Name = "%s_outlet" % (dname,)
return aduct |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def makepipebranch(idf, bname):
"""make a branch with a pipe use standard inlet outlet names""" |
# make the pipe component first
pname = "%s_pipe" % (bname,)
apipe = makepipecomponent(idf, pname)
# now make the branch with the pipe in it
abranch = idf.newidfobject("BRANCH", Name=bname)
abranch.Component_1_Object_Type = 'Pipe:Adiabatic'
abranch.Component_1_Name = pname
abranch.Compo... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def makeductbranch(idf, bname):
"""make a branch with a duct use standard inlet outlet names""" |
# make the duct component first
pname = "%s_duct" % (bname,)
aduct = makeductcomponent(idf, pname)
# now make the branch with the duct in it
abranch = idf.newidfobject("BRANCH", Name=bname)
abranch.Component_1_Object_Type = 'duct'
abranch.Component_1_Name = pname
abranch.Component_1_Inl... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getbranchcomponents(idf, branch, utest=False):
"""get the components of the branch""" |
fobjtype = 'Component_%s_Object_Type'
fobjname = 'Component_%s_Name'
complist = []
for i in range(1, 100000):
try:
objtype = branch[fobjtype % (i,)]
if objtype.strip() == '':
break
objname = branch[fobjname % (i,)]
complist.append(... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def renamenodes(idf, fieldtype):
"""rename all the changed nodes""" |
renameds = []
for key in idf.model.dtls:
for idfobject in idf.idfobjects[key]:
for fieldvalue in idfobject.obj:
if type(fieldvalue) is list:
if fieldvalue not in renameds:
cpvalue = copy.copy(fieldvalue)
ren... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getfieldnamesendswith(idfobject, endswith):
"""get the filednames for the idfobject based on endswith""" |
objls = idfobject.objls
tmp = [name for name in objls if name.endswith(endswith)]
if tmp == []:
pass
return [name for name in objls if name.endswith(endswith)] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getnodefieldname(idfobject, endswith, fluid=None, startswith=None):
"""return the field name of the node fluid is only needed if there are air and water node... |
if startswith is None:
startswith = ''
if fluid is None:
fluid = ''
nodenames = getfieldnamesendswith(idfobject, endswith)
nodenames = [name for name in nodenames if name.startswith(startswith)]
fnodenames = [nd for nd in nodenames if nd.find(fluid) != -1]
fnodenames = [name for... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def connectcomponents(idf, components, fluid=None):
"""rename nodes so that the components get connected fluid is only needed if there are air and water nodes fl... |
if fluid is None:
fluid = ''
if len(components) == 1:
thiscomp, thiscompnode = components[0]
initinletoutlet(idf, thiscomp, thiscompnode, force=False)
outletnodename = getnodefieldname(thiscomp, "Outlet_Node_Name",
fluid=fluid, startswit... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def initinletoutlet(idf, idfobject, thisnode, force=False):
"""initialze values for all the inlet outlet nodes for the object. if force == False, it willl init o... |
def blankfield(fieldvalue):
"""test for blank field"""
try:
if fieldvalue.strip() == '':
return True
else:
return False
except AttributeError: # field may be a list
return False
def trimfields(fields, thisnode):
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def componentsintobranch(idf, branch, listofcomponents, fluid=None):
"""insert a list of components into a branch fluid is only needed if there are air and water... |
if fluid is None:
fluid = ''
componentlist = [item[0] for item in listofcomponents]
# assumes that the nodes of the component connect to each other
# empty branch if it has existing components
thebranchname = branch.Name
thebranch = idf.removeextensibles('BRANCH', thebranchname) # empt... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _clean_listofcomponents(listofcomponents):
"""force it to be a list of tuples""" |
def totuple(item):
"""return a tuple"""
if isinstance(item, (tuple, list)):
return item
else:
return (item, None)
return [totuple(item) for item in listofcomponents] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _clean_listofcomponents_tuples(listofcomponents_tuples):
"""force 3 items in the tuple""" |
def to3tuple(item):
"""return a 3 item tuple"""
if len(item) == 3:
return item
else:
return (item[0], item[1], None)
return [to3tuple(item) for item in listofcomponents_tuples] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getmakeidfobject(idf, key, name):
"""get idfobject or make it if it does not exist""" |
idfobject = idf.getobject(key, name)
if not idfobject:
return idf.newidfobject(key, Name=name)
else:
return idfobject |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def main():
"""the main routine""" |
from six import StringIO
import eppy.iddv7 as iddv7
IDF.setiddname(StringIO(iddv7.iddtxt))
idf1 = IDF(StringIO(''))
loopname = "p_loop"
sloop = ['sb0', ['sb1', 'sb2', 'sb3'], 'sb4']
dloop = ['db0', ['db1', 'db2', 'db3'], 'db4']
# makeplantloop(idf1, loopname, sloop, dloop)
loopname ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def area(poly):
"""Area of a polygon poly""" |
if len(poly) < 3: # not a plane - no area
return 0
total = [0, 0, 0]
num = len(poly)
for i in range(num):
vi1 = poly[i]
vi2 = poly[(i+1) % num]
prod = np.cross(vi1, vi2)
total[0] += prod[0]
total[1] += prod[1]
total[2] += prod[2]
if total == [... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def unit_normal(pt_a, pt_b, pt_c):
"""unit normal vector of plane defined by points pt_a, pt_b, and pt_c""" |
x_val = np.linalg.det([[1, pt_a[1], pt_a[2]], [1, pt_b[1], pt_b[2]], [1, pt_c[1], pt_c[2]]])
y_val = np.linalg.det([[pt_a[0], 1, pt_a[2]], [pt_b[0], 1, pt_b[2]], [pt_c[0], 1, pt_c[2]]])
z_val = np.linalg.det([[pt_a[0], pt_a[1], 1], [pt_b[0], pt_b[1], 1], [pt_c[0], pt_c[1], 1]])
magnitude = (x_val**2 + ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def width(poly):
"""Width of a polygon poly""" |
num = len(poly) - 1
if abs(poly[num][2] - poly[0][2]) < abs(poly[1][2] - poly[0][2]):
return dist(poly[num], poly[0])
elif abs(poly[num][2] - poly[0][2]) > abs(poly[1][2] - poly[0][2]):
return dist(poly[1], poly[0])
else: return max(dist(poly[num], poly[0]), dist(poly[1], poly[0])) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def height(poly):
"""Height of a polygon poly""" |
num = len(poly) - 1
if abs(poly[num][2] - poly[0][2]) > abs(poly[1][2] - poly[0][2]):
return dist(poly[num], poly[0])
elif abs(poly[num][2] - poly[0][2]) < abs(poly[1][2] - poly[0][2]):
return dist(poly[1], poly[0])
else:
return min(dist(poly[num], poly[0]), dist(poly[1], poly[0... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def angle2vecs(vec1, vec2):
"""angle between two vectors""" |
# vector a * vector b = |a|*|b|* cos(angle between vector a and vector b)
dot = np.dot(vec1, vec2)
vec1_modulus = np.sqrt(np.multiply(vec1, vec1).sum())
vec2_modulus = np.sqrt(np.multiply(vec2, vec2).sum())
if (vec1_modulus * vec2_modulus) == 0:
cos_angle = 1
else: cos_angle = dot / (ve... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def azimuth(poly):
"""Azimuth of a polygon poly""" |
num = len(poly) - 1
vec = unit_normal(poly[0], poly[1], poly[num])
vec_azi = np.array([vec[0], vec[1], 0])
vec_n = np.array([0, 1, 0])
# update by Santosh
# angle2vecs gives the smallest angle between the vectors
# so for a west wall angle2vecs will give 90
# the following 'if' statemen... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def tilt(poly):
"""Tilt of a polygon poly""" |
num = len(poly) - 1
vec = unit_normal(poly[0], poly[1], poly[num])
vec_alt = np.array([vec[0], vec[1], vec[2]])
vec_z = np.array([0, 0, 1])
# return (90 - angle2vecs(vec_alt, vec_z)) # update by Santosh
return angle2vecs(vec_alt, vec_z) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getfields(comm):
"""get all the fields that have the key 'field' """ |
fields = []
for field in comm:
if 'field' in field:
fields.append(field)
return fields |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def repeatingfieldsnames(fields):
"""get the names of the repeating fields""" |
fnames = [field['field'][0] for field in fields]
fnames = [bunchhelpers.onlylegalchar(fname) for fname in fnames]
fnames = [fname for fname in fnames if bunchhelpers.intinlist(fname.split())]
fnames = [(bunchhelpers.replaceint(fname), None) for fname in fnames]
dct = dict(fnames)
repnames = fna... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def missingkeys_standard(commdct, dtls, skiplist=None):
"""put missing keys in commdct for standard objects return a list of keys where it is unable to do so com... |
if skiplist == None:
skiplist = []
# find objects where all the fields are not named
gkeys = [dtls[i] for i in range(len(dtls)) if commdct[i].count({}) > 2]
nofirstfields = []
# operatie on those fields
for key_txt in gkeys:
if key_txt in skiplist:
continue
#... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def missingkeys_nonstandard(block, commdct, dtls, objectlist, afield='afiled %s'):
"""This is an object list where thre is no first field name to give a hint of ... |
afield = 'afield %s'
for key_txt in objectlist:
key_i = dtls.index(key_txt.upper())
comm = commdct[key_i]
if block:
blk = block[key_i]
for i, cmt in enumerate(comm):
if cmt == {}:
first_i = i
break
for i, cmt in enu... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_event_loop():
"""Return a EventLoop instance. A new instance is created for each new HTTP request. We determine that we're in a new request by inspecting... |
ev = _state.event_loop
if not os.getenv(_EVENT_LOOP_KEY) and ev is not None:
ev.clear()
_state.event_loop = None
ev = None
if ev is None:
ev = EventLoop()
_state.event_loop = ev
os.environ[_EVENT_LOOP_KEY] = '1'
return ev |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def clear(self):
"""Remove all pending events without running any.""" |
while self.current or self.idlers or self.queue or self.rpcs:
current = self.current
idlers = self.idlers
queue = self.queue
rpcs = self.rpcs
_logging_debug('Clearing stale EventLoop instance...')
if current:
_logging_debug(' current = %s', current)
if idlers:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def insort_event_right(self, event, lo=0, hi=None):
"""Insert event in queue, and keep it sorted assuming queue is sorted. If event is already in queue, insert i... |
if lo < 0:
raise ValueError('lo must be non-negative')
if hi is None:
hi = len(self.queue)
while lo < hi:
mid = (lo + hi) // 2
if event[0] < self.queue[mid][0]:
hi = mid
else:
lo = mid + 1
self.queue.insert(lo, event) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def queue_call(self, delay, callback, *args, **kwds):
"""Schedule a function call at a specific time in the future.""" |
if delay is None:
self.current.append((callback, args, kwds))
return
if delay < 1e9:
when = delay + self.clock.now()
else:
# Times over a billion seconds are assumed to be absolute.
when = delay
self.insort_event_right((when, callback, args, kwds)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def queue_rpc(self, rpc, callback=None, *args, **kwds):
"""Schedule an RPC with an optional callback. The caller must have previously sent the call to the servic... |
if rpc is None:
return
if rpc.state not in (_RUNNING, _FINISHING):
raise RuntimeError('rpc must be sent to service before queueing')
if isinstance(rpc, datastore_rpc.MultiRpc):
rpcs = rpc.rpcs
if len(rpcs) > 1:
# Don't call the callback until all sub-rpcs have completed.
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def add_idle(self, callback, *args, **kwds):
"""Add an idle callback. An idle callback can return True, False or None. These mean: - None: remove the callback (d... |
self.idlers.append((callback, args, kwds)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def run_idle(self):
"""Run one of the idle callbacks. Returns: True if one was called, False if no idle callback was called. """ |
if not self.idlers or self.inactive >= len(self.idlers):
return False
idler = self.idlers.popleft()
callback, args, kwds = idler
_logging_debug('idler: %s', callback.__name__)
res = callback(*args, **kwds)
# See add_idle() for the meaning of the callback return value.
if res is not No... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _args_to_val(func, args):
"""Helper for GQL parsing to extract values from GQL expressions. This can extract the value from a GQL literal, return a Parameter... |
from .google_imports import gql # Late import, to avoid name conflict.
vals = []
for arg in args:
if isinstance(arg, (int, long, basestring)):
val = Parameter(arg)
elif isinstance(arg, gql.Literal):
val = arg.Get()
else:
raise TypeError('Unexpected arg (%r)' % arg)
vals.append(... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _get_prop_from_modelclass(modelclass, name):
"""Helper for FQL parsing to turn a property name into a property object. Args: modelclass: The model class spec... |
if name == '__key__':
return modelclass._key
parts = name.split('.')
part, more = parts[0], parts[1:]
prop = modelclass._properties.get(part)
if prop is None:
if issubclass(modelclass, model.Expando):
prop = model.GenericProperty(part)
else:
raise TypeError('Model %s has no property ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def gql(query_string, *args, **kwds):
"""Parse a GQL query string. Args: query_string: Full GQL query, e.g. 'SELECT * FROM Kind WHERE prop = 1'. *args, **kwds: I... |
qry = _gql(query_string)
if args or kwds:
qry = qry._bind(args, kwds)
return qry |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _apply(self, key_value_map):
"""Apply the filter to values extracted from an entity. Think of self.match_keys and self.match_values as representing a table w... |
columns = []
for key in self.match_keys:
column = key_value_map.get(key)
if not column: # None, or an empty list.
return False # If any column is empty there can be no match.
columns.append(column)
# Use izip to transpose the columns into rows.
return self.match_values in it... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _fix_namespace(self):
"""Internal helper to fix the namespace. This is called to ensure that for queries without an explicit namespace, the namespace used by... |
if self.namespace is not None:
return self
namespace = namespace_manager.get_namespace()
return self.__class__(kind=self.kind, ancestor=self.ancestor,
filters=self.filters, orders=self.orders,
app=self.app, namespace=namespace,
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def is_distinct(self):
"""True if results are guaranteed to contain a unique set of property values. This happens when every property in the group_by is also in ... |
return bool(self.__group_by and
set(self._to_property_names(self.__group_by)) <=
set(self._to_property_names(self.__projection))) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def fetch_async(self, limit=None, **q_options):
"""Fetch a list of query results, up to a limit. This is the asynchronous version of Query.fetch(). """ |
if limit is None:
default_options = self._make_options(q_options)
if default_options is not None and default_options.limit is not None:
limit = default_options.limit
else:
limit = _MAX_LIMIT
q_options['limit'] = limit
q_options.setdefault('batch_size', limit)
if self._... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def count_async(self, limit=None, **q_options):
"""Count the number of query results, up to a limit. This is the asynchronous version of Query.count(). """ |
qry = self._fix_namespace()
return qry._count_async(limit=limit, **q_options) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def fetch_page_async(self, page_size, **q_options):
"""Fetch a page of results. This is the asynchronous version of Query.fetch_page(). """ |
qry = self._fix_namespace()
return qry._fetch_page_async(page_size, **q_options) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _make_options(self, q_options):
"""Helper to construct a QueryOptions object from keyword arguments. Args: q_options: a dict of keyword arguments. Note that ... |
if not (q_options or self.__projection):
return self.default_options
if 'options' in q_options:
# Move 'options' to 'config' since that is what QueryOptions() uses.
if 'config' in q_options:
raise TypeError('You cannot use config= and options= at the same time')
q_options['confi... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def analyze(self):
"""Return a list giving the parameters required by a query.""" |
class MockBindings(dict):
def __contains__(self, key):
self[key] = None
return True
bindings = MockBindings()
used = {}
ancestor = self.ancestor
if isinstance(ancestor, ParameterizedThing):
ancestor = ancestor.resolve(bindings, used)
filters = self.filters
if fi... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _bind(self, args, kwds):
"""Bind parameter values. Returns a new Query object.""" |
bindings = dict(kwds)
for i, arg in enumerate(args):
bindings[i + 1] = arg
used = {}
ancestor = self.ancestor
if isinstance(ancestor, ParameterizedThing):
ancestor = ancestor.resolve(bindings, used)
filters = self.filters
if filters is not None:
filters = filters.resolve(b... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def cursor_before(self):
"""Return the cursor before the current item. You must pass a QueryOptions object with produce_cursors=True for this to work. If there i... |
if self._exhausted:
return self.cursor_after()
if isinstance(self._cursor_before, BaseException):
raise self._cursor_before
return self._cursor_before |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def cursor_after(self):
"""Return the cursor after the current item. You must pass a QueryOptions object with produce_cursors=True for this to work. If there is ... |
if isinstance(self._cursor_after, BaseException):
raise self._cursor_after
return self._cursor_after |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def has_next_async(self):
"""Return a Future whose result will say whether a next item is available. See the module docstring for the usage pattern. """ |
if self._fut is None:
self._fut = self._iter.getq()
flag = True
try:
yield self._fut
except EOFError:
flag = False
raise tasklets.Return(flag) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def positional(max_pos_args):
"""A decorator to declare that only the first N arguments may be positional. Note that for methods, n includes 'self'. """ |
__ndb_debug__ = 'SKIP'
def positional_decorator(wrapped):
if not DEBUG:
return wrapped
__ndb_debug__ = 'SKIP'
@wrapping(wrapped)
def positional_wrapper(*args, **kwds):
__ndb_debug__ = 'SKIP'
if len(args) > max_pos_args:
plural_s = ''
if max_pos_args != 1:
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def decorator(wrapped_decorator):
"""Converts a function into a decorator that optionally accepts keyword arguments in its declaration. Example usage: @utils.dec... |
def helper(_func=None, **options):
def outer_wrapper(func):
@wrapping(func)
def inner_wrapper(*args, **kwds):
return wrapped_decorator(func, args, kwds, **options)
return inner_wrapper
if _func is None:
# Form (2), with options.
return outer_wrapper
# Form (1), van... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def fibonacci(n):
"""A recursive Fibonacci to exercise task switching.""" |
if n <= 1:
raise ndb.Return(n)
a, b = yield fibonacci(n - 1), fibonacci(n - 2)
raise ndb.Return(a + b) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def memoizing_fibonacci(n):
"""A memoizing recursive Fibonacci to exercise RPCs.""" |
if n <= 1:
raise ndb.Return(n)
key = ndb.Key(FibonacciMemo, str(n))
memo = yield key.get_async(ndb_should_cache=False)
if memo is not None:
assert memo.arg == n
logging.info('memo hit: %d -> %d', n, memo.value)
raise ndb.Return(memo.value)
logging.info('memo fail: %d', n)
a = yield memoizin... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def run_queue(self, options, todo):
"""Actually run the _todo_tasklet.""" |
utils.logging_debug('AutoBatcher(%s): %d items',
self._todo_tasklet.__name__, len(todo))
batch_fut = self._todo_tasklet(todo, options)
self._running.append(batch_fut)
# Add a callback when we're done.
batch_fut.add_callback(self._finished_callback, batch_fut, todo) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def add(self, arg, options=None):
"""Adds an arg and gets back a future. Args: arg: one argument for _todo_tasklet. options: rpc options. Return: An instance of ... |
fut = tasklets.Future('%s.add(%s, %s)' % (self, arg, options))
todo = self._queues.get(options)
if todo is None:
utils.logging_debug('AutoBatcher(%s): creating new queue for %r',
self._todo_tasklet.__name__, options)
if not self._queues:
eventloop.add_idle(self... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _finished_callback(self, batch_fut, todo):
"""Passes exception along. Args: batch_fut: the batch future returned by running todo_tasklet. todo: (fut, option)... |
self._running.remove(batch_fut)
err = batch_fut.get_exception()
if err is not None:
tb = batch_fut.get_traceback()
for (fut, _) in todo:
if not fut.done():
fut.set_exception(err, tb) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_namespaces(start=None, end=None):
"""Return all namespaces in the specified range. Args: start: only return namespaces >= start if start is not None. end... |
q = Namespace.query()
if start is not None:
q = q.filter(Namespace.key >= Namespace.key_for_namespace(start))
if end is not None:
q = q.filter(Namespace.key < Namespace.key_for_namespace(end))
return [x.namespace_name for x in q] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_kinds(start=None, end=None):
"""Return all kinds in the specified range, for the current namespace. Args: start: only return kinds >= start if start is n... |
q = Kind.query()
if start is not None and start != '':
q = q.filter(Kind.key >= Kind.key_for_kind(start))
if end is not None:
if end == '':
return []
q = q.filter(Kind.key < Kind.key_for_kind(end))
return [x.kind_name for x in q] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_properties_of_kind(kind, start=None, end=None):
"""Return all properties of kind in the specified range. NOTE: This function does not return unindexed pr... |
q = Property.query(ancestor=Property.key_for_kind(kind))
if start is not None and start != '':
q = q.filter(Property.key >= Property.key_for_property(kind, start))
if end is not None:
if end == '':
return []
q = q.filter(Property.key < Property.key_for_property(kind, end))
return [Property.k... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_representations_of_kind(kind, start=None, end=None):
"""Return all representations of properties of kind in the specified range. NOTE: This function does... |
q = Property.query(ancestor=Property.key_for_kind(kind))
if start is not None and start != '':
q = q.filter(Property.key >= Property.key_for_property(kind, start))
if end is not None:
if end == '':
return {}
q = q.filter(Property.key < Property.key_for_property(kind, end))
result = {}
for ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_entity_group_version(key):
"""Return the version of the entity group containing key. Args: key: a key for an entity group whose __entity_group__ key you ... |
eg = EntityGroup.key_for_entity_group(key).get()
if eg:
return eg.version
else:
return None |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def key_for_namespace(cls, namespace):
"""Return the Key for a namespace. Args: namespace: A string giving the namespace whose key is requested. Returns: The Key... |
if namespace:
return model.Key(cls.KIND_NAME, namespace)
else:
return model.Key(cls.KIND_NAME, cls.EMPTY_NAMESPACE_ID) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def key_for_entity_group(cls, key):
"""Return the key for the entity group containing key. Args: key: a key for an entity group whose __entity_group__ key you wa... |
return model.Key(cls.KIND_NAME, cls.ID, parent=key.root()) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def process_request(self, unused_request):
"""Called by Django before deciding which view to execute.""" |
# Compare to the first half of toplevel() in context.py.
tasklets._state.clear_all_pending()
# Create and install a new context.
ctx = tasklets.make_default_context()
tasklets.set_context(ctx) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _make_ctx_options(ctx_options, config_cls=ContextOptions):
"""Helper to construct a ContextOptions object from keyword arguments. Args: ctx_options: A dict o... |
if not ctx_options:
return None
for key in list(ctx_options):
translation = _OPTION_TRANSLATIONS.get(key)
if translation:
if translation in ctx_options:
raise ValueError('Cannot specify %s and %s at the same time' %
(key, translation))
ctx_options[translatio... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.