コード例 #1
0
    def p_dtypeSolo(p):
        '''dtypeSolo : DTYPE_SOLO
                     | DTYPE_BOTH_1PARAM
                     | DTYPE_SOLO_1PARAM2
                     | DTYPE_BOTH_1PARAM LPAREN parameter RPAREN
                     | DTYPE_SOLO_1PARAM2 LPAREN parameter RPAREN
                     | DTYPE_SOLO_1PARAM2 LPAREN parameter COMMA parameter RPAREN'''
        debug("dtypeSolo")

        p[0] = p[1]

        global param_list
        param_list = []  # inicializes param_list

        #NOTE: we add our own limitations to this potentially unlimited numeric
        #      for filling reasons
        if len(p) == 2 and p[1] == "numeric":
            param_list.append(NUMERIC_INT)
            param_list.append(NUMERIC_FRAC)

        elif len(p) == 2 and (p[1] == "bit" or p[1] == "character"):
            param_list.append(DEFAULT_BIT_CHAR)

        if len(p) == 5:  # variant: DTYPE_BOTH_1PARAM LPAREN parameter RPAREN
            param_list.append(p[3])

        elif len(p) == 7:  # variant: DTYPE_SOLO_1PARAM2 LPAREN parameter COMMA parameter RPAREN
            param_list.append(p[3])
            param_list.append(p[5])
コード例 #2
0
    def p_multi_1param(p):
        '''multi_1param : idOrDtypeName COMMA
                        | idOrDtypeName'''
        debug("multi_1param")

        global alter_attr
        global alter_table
        global TO_SET_CONSTR
        global PARAM_COUNTER

        alter_attr = None
        alter_name = None

        #finding the attribute to get altered
        for attr in alter_table.attr_list:
            if attr.name == p[1]:  # p[1] stands for the attribute name in both cases
                alter_attr = attr
                break

        #did we find anything?
        if alter_attr is None:
            msg = "Input error: Couldn't find the given attribute name '" + p[7] \
                + "' in the list of attributes of table '" + alter_table.name \
                + "' while processing a multiparameter ADD CONSTRAINT.\n"
            errprint(msg, ERRCODE["INPUT"])

        alter_attr.constraint_flag = True
        alter_attr.constraint_cnt += 1  # increments the cnt

        TO_SET_CONSTR.append(alter_attr)  # we pass the attribute to alter
コード例 #3
0
    def p_constraints(p):
        '''constraints : NOT NULL
                       | NULL
                       | UNIQUE
                       | DEFAULT NUMBER retype
                       | DEFAULT FLOATNUM retype
                       | DEFAULT QUOTE QUOTE retype
                       | DEFAULT QUOTE inquote QUOTE retype
                       | DEFAULT LPAREN NUMBER RPAREN retype
                       | DEFAULT LPAREN FLOATNUM RPAREN retype'''
        debug("constraints")

        if p[1] == "NOT":
            constr = p[1] + ' ' + p[2]
        else:
            constr = p[1]

        global new_attribute
        new_attribute.constraint_flag = True
        new_attribute.constraint_cnt += 1  # increments the cnt
        new_attribute.set_constraint(constr)

        if new_attribute.default:

            if len(p) == 6:  # default different than just ''
                new_attribute.default_value = p[3]

            elif len(p) == 4 and p[1] == "DEFAULT":
                new_attribute.default_value = p[2]
コード例 #4
0
    async def read_datas(self):
        while True:
            datas = await self._read_bytes()
            # 本函数对bytes进行相关操作,不特别声明,均为bytes
            if datas is None:
                return
            data_l = 0
            len_datas = len(datas)
            while data_l != len_datas:
                # 每片data都分为header和body,data和data可能粘连
                # data_l == header_l && next_data_l = next_header_l
                # ||header_l...header_r|body_l...body_r||next_data_l...
                tuple_header = self.structer.unpack_from(datas[data_l:])
                len_data, len_header, ver, opt, seq = tuple_header
                body_l = data_l + len_header
                next_data_l = data_l + len_data
                body = datas[body_l:next_data_l]
                # 人气值(或者在线人数或者类似)以及心跳
                if opt == 3:
                    # UserCount, = struct.unpack('!I', remain_data)
                    printer.debug(f'弹幕心跳检测{self._area_id}')
                # cmd
                elif opt == 5:
                    if not self.handle_danmu(body):
                        return
                # 握手确认
                elif opt == 8:
                    printer.info([f'{self._area_id}号弹幕监控进入房间({self._room_id})'], True)
                else:
                    printer.warn(datas[data_l:next_data_l])

                data_l = next_data_l
