示例#1
0
文件: root.py 项目: Alfr0475/alfred.d
	def _sync_children(self):
		from list import List
		from preferences import Preferences

		Preferences.sync()
		List.sync()
		User.sync()
示例#2
0
 def __init__(self, name, age):
     self.name = name
     self.age = age
     self.ID = Person.numMade
     Person.numMade += 1
     self.friend = List()
     self.curBook = List()
     self.bookHistory = List()
     self.curState = ''
示例#3
0
    def test_init_with_List(self):
        list1 = List([1, 2, 3])
        list2 = List(list1)
        list3 = List(List())
        self.assertEqual(str(list2), "[1, 2, 3]")
        self.assertEqual(len(list2), 3)

        self.assertEqual(str(list3), "[]")
        self.assertEqual(len(list3), 0)
示例#4
0
    def test_get_by_positive_index(self):
        list = List([1, 2, 3])

        self.assertEqual(list[0], 1)
        self.assertEqual(list[2], 3)
        with self.assertRaises(IndexError):
            list[6]
        with self.assertRaises(IndexError):
            list[-1]
        with self.assertRaises(IndexError):
            List()[0]
示例#5
0
    def test_init_with_one_object(self):
        list1 = List(1)
        list2 = List('well')
        list3 = List({'first': 'second'})
        self.assertEqual(str(list1), '[1]')
        self.assertEqual(len(list1), 1)

        self.assertEqual(str(list2), '[well]')
        self.assertEqual(len(list2), 1)

        self.assertEqual(str(list3), "[{'first': 'second'}]")
        self.assertEqual(len(list3), 1)
示例#6
0
    def test_append_list(self):
        self.list1.append([1, 2, 3, 4])
        self.assertEqual(str(self.list1), "[1, 2, 3, [1, 2, 3, 4]]")
        self.assertEqual(len(self.list1), 4)

        self.list1.append(List([1, 2]))
        self.assertEqual(str(self.list1), "[1, 2, 3, [1, 2, 3, 4], [1, 2]]")
        self.assertEqual(len(self.list1), 5)

        self.list2.append(List())
        self.assertEqual(str(self.list2), "[[]]")
        self.assertEqual(len(self.list2), 1)
示例#7
0
    def test_init_with_default_list(self):
        list1 = List([1, "sda", 6])
        list2 = List([1])
        list3 = List([])

        self.assertEqual(str(list1), "[1, sda, 6]")
        self.assertEqual(len(list1), 3)

        self.assertEqual(str(list2), "[1]")
        self.assertEqual(len(list2), 1)

        self.assertEqual(str(list3), "[]")
        self.assertEqual(len(list3), 0)
示例#8
0
 def borrow(self, bookInfo, infoType):
     print(">>>", self.getName(), "wants to borrow:",
           str(bookInfo) + ",[" + infoType + "]")
     if self.getFriend().isEmpty():
         print("There's no one to borrow from...")
         return False
     else:
         queue = List()
         historicQueue = List()
         historicQueue.append(self)
         for friend in self.getFriend():
             queue.append(friend)
             historicQueue.append(friend)
     return self.recBorrow(bookInfo, infoType, queue, historicQueue)
示例#9
0
    def test_get_reverse(self):
        list = List([1, 2, 3])
        temp = list.reverse()

        self.assertEqual(str(list), '[1, 2, 3]')
        self.assertEqual(str(temp), '[3, 2, 1]')
        self.assertEqual(len(temp), 3)
        self.assertEqual(len(list), 3)

        list1 = List()
        temp = list1.reverse()

        self.assertEqual(str(temp), '[]')
        self.assertEqual(len(temp), 0)
示例#10
0
    def test_add(self):
        list = List()
        list = list + 1
        self.assertEqual(str(list), '[1]')
        self.assertEqual(len(list), 1)

        temp = list + List()
        self.assertEqual(str(temp), '[1, []]')
        self.assertEqual(str(list), '[1]')
        self.assertEqual(len(temp), 2)

        temp = list + {1: 2}
        self.assertEqual(str(temp), '[1, {1: 2}]')
        self.assertEqual(len(temp), 2)
示例#11
0
文件: globals.py 项目: diiq/oyoy
def populate_globals(env):
    # Builtin *functions* take an environment, rather than individual
    # args.

    ##
    # Add:
    #
    def builtin_add(env):
        x = env.lookup("x").number
        y = env.lookup("y").number
        return Number(x + y)

    # Builtin *objects* have arglists, though.
    iplus = Builtin(builtin_add, [Symbol("x"), Symbol("y")])

    env.set("add", iplus)

    ##
    # Lambda:
    #
    def builtin_lambda(env):
        args = env.lookup("args")
        body = env.lookup("body")
        return Lambda(args.items, body, env.calling_environment)

    fn = Builtin(builtin_lambda, [
        List([Symbol("quote"), Symbol("args")]),
        List([Symbol("quote"), Symbol("body")])
    ])
    env.set("fn", fn)
    env.set("λ", fn)

    ##
    # Set:
    #
    def builtin_set(env):
        sym = env.lookup("symbol")
        val = env.lookup("value")
        env.calling_environment.set(sym.symbol, val)
        return val

    env.set(
        "set",
        Builtin(builtin_set,
                [List([Symbol("quote"), Symbol("symbol")]),
                 Symbol("value")]))

    return env
