-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode.py
89 lines (77 loc) · 2.58 KB
/
node.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#
# Copyright (c) 2018-2021 FASTEN.
#
# This file is part of FASTEN
# (see https://www.fasten-project.eu/).
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
class Node:
def __init__(self, uri_str, product=None, super_cls=None, version=None, first=None, last=None):
self.uri_str = uri_str
self.product = product
self.version = version
self.super_cls = super_cls or []
self.first = first
self.last=last
if len(uri_str.split("/")) == 5:
self.internal = False
self.external = True
else:
self.internal = True
self.external = False
self.modname = self.callable = ""
splitted = self.uri_str.split("/")
if self.internal:
self.modname = splitted[1]
self.callable = splitted[2]
else:
self.product = splitted[2]
self.callable = splitted[4]
self.is_class = super_cls != None
self.is_func = False
if self.callable.endswith("()"):
self.is_func = True
self.callable = self.callable[:-2]
def get_product(self):
return self.product
def get_version(self):
return self.version
def get_modname(self):
return self.modname
def get_callable(self):
return self.callable
def get_class_hier(self):
return self.super_cls
def get_metadata(self):
return {"first": self.first,
"last":self.last
}
def to_string(self, simple=False):
uri = ""
if not simple:
uri += "fasten://PyPI!"
else:
uri += "//"
uri += self.product
if self.version and not simple:
uri += "$" + self.version
uri += "/" + self.modname + "/" + self.callable
if self.is_func:
uri += "()"
return uri