Exemple #1
0
def dumpQ(u):
    qname, qtype, qclass = u.getQuestion()
    print
    'qname=%s, qtype=%d(%s), qclass=%d(%s)' \
    % (qname,
       qtype, Type.typestr(qtype),
       qclass, Class.classstr(qclass))
Exemple #2
0
def dumpRR(u):
    name, type, klass, ttl, rdlength = u.getRRheader()
    typename = Type.typestr(type)
    print 'name=%s, type=%d(%s), class=%d(%s), ttl=%d' \
              % (name,
                 type, typename,
                 klass, Class.classstr(klass),
                 ttl)
    mname = 'get%sdata' % typename
    if hasattr(u, mname):
        print '  formatted rdata:', getattr(u, mname)()
    else:
        print '  binary rdata:', u.getbytes(rdlength)
Exemple #3
0
def dumpRR(u):
    name, type, klass, ttl, rdlength = u.getRRheader()
    typename = Type.typestr(type)
    print
    'name=%s, type=%d(%s), class=%d(%s), ttl=%d' \
    % (name,
       type, typename,
       klass, Class.classstr(klass),
       ttl)
    mname = 'get%sdata' % typename
    if hasattr(u, mname):
        print
        '  formatted rdata:', getattr(u, mname)()
    else:
        print
        '  binary rdata:', u.getbytes(rdlength)
Exemple #4
0
 def storeRR(self,u):
     r={}
     r['name'],r['type'],r['class'],r['ttl'],r['rdlength'] = u.getRRheader()
     r['typename'] = Type.typestr(r['type'])
     r['classstr'] = Class.classstr(r['class'])
     #print 'name=%s, type=%d(%s), class=%d(%s), ttl=%d' \
     #      % (name,
     #        type, typename,
     #        klass, Class.classstr(class),
     #        ttl)
     mname = 'get%sdata' % r['typename']
     if hasattr(u, mname):
         r['data']=getattr(u, mname)()
     else:
         r['data']=u.getbytes(r['rdlength'])
     return r
Exemple #5
0
 def storeRR(self, u):
     r = {}
     r['name'], r['type'], r['class'], r['ttl'], r[
         'rdlength'] = u.getRRheader()
     r['typename'] = Type.typestr(r['type'])
     r['classstr'] = Class.classstr(r['class'])
     #print 'name=%s, type=%d(%s), class=%d(%s), ttl=%d' \
     #      % (name,
     #        type, typename,
     #        klass, Class.classstr(class),
     #        ttl)
     mname = 'get%sdata' % r['typename']
     if hasattr(u, mname):
         r['data'] = getattr(u, mname)()
     else:
         r['data'] = u.getbytes(r['rdlength'])
     return r
 def accessType(self, name):
     type = Type()
     try:
         self.cur.execute("""SELECT * FROM TYPE
                         WHERE NAME = '%s'""" % name)
         result = self.cur.fetchone()  # change this later
         if result:
             type.name = result[0]
             type.superEffective = result[1]
             type.notEffective = result[2]
             type.noEffect = result[3]
         else:
             raise Exception('Invalid Type!')
     except DatabaseError as errDB:
         print(str(errDB))
     except Exception as err:
         print(str(err))
     return type
Exemple #7
0
 def __init__(self, fileName):
     self.line = 0
     self.type = type.Type()
     self.fileName = fileName
     self.reservedWords = {
         'inteiro': self.type.INTEIRO,
         'real': self.type.REAL,
         'logico': self.type.LOGICO,
         'caracter': self.type.CARACTER,
         'se': self.type.SE,
         'senao': self.type.SENAO,
         'enquanto': self.type.ENQUANTO,
         'leia': self.type.LEIA,
         'escreva': self.type.ESCREVA,
         'falso': self.type.FALSO,
         'verdadeiro': self.type.VERDADEIRO,
         'programa': self.type.PROGRAMA,
         'variaveis': self.type.VARIAVEIS,
     }
Exemple #8
0
def get_views_task ():
    types  = Type.get_types()
    lookup = OpLookup.OpLookup()
    report = []
    for asset_type in types:
        search  = {'__order__':      'views DESC',
                   'asset_types_id':  asset_type['id']}

        try:
            results = lookup(search)
        except:
            results = []

        acl = ACL()
        results = acl.filter_assets ("co" , results)

        if not results:
            continue
        if len(results) > REPORT_ITEM_SZ:
            results = results[:REPORT_ITEM_SZ]

        report.append((asset_type['name'], results))
    return report
Exemple #9
0
    def visitBopMul2DTensor(self, node: AST.BOp, args=None):
        (prog_1, expr_1) = self.visit(node.expr1)
        (prog_2, expr_2) = self.visit(node.expr2)

        # decl fresh vars
        expr_3 = self.getTempVar()

        typ_1 = node.expr1.type
        typ_2 = node.expr2.type
        typ_3 = node.type

        [I, J] = typ_1.shape
        [J, K] = typ_2.shape
        typ_mul = Type.Tensor([J])

        shrT = Util.Config.consSF

        cmd0 = IR.Comment(expr_1.idf + ' * ' + expr_2.idf)
        funcCallArgsDict = OrderedDict()
        funcCallArgsDict[IR.Int(I, 32)] = "I"
        funcCallArgsDict[IR.Int(J, 32)] = "J"
        funcCallArgsDict[IR.Int(K, 32)] = "K"
        funcCallArgsDict[expr_1] = "A"
        funcCallArgsDict[expr_2] = "B"
        funcCallArgsDict[expr_3] = "C"
        funcCallArgsDict[IR.Int(shrT)] = "shrT"

        funcCall = IR.FuncCall("MatMulCSF2D", funcCallArgsDict)
        comment = IR.Comment(str(node.metadata))
        prog_3 = IRUtil.prog_merge(prog_1, prog_2,
                                   IR.Prog([comment, cmd0, funcCall]))
        self.decls[expr_3.idf] = [typ_3]
        prog_3 = IRUtil.prog_merge(IR.Prog([IR.Decl(expr_3.idf, node.type)]),
                                   prog_3)

        return (prog_3, expr_3)