コード例 #5
0
    def p_multi_attr_constr(p):
        '''multi_attr_constr : ADD CONSTRAINT IDENTIFIER UNIQUE LPAREN multi_params RPAREN
                             | ADD CONSTRAINT IDENTIFIER PRIMARY KEY LPAREN multi_params RPAREN'''
        debug("multi_attr_constr")

        global TO_SET_CONSTR
        global GROUP_COUNTER
        global PARAM_COUNTER

        if len(p) == 9:  # two word constraint
            constr = p[4] + " " + p[5]
        else:
            constr = p[4]

        PARAM_COUNTER = len(TO_SET_CONSTR)  # gets size of PARAM_COUNTER so we know how many there are

        #checking if we got more than 1 param. If yes, it means more attributes create a unique group
        for attr in TO_SET_CONSTR:
            attr.set_constraint(
                constr)  # sets flag for each attribute

            if PARAM_COUNTER > 1:  # more than one attribute given as parameter -> group
                attr.unique_group = GROUP_COUNTER  # puts all attributes into the same group
            else:
                attr.unique_group = 0  # single unique attr

        if PARAM_COUNTER > 1:  # if we used the current group number
            GROUP_COUNTER = GROUP_COUNTER + 1  # we increment the counter

        TO_SET_CONSTR = []  # inicialize the set
        PARAM_COUNTER = 0  # and turns param counter back to zero
コード例 #6
0
    def p_dtypes(p):
        '''dtypes : TYPE_NOPARAM
                  | TYPE_1PARAM LPAREN NUMBER RPAREN
                  | TYPE_2PARAM LPAREN NUMBER COMMA NUMBER RPAREN
                  | TYPE_2PARAM_TIME LPAREN NUMBER COMMA TIMEZONE_PARAM RPAREN'''

        global new_attribute
        global new_table
        new_attribute.data_type = p[1]
        new_attribute.parameters = []  # inicializes to no parameters

        if len(p) == 5:  # stands for "DTYPE (1_param)"
            new_attribute.parameters.append(p[3])  # appends the parameter

        elif len(p) == 7:  # DTYPE_2PARAM
            new_attribute.parameters.append(p[3])
            new_attribute.parameters.append(p[5])

        if p[1] == 'SERIAL' or p[1] == 'BIGSERIAL':
            new_attribute.serial = True

        if p[1] == "TIME":
            print new_attribute.parameters

        debug("dtypes")
コード例 #7
0
    async def handle_msg(self):
        while True:
            bytes_datas = await self.__read_msg()
            if bytes_datas is None:
                return
            len_read = 0
            len_bytes_datas = len(bytes_datas)
            while len_read != len_bytes_datas:
                split_header = self.structer.unpack(bytes_datas[len_read:16 +
                                                                len_read])
                len_data, len_header, ver, opt, seq = split_header
                remain_data = bytes_datas[len_read + 16:len_read + len_data]
                # 人气值/心跳 3s间隔
                if opt == 3:
                    # self._UserCount, = struct.unpack('!I', remain_data)
                    printer.debug(f'弹幕心跳检测{self.area_id}')
                # cmd
                elif opt == 5:
                    if not self.handle_danmu(remain_data):
                        return
                # 握手确认
                elif opt == 8:
                    printer.info([f'{self.area_id}号弹幕监控进入房间({self.roomid})'],
                                 True)
                else:
                    printer.warn(bytes_datas[len_read:len_read + len_data])

                len_read += len_data