示例#12
0
文件: test.py 项目: ABorgna/algo2
def strToList(s):
    #asumo que el string representa una lista bien formada.
    s = s.replace(' ', '')
    if len(s) < 3:
        raise Exception('Ingresaste una lista vacia... :\'(')
    l = map(int,s[1:-1].split(','))
    return List.from_list(l)
示例#13
0
 def test_list_peoperties_with_unique_object_peoperty(self):
     a, b = Mock(), Mock()
     a.foo = [1]
     b.bar = [2]
     self.list = List(a, b)
     self.assertEqual(self.list.foo, [1])
     self.assertEqual(self.list.bar, [2])
示例#14
0
 def createList(self, list_json):
     """
     Create List object from JSON object
     """
     return List(trello_client=self,
                 list_id=list_json['id'].encode('utf-8'),
                 name=list_json['name'].encode('utf-8'))
示例#15
0
 def test_concat_method(self):
     m = Mock()
     m.name = 'Avi'
     l2 = List(m)
     concatinated_list = self.list.concat(l2)
     self.assertEqual(len(concatinated_list), 3)
     self.assertEqual(concatinated_list[-1], m)
示例#16
0
 def _callback (self, params):
     
     args = []
     list = List.from_pointer (ctypes.c_void_p (params))
     
     for val in list:
         args.append (val.get())
     
     
     # class method
     if self._self_object is not None:
         ret = self._callback_func (self._self_object(), *args)
     else:
         ret = self._callback_func (*args)
     
     
     if isinstance (ret, Value):
         _lib.myelin_value_ref (ret)
         return ret._ptr
     
     else:
         val = Value()
         
         if ret is not None:
             val.set (ret)
         
         _lib.myelin_value_ref (val)
         return val._ptr
def stack_using_linklist():
    list = List()
    choice = 1
    while choice != 0:
        print("1. Push")
        print("2. Pop")
        print("3. Top")
        choice = int(input(">"))

        if choice == 1:
            continue_add = 'y'
            while continue_add != 'n':
                list.add(input("Enter the element: "))
                continue_add = input("Continue (y/n): ")

            print("\nThe List is: ", list.print(), "\n")

        elif choice == 2:
            if not list.isEmpty():
                print("\nThe popped element is: ", list.remove())
                print("The List now is: ", list.print(), "\n")

            else:
                print("Stack empty")

        elif choice == 3:
            if not list.isEmpty():
                print("\nThe top element is: ", list.printTop())

            else:
                print("Stack empty")
def queue_from_linklist():
    list = List()
    choice = 1
    while choice != 0:
        print("1. Enqueue")
        print("2. Dequeue")
        print("3. Front")
        choice = int(input(">"))

        if choice == 1:
            continue_add = 'y'
            while continue_add != 'n':
                list.add2(input("Enter the element: "))
                continue_add = input("Continue (y/n): ")

        elif choice == 2:
            if not list.isEmpty():
                print("\nThe dequeued element is: ", list.remove2())

            else:
                print("Queue empty")

        elif choice == 3:
            if not list.isEmpty():
                print("\nThe front element is: ", list.printFront())

            else:
                print("Queue empty")
示例#19
0
文件: test.py 项目: mnPanic/algo2
def strToList(s):
    #asumo que el string representa una lista bien formada.
    s = s.replace(' ', '')
    if len(s) < 3:
        raise Exception('Ingresaste una lista vacia... :\'(')
    l = list(map(int, s[1:-1].split(',')))
    return List.from_list(l)
示例#20
0
    def __init__(self, path=None):
        # setup and parse command line args
        parser = argparse.ArgumentParser(description="""
            Todo list application.""")
        parser.add_argument('-f',
                            metavar='path_to_list',
                            default='',
                            help='Path to the database file to use/create.')
        parser.add_argument('-c',
                            metavar='item_id',
                            type=int,
                            default=None,
                            help='Check item with ID')
        parser.add_argument('-d',
                            metavar='item_id',
                            type=int,
                            default=None,
                            help='Delete item with ID')
        parser.add_argument('--clear',
                            default='',
                            action='store_true',
                            help='Clear the database')
        self.args = parser.parse_args()

        # get path (if given) and connect to it
        path = path or self.args.f or os.path.expanduser("~/.todo.db")
        self.conn = sqlite3.connect(path)
        self.cursor = self.conn.cursor()

        # create table if it doesn't exist
        self.cursor.execute("""CREATE TABLE IF NOT EXISTS items
                               (id PRIMARY KEY, content TEXT,
                                checked TEXT, date_created TEXT)""")

        self.list = List.get_all(cursor=self.cursor)