Exemple #10
0
def get_24h_task ():
    types  = Type.get_types()
    lookup = OpLookup.OpLookup()
    report = []
    for asset_type in types:
        search  = {'__order__':      'date_created DESC',
                   'asset_types_id':  asset_type['id'],
                   'date_created-':  'DATE_SUB(NOW(),INTERVAL 1 DAY)'}

        try:
            results = lookup(search)
        except:
            results = []

        acl = ACL()
        results = acl.filter_assets ("co" , results)

        if not results:
            continue
        if len(results) > REPORT_ITEM_SZ:
            results = results[:REPORT_ITEM_SZ]

        report.append((asset_type['name'], results))
    return report
Exemple #11
0
	def visitBopMul2DTensor(self, node:AST.BOp, args=None):
		(prog_1, expr_1) = self.visit(node.expr1)
		(prog_2, expr_2) = self.visit(node.expr2)

		# decl fresh vars
		expr_3 = self.getTempVar()

		typ_1 = node.expr1.type
		typ_2 = node.expr2.type
		typ_3 = node.type

		[I, J] = typ_1.shape
		[J, K] = typ_2.shape
		typ_mul = Type.Tensor([J])

		shrT = Util.Config.consSF

		cmd0 = IR.Comment(expr_1.idf + ' * ' + expr_2.idf)
		funcCallArgsDict = OrderedDict()
		funcCallArgsDict[IR.Int(I, 32)] = "I"
		funcCallArgsDict[IR.Int(J, 32)] = "J"
		funcCallArgsDict[IR.Int(K, 32)] = "K"
		funcCallArgsDict[expr_1] = "A"
		funcCallArgsDict[expr_2] = "B"
		funcCallArgsDict[expr_3] = "C"

		#Add an arg as to which arg out of A or B is the model
		#	This is ok, since Athos is right now tailored for neural network inference
		#	and in inference, in every linear layer, either of A or B will be the model.
		#	This is required because for some backends, knowing which of A or B is the model
		#	can make a difference in their performance.
		modelIsA = True
		if ((expr_1.idf in self.inputByPartyMapping) and (self.inputByPartyMapping[expr_1.idf]==0)):
			modelIsA = True
		elif ((expr_2.idf in self.inputByPartyMapping) and (self.inputByPartyMapping[expr_2.idf]==0)):
			modelIsA = False
		else:
			print("Expecting one of A or B to be the model, input by the server.")
			assert(False)
		funcCallArgsDict[IR.Bool(modelIsA)] = "modelIsA"

		progExtraBefore = IR.Prog([])
		progExtraAfter = IR.Prog([])
		if (Util.Config.disableTruncOpti):
			progExtraAfter = self.addTruncateFunctionCall(node, "MatMul2D", expr_3, Util.Config.consSF)
		else:
			expr1_sf = self.scaleFacMapping[expr_1.idf]
			expr2_sf = self.scaleFacMapping[expr_2.idf]
			if (expr1_sf > self.scaleFac):
				progExtraBefore = self.addTruncateFunctionCall(node.expr1, "MatMul2D", expr_1, expr1_sf-self.scaleFac)
				self.scaleFacMapping[expr_1.idf] = self.scaleFac
			if (expr2_sf > self.scaleFac):
				progExtraBefore = IRUtil.prog_merge(progExtraBefore, self.addTruncateFunctionCall(node.expr2, "MatMul2D", expr_2, expr2_sf-self.scaleFac))
				self.scaleFacMapping[expr_2.idf] = self.scaleFac
			self.scaleFacMapping[expr_3.idf] = 2*self.scaleFac
		
		funcCall = IR.FuncCall("MatMul2D", funcCallArgsDict)
		comment = IR.Comment(str(node.metadata))
		prog_3 = IRUtil.prog_merge(prog_1, prog_2, progExtraBefore, IR.Prog([comment, cmd0, funcCall]))
		prog_3 = IRUtil.prog_merge(IR.Prog([IR.Decl(expr_3.idf, node.type)]), prog_3, progExtraAfter)

		return (prog_3, expr_3)
Exemple #12
0
	def visitReshape(self, node:AST.Reshape, args=None):
		(prog_1, expr_1) = self.visit(node.expr)

		'''
		reshape(A, n, h, w)

		cmd1:  t1 = t2 = t3 = 0;
		loop2: for n in 0:N:
				 for h in 0:H:
				   for w in 0:W:
		cmd3:        B[n][h][w] = A[t1][t2][t3]
		cmd4:        t3++;
		cmd5:        if (t3 == WW)
					   t3 = 0;
					   t2++;
					   if (t2 == HH)
						 t2 = 0;
						 t1++;
		'''

		typ_1 = node.expr.type
		typ_2 = node.type

		# Declare variables
		expr_2 = self.getTempVar()
		iters_1 = self.getTempIterators(typ_1.dim)
		iters_2 = self.getTempIterators(typ_2.dim)

		# Initialize to 0
		cmd1 = [IR.Assn(var, IRUtil.zero) for var in iters_1]

		# Incrementing the first index
		first_iter = iters_1[0]
		cmd4 = IRUtil.incCmd(first_iter)

		# Incrementing other indices using a loop
		cmd5 = [cmd4]
		for i in range(1, typ_1.dim):
			curr_iter = iters_1[i]
			curr_size = IR.Int(typ_1.shape[i])
			cmd5 = [IRUtil.incCmd(curr_iter), IR.If(IRUtil.eq(curr_iter, curr_size), [IRUtil.initVarToZero(curr_iter)] + cmd5)]
		
		# Outer loop
		# The iterators are selected based on the selection order specified by the user
		loopShape = []
		loopIters = []

		if(node.order):
			for order in node.order:
				order = order - 1
				loopShape.append(typ_2.shape[order])
				loopIters.append(iters_2[order])
		else:
			loopShape = typ_2.shape
			loopIters = iters_2

		loop2 = IRUtil.loop(loopShape, loopIters, [IR.Assn(IRUtil.addIndex(expr_2, iters_2), IRUtil.addIndex(expr_1, iters_1))] + cmd5)

		# Finalize
		comment1 = IR.Comment(str(node.metadata))
		comment2 = IR.Comment("reshape(" + expr_1.idf + ", " + ', '.join(str(e) for e in typ_2.shape) + ")")
		reshape_prog = IR.Prog([comment1, comment2] + cmd1 + loop2)
		prog_2 = IRUtil.prog_merge(prog_1, reshape_prog)

		for var in iters_1:
			prog_2 = IRUtil.prog_merge(IR.Prog([IR.Decl(var.idf, Type.Int(), isSecret=False)]), prog_2)
		for var in iters_2:
			prog_2 = IRUtil.prog_merge(IR.Prog([IR.Decl(var.idf, Type.Int(), isSecret=False)]), prog_2)
		prog_2 = IRUtil.prog_merge(IR.Prog([IR.Decl(expr_2.idf, typ_2)]), prog_2)

		if not(Util.Config.disableTruncOpti):
			self.scaleFacMapping[expr_2.idf] = self.scaleFacMapping[expr_1.idf]

		return (prog_2, expr_2)