コード例 #8
0
    async def ReceiveMessageLoop(self):
        while True:
            bytes_datas = await self.ReadSocketData()
            if bytes_datas is None:
                break
            len_read = 0
            len_bytes_datas = len(bytes_datas)
            while len_read != len_bytes_datas:
                state = None
                split_header = self.structer.unpack(bytes_datas[len_read:16 +
                                                                len_read])
                len_data, len_header, ver, opt, seq = split_header
                remain_data = bytes_datas[len_read + 16:len_read + len_data]
                # 人气值/心跳 3s间隔
                if opt == 3:
                    # self._UserCount, = struct.unpack('!I', remain_data)
                    printer.debug(f'弹幕心跳检测{self.area_id}')
                # cmd
                elif opt == 5:
                    messages = remain_data.decode('utf-8')
                    dic = json.loads(messages)
                    state = self.loop_func(dic)
                # 握手确认
                elif opt == 8:
                    printer.info([f'{self.area_id}号弹幕监控进入房间({self.roomid})'],
                                 True)
                else:
                    printer.warn(bytes_datas[len_read:len_read + len_data])

                if state is not None and not state:
                    return
                len_read += len_data
コード例 #9
0
    def p_attributeName(p):
        'attributeName : DOUBLE_COLON IDENTIFIER endline'

        global new_attribute
        new_attribute = table.Attribute()  # new attribute instance
        new_attribute.values_list = []
        new_attribute.name = p[2]
        debug("attributeName")
コード例 #10
0
    def p_moreBlocks(p):
        '''moreBlocks : moreBlocks tableBlock
                      | empty'''
        debug("moreBlocks")

        global table_list
        global new_table

        table_list.append(new_table)
コード例 #11
0
    def p_alterBody(p):
        '''alterBody : ADD CONSTRAINT IDENTIFIER PRIMARY KEY LPAREN idOrDtypeName RPAREN
                     | ADD CONSTRAINT IDENTIFIER FOREIGN KEY LPAREN idOrDtypeName RPAREN REFERENCES IDENTIFIER LPAREN IDENTIFIER RPAREN
                     | multi_attr_constr'''
        debug("alterBody")

        global alter_attr
        global alter_table
        alter_attr = None
        alter_name = None

        #the multi_attr constraint has been solved already
        #this goes just for the KEYs
        if len(p) != 2:

            constr = p[4] + " " + p[5]

            #finding the attribute to get altered
            for attr in alter_table.attr_list:
                if attr.name == p[7]:  # p[7] stands for the attribute name in both cases
                    alter_attr = attr
                    break

            #did we find anything?
            if alter_attr is None:
                msg = "Input error: Couldn't find the given attribute name '" + p[7] \
                    + "' in the list of attributes of table '" + alter_table.name \
                    + "' while processing a " + constr + ".\n"
                errprint(msg, ERRCODE["INPUT"])

            alter_attr.constraint_flag = True
            alter_attr.constraint_cnt += 1  # increments the cnt
            alter_attr.set_constraint(constr)

            #for foreign key
            if p[4] == 'FOREIGN':

                #existence of foreign table check
                if not p[10] in name_dict.keys():
                    msg = "Input error: Foreign table '" + \
                        p[10] + "' couldn't be found.\n"
                    errprint(msg, ERRCODE["INPUT"])

                alter_attr.fk_table = name_dict[p[10]]
                    #gets the foreign table object

                for attr in alter_attr.fk_table.attr_list:
                    if attr.name == p[12]:
                        alter_attr.fk_attribute = attr
                        break

                #existence of foreign attribute check
                if alter_attr.fk_attribute is None:
                    msg = "Input error: Foreign attribute '" + p[12] \
                        + "' couldn't be found in table '" + p[10] \
                        + "' while processing a " + constr + ".\n"
                    errprint(msg, ERRCODE["INPUT"])
コード例 #12
0
 def p_dtypeNames(p):
     '''dtypeNames : DTYPE_SOLO
                   | DTYPE_BOTH_1PARAM
                   | DTYPE_SOLO_1PARAM2
                   | DTYPE_TIMEZONE_PARAM
                   | DTYPE_PART2
                   | DTYPE_PART1'''
     debug("dtypeNames")
     p[0] = p[1]
