本文整理汇总了Python中network.Network.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Network.from_file方法的具体用法?Python Network.from_file怎么用?Python Network.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.from_file方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import from_file [as 别名]
from urllib.parse import quote, unquote, parse_qs
from jinja2 import Environment, FileSystemLoader
from network import Network
filename = 'network0.pimesh'
with open(filename) as net_file:
net = Network.from_file(net_file)
jinja_env = Environment(loader=FileSystemLoader('./html'),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
tpl_list = jinja_env.get_template('list.html')
tpl_view = jinja_env.get_template('view.html')
def application(env, start_response):
path = env.get('PATH_INFO', "").lstrip('/')
cmd, *rest = path.split("/", 1)
arg = unquote(rest[0]).strip() if rest else ""
try:
request_body_size = int(env.get('CONTENT_LENGTH', 0))
except (ValueError):
request_body_size = 0
request_body = env['wsgi.input'].read(request_body_size).decode()
status = "200 OK"
示例2: open
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import from_file [as 别名]
#!/usr/bin/env python3
#Top-level wrapper script for a general-purpose information-management tool
import sys
from network import Network
from cliui import UI
try:
filename = sys.argv[1]
try:
networkfile = open(filename, 'r+')
network = Network.from_file(networkfile) # Note that this does not (and should not) create a new file
print("Loaded PIMesh network from file")
except FileNotFoundError:
network = Network()
print("Created empty network (file not found)")
ui = UI(network)
try:
ui.run()
except KeyboardInterrupt:
print("Caught leopard interrupt")
try:
network.to_file(networkfile)
print("Saved session changes to file.")
except:
print("Saving to file failed!")
except IndexError:
示例3: open
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import from_file [as 别名]
#!/usr/bin/env python3
#Top-level wrapper script for a general-purpose information-management tool
import sys
from network import Network
from cliui import UI
try:
filename = sys.argv[1]
try:
networkfile = open(filename, 'r+')
# Note that this does not (and should not) create a new file
network = Network.from_file(networkfile)
print("Loaded PIMesh network from file")
except FileNotFoundError:
networkfile = open(filename, 'w')
network = Network()
print("Created empty network (file not found)")
ui = UI(network)
try:
ui.run()
except KeyboardInterrupt:
print("Caught leopard interrupt")
networkfile.seek(0)
try:
network.to_file(networkfile)
networkfile.truncate()
print("Saved session changes to file.")
示例4: __init__
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import from_file [as 别名]
class UI:
def __init__(self, lines, cols):
self.mode = Mode.list
self.status = "Started PIMesh"
self.lines = lines
self.cols = cols
UI = UI(shutil.get_terminal_size()[0], shutil.get_terminal_size()[1])
print("\x1B]0;%s\x07" % "PIMesh") # Set window title
filename = "network0.pimesh" # Currently fixed filename - should it really be an argument when starting the script?
try:
network = Network.from_file(open(filename))
UI.status = "Loaded PIMesh network from file"
except FileNotFoundError:
network = Network()
UI.status = "Created empty network (file not found)"
def print_entity_list():
"""Print a list of entitites which have one of more links to/from them"""
#global UI.status
if len(network) == 0:
print("(No entities in network)") # Could be slightly confusing, but saves a big empty space
return 1
for n, name in enumerate(network.origins):
print(str(n) + " | " + name)
return len(network) # number of lines printed by this function, needed to pad vertically by the right amount