Exemple #13
0
	def visitBopAddOrSubLike(self, node:AST.BOp, args=None):
		(prog_1, expr_1) = self.visit(node.expr1)
		(prog_2, expr_2) = self.visit(node.expr2)

		op = node.op
		if (op == AST.Operators.ADD):
			(op_ir, op_fn) = (IR.Op.Op['+'], operator.add)
			funcName = "MatAdd"
		elif (op == AST.Operators.SUB):
			(op_ir, op_fn) = (IR.Op.Op['-'], operator.sub)
			funcName = "MatSub"
		elif (op == AST.Operators.Equal):
			(op_ir, op_fn) = (IR.Op.Op['=='], operator.eq)
			funcName = "MatEqual"
		else:
			assert False

		typ_3 = node.type
		expr_3 = self.getTempVar()
		cmd0 = IR.Comment(expr_1.idf + ' ' + op_ir.name + ' ' + expr_2.idf)
		comment = IR.Comment(str(node.metadata))

		if not(Util.Config.disableTruncOpti):
			expr1_sf = self.scaleFacMapping[expr_1.idf]
			expr2_sf = self.scaleFacMapping[expr_2.idf]
			scaleUpFactor = -1
			if (expr1_sf > expr2_sf):
				exprToScale = expr_2
				typeOfExprToScale = node.expr2.type
				scaleUpFactor = expr1_sf - expr2_sf
				self.scaleFacMapping[expr_2.idf] = expr1_sf
			elif (expr2_sf > expr1_sf):
				exprToScale = expr_1
				typeOfExprToScale = node.expr1.type
				scaleUpFactor = expr2_sf - expr1_sf
				self.scaleFacMapping[expr_1.idf] = expr2_sf

			if scaleUpFactor!=-1:
				comm = IR.Comment('Scale up of args needed was found while doing OptimizeTruncations.')
				argsDict = OrderedDict()
				curFuncName = "ScaleUp"
				if not(Type.isInt(typeOfExprToScale)):
					outputShape = typeOfExprToScale.shape
					for ii,curDimSize in enumerate(outputShape):
						argsDict[IR.Int(curDimSize, 32)] = "size_" + str(ii)
					curFuncName += str(len(outputShape))
				argsDict[exprToScale] = "exprToScale, arg#{0}".format(2 if (expr1_sf>expr2_sf) else 1)
				argsDict[IR.Int(scaleUpFactor, 32)] = "ScaleUpFactor"
				funcCall = IR.FuncCall(curFuncName, argsDict)
				curProg = IR.Prog([comm,funcCall])
				prog_1 = IRUtil.prog_merge(curProg, prog_1)

			self.scaleFacMapping[expr_3.idf] = self.scaleFacMapping[expr_1.idf]

		if Type.isInt(typ_3):
			decl = IR.Decl(expr_3.idf, typ_3, typ_3.bitlen, typ_3.isSecret)
			assign = IR.Assn(expr_3, IR.IntBop(expr_1, op_ir, expr_2))
			prog_3 = IRUtil.prog_merge(prog_1, prog_2, IR.Prog([comment, cmd0, decl, assign]))
		else:
			## TODO
			if (node.type.dim != node.expr1.type.dim):
				# This needs broadcast of expr1
				assert False # For now this shouldn't occur
			if (node.type.dim != node.expr2.type.dim):
				# This needs broadcast of expr2
				funcName += 'BroadCast'

			outputShape = typ_3.shape
			argsDict = OrderedDict()
			inp1_shape = node.expr1.type.shape
			inp2_shape = node.expr2.type.shape
			for ii,curDimSize in enumerate(inp1_shape):
				argsDict[IR.Int(curDimSize, 32)] = "size_" + str(ii)
			for ii,curDimSize in enumerate(inp2_shape):
				argsDict[IR.Int(curDimSize, 32)] = "size_" + str(ii)
			for ii,curDimSize in enumerate(outputShape):
				argsDict[IR.Int(curDimSize, 32)] = "size_" + str(ii)
			argsDict[expr_1] = "A"
			argsDict[expr_2] = "B"
			argsDict[expr_3] = "C"
			funcCall = IR.FuncCall(funcName + self.varNameDelim + str(len(outputShape)), argsDict)
			prog_3 = IRUtil.prog_merge(prog_1, prog_2, IR.Prog([comment, cmd0, funcCall]))
			prog_3 = IRUtil.prog_merge(IR.Prog([IR.Decl(expr_3.idf, node.type)]), prog_3)

		return (prog_3, expr_3)
# coding=utf-8

# python2.7
# 设置vs开始执行快捷键F12
import Const
# Const.pi=3.1415926

import Type
Type.TypeFun()

from Class import ClassFun
ClassFun()

