本文整理汇总了Python中link.Link类的典型用法代码示例。如果您正苦于以下问题:Python Link类的具体用法?Python Link怎么用?Python Link使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Link类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_domains_id
def fetch_domains_id(self):
self.domain_ids = []
for n in self.links:
url = Link(n, self.url)
if url.is_valid():
self.domain_ids.append(url.netloc)
return self.domain_ids
示例2: export
def export(self):
l = Link(self.url,self.source_url)
l = l.parse_url(self.url)
return {
"url": self.url,
"domain": l.domain,
"subdomain": l.subdomain,
"extension": l.extension,
"filetype": l.filetype,
"date": [dt.now()],
"source": self.source_url,
"title": self.title,
"cited_links": self.links,
"cited_links_ids": self.domain_ids,
"cited_domains": self.domains,
"html": self.html,
"text": self.text,
"depth": self.depth,
#"keywords": self.keywords,
#"description": self.description,
"meta": self.meta,
"crawl_nb": 0,
"status": [True],
"msg": ["Ok"]
#"lang": self.metalang,
}
示例3: fetch_domains
def fetch_domains(self):
self.domains = []
for n in self.links:
url = Link(n, self.url)
if url.is_valid():
self.domains.append(url.domain)
return self.domains
示例4: post_link
def post_link():
'''
Performed when a link is POSTed.
Inserts the (sanitized) data into the database. The description is parsed as Markdown
and saved in HTML, while allowing a few attributes
------------------
NOTE: `request` is global and is implicitly passed as a parameter. It would probably
be better to pass the data as a param for testing purposes.
------------------
NOTE: Maybe save the raw data as Markdown and only render it once needed ? Makes editing
posts easier, but puts more load on the server.
'''
allowed_tags = ("p", "h1", "h2", "h3", "h4", "h5", "h6", "b", "em", "small", "code", "i", "pre", "strong", "table", 'thead', 'tbody', 'th', 'tr', 'td', 'ul', 'ol', 'li', 'input')
allowed_attrs = ('type', 'disabled', 'checked')
title = bleach.clean(request.form['title'])
desc = bleach.clean(request.form['desc'], tags=allowed_tags, attributes=allowed_attrs)
url = bleach.clean(request.form["url"])
timestamp = time.time()
tags = []
post = Link(title, url, desc, timestamp)
post.set_tags(bleach.clean(request.form['tags']))
post.write()
return redirect("/")
示例5: nav_dd_icon
def nav_dd_icon(icon_class="fa fa-envelope-o", label_class="label label-success", label_text=""):
link = Link(href="#", css_classes="dropdown-toggle", data_toggle="dropdown")
icon = Icon(icon_class)
span = Span(label_class, label_text)
icon.append_widget(span)
link.append_widget(icon)
return link
示例6: TestLinkMethods
class TestLinkMethods(unittest.TestCase):
def setUp(self):
self.c = Link()
pass
def tearDown(self):
pass
def test_connectMysql(self):
db = self.c.connectMysql(db = 'maimai')
db.query('show tables')
rows = db.fetchAllRows()
self.assertEqual(type(rows), tuple)
def test_connectRedis(self):
redis = self.c.connectRedis()
keys = redis.keys()
self.assertEqual(type(keys), list)
def test_connectSphinx(self):
sphinx = self.c.connectSphinx()
res = sphinx.query('a')
self.assertIn('status', res)
self.assertIn('matches', res)
示例7: create_links
def create_links(self):
link1 = Link(self.core1, self.core2)
self.links.append(link1)
link2 = Link(self.core2, self.core1)
self.links.append(link2)
if link1.get_link_id() is link2.get_link_id():
self.link_id = link1.get_link_id()
self.core1.add_link_id(self.link_id)
self.core2.add_link_id(self.link_id)
示例8: delete_link
def delete_link(id):
form = forms.DeleteLinkForm()
link = Link.from_id(id)
if link is None:
return redirect('/404')
if request.method == "GET":
return render_template(Config.theme + "delete.jinja", app=Config, link=link, form=form)
else:
Link.delete_from_id(id)
return redirect("/")
示例9: is_valid
def is_valid(self):
#logging.info("Valid url?")
url = Link(self.url, self.source_url, self.debug)
if url.is_valid():
#logging.info("Yes")
return True
else:
self.msg = url.msg
self.code = url.code
self.step = "Validating page"
self.status = False
return False
示例10: add_link
def add_link(self, node1, node2, bandwidth):
link = Link(node1.get_id(), node2.get_id(), bandwidth, bandwidth)
end_point = link.get_end_points()
if link in self.links:
raise Exception("Link already exist...")
else:
self.links[end_point] = link
node1.add_link(link)
node2.add_link(link)
self.links[end_point] = link
示例11: service
def service(self):
"""Listen on iport, accept incomming connections. For a new
connection, the first 4 bytes indicate neighbor id."""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind( ('', self.iport) )
s.listen(1)
while True:
conn, addr = s.accept()
neighbour = struct.unpack('!I', get_data(4, conn)[0])[0]
link_property = self.topology[(neighbour, self.vrid)]
tlink = Link(link_property, self.iqueue)
self.l2p[neighbour] = {'addr':addr, 'link':tlink}
tlink.setup(conn)
pass
示例12: process
def process(self,filexml,mgrEvent):
xmldoc = minidom.parse(filexml)
itemlist2 = xmldoc.getElementsByTagName('manager')
for ast in itemlist2 :
self.asterisk_server = ast.getElementsByTagName('server')[0].firstChild.nodeValue
self.asterisk_login = ast.getElementsByTagName('login')[0].firstChild.nodeValue
self.asterisk_secret = ast.getElementsByTagName('secret')[0].firstChild.nodeValue
print('server: ' + self.asterisk_server + ' login: ' + self.asterisk_login + ' secret: ' + self.asterisk_secret)
itemlist = xmldoc.getElementsByTagName('link')
print len(itemlist)
for s in itemlist :
link = Link(mgrEvent)
link.linkid = s.attributes['id'].value
link.csp = s.getElementsByTagName('csp')[0].firstChild.nodeValue
link.channels = s.getElementsByTagName('channels')[0].firstChild.nodeValue
link.freeChannels = link.channels
aux = s.getElementsByTagName('routes')[0].firstChild.nodeValue
link.routes = aux.split(',')
print(s.attributes['id'].value)
print(s.getElementsByTagName('csp')[0].firstChild.nodeValue)
print(s.getElementsByTagName('routes')[0].firstChild.nodeValue)
self.links[link.linkid] = link
link.startLink()
示例13: _createLink
def _createLink(self):
pos, rot = self._getInitialValues(LINK)
name = '%s.link' % self.name
self.link = Link(self.world, name=name, pos=pos, rot=rot,
cfg=self.cfg['link'], module=self, data=self.data)
self.world.add(self.link)
logger.info("using link pos: %s" % pos)
示例14: merge_paths
def merge_paths(self, used_paths):
# TODO: Need to rethink if apps have min. bandwidth requirement
for paths in used_paths:
path = paths[1]
for i in range(len(path) - 1):
l = self.links[Link.get_id(path[i], path[i + 1])]
l.set_bandwidth(l.get_bandwidth() - self.bandwidth / 10)
示例15: get_link
def get_link(self, node1, node2):
ret = None
link_id = Link.get_id(node1.get_id(), node2.get_id())
if link_id in self.links:
ret = self.links[link_id]
return ret