示例#21
0
    def __init__(self, main_thread):
        self.serial_port = None
        self.is_running = False
        self.queue = List()
        self.mainThread = main_thread

        self.wait_for_conection()
示例#22
0
 def _get_dynamic_list_with_mocks(self):
     a, b = Mock(), Mock()
     a.name = 'bob'
     a.age = 20
     b.name = 'john'
     b.age = 20
     return List(a, b)
示例#23
0
 def ensure_site_assets_library(self):
     """Gets a list that is the default asset location for images or other files, which the users
     upload to their wiki pages."""
     list_site_assets = List(self.context)
     qry = ClientQuery.service_operation_query(self, ActionType.PostMethod, "ensuresiteassetslibrary")
     self.context.add_query(qry, list_site_assets)
     return list_site_assets
    def test(self):
        list = List()
        self.assertTrue(list.is_empty())
        self.assertFalse(list.has_access())

        list.insert(3)
        self.assertFalse(list.is_empty())
        self.assertFalse(list.has_access())

        list.to_first()
        self.assertTrue(list.has_access())
        self.assertEqual(list.get_content(), 3)

        list.set_content(4)
        self.assertTrue(list.has_access())
        self.assertEqual(list.get_content(), 4)

        list.append(5)
        self.assertTrue(list.has_access())
        self.assertEqual(list.get_content(), 4)

        list.to_last()
        self.assertTrue(list.has_access())
        self.assertEqual(list.get_content(), 5)

        list.next()
        self.assertFalse(list.has_access())
        self.assertEqual(list.get_content(), None)

        list.to_first()
        list.remove()
        self.assertTrue(list.has_access())
        self.assertEqual(list.get_content(), 5)
示例#25
0
 def GetList(self, list_key):
     cursor = self.db.cursor(dictionary=True)
     sql = "SELECT * FROM list where ListId = %s"
     cursor.execute(sql, (list_key,))  
     selectedList = cursor.fetchone()
     list_ = List(selectedList['Title'], selectedList['DueDate'],selectedList['OwnerId'],selectedList['CreatedDate'],selectedList['ListId'])
     return list_
示例#26
0
def list_add_page():
    if 'user_id' in session:
        db = getDb()
        error = ''
        if request.method == "POST":
            if request.form['title'] == '' or request.form["year"] is None:
                error = 'Please fill all required fields.'
                return render_template("list_edit.html",
                                       min_year=datetime.now().year,
                                       error=error)
            else:
                newList = List(request.form['title'],
                               dueDate=request.form["year"])
                isSuccess = db.createList(newList)
                if (isSuccess):
                    return redirect("/lists")
                else:
                    error = 'Problem occured.'
                    return render_template("list_edit.html",
                                           min_year=datetime.now().year,
                                           error=error)
        else:
            return render_template("list_edit.html",
                                   min_year=datetime.now().year,
                                   error=error)
    else:
        return redirect(url_for('login_page'))
示例#27
0
 def test_insert_any_and_search(self):
     test_list = List(None, 0)
     test_list.insert(0, 0)
     test_list.insert(1, 1)
     test_list.insert(2, 2)
     test_list.insert(3, 3)
     test_list.insert(4, 2)
     self.assertEqual(test_list.search(4), 2)
示例#28
0
def loadLista(lista):
    if not lista is None:
        MyList = List()
        for item in lista:
            MyList.append(item)

        return MyList
    return None
示例#29
0
def chosen_result(bot, update):

    # it can't be an empty query, and it can't be a search
    if update.chosen_inline_result.query and "id*" not in update.chosen_inline_result.query:

        List(id=update.chosen_inline_result.result_id,
             from_user_id=update.chosen_inline_result.from_user.id,
             title=update.chosen_inline_result.query)
示例#30
0
 def test_remove(self):
     test_list = List(None, 0)
     test_list.insert(0, 0)
     test_list.insert(1, 1)
     test_list.insert(2, 2)
     test_list.insert(3, 3)
     test_list.remove(3)
     self.assertEqual(test_list.search(2), -1)
示例#31
0
 def add(self, list_creation_information):
     """Creates a List resource"""
     list_entry = List(self.context)
     list_creation_information._include_metadata = self.include_metadata
     qry = ClientQuery.create_entry_query(self, list_creation_information.payload)
     self.context.add_query(qry, list_entry)
     self.add_child(list_entry)
     return list_entry
