本文整理汇总了Python中network.Network.reciprocal方法的典型用法代码示例。如果您正苦于以下问题:Python Network.reciprocal方法的具体用法?Python Network.reciprocal怎么用?Python Network.reciprocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类network.Network
的用法示例。
在下文中一共展示了Network.reciprocal方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: command_add
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import reciprocal [as 别名]
def command_add(arguments):
"""Add a new link to the current entity"""
global current_name
tag, target, *rest = arguments[0], arguments[1]
inverse_tag = rest[0] if rest else Network.reciprocal(tag)
try:
network.addlink(current_name, tag, target, inverse_tag)
return 'Added link "' + tag + ": " + target + '"'
except ValueError:
return "Link already existed."
示例2: command_remove
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import reciprocal [as 别名]
def command_remove(arguments):
"""Remove a specific link associated with the current entity"""
global current_name
tag, target, *rest = arguments[0], arguments[1]
inverse_tag = rest[0] if rest else Network.reciprocal(tag)
try:
network.unlink(current_name, tag, target, inverse_tag)
return 'Removed link "' + tag + ": " + target + '"'
except ValueError:
return "No such link."
示例3: application
# 需要导入模块: from network import Network [as 别名]
# 或者: from network.Network import reciprocal [as 别名]
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"
headers = [('Content-Type','text/html')]
if path == "plain":
headers = [
('Content-Type','text/plain'),
('Content-Disposition', 'attachment; filename="%s"' %(filename))
]
with open(filename) as net_file:
body = net_file.read()
elif cmd == "list" and env['REQUEST_METHOD'] == 'POST':
try:
view_entity = parse_qs(request_body)['view'][0]
new_url = '/view/%s' %quote(view_entity)
except:
new_url = '/list'
status = "303 See Other"
headers.append(('Location', new_url))
body = '<a href="%s">Redirect</a>' %new_url
elif cmd == "view" and arg and env['REQUEST_METHOD'] == 'POST':
try:
request_dict = parse_qs(request_body)
tag = request_dict['tag'][0].strip()
target = request_dict['target'][0].strip()
inverse_tag = request_dict.get('inverse_tag', [""])[0].strip()
if not inverse_tag:
inverse_tag = Network.reciprocal(tag)
if not all((tag, target, inverse_tag)):
raise ValueError()
net.addlink(arg, tag, target, inverse_tag)
status = "200 OK"
except:
status = "400 Bad Request"
body = tpl_view.render(name=arg, links=net[arg])
elif cmd == "view" and arg:
body = tpl_view.render(name=arg, links=net[arg])
elif path == "list":
body = tpl_list.render(entities=net.origin_counts())
elif not path:
status = "301 Moved Permanently"
headers.append(('Location', '/list'))
body = body = '<a href="/list">Redirect</a>'
else:
status = "404 Not Found"
body = "No such place!"
start_response(status, headers)
return [bytes(body, 'UTF-8')]