Exemple #15
0
    from Element import *
    from Type import *

    try:
        c = Sequence([{
            'name': "AnyBIC",
            'type': "AnyBICIdentifier",
            'maxOccurs': 2,
            'minOccurs': 1
        }, {
            'name': "PrtryId",
            'type': "GenericIdentification29",
            'minOccurs': 0
        }, {
            'name': "NmAndAdr",
            'type': "NameAndAddress6",
            'maxOccurs': 2,
            'minOccurs': 0
        }])
        print(c.render())

        c.check([
            Element('AnyBIC', Type('test', c)),
            # Element('AnyBIC', Type('test', c)),
            Element('PrtryId', Type('test', c)),
            Element('NmAndAdr', Type('test', c)),
            Element('NmAndAdr', Type('test', c)),
            Element('AnyBIC', Type('test', c))
        ])
    except BaseException as e:
        print(e)
Exemple #16
0
import sys

stallmates = set()

# i = 0
for pokemon1_t1 in Type.types:
    for pokemon1_t2 in Type.types:
        for pokemon2_t1 in Type.types:
            for pokemon2_t2 in Type.types:
                # sys.stdout.write("\r" + str(i))
                poke1 = frozenset([pokemon1_t1, pokemon1_t2])
                poke2 = frozenset([pokemon2_t1, pokemon2_t2])
                pair = frozenset([poke1, poke2])
                if pair in stallmates:
                    continue
                first = [t in Type.resistances(pokemon2_t1, pokemon2_t2) for \
                         t in Type.weaknesses(pokemon1_t1, pokemon1_t2)]
                second = [t in Type.resistances(pokemon1_t1, pokemon1_t2) for \
                       t in Type.weaknesses(pokemon2_t1, pokemon2_t2)]
                if all(first) and all(second):
                    # print "Found pair!"
                    stallmates.add(pair)
                # i = i + 1
# sys.stdout.write("\n")

for [typing1, typing2] in stallmates:
    try:
        [p1_t1, p1_t2] = typing1
    except:
        p1_t2 = None
    try:
Exemple #17
0
                dtype=str,
                engine='python',
                error_bad_lines=False))
# ★★ チェック対象となるtxtファイル名を変えてください!! ↓(緑色のここ) ★★
b = pd.DataFrame(
    pd.read_csv(path + 'USA_U_Product.txt',
                sep='\t',
                encoding='utf_16',
                dtype=str,
                engine='python',
                error_bad_lines=False))

a = a.sort_values(by='Inner Code')
b = b.sort_values(by='Inner Code')

a = a.astype(Type.type())  # データ型をそろえる
a = a.fillna('')
a.to_csv(path + 'A_product.txt', sep='\t', encoding='utf_16', index=False)

b = b.astype(Type.type())  # データ型をそろえる
b = b.fillna('')
b.to_csv(path + 'B_product.txt', sep='\t', encoding='utf_16', index=False)

dictB = {}
h = []
with open(path + 'A_product.txt', encoding='utf_16') as fileB:
    reader = csv.reader(fileB, delimiter='\t')
    reader = csv.reader((line.replace('\0', '') for line in fileB))
    for row in reader:
        for sel in row:
            dictB[sel] = True
Exemple #18
0
    def visitBopAddOrSubLike(self, node: AST.BOp, args=None):
        (prog_1, expr_1) = self.visit(node.expr1)
        (prog_2, expr_2) = self.visit(node.expr2)

        # op_ir, typ_3
        op = node.op
        if (op == AST.Operators.ADD):
            (op_ir, op_fn) = (IR.Op.Op['+'], operator.add)
            funcName = "MatAdd"
        elif (op == AST.Operators.SUB):
            (op_ir, op_fn) = (IR.Op.Op['-'], operator.sub)
            funcName = "MatSub"
        elif (op == AST.Operators.Equal):
            (op_ir, op_fn) = (IR.Op.Op['=='], operator.eq)
            funcName = "MatEqual"
        elif (op == AST.Operators.Max):
            (op_ir, op_fn) = (
                IR.Op.Op['max'], None
            )  #TODO : the operator for max is not needed right now -- add this later
            funcName = "MatMax"
        else:
            assert False

        typ_3 = node.type

        # e : Int
        if Type.isInt(typ_3):
            prog_3 = IRUtil.prog_merge(prog_1, prog_2)
            expr_3 = IR.IntBop(expr_1, op_ir, expr_2)

        # e : Tensor() -- float, or Tensor(..)
        else:
            ## TODO : Hack for techfest
            if (node.type.dim != node.expr1.type.dim):
                # This needs broadcast of expr1
                assert False  # For now this shouldn't occur
            if (node.type.dim != node.expr2.type.dim):
                # This needs broadcast of expr2
                funcName += 'BroadCast'

            # decl fresh vars
            expr_3 = self.getTempVar()

            cmd0 = IR.Comment(expr_1.idf + ' ' + op_ir.name + ' ' + expr_2.idf)
            outputShape = typ_3.shape
            argsDict = OrderedDict()
            for ii, curDimSize in enumerate(outputShape):
                argsDict[IR.Int(curDimSize, 32)] = "size_" + str(ii)
            argsDict[expr_1] = "A"
            argsDict[expr_2] = "B"
            argsDict[expr_3] = "C"
            funcCall = IR.FuncCall(
                funcName + self.varNameDelim + str(len(outputShape)), argsDict)
            comment = IR.Comment(str(node.metadata))
            prog_3 = IRUtil.prog_merge(prog_1, prog_2,
                                       IR.Prog([comment, cmd0, funcCall]))
            self.decls[expr_3.idf] = [typ_3]
            prog_3 = IRUtil.prog_merge(
                IR.Prog([IR.Decl(expr_3.idf, node.type)]), prog_3)

        return (prog_3, expr_3)
def getBool():
    '''se retorna el tipo de bool'''
    return Type(0)
	def verify(p1t1, p1t2, p2t1, p2t2):
		first = [t in Type.resistances(p2t1, p2t2) for t in Type.weaknesses(p1t1, p1t2)]
		second = [t in Type.resistances(p1t1, p1t2) for t in Type.weaknesses(p2t1, p2t2)]
		return all(first) and all(second)