コード例 #13
0
    def p_moreBlocks(p):
        '''moreBlocks : moreBlocks tableBlock
                      | empty'''

        global new_table
        global attr_list
        new_table.attr_list = attr_list   # adds complete list of attributes
        new_table.count_attributes(
            )      # stores the count of attributes in table.attr_count
        debug("moreBlocks")
コード例 #14
0
    def p_alterHeader(p):
        'alterHeader : ALTER TABLE ONLY IDENTIFIER'
        debug("alterHeader")

        global alter_table
        if not p[4] in name_dict.keys():
            msg = "Input error: Table '" + p[4] + \
                "'given in ALTER part couldn't be found.\n"
            errprint(msg, ERRCODE["INPUT"])
        alter_table = name_dict[p[4]]
コード例 #15
0
    def p_tableHeader(p):
        'tableHeader : CREATE TABLE IDENTIFIER LPAREN'
        debug("tableHeader")

        global new_table
        global name_dict

        new_table = table.Table()  # creates new table instance
        new_table.name = p[3]

        name_dict[new_table.name] = new_table
コード例 #16
0
    def p_attributeName(p):
        '''attributeName : IDENTIFIER
                         | dtypeNames
                         | DQUOTES IDENTIFIER DQUOTES
                         | DQUOTES dtypeNames DQUOTES'''
        debug("attributeName")

        if len(p) == 2:
            p[0] = p[1]  # we pass the attribute name
        else:
            p[0] = p[2]
コード例 #17
0
    def p_parameter(p):
        '''parameter : PATH
                     | REGEX
                     | NUMBER
                     | IDENTIFIER
                     | IDENTIFIER COLON IDENTIFIER'''
        p[0] = p[1]  # returns the value in p[0]
        debug("parameter")

        if len(p) == 4:  # IDENTIFIER COLON IDENTIFIER variant
            p[0] = p[1] + ":" + p[3]
コード例 #18
0
    def p_fillMethod(p):
        '''fillMethod : FILL FILL_METHOD_NOPARAM LPAREN RPAREN endline
                      | FILL FILL_METHOD_1PARAM LPAREN parameter RPAREN endline'''

        global new_attribute
        global new_table
        new_attribute.fill_method = p[2].lower()  # lower case to be sure
        debug("fillMethod")

        if len(p) == 7:  # one parameter
            new_attribute.fill_parameters = []  # clears the list
            new_attribute.fill_parameters.append(p[4])
コード例 #19
0
    def p_tableHeader(p):
        '''tableHeader : TABLE COLON IDENTIFIER LPAREN NUMBER RPAREN endline
                       | TABLE COLON IDENTIFIER LPAREN FILLED RPAREN endline'''

        global new_table
        new_table = table.Table()  # creates new table instance
        new_table.fill_count = p[5]
        new_table.name = p[3]     # corresponds to the IDENTIFIER token

        global attr_list
        attr_list = []            # inicializes empty list for this table
        debug("tableHeader")
コード例 #20
0
    def p_attributeBlock(p):
        '''attributeBlock : attributeName dtypes COMMA
                          | attributeName dtypes constraintPart COMMA
                          | attributeName dtypes
                          | attributeName dtypes constraintPart'''
        debug("attributeBlock")

        global new_table
        global new_attribute

        new_attribute.name = p[1]
        new_table.attr_list.append(new_attribute)
コード例 #21
0
    def p_attributeBlock(p):
        '''attributeBlock : attributeName dataType fillMethod
                          | attributeName dataType fillMethod constraintPart'''

        global new_attribute
        global attr_list

        #first we check compatibility of given functions, parameters and data types
        check_valid(new_attribute)

        #then we check possible data_type and constraint collisions
        check_collision()

        attr_list.append(new_attribute)  # appends the new attribute
        new_attribute.constraint_flag = False  # nulls the flag
        debug("attributeBlock")
