-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUrlsManager.py
49 lines (40 loc) · 1.38 KB
/
UrlsManager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class UrlsManager(object):
"""docstring for UrlsManager"""
def __init__(self):
super(UrlsManager, self).__init__()
self.highArray = []
self.normalArray = []
self.lowArray = []
def add(self, obj):
# priors = ['high', 'normal', 'low']
# positions = ['head', 'tail']
target_array = self.normalArray
if obj.get('priority') == 'high':
target_array = self.highArray
elif obj.get('priority') == 'low':
target_array = self.lowArray
if obj.get('position') == 'head':
target_array.insert(0, obj)
else:
target_array.append(obj)
def pop(self):
target = self.highArray or self.normalArray or self.lowArray
if target:
ret = target[0]
target.remove(ret)
return ret
else:
return {}
def getN(self, numbers):
dest = self.highArray[0:numbers]
self.highArray[0:numbers] = []
if len(dest) < numbers:
dest.append(self.normalArray[0: numbers - len(dest)])
self.normalArray[0: numbers - len(dest)] = []
if len(dest) < numbers:
dest.append(self.lowArray[0: numbers - len(dest)])
self.lowArray[0: numbers - len(dest)] = []
return dest
gUrls = UrlsManager()