Exemple #21
0
 def leader_prepare_phase(self):
     self.ballot.increment_num()
     self.ballot.process_id = self.process_id
     self.ballot.depth = len(self.chain.chain)
     self.send_message_to_all_process(Type.Prepare(self.ballot))
     print("Leader has walked through Prepare()")
import sys

stallmates = set()

# i = 0
for pokemon1_t1 in Type.types:
	for pokemon1_t2 in Type.types:
		for pokemon2_t1 in Type.types:
			for pokemon2_t2 in Type.types:
				# sys.stdout.write("\r" + str(i))
				poke1 = frozenset([pokemon1_t1, pokemon1_t2])
				poke2 = frozenset([pokemon2_t1, pokemon2_t2])
				pair = frozenset([poke1,poke2])
				if pair in stallmates:
					continue
				first = [t in Type.resistances(pokemon2_t1, pokemon2_t2) for \
				         t in Type.weaknesses(pokemon1_t1, pokemon1_t2)]
				second = [t in Type.resistances(pokemon1_t1, pokemon1_t2) for \
					      t in Type.weaknesses(pokemon2_t1, pokemon2_t2)]
				if all(first) and all(second):
					# print "Found pair!"
					stallmates.add(pair)
				# i = i + 1
# sys.stdout.write("\n")

for [typing1, typing2] in stallmates:
	try:
		[p1_t1, p1_t2] = typing1
	except:
		p1_t2 = None
	try:
Exemple #23
0
    def parseFunc(self, statement, state):
        isclass = False

        if type(state["sobj"]) is Section.Class:
            isclass = True
        elif type(state["sobj"]) is Section.Namespace:
            isclass = False
        else:
            print("Internal Error: sobj is `" + str(type(state["sobj"])) +
                  "` not Class or Namespace")
            state["error"] = True
            return state

        func = statement[4:].lstrip()

        func, rtype = func.rsplit("->", 1)

        func = func.rstrip()
        rtype = rtype.lstrip()

        const = False
        static = False
        virtual = False
        abstract = False

        # class specific parsing
        # We check the space after each one to make sure the keywords aren't part of the next token
        if func.startswith("const "):
            if not isclass:
                print("Error: const only allowed on class sections.")
                state["error"] = True
                return state
            const = True
            func = func[5:].lstrip()
        if func.startswith("static "):
            if not isclass:
                print("Error: static only allowed on class sections.")
                state["error"] = True
                return state
            static = True
            func = func[6:].lstrip()
        elif func.startswith("virtual "):
            if not isclass:
                print("Error: virtual only allowed on class sections.")
                state["error"] = True
                return state
            virtual = True
            func = func[8:].lstrip()
        elif func.startswith("abstract "):
            if not isclass:
                print("Error: abstract only allowed on class sections.")
                state["error"] = True
                return state
            virtual = True
            abstract = True
            func = func[9:].lstrip()

        func_and_tparams, param_str = func.split('(', 1)
        if ('<') in func_and_tparams:
            func, tparams = func_and_tparams.split('<')
            tparams = '<' + tparams
        else:
            func = func_and_tparams
            tparams = "<>"
        param_str = '(' + param_str.lstrip()

        if ENABLE_DEBUG:
            print(
                "Parsing function `" + func + "` with rtype `" + rtype +
                "`, parameters", param_str, "tparams", tparams,
                "and modifiers", ("const " if const else ""),
                ("static " if static else ""), ("virtual" if virtual else ""),
                ("abstract" if abstract else ""))

        param_list, throws_str = self.parseParamList(param_str)
        tparam_list = self.parseTParams(tparams)

        throws = self.parseThrowsStr(throws_str)

        # Verify that there are no spaces in the function name
        if re.match('^[\w]+$', func) is None:
            print("Invalid function name `" + func + '`')
            state["error"] = True
            return state

        # Generate Function object and append to sobj
        if not func in state["sobj"].functions:
            state["sobj"].functions[func] = []

        default_overloads = []
        first_defaulted = next(
            (i for i in range(len(param_list)) if param_list[i][1]),
            len(param_list))
        for i in range(first_defaulted, len(param_list) + 1):
            default_overloads.append(
                Function(func, Type.parseType(rtype), param_list[:i],
                         tparam_list, const, static, virtual, abstract, throws,
                         state["sobj"]))

        state["sobj"].functions[func] += default_overloads
        if virtual:
            if not func in state["sobj"].virtual_funcs:
                state["sobj"].virtual_funcs[func] = []
            state["sobj"].virtual_funcs[func] += default_overloads
        if abstract:
            state["sobj"].abstract = True

        return state
Exemple #24
0
 def __init__(self, name, type):
     self.name = name
     self.type = Type(type)
     self.subVariables = []
     self.containerSize = 0
     self.value = None