コード例 #22
0
    def p_dtypeTwopart(p):
        '''dtypeTwopart : DTYPE_BOTH_1PARAM DTYPE_PART2
                        | DTYPE_PART1 DTYPE_PART2
                        | DTYPE_BOTH_1PARAM DTYPE_PART2 LPAREN parameter RPAREN'''
        debug("dtypeTwopart")

        p[0] = p[1] + ' ' + p[2]
            #creates one string from the two-part name

        global param_list
        param_list = []

        if len(p) == 6:  # variant: DTYPE_BOTH_1PARAM DTYPE_PART2 LPAREN parameter RPAREN
            param_list.append(p[4])

        global TO_ADD
        global ADD_VAL
        if p[0] in TO_ADD and len(param_list) == 0:  # we will add parameter for filling purposes if not given
            param_list.append(
                ADD_VAL)  # -> varchar(8) and varbit(8)
コード例 #23
0
    def p_constr(p):
        '''constr : CONSTR_NOPARAM
                  | CONSTR_1PARAM LPAREN NUMBER RPAREN'''
        debug("constraintPart")

        global new_attribute

        if p[1] == "foreign_key":
            #new_attribute.foreign_key = True
            return  # like nothing happened, fm_reference sets the flag
        elif p[1] == "primary_key":
            new_attribute.primary_key = True
            new_attribute.unique_group = p[3]
        elif p[1] == "unique":
            new_attribute.unique = True
            new_attribute.unique_group = p[3]
        elif p[1] == "null":
            new_attribute.null = True
            new_attribute.constraint_parameters = p[3]
        elif p[1] == "not_null":
            new_attribute.not_null = True

        elif p[1] == "default":
            new_attribute.default = True

            #if len(p) == 5:
            #    val = p[3]
            #elif len(p) == 6:
            #    val = "''"
            #else:
            #    val = p[4]

            new_attribute.default_value = p[3]  # stores the percentage

        new_attribute.constraint_type = p[1]
        new_attribute.constraint_flag = True
        new_attribute.constraint_cnt += 1

        #TODO:check if it's really neccessary to make generator go more easy, feels chaotic here
        if new_attribute.primary_key:
            new_attribute.unique = True
コード例 #24
0
    def p_dtypeTimezone(p):
        '''dtypeTimezone : DTYPE_TIMEZONE_PARAM LPAREN parameter RPAREN
                         | DTYPE_TIMEZONE_PARAM IDENTIFIER DTYPE_TIMEZONE_PARAM IDENTIFIER
                         | DTYPE_TIMEZONE_PARAM LPAREN parameter RPAREN IDENTIFIER DTYPE_TIMEZONE_PARAM IDENTIFIER'''

        #The second DTYPE_TIMEZONE_PARAM token is there because "time" is already a keyword
        #'with' and 'zone' could be keywords but I didn't think it was necessary
        debug("dtypeTimezone")
        p[0] = p[1]
        global param_list
        param_list = []  # inicializes param_list

        #if with/without timezone is missing, it's automatically without
        if len(p) == 5 and p[2] == "(":
            word1 = "without"
            word2 = "time"
            word3 = "zone"
            param_list.append(p[3])  # we append precision

        if len(p) == 5:
            word1 = p[2]
            word2 = p[3]
            word3 = p[4]
            param_list.append(DEFAULT_TIME_PRECISION)  # we append precision
        else:
            word1 = p[5]
            word2 = p[6]
            word3 = p[7]
            param_list.append(p[3])  # we append precision

        st1 = (word1 == "with" or word1 == "without")
        st2 = (word2 == "time")
        st3 = (word3 == "zone")

        if st1 and st2 and st3:  # all true
            if word1 == "with":
                x = "+TMZ"
            else:
                x = "-TMZ"

        param_list.append(x)  # we append with/without code