示例#32
0
 def test_linearsearch(self):
     l = List()
     l.add(3)
     l.add(5)
     l.add(7)
     self.assertEqual(1, l.linear_search(5))
     self.assertEqual(0, l.linear_search(3))
     self.assertEqual(2, l.linear_search(7))
示例#33
0
 def test_different_types_sanity(self):
     a, b = Mock(), Mock()
     a.foo = 'a'
     b.foo = 1
     self.list = List(a, b)
     self.assertTrue('a' in self.list.foo)
     self.assertTrue(1 in self.list.foo)
     self.assertTrue(len(self.list.foo) == 2)
示例#34
0
文件: dict.py 项目: tonibagur/appy
 def __init__(self, keys, fields, validator=None, multiplicity=(0,1),
              default=None, show=True, page='main', group=None, layouts=None,
              move=0, specificReadPermission=False,
              specificWritePermission=False, width='', height=None,
              maxChars=None, colspan=1, master=None, masterValue=None,
              focus=False, historized=False, mapping=None, label=None,
              subLayouts=Table('frv', width=None), widths=None, view=None,
              xml=None):
     List.__init__(self, fields, validator, multiplicity, default, show, page,
                   group, layouts, move, specificReadPermission,
                   specificWritePermission, width, height, maxChars, colspan,
                   master, masterValue, focus, historized, mapping, label,
                   subLayouts, widths, view, xml)
     # Method in "keys" must return a list of tuples (key, title): "key"
     # determines the key that will be used to store the entry in the
     # database, while "title" will get the text that will be shown in the ui
     # while encoding/viewing this entry.
     # WARNING: a key must be a string, cannot contain digits only and
     # cannot contain char "*". A key is typically an object ID.
     self.keys = keys
示例#35
0
def generate_dots(sorting_algorithm):
    res= []
    print "Ejecutando el algoritmo..."
    for i in xrange(50, 300, 10):
        l = range(i)
        shuffle(l)
        l= List.from_list(l) 
        sorting_algorithm(l)

        res.append((i, l.counter.cnt))

    return res
示例#36
0
 def get_namespaces (self):
     list = _lib.myelin_repository_get_namespaces (self)
     return List.from_pointer (list)
示例#37
0
 def test_make_list_with_nested_list(self):
     list = List.make(1, List.make(2, 3), 4)
     result = list.asString()
     self.assertEqual("(1 (2 3) 4)", result)
示例#38
0
 def test_make_list_with_head_none(self):
     list = List.make(None)
     result = list.asString()
     self.assertEqual("(nil)", result)
示例#39
0
 def test_make_simple_list(self):
     list = List.make(1, 2, 3)
     result = list.asString()
     self.assertEqual("(1 2 3)", result)
示例#40
0
文件: class_.py 项目: gsterjov/Myelin
 def get_all_functions (self):
     list = _lib.myelin_class_get_all_functions (self)
     return List.from_pointer (list)
示例#41
0
文件: class_.py 项目: gsterjov/Myelin
 def get_bases (self):
     list = _lib.myelin_class_get_bases (self)
     return List.from_pointer (list)
示例#42
0
文件: class_.py 项目: gsterjov/Myelin
 def get_constructors (self):
     list = _lib.myelin_class_get_constructors (self)
     return List.from_pointer (list)
示例#43
0
文件: clean.py 项目: cgallag/swabbie
    def nuke(cls):
        images_change_report = List.change_report(cls.Commands.ALL_IMAGE, List.Commands.ALL_IMAGE)
        containers_change_report = List.change_report(cls.Commands.ALl_CONTAINER, List.Commands.ALL_CONTAINER)

        return cls._summary(images_change_report, 'Images') + cls._summary(containers_change_report, 'Containers')
示例#44
0
文件: clean.py 项目: cgallag/swabbie
    def clean(cls):
        images_change_report = List.change_report(cls.Commands.DANGLING_IMAGE, List.Commands.EXITED_IMAGE)
        containers_change_report = List.change_report(cls.Commands.EXITED_CONTAINER, List.Commands.EXITED_CONTAINER)

        return cls._summary(images_change_report, 'Dangling images') + cls._summary(
            containers_change_report, 'Exited containers')
示例#45
0
 def get_param_types (self):
     list = _lib.myelin_constructor_get_param_types (self)
     return List.from_pointer (list)
示例#46
0
 def get_param_types (self):
     list = _lib.myelin_function_type_get_param_types (self)
     return List.from_pointer (list)
示例#47
0
 def get_classes (self):
     list = _lib.myelin_namespace_get_classes (self)
     return List.from_pointer (list)