Example #1
0
    def _create_dummy_wrappers(self):
        assert self.header_decl is None

        namespace = self._get_cxx_namespace()
        down = False

        for ddef in self.blacklist.dummy_classes.values():
            if Registry.get_class(ddef.full_name):
                continue

            if ddef.namespace != namespace:
                down = True
                continue

            cls = Class.Class(self.root, None, self, ddef)
            if ddef.header:
                cls.set_header(ddef.header)

            self.register_class(cls)
            self.modified = True

        if down:
            for submodule in self.submodules:
                # noinspection PyProtectedMember
                submodule._create_dummy_wrappers()
Example #2
0
    def extractFileData(self, path):

        curClass = Class.Class()

        for line in fileinput.input([path]):
            if line.startswith('.class '):
                if self.pkgpath not in line:
                    continue

                curClass.setPackage(self.extractPackage(line))
                curClass.setName(self.extractClassName(line))

            elif line.startswith('.super '):
                if (self.pkgpath in line):
                    curClass.setParent(self.extractClassName(line))
                matches = re.findall("Landroid/app/(.*?)Activity", line)
                curClass.isController = (len(matches) > 0)
            elif (line.startswith('.field')):
                fieldName = line[line.rfind(" ") + 1:line.rfind(":")]
                curClass.addField(fieldName)
                if (' public ' in line or ' protected ' in line):
                    curClass.addPublicField(fieldName)
            elif (line.startswith('.method ')):
                if ('<init>' in line):
                    curMethod = Method.Method('constructor')
                else:
                    match = re.findall(".method (.*?)\(", line)[0].split(" ")
                    l = len(re.findall(".method (.*?)\(", line)[0].split(" "))
                    if l == 3:
                        curMethod = Method.Method(str(match[2]))
                    elif l == 2:
                        curMethod = Method.Method(str(match[1]))
                    elif l == 1:
                        curMethod = Method.Method(str(match[0]))
                    curMethod = Method.Method("Generic")

                    curClass.addMethod(curMethod)
            elif (";->" in line):
                if (self.usesField(curClass, line)):  #for LCOM
                    fieldName = line[line.rfind(";->") + 3:line.rfind(":")]
                    curMethod.addFieldUsed(fieldName)
                    if fieldName in curClass.getPublicFields():
                        self.apd = self.apd + 1
                    else:  #for CBO
                        if not curClass.isController and self.refsNonJavaClass(
                                line):
                            objName = line[line.index("L"):line.index(";->")]
                            if not objName == curClass.getName(
                            ) and not self.inSameTree(curClass, objName):
                                curClass.addCoupledObject(objName)
        self.classes.append(curClass)
Example #3
0
 def __init__(self):
     super().__init__()
     self.title("College Courses")
     self.geometry("500x500")
     self.resizable(False, False)
     self.windows = [
         Student(self),
         Teacher(self),
         Subject(self),
         Course(self),
         Class(self)
     ]
     self.set_navigation()
     self.set_window(0)
Example #4
0
    def initialize(self):
        depts = self._data.get_depts()
        for i in range(0, len(depts)):
            courses = depts[i].get_courses()
            for j in range(0, len(courses)):
                newClass = Class.Class(self._classNum, depts[i], courses[j])
                self._classNum += 1
                newClass.set_meetingTime(
                    data.get_meetingTimes()[random.randrange(
                        0, len(data.get_meetingTimes()))])
                newClass.set_room(data.get_rooms()[random.randrange(
                    0, len(data.get_rooms()))])
                newClass.set_instructor(
                    data.get_instructors()[random.randrange(
                        0, len(data.get_instructors()))])

                self._classes.append(newClass)
        return self
Example #5
0
    def _do_process_classes(self, context_id):
        for decl_type in ("Class", "Struct"):
            xpath = ".//%s[@file='%s'][@context='%s']" % (
                decl_type, self.current_file_id(), context_id
            )

            for cls_node in self.root.findall(xpath):
                full_name = cls_node.attrib["demangled"]

                if self.blacklist.klass(full_name):
                    Session.ignored_classes.add(full_name)
                    continue

                if full_name in self.blacklist.dummy_classes:
                    Session.dummy_classes.add(full_name)
                    continue

                if Access.access_type(cls_node) == Access.PRIVATE:
                    continue

                if cls_node.attrib.get("incomplete", None) == "1":
                    continue

                # TODO: anonymous class
                # typedef struct { int a; } A;
                if cls_node.attrib.get("name", "") == "":
                    continue

                logging.info("---------------------------------------------")
                logging.info(">>> %s <<<" % full_name)
                logging.info("---------------------------------------------")

                cls = Class.Class(self.root, cls_node, self)
                self.register_class(cls)

                # Inner (nested) classes
                self._do_process_classes(cls_node.attrib["id"])

                self.modified = True