コード例 #25
0
    def p_sequenceBlock(p):
        'sequenceBlock : SEQUENCE IDENTIFIER OWNED BY IDENTIFIER PERIOD IDENTIFIER SEMICOLON'

        debug("sequenceBlock")

        #we find the table
        if not p[5] in name_dict.keys():
            msg = "Semantic error: Table '" + p[5] + \
                "'given in ALTER SEQUENCE part couldn't be found.\n"
            errprint(msg, ERRCODE["SEMANTIC"])
        seq_table = name_dict[p[5]]

        name = p[7]  # name of the attribute
        seq_attr = None

        #search for the attribute
        for attr in seq_table.attr_list:
            if attr.name == name:
                seq_attr = attr
                break

        #we didn't find it, there is a prob (shouldn't happen with not-edited dump but you never know)
        if seq_attr is None:
            msg = "Semantic error: Couldn't find the attribute which SEQUENCE '" + p[2] \
                + "' refers to in table '" + p[5] \
                + "' while processing a " + constr + ".\n"
            errprint(msg, ERRCODE["INPUT"])

        #now we simply change the data type to corresponding serial type
        if seq_attr.data_type == "integer":
            seq_attr.data_type = "serial"

        elif seq_attr.data_type == "bigint":
            seq_attr.data_type = "bigserial"

            #any other type that has a filling sequence gets serial dtype
            #gonna get 'DEFAULT' as insert value
        else:
            seq_attr.data_type = "serial"
コード例 #26
0
    def p_dtypes(p):
        '''dtypes : dtype moreDimensions'''

        debug("dtypes")

        global new_attribute
        global param_list

        global ARRAY_FLAG
        global DIM_CNT
        global DIM_SIZE

        new_attribute = table.Attribute()
        new_attribute.data_type = p[1]
        new_attribute.parameters = param_list

        if ARRAY_FLAG:
            new_attribute.array_flag = True
            new_attribute.array_dim_cnt = DIM_CNT
            new_attribute.array_dim_size = DIM_SIZE

            ARRAY_FLAG = False  # iniciates them for next attributes
            DIM_CNT = 0
            DIM_SIZE = []
コード例 #27
0
ファイル: cml.py プロジェクト: sipjca/cmlparser_py
    thorings = monomer.mark_thio(monomer1)
    intermono = monomer.find_intermono(monomer1)
    halfmono = monomer.get_single_alist(monomer1)
    attach = monomer.find_attach(monomer1,halfmono)
    test2 = monomer.attach(halfmono,attach,monomer1,length)
    monomer.print_mono(test2,"outputs/test")
    #monomer.create_polymer_cml(mname,halfmono,attach,monomer1)
    sys.stdout = sys.__stdout__

#create babel and read to get better partials
babel.read_babel_set(mname,atoms)
atom.adjust_partials(atoms)

#write different dft finders
#write_nwchem.dft(dihedrals)
#write_qchem.write(atoms,dihedrals)
sys.stdout = sys.__stdout__

if debug:
    printer.debug(atoms,bonds,angles,dihedrals,rings,fused_rings,opls_atoms,opls_bonds,opls_angles,opls_dihedrals)

#print all the output files
printer.print_data(dname,atoms,bonds,angles,dihedrals,unique_a,unique_b,unique_ang,unique_d,xmin,xmax,ymin,ymax,zmin,zmax)
if help == False or isfile == False:
    printer.print_lammpsin(inname,dataname,lammpsinput)
sys.stdout = sys.__stdout__
printer.print_srun(lammpsinput)

#autorun
#os.system('sbatch run_%s' % lammpsinput)
コード例 #28
0
    def p_alterBlock(p):
        'alterBlock : alterHeader alterBody SEMICOLON'

        debug("alterBlock")
コード例 #29
0
 def p_checkBlock(p):
     '''checkBlock : CONSTRAINT IDENTIFIER CHECK CHECKATTR
                   | CONSTRAINT IDENTIFIER CHECK CHECKATTR COMMA'''
     debug("moreCheckBlocks")
コード例 #30
0
 def p_moreSequenceBlocks(p):
     '''moreSequenceBlocks : moreSequenceBlocks sequenceBlock
                           | empty'''
     debug("moreSequenceBlocks")
コード例 #31
0
 def p_multi_params(p):
     '''multi_params : multi_1param multi_params
                     | empty'''
     debug("multi_params")
コード例 #32
0
 def p_moreAlterBlocks(p):
     '''moreAlterBlocks : moreAlterBlocks alterBlock
                        | empty'''
     debug("moreAlterBlocks")
コード例 #33
0
 def p_idOrDtypeName(p):
     '''idOrDtypeName : IDENTIFIER
                      | dtypeNames'''
     debug("idOrDtypeName")
     p[0] = p[1]