Exemple #25
0
	def visitUninterpFuncCall(self, node:AST.UninterpFuncCall, args=None):
		progList = []
		exprList = []
		for ii, curArg in enumerate(node.argsList):
			(progN, exprN) = self.visit(curArg)
			progList.append(progN)
			exprList.append(exprN)
		
		returnExpr = self.getTempVar()

		funcName = node.funcName
		funcName += self.varNameDelim + str(len(node.outputShape))
		for ii, curArg in enumerate(node.argsList):
			if Type.isTensor(curArg.type):
				curShape = curArg.type.shape

				# If len(shape) == 0 : that means its a float - no need to qualify
				#	the function name with 0 in that case, since its essentially
				#	become an int.
				if (len(curShape) > 0):
					funcName += self.varNameDelim + str(len(curShape))
				### TODO : right now if random strings like int are passed, its being set as datatype int -- int datatype in
				#		   unintrepreted func call is being used in a hacky way right now

		# Policy : 
		#	First output tensor sizes are inserted in args.
		#	Then for each input tensor, its shape is inserted in args, followed by the input tensor itself.
		#	If the current input tensor has the same shape as any of the previous tensors, then its shape is not inserted.
		funcArgsList = OrderedDict()

		if not(Util.Config.disableTruncOpti):
			#TODO -- remove CreateTensor from uninterp function calls
			for ii, curArg in enumerate(node.argsList):
				curExpr = exprList[ii]
				curScale = self.scaleFacMapping[curExpr.idf]
				curType = curArg.type
				if (not(Type.isInt(curType))) and (curScale > self.scaleFac) and (curType.isSecret):
					curProg = self.addTruncateFunctionCall(curArg, "UninterpFuncCall", curExpr, curScale - self.scaleFac)
					progList.insert(0,curProg)
					self.scaleFacMapping[curExpr.idf] = self.scaleFac

			self.scaleFacMapping[returnExpr.idf] = self.scaleFac

		tensorShapesFound = {}
		outputShape = node.type.shape
		for ii, curDim in enumerate(outputShape):
			funcArgsList[IR.Int(curDim, 32)] = "OutputShape_" + str(ii)
		tensorShapesFound[tuple(outputShape)] = True
		for ii in range(0, len(node.argsList)):
			if node.outputDiffInpDims < 2 and Type.isTensor(node.argsList[ii].type):
				curInpShape = node.argsList[ii].type.shape
				if ((node.outputDiffInpDims == 1) or (node.outputDiffInpDims == 0 and tuple(curInpShape) not in tensorShapesFound)):
					for jj, curDim in enumerate(curInpShape):
						funcArgsList[IR.Int(curDim, 32)] = "Input_" + str(ii) + self.varNameDelim + str(jj)
					tensorShapesFound[tuple(curInpShape)] = True
			funcArgsList[exprList[ii]] = "inpExpr_" + str(ii)
		funcArgsList[returnExpr] = "output"

		comment = IR.Comment(str(node.metadata))
		progFinal = progList[0]
		if len(progList) > 1:
			for ii in range(1, len(progList)):
				progFinal = IRUtil.prog_merge(progFinal, progList[ii])
		progFinal = IRUtil.prog_merge(progFinal, IR.Prog([comment, IR.FuncCall(funcName, funcArgsList)]))

		progFinal = IRUtil.prog_merge(IR.Prog([IR.Decl(returnExpr.idf, 
														node.type, 
														isSecret=False if node.isSecret is False else "secret")]), 
										progFinal)
		return (progFinal, returnExpr)
def getFunc():
    '''se retorna el tipo de  func'''
    return Type(2)
Exemple #27
0
	def defineType(self, typeTitle):
		self.type = Type.Type(typeTitle)
Exemple #28
0
    def _compile_tags (self):
        # Versions & Source
        version_of = None
        version    = self._db.get('version', None)
        versions   = [x['id'] for x in self._versions if x['id']!=self['id']]
        source     = self._parent_id
        if self['version'] != 1:
            version_of = self._replacements.get('replaces')

        # Formats
        has_formats  = None
        is_format_of = None
        if self._formats:
            format_list  =[x['format'] for x in self._formats if x['id']!=self['id']]
            has_formats  = dict.fromkeys(format_list).keys()
            for f in self._formats:
                if f['source'] == None and f['id'] != self['id']:
                    is_format_of = f['id']

        self._tags = {
            'Creator':          self._db.get('creator_id'),
            'Date':             max(self._db.get('date_modified'), self._db.get('date_edited'), self._db.get('date_created')),
            'Date Created':     self._db.get('date_created'),
            'Date (Modified)':  self._db.get('date_modified'),
            'Date Available':   self._db.get('date_available'),
            'Description':      self._db.get('description'),
            'Extent':           self._file.get('extent'),
            'Format':           self._file.get('formats_id'),
            'Has Format':       has_formats,
            'Has Part':         self._parts.get('has_parts_of'),
            'Has Version':      versions,
            'Identifier':       self._db.get('id'),
            'Is Format Of':     is_format_of,
            'Is Part Of':       self._parts.get('is_part_of'),
            'Is Referenced By': self._db.get('collections_id'),
            'Is Replaced By':   self._replacements.get('replaced_by'),
            'Is Version Of':    version_of,
            'Language':         self._db.get('language'),
            'Publisher':        self._db.get('publisher_id'),
            'Relation':         self._collection,
            'Replaces':         self._replacements.get('replaces'),
            'Source':           source,
            'Subject':          self._db.get('subject'),
            'Title':            self._db.get('title'),
            'Type':             self._db.get('asset_types_id'),
            'Rights':           self._db.get('licenses_id'),
            }

        if self['Creator']:
            self._tags['Creator'] = Auth.get_user_name (self['tags']['Creator'])
        if self['Publisher']:
            self._tags['Publisher'] = Auth.get_user_name (self['tags']['Publisher'])
        if self['Rights']:
            self._tags['Rights']    = License.get_license_name(self['tags']['Rights'])
        if self['Format']:
            self._tags['Format']    = Format.get_format_name (self['tags']['Format'])
        if self['Type']:
            self._tags['Type']      = Type.get_type_name (self['tags']['Type'])

        for key in self._tags.keys():
            if key.startswith('Date') and self._tags[key] == '0000-00-00 00:00:00':
                self._tags[key] = None
def getInt():
    '''se retorna el objeto de  tipo entero
    '''
    return Type(1)