Example #6
0
def get_info(soup, course):
    '''(BeautifulSoup, str) -> list of Class

    Return a Class object with all information only
    related to the provided course code when given a valid soup object
    and the valid course code.

    REQ: soup must be html code obtained from the UTSC timetable site
    REQ: course is a list of full course codes in string form
    '''
    # Get all table rows in the page
    all_tr = soup.find_all('tr')
    # A switch that flips to True when the below loop starts
    # iterating over the corrent range of data
    on = False
    # A switch that flips to True when the specific course is found
    found = False
    # Initialization of the list to hold all the classes
    all_classes = []
    # Since lectures typically have multiple sessions, hold which
    # lecture number is currently being iterated over
    curr = None
    # Check one row at a time
    for tr in all_tr:
        # If a link tag is found, and the string of the link is
        # the course code without any whitespaces, that means the
        # course info has been found
        if tr.find('a') and \
                        tr.a.string.lower().replace(' ', '') == course.lower():
            found = True
        if on:
            # The first data holds the session (t)ype and (num)ber
            # For example, LEC01, TUT0026, PRA0002
            tnum = tr.contents[0].string
            # If the session is blank, then it extends from the previous one
            # So, copy over the previous session type and number
            if tnum is None:
                tnum = curr
            else:
                curr = tnum
            # The second data holds the session date in the week
            # For example, MO, TH, FR
            date = tr.contents[1].string
            # The third data holds the starting time of the session
            # For example, 13:00, 16:30
            s_time = tr.contents[2].string
            # The fourth data holds the ending time of the session
            # For example, 19:00, 11:30
            e_time = tr.contents[3].string
            # The fifth data holds the location
            # For example, IC130, HW216, AA112
            room = tr.contents[4].string.replace(" ", "")
            # The sixth data holds the prof name, if applicable
            prof = tr.contents[5].string
            # The seventh data holds notes if they exist
            notes = tr.contents[6].string
            # Create a Class
            uclass = Class(tnum, date, s_time, e_time, room, prof, notes)
            # Add Class to the list that will hold all Classes
            all_classes.append(uclass)
        # If the loop doesn't reach the data, then check:
        # 1) The table row has a child, and if True,
        # 2) The table row's child has a string, and if True,
        # 3) The table row's child's string refers to the row
        # 4) The course has been found and this is not some other course
        #    right before the actual data
        if tr.contents is not None and tr.contents[0].string is not None \
                and 'Meeting Section' in tr.contents[0].string and found:
            # If conditions are true, that means the loop has reached
            # the current table row and now flip the switch
            on = True
    return all_classes
