本文整理匯總了Python中lib.loader.Loader類的典型用法代碼示例。如果您正苦於以下問題:Python Loader類的具體用法?Python Loader怎麽用?Python Loader使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Loader類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _mount
def _mount(self):
if self._children:
self._mode |= MODE_VIRT
if self._mode & MODE_VIRT or self._index == None:
mode = None
freq = None
prof = None
else:
mode = self._mode
freq = self._freq
prof = self.d_profile
path = get_mnt_path(self._uid, self._name)
if os.path.exists(path):
loader = Loader(self._uid)
curr_prof = loader.get_profile(self._name)
if curr_prof['type'] == prof['type']:
curr_mode = loader.get_attr(self._name, ATTR_MODE, int)
if ((curr_mode | MODE_SYNC) == (mode | MODE_SYNC)) and curr_prof.get('spec') == prof.get('spec'):
mode = None
freq = None
prof = None
else:
if not (curr_mode & MODE_SYNC):
mode &= ~MODE_SYNC
else:
mode |= MODE_SYNC
freq = loader.get_attr(self._name, ATTR_FREQ, float)
if not self._children:
api_mount(self._uid, name=self.d_name, mode=mode, freq=freq, prof=prof)
self._log('mount %s [%s*]' % (self.d_type, self.d_name[:8]))
示例2: Application
class Application(tornado.web.Application):
def __init__(self):
settings = dict(
blog_title = u"mifan.tv",
template_path = os.path.join(os.path.dirname(__file__), "templates"),
static_path = os.path.join(os.path.dirname(__file__), "static"),
xsrf_cookies = False,
cookie_secret = "cookie_secret_code",
login_url = "/login",
autoescape = None,
jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
debug=True,
)
handlers = [
(r"/", handler.index.IndexHandler),
(r"/community", handler.community.CommunityHandler),
(r"/p/(\d+)", handler.post.PostHandler),
(r"/create", handler.post.CreatePostHandler),
(r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
(r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
(r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
(r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
]
tornado.web.Application.__init__(self, handlers, **settings)
# Have one global connection to the blog DB across all handlers
self.db = torndb.Connection(
host = options.mysql_host, database = options.mysql_database,
user = options.mysql_user, password = options.mysql_password
)
# Have one global loader for loading models and handles
self.loader = Loader(self.db)
# Have one global model for db query
self.user_model = self.loader.use("user.model")
self.post_model = self.loader.use("post.model")
self.head1_model = self.loader.use("head1.model")
self.head2_model = self.loader.use("head2.model")
self.std_model = self.loader.use("std.model")
self.hot_model = self.loader.use("hot.model")
self.comment_model = self.loader.use("comment.model")
# Have one global session controller
self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)
# Have one global memcache controller
self.mc = memcache.Client(["127.0.0.1:11211"])
示例3: __init__
def __init__(self):
self.screen = pygame.display.set_mode((800, 600),1)
pygame.display.set_caption("PaintBrush simple demo v1.0 - Press space to clear paper")
loader = Loader()
self.brush = PaintBrush(self.screen)
self.brush.set_brush(loader.load_image("brush_6.png", True))
self.brush.set_follow_angle(True)
self.brush.set_color(pygame.Color("Blue"))
self.brush.set_alpha(0.2)
self.screen.fill((255,255,255))
示例4: __init__
def __init__(self):
self.screen = pygame.display.set_mode((800, 600),1)
pygame.display.set_caption("Music Painter")
pygame.init()
loader = Loader()
self.canvas = Canvas(800, 600)
self.brush = PaintBrush(self.screen)
self.brush.set_brush(loader.load_image("brush_6.png", True))
self.brush.set_follow_angle(True)
self.brush.set_color(pygame.Color("Blue"))
self.brush.set_alpha(0.2)
self.screen.fill((255,255,255))
示例5: __init__
def __init__(self):
settings = dict(
blog_title = u"ttx",
template_path = os.path.join(os.path.dirname(__file__), "templates"),
static_path = os.path.join(os.path.dirname(__file__), "static"),
root_path = os.path.join(os.path.dirname(__file__), "/"),
xsrf_cookies = False,
cookie_secret = "cookie_secret_code",
login_url = "/login",
autoescape = None,
jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
debug=True,
)
handlers = [
(r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
(r"/(sitemap.*$)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
(r"/(bdsitemap\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
(r"/(orca\.txt)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
(r"/", handler.index.IndexHandler),
(r"/p/(\d+)", handler.index.PostHandler),
(r"/baicai", handler.index.ListHandler),
(r"/baicai/items", handler.index.GetListItemsHandler),
(r"/item", handler.index.TaobaoHandler),
(r"/coupon", handler.index.CouponHandler),
(r"/prompt", handler.index.TaobaoPromptHandler),
]
tornado.web.Application.__init__(self, handlers, **settings)
# Have one global connection to the blog DB across all handlers
self.db = torndb.Connection(
host = options.mysql_host, database = options.mysql_database,
user = options.mysql_user, password = options.mysql_password
)
# Have one global loader for loading models and handles
self.loader = Loader(self.db)
# Have one global model for db query
self.user_model = self.loader.use("user.model")
self.post_model = self.loader.use("post.model")
# Have one global session controller
self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)
# Have one global memcache controller
self.mc = memcache.Client(["127.0.0.1:11211"])
DEBUG_FLAG = False
if DEBUG_FLAG:
self.debug_flag = True
self.static_path = "/static"
self.template_path = ""
else:
self.debug_flag = False
self.static_path = "/static/dist"
self.template_path = "dist/"
示例6: Mode
class Mode(object):
def __init__(self, uid):
self._mode = {}
self._loader = Loader(uid)
def _log(self, text):
if LOG_MODE:
log_debug(self, text)
def _get(self, name):
mode = self._loader.get_attr(name, ATTR_MODE, int)
if mode != None:
self._mode[name] = mode
self._log('name=%s, mode=%s' % (str(name), str(mode)))
return mode
def get(self, name):
if self._mode.has_key(name):
ret = self._mode.get(name)
if ret != None:
return ret
return self._get(name)
def remove(self, name):
if self._mode.has_key(name):
del self._mode[name]
示例7: __init__
def __init__(self):
settings = dict(
blog_title = u"Home of 360",
template_path = os.path.join(os.path.dirname(__file__), "templates"),
static_path = os.path.join(os.path.dirname(__file__), "static"),
xsrf_cookies = False,
cookie_secret = "cookie_secret_code",
login_url = "/login",
autoescape = None,
jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
)
handlers = [
(r"/", handler.home.IndexHandler),
(r"/register", handler.user.RegisterHandler),
(r"/u/(\w+)", handler.user.UserDetailHandler),
(r"/edit", handler.user.UserModifyHandler),
(r"/b", handler.blog.BlogHandler),
]
tornado.web.Application.__init__(self, handlers, **settings)
conn = MongoClient("localhost", 27017)
self.db = conn.example
self.loader = Loader(self.db)
self.user_model = self.loader.use("user.model")
self.blog_model = self.loader.use("blog.model")
self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)
self.mc = memcache.Client(["127.0.0.1:11211"])
示例8: Freq
class Freq(object):
def __init__(self, uid):
self._freq = {}
self._loader = Loader(uid)
def _log(self, text):
if LOG_FREQ:
log_debug(self, text)
def _get(self, name):
freq = self._loader.get_attr(name, ATTR_FREQ, float)
if freq:
self._freq[name] = freq
self._log('name=%s, freq=%s' % (str(name), str(freq)))
return freq
def get(self, name):
if self._freq.has_key(name):
return self._freq.get(name)
else:
return self._get(name)
def remove(self, name):
if self._freq.has_key(name):
del self._freq[name]
示例9: Application
class Application(tornado.web.Application):
def __init__(self):
settings = dict(
blog_title = u"Dota2Ark Community",
template_path = os.path.join(os.path.dirname(__file__), "templates"),
static_path = os.path.join(os.path.dirname(__file__), "static"),
avatar_path = os.path.join(os.path.dirname(__file__), 'static/avatar'),
xsrf_cookies = True,
cookie_secret = "cookie_secret_code",
login_url = "/login",
autoescape = None,
jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
# debug = True,
)
tornado.web.Application.__init__(self, routes, **settings)
# Have one global connection to the blog DB across all handlers
self.db = torndb.Connection(
host = options.mysql_host, database = options.mysql_database,
user = options.mysql_user, password = options.mysql_password
)
# Have one global loader for loading models and handles
self.loader = Loader(self.db)
# Have one global model for db query
self.user_model = self.loader.use("user.model")
self.topic_model = self.loader.use("topic.model")
self.reply_model = self.loader.use("reply.model")
self.plane_model = self.loader.use("plane.model")
self.node_model = self.loader.use("node.model")
self.notification_model = self.loader.use("notification.model")
self.vote_model = self.loader.use("vote.model")
self.favorite_model = self.loader.use("favorite.model")
self.panel_model = self.loader.use('panel.model')
self.item_model = self.loader.use('item.model')
self.inventory_model = self.loader.use('inventory.model')
# Have one global session controller
self.session_manager = SessionManager(settings["cookie_secret"], ["127.0.0.1:11211"], 0)
# Have one global memcache controller
self.mc = memcache.Client(["127.0.0.1:11211"])
示例10: __init__
def __init__(self):
self.screen = pygame.display.set_mode((800, 600),1)
pygame.display.set_caption("PaintBrush advanced demo v1.1")
self.loader = Loader()
self.simple_pal = self.loader.load_image("simple.png",False)
self.advanced_pal = self.loader.load_image("advanced.png",False)
self.simple = True
self.knob = self.loader.load_image("knob.png",True)
self.knob_rect = self.knob.get_rect()
self.knob_rect.topleft = (14,215)
self.back = self.loader.load_image("back.png", False)
self.help = self.loader.load_image("help.png", True)
self.b1 = self.loader.load_image("brush_1.png", True)
self.b2 = self.loader.load_image("brush_2.png", True)
self.b3 = self.loader.load_image("brush_3.png", True)
self.b4 = self.loader.load_image("brush_4.png", True)
self.b5 = self.loader.load_image("brush_5.png", True)
self.b6 = self.loader.load_image("brush_6.png", True)
self.b7 = self.loader.load_image("brush_7.png", True)
self.b8 = self.loader.load_image("brush_8.png", True)
self.b9 = self.loader.load_image("brush_9.png", True)
self.cur_color = pygame.Color(0,0,0)
self.paper_rect = pygame.Rect(127,12,659,574)
self.paper = (pygame.Surface(self.paper_rect.size,1)).convert()
self.paper.fill((255,255,255))
self.painting = False
self.undo_cache = []
self.pal_rect = pygame.Rect(12,12,101,200)
self.brush_rect = pygame.Rect(12,231,101,355)
self.brush_rects = []
self.brush_rects.append(pygame.Rect(12,231,101,200))
self.brush_rects.append(pygame.Rect(12,332,50,50))
self.brush_rects.append(pygame.Rect(63,332,50,50))
self.brush_rects.append(pygame.Rect(12,332+51*1,50,50))
self.brush_rects.append(pygame.Rect(63,332+51*1,50,50))
self.brush_rects.append(pygame.Rect(12,332+51*2,50,50))
self.brush_rects.append(pygame.Rect(63,332+51*2,50,50))
self.brush_rects.append(pygame.Rect(12,332+51*3,50,50))
self.brush_rects.append(pygame.Rect(63,332+51*3,50,50))
self.brush_rects.append(pygame.Rect(12,332+51*4,50,50))
self.brush_rects.append(pygame.Rect(63,332+51*4,50,50))
self.brush = PaintBrush(self.paper)
self.set_brush(2)
示例11: Application
class Application(tornado.web.Application):
def __init__(self):
settings = dict(
blog_title = u"Git Eye",
template_path = os.path.join(os.path.dirname(__file__), "templates"),
static_path = os.path.join(os.path.dirname(__file__), "static"),
xsrf_cookies = True,
cookie_secret = "cookie_secret_code",
login_url = "/login",
autoescape = None,
jinja2 = Environment(loader = FileSystemLoader(os.path.join(os.path.dirname(__file__), "templates")), trim_blocks = True),
reserved = ["user", "topic", "home", "setting", "forgot", "login", "logout", "register", "admin"],
)
handlers.append(
(r"/(favicon\.ico)", tornado.web.StaticFileHandler, dict(path = settings["static_path"])),
)
tornado.web.Application.__init__(self, handlers, **settings)
# Have one global connection to the DB across all handlers
self.db = torndb.Connection(
host = options.mysql_host, database = options.mysql_database,
user = options.mysql_user, password = options.mysql_password
)
# Have one global loader for loading models and handles
self.loader = Loader(self.db)
# Have one global model for db query
self.user_model = self.loader.use("user.model")
self.socialauth_model = self.loader.use("socialauth.model")
# Have one global redis controller
pool = redis.ConnectionPool(host=options.redis_host, port=options.redis_port, db=options.redis_db)
self.rc = redis.StrictRedis(connection_pool=pool)
# Have one global session controller
self.session_manager = SessionManager(settings["cookie_secret"], self.rc, 86400 * 15)
示例12: __init__
def __init__(self, uid, channel, core, addr=PROC_ADDR):
self._uid = uid
self._queue = []
self._paths = {}
self._hidden = {}
self._core = core
self._addr = addr
self._pool = None
self._visible = {}
self._dispatchers = {}
self._channel = channel
self._lock = NamedLock()
self._loader = Loader(self._uid)
self._pool = DispatcherPool(core)
示例13: Handler
class Handler(object):
def __init__(self, uid, addr=PROC_ADDR):
self._handlers = {}
self._loader = Loader(uid)
self._addr = addr
def _get_code(self, name):
buf = self._handlers.get(name)
if not buf:
buf = self._loader.get_attr(name, ATTR_HANDLER, str)
self._handlers.update({name:buf})
return buf
def remove(self, name):
if self._handlers.has_key(name):
del self._handlers[name]
def check(self, name):
if self._handlers.get(name):
return True
else:
buf = self._loader.get_attr(name, ATTR_HANDLER, str)
if buf:
self._handlers.update({name:buf})
return True
def put(self, name, buf):
try:
code = self._get_code(name)
if code == None:
code = self._get_code(name)
if not code:
return
return proc.put(self._addr, HANDLER_PORT, code, buf)
except:
log_err(self, 'failed to put')
示例14: Lo
class Lo(UDI):
def get_name(self, device, child=None):
return _get_name(device)
def get_mode(self, device):
return _get_mode(device)
def setup(self):
self._active = False
self._loader = Loader(self.get_uid())
Thread(target=create_server, args=(LO_ADDR, LO_PORT, LoDaemon)).start()
def _get_device(self, name):
mode = self._core.get_mode(name)
prof = self._loader.get_profile(name)
if prof:
return device_name(prof['type'], name, mode)
def scan(self):
device_list = []
if not self._active:
self._active = True
names = get_devices(self._uid, sort=True)
if names:
for name in names:
device = self._get_device(name)
if device and device not in _devices:
device_list.append(device)
return device_list
def connect(self, device):
return (connect(device), True)
@property
def compute_unit(self):
if not _devices:
return
keys = _devices.keys()
length = len(keys)
i = randint(0, length - 1)
for _ in range(length):
device = _devices[keys[i]]
if device.get_mode() & MODE_CTRL:
return device
i += 1
if i == length:
i = 0
示例15: __init__
def __init__(self):
self.screen = pygame.display.set_mode((800, 600),1)
pygame.display.set_caption("Memory v1.0")
self.loader = Loader()
self.game_board = GameBoard()
self.side_panel = SidePanel()
self.robot_mouse = RobotMouse()
self.ai_player = AIPlayer(3)
self.side_panel.ai_level = self.ai_player.level
self.side_panel.update_stats()
self.pair_snd = self.loader.load_sound("pair.wav")
self.win_snd = self.loader.load_sound("win.wav")
self.win_snd.set_volume(0.5)
self.boom_snd = self.loader.load_sound("boom.wav")
self.boom_snd.set_volume(0.3)
self.stardust = StarDustAnim()
self.starburst = StarBurstAnim()