Exemple #30
0
    def updateContent(self, str):
        connectState = str[0:1]
        info = str[1:]
        # print connectState,info
        if connectState == "S":
            splitArray = info.split(',')
            trump = int(splitArray[1])
            lastUser = int(splitArray[3])

            self.S.trump = ("%d%s") % (trump / 7 + 1, Trumps[trump % 7])
            self.S.trumpRaw = trump
            self.S.attackWinNumber = (trump / 7 + 7)

            if self.S.threeMode:
                self.S.attackIndex[0] = 0
                self.S.attackIndex[1] = 2
            else:
                self.S.attackIndex[0] = (lastUser + 1) % 4
                self.S.attackIndex[1] = (lastUser + 3) % 4

            attackTeam = ''
            defenseTeam = ''

            for i in range(0, 4):
                player = self.S.players[i]
                if self.S.threeMode:
                    player = self.S.threeModeUsers[i]
                if i in self.S.attackIndex:
                    attackTeam = attackTeam + player + ' , '
                else:
                    defenseTeam = defenseTeam + player + ' , '
            self.S.attackTeam = attackTeam[0:len(attackTeam) - 3]
            self.S.defenseTeam = defenseTeam[0:len(defenseTeam) - 3]

        elif connectState == "T":
            self.S.threeMode = True
        elif connectState == "C":
            splitArray = info.split(',')
            lastUser = int(splitArray[0])
            trump = int(splitArray[2])
            updateRecord = self.S.callsRecord[lastUser]
            updateRaw = self.S.callsRaw[lastUser]
            if trump != -1:
                tempStr = ("%d%s,") % ((trump / 7) + 1, Trumps[trump % 7])
            else:
                tempStr = "Pass,"
            self.S.callsRecord[lastUser] = updateRecord + tempStr
            self.S.callsRaw[lastUser] = updateRaw + ("%d^") % trump

        elif connectState == "P":
            splitArray = info.split(',')
            nextUser = int(splitArray[2])
            lastUser = (nextUser + 4 - 1) % 4
            poker = int(splitArray[0])
            playState = Type.PlayState(int(splitArray[1]))

            if poker != 0:
                removeIndex = lastUser
                updateRecord = self.S.playsRecord[lastUser]
                updateRaw = self.S.playsRaw[lastUser]
                tempStr = showPokerStr(poker)
                self.S.playsRecord[lastUser] = updateRecord + tempStr
                self.S.playsRaw[lastUser] = updateRaw + ("%d^") % poker
                flower = int((poker - 1) / 13)
                self.S.flowerCountRecord[flower] += 1
                if self.S.threeMode:
                    removeIndex = self.S.threeModeIndex[lastUser]
                self.S.playsPokerHand[removeIndex].remove(poker)
            else:
                if nextUser in self.S.attackIndex:
                    self.S.attackScore += 1
                else:
                    self.S.defenseScore += 1

                self.S.boutsWinRecord.append(nextUser)
                if poker != 0:
                    flower = int((poker - 1) / 13)
                    self.S.flowerCountRecord[flower] += 1

                for index in range(4):
                    tempStr = self.S.playsRecord[index]
                    tempStr = tempStr[:-1]
                    if index == nextUser:
                        tempStr += "✓,"
                    else:
                        tempStr += "✗,"
                    self.S.playsRecord[index] = tempStr

            if playState == Type.PlayState.GameOver:
                self.recordCSV()
                self.saveShowRecord()

        self.server.send_message_to_all(self.S.getUpdateInfo())
def getError():
    '''se retorna el tipo error'''
    return Type(-1)
Exemple #32
0
        if not values[0].name in tuple(v['name'] for v in self.criteria):
            raise BaseException('Invalid data \'Element.' + values[0].name +
                                '\'')

    def _toHtml(self):
        resVal = '('
        for cri in self.criteria:
            resVal += cri['name'] + ', '
        return resVal[:-2:] + ')'


if __name__ == '__main__':
    from Element import *
    from Type import *

    try:
        c = Choice([{
            'name': "AnyBIC",
            'type': "AnyBICIdentifier"
        }, {
            'name': "PrtryId",
            'type': "GenericIdentification29"
        }, {
            'name': "NmAndAdr",
            'type': "NameAndAddress6"
        }])
        print(c.render())

        c.check([Element('AnyBIC', Type('test', c))])
    except BaseException as e:
        print(e)
Exemple #33
0
    def open(self,
             file=None,
             mode='rb',
             cryptoType=-1,
             cryptoKey=-1,
             cryptoCounter=-1):
        super(NcaHeader, self).open(file, mode, cryptoType, cryptoKey,
                                    cryptoCounter)
        self.rewind()
        self.signature1 = self.read(0x100)
        self.signature2 = self.read(0x100)
        self.magic = self.read(0x4)
        self.isGameCard = self.readInt8()
        self.contentType = self.readInt8()

        try:
            self.contentType = Type.Content(self.contentType)
        except:
            pass

        self.cryptoType = self.readInt8()
        self.keyIndex = self.readInt8()
        self.size = self.readInt64()
        self.titleId = hx(self.read(8)[::-1]).decode('utf-8').upper()

        self.readInt32()  # padding

        self.sdkVersion = self.readInt32()
        self.cryptoType2 = self.readInt8()

        self.read(0xF)  # padding

        self.rightsId = hx(self.read(0x10))

        if self.magic not in [b'NCA3', b'NCA2']:
            raise Exception('Failed to decrypt NCA header: ' + str(self.magic))

        self.sectionHashes = []

        for i in range(4):
            self.sectionTables.append(SectionTableEntry(self.read(0x10)))

        for i in range(4):
            self.sectionHashes.append(self.sectionTables[i])

        self.masterKey = (self.cryptoType if self.cryptoType > self.cryptoType2
                          else self.cryptoType2) - 1

        if self.masterKey < 0:
            self.masterKey = 0

        self.encKeyBlock = self.getKeyBlock()
        #for i in range(4):
        #	offset = i * 0x10
        #	key = encKeyBlock[offset:offset+0x10]
        #	Print.info('enc %d: %s' % (i, hx(key)))

        if Keys.keyAreaKey(self.masterKey, self.keyIndex):
            crypto = aes128.AESECB(
                Keys.keyAreaKey(self.masterKey, self.keyIndex))
            self.keyBlock = crypto.decrypt(self.encKeyBlock)
            self.keys = []
            for i in range(4):
                offset = i * 0x10
                key = self.keyBlock[offset:offset + 0x10]
                #Print.info('dec %d: %s' % (i, hx(key)))
                self.keys.append(key)
        else:
            self.keys = [None, None, None, None, None, None, None]

        if self.hasTitleRights():
            if self.titleId.upper() in Titles.keys() and Titles.get(
                    self.titleId.upper()).key:
                self.titleKeyDec = Keys.decryptTitleKey(
                    uhx(Titles.get(self.titleId.upper()).key), self.masterKey)
            else:
                pass
                #Print.info('could not find title key!')
        else:
            self.titleKeyDec = self.key()