Example #7
0
    def applyToDirectory(self, directory, kind, path):
        path = os.path.join(path, directory.name)

        newDirectoryFileChildren = copy.copy(directory.fileChildren)
        self.priorityValues = {}

        classesToExpand = []

        i = 0
        for virtualFile in directory.fileChildren:
            if virtualFile.name.endswith(self.OBJECT_FILE_EXTENSION):
                newDirectoryFileChildren.remove(virtualFile)

                virtualFile.contents = self.replaceStringKeys(
                    virtualFile, kind, path)
                virtualObjectFileLines = virtualFile.getContentsLines()

                priority = 0
                if len(virtualObjectFileLines) > 0 and virtualObjectFileLines[
                        0].startswith(self.CLASS_LINE_METACHARACTER +
                                      self.PRIORITY_KEYWORD + ' '):
                    priorityString = virtualObjectFileLines[0][
                        len(self.CLASS_LINE_METACHARACTER +
                            self.PRIORITY_KEYWORD + ' '):]
                    virtualObjectFileLines = virtualObjectFileLines[1:]
                    try:
                        priority = int(priorityString)
                    except ValueError:
                        self.strings.raiseExportWarning(
                            os.path.join(path, virtualFile.name), 1,
                            'Cannot parse priority value (Must be an integer): '
                            + str(priorityString))
                    if priority < 0:
                        self.strings.raiseExportWarning(
                            os.path.join(path, virtualFile.name), 1,
                            'Illegal priority value (Must be positive): ' +
                            str(priority))
                        priority = 0

                objects = [
                    Object(self.parseObject(line))
                    for line in virtualObjectFileLines
                    if self.lineIsObject(line)
                ]
                classObjectAssociationName = virtualFile.name[:-len(
                    self.OBJECT_FILE_EXTENSION)]

                classesToExpand.append(
                    Class(objects, priority, classObjectAssociationName))
            i += 1

        classesToExpand.sort(key=lambda c: c.priority, reverse=True)
        for classToExpand in classesToExpand:
            classKeyword = self.CLASS_KEYWORD
            if not classToExpand.classObjectAssociationName == self.CLASS_OBJECT_ASSOCIATION_DEFAULT_NAME:
                classKeyword = self.CLASS_KEYWORD + self.CLASS_OBJECT_ASSOCIATION_METACHARACTER + classToExpand.classObjectAssociationName

            #directory class
            for virtualClassDirectory in directory.directoryChildren:
                if virtualClassDirectory.name == classKeyword:
                    directory.directoryChildren.remove(virtualClassDirectory)

                    for obj in classToExpand.objects:
                        merge = False
                        for virtualObjectDirectory in directory.directoryChildren:
                            if virtualObjectDirectory.name == obj.name:
                                merge = True
                                transientVirtualObjectDirectory = copy.deepcopy(
                                    virtualClassDirectory)
                                self.replaceObjectKeysInDirectory(
                                    transientVirtualObjectDirectory, obj.args)
                                self.mergeDirectories(
                                    virtualObjectDirectory,
                                    transientVirtualObjectDirectory,
                                    classToExpand.priority,
                                    os.path.join(path, obj.name))
                                break

                        if not merge:
                            virtualObjectDirectory = copy.deepcopy(
                                virtualClassDirectory)
                            virtualObjectDirectory.name = obj.name
                            self.replaceObjectKeysInDirectory(
                                virtualObjectDirectory, obj.args)
                            directory.directoryChildren.append(
                                virtualObjectDirectory)
                    break

            for virtualClassFile in directory.fileChildren:
                #file class
                if virtualClassFile.name.startswith(
                        classKeyword +
                        '.') or virtualClassFile.name == classKeyword:
                    newDirectoryFileChildren.remove(virtualClassFile)

                    classFileNameComponents = virtualClassFile.name.split(
                        '.', 1)
                    classFileExtension = '.' + classFileNameComponents[
                        1] if len(classFileNameComponents) > 1 else ''

                    for obj in classToExpand.objects:
                        virtualObjectFile = copy.copy(virtualClassFile)
                        virtualObjectFile.name = obj.name + classFileExtension
                        if virtualObjectFile.name not in list(
                                map(lambda f: f.name,
                                    newDirectoryFileChildren)):
                            self.replaceObjectKeysInFile(
                                virtualObjectFile, obj.args)
                            newDirectoryFileChildren.append(virtualObjectFile)

                #line class
                else:
                    classLineEstablisher = self.CLASS_LINE_METACHARACTER + classKeyword + ' '
                    virtualClassFileLines = virtualClassFile.getContentsLines()
                    virtualClassFileLines = [
                        line + '\n' for line in virtualClassFileLines
                    ]

                    virtualClassFile.contents = ''
                    for line in virtualClassFileLines:
                        if line.startswith(classLineEstablisher):
                            classLine = line[len(classLineEstablisher):]
                            line = ''

                            for obj in classToExpand.objects:
                                objectLine = classLine

                                i = 0
                                while i < len(obj.args):
                                    objectLine = objectLine.replace(
                                        self.
                                        OBJECT_PARAMETER_METACHARACTER_START +
                                        str(i) + self.
                                        OBJECT_PARAMETER_METACHARACTER_END,
                                        obj.args[i])
                                    i += 1

                                line += objectLine
                        virtualClassFile.contents += line
                    virtualClassFile.contents = virtualClassFile.contents.rstrip(
                        '\n')

        directory.fileChildren = newDirectoryFileChildren

        for virtualFile in directory.fileChildren:
            virtualFile.contents = self.replaceStringKeys(
                virtualFile, kind, path)

        for virtualDirectory in directory.directoryChildren:
            self.applyToDirectory(virtualDirectory, kind, path)
Example #8
0
from Class import *

obj = Class(1)
print(obj.a)
print(obj.b)
Example #9
0
 def setUp(self):
     self.clase = Class.Class('Redes 2', 5)
Example #10
0
 def test_insert_class(self):
     self.clase_insertar = Class.Class('Vacaciones2017', 1)
     self.assertEqual("{\"mensaje\": \"curso creado con exito\"}",
                      self.clase_insertar.insert_class())
Example #11
0
def insertClass(json):
    c = Class()
    saveClass(json, c)
    saveClassModifiers(json, c)
    return {'class_id': c.id, 'class_name': c.class_name}