Exemple #34
0
def dumpQ(u):
    qname, qtype, qclass = u.getQuestion()
    print 'qname=%s, qtype=%d(%s), qclass=%d(%s)' \
              % (qname,
                 qtype, Type.typestr(qtype),
                 qclass, Class.classstr(qclass))
Exemple #35
0
 def storeQ(self,u):
     q={}
     q['qname'], q['qtype'], q['qclass'] = u.getQuestion()
     q['qtypestr']=Type.typestr(q['qtype'])
     q['qclassstr']=Class.classstr(q['qclass'])
     return q
Exemple #36
0
def home():
    if request.method == 'POST':
        data = request.get_json()  # Get Data from JS
        aux = data['cadena'].split('\n')
        lista = []
        for x in aux:
            for j in x.split(';'):
                if len(j) > 0:
                    lista.append(j)
        errores = []
        var = []
        count = 0
        lista, errores = While.While(lista).Search_While(errores)
        for l in lista:
            if '<' in l or '>' in l or '==' in l:
                if Logic.Logic().SintaxLogic(l):
                    # Check if they are the same typ
                    errores = Logic.Logic().CheckSintax(l, var, errores)
                else:
                    errores.append('Error de la sintaxis en ' + l)
            if '=' in l and Equals.Equals(l).CheckString() == True:
                temp = l.split('=')
                if len(temp) < 2 or len(temp) > 2:
                    errores.append('Error de sintaxis' + l)
                else:
                    # we hake to check if the var has already been in the list
                    result, T, index = Search.Search().Search_Name(
                        var, temp[0])
                    if result == True:
                        # Check if the value is a number or a var
                        if Is_there_letter(temp[1]) and ('"' in l
                                                         or "'" in l) == False:
                            if '+' in temp[1] or '-' in temp[1] or '*' in temp[
                                    1] or '/' in temp[1]:
                                errores, var = Operation.Operation(l).Convert(
                                    var, errores)
                            else:
                                errores, var = CheckAssig.Check(
                                ).Check_Var_Var(l, T, index, errores, var,
                                                temp)
                        else:
                            if '+' in temp[1] or '-' in temp[1] or '*' in temp[
                                    1] or '/' in temp[1]:
                                errores, var = Operation.Operation(l).Convert(
                                    var, errores)
                            else:
                                errores, var = CheckAssig.Check(
                                ).Check_Var_Value(l, AssignTree, errores, var,
                                                  index, T, temp)
                    else:
                        errores.append('Error variable no declarada ' + l)
            if ('Write(' in l) == False and (
                    'while' in l
            ) == False and l != '(' and l != ')' and l != '{' and l != '}' and (
                    '=' in l) == False and ('<' in l or '>' in l) == False:
                errores, var = Type.Type().types(Trees, l, errores, var)
            if 'Write(' in l:
                errores = write.Write(l, var=var,
                                      errores=errores).CheckSintax()
                pass
            count = count + 1
        #aqui tengo q convertir el diccionario a json
        diccionario_vars = {}
        for let in var:
            diccionario_vars[let.name] = {
                'type': let.Type,
                'name': let.name,
                'value': let.value
            }

        return jsonify({'mensajes': errores, 'variables': diccionario_vars})
    return render_template('index.html')
Exemple #37
0
 def storeQ(self, u):
     q = {}
     q['qname'], q['qtype'], q['qclass'] = u.getQuestion()
     q['qtypestr'] = Type.typestr(q['qtype'])
     q['qclassstr'] = Class.classstr(q['qclass'])
     return q
Exemple #38
0
    def parseOperator(self, statement, state):
        isclass = False

        if type(state["sobj"]) is Section.Class:
            isclass = True
        else:
            print("Internal Error: sobj is `" + str(type(state["sobj"])) +
                  "` not Class")
            state["error"] = True
            return state

        func = statement[8:].lstrip()

        func, rtype = func.rsplit("->", 1)

        func = func.rstrip()
        rtype = rtype.lstrip()

        const = False
        static = False
        virtual = False
        abstract = False

        # class specific parsing
        # We check the space after each one to make sure the keywords aren't part of the next token
        if func.startswith("const "):
            if not isclass:
                print("Error: const only allowed on class sections.")
                state["error"] = True
                return state
            const = True
            func = func[5:].lstrip()
        if func.startswith("static "):
            if not isclass:
                print("Error: static only allowed on class sections.")
                state["error"] = True
                return state
            static = True
            func = func[6:].lstrip()
        elif func.startswith("virtual "):
            if not isclass:
                print("Error: virtual only allowed on class sections.")
                state["error"] = True
                return state
            virtual = True
            func = func[6:].lstrip()
        elif func.startswith("abstract "):
            if not isclass:
                print("Error: abstract only allowed on class sections.")
                state["error"] = True
                return state
            virtual = True
            abstract = True
            func = func[9:].lstrip()

        func_and_tparams, param_str = func.split('(', 1)
        if ('<') in func_and_tparams:
            func, tparams = func_and_tparams.split('<')
            tparams = '<' + tparams
        else:
            func = func_and_tparams
            tparams = "<>"
        param_str = '(' + param_str.lstrip()

        if ENABLE_DEBUG:
            print(
                "Parsing function `" + func + "` with rtype `" + rtype +
                "`, parameters", param_str, "tparams", tparams,
                "and modifiers", ("const " if const else ""),
                ("static " if static else ""), ("virtual" if virtual else ""),
                ("abstract" if abstract else ""))

        param_list, throws_str = self.parseParamList(param_str)
        tparam_list = self.parseTParams(tparams)

        throws = self.parseThrowsStr(throws_str)

        if not func in state["sobj"].functions:
            state["sobj"].functions[func] = []
        # Generate Function object and append to sobj
        state["sobj"].functions[func].append(
            Operator(func, Type.parseType(rtype), param_list, tparam_list,
                     const, static, virtual, abstract, throws, state["sobj"]))

        if abstract:
            state["sobj"].abstract = True

        return state