Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testBasics(self):
"""Test basic tool functions."""
assert join_uri("/a/b", "c") == "/a/b/c"
assert join_uri("/a/b/", "c") == "/a/b/c"
assert join_uri("/a/b", "c", "d") == "/a/b/c/d"
assert join_uri("a/b", "c", "d") == "a/b/c/d"
assert join_uri("/", "c") == "/c"
assert join_uri("", "c") == "/c"
assert not is_child_uri("/a/b", "/a/")
assert not is_child_uri("/a/b", "/a/b")
assert not is_child_uri("/a/b", "/a/b/")
assert not is_child_uri("/a/b", "/a/bc")
assert not is_child_uri("/a/b", "/a/bc/")
assert is_child_uri("/a/b", "/a/b/c")
assert is_child_uri("/a/b", "/a/b/c")
assert not is_equal_or_child_uri("/a/b", "/a/")
assert is_equal_or_child_uri("/a/b", "/a/b")
assert is_equal_or_child_uri("/a/b", "/a/b/")
assert not is_equal_or_child_uri("/a/b", "/a/bc")
assert not is_equal_or_child_uri("/a/b", "/a/bc/")
assert is_equal_or_child_uri("/a/b", "/a/b/c")
def testBasics(self):
"""Test basic tool functions."""
assert join_uri("/a/b", "c") == "/a/b/c"
assert join_uri("/a/b/", "c") == "/a/b/c"
assert join_uri("/a/b", "c", "d") == "/a/b/c/d"
assert join_uri("a/b", "c", "d") == "a/b/c/d"
assert join_uri("/", "c") == "/c"
assert join_uri("", "c") == "/c"
assert not is_child_uri("/a/b", "/a/")
assert not is_child_uri("/a/b", "/a/b")
assert not is_child_uri("/a/b", "/a/b/")
assert not is_child_uri("/a/b", "/a/bc")
assert not is_child_uri("/a/b", "/a/bc/")
assert is_child_uri("/a/b", "/a/b/c")
assert is_child_uri("/a/b", "/a/b/c")
assert not is_equal_or_child_uri("/a/b", "/a/")
assert is_equal_or_child_uri("/a/b", "/a/b")
assert is_equal_or_child_uri("/a/b", "/a/b/")
assert not is_equal_or_child_uri("/a/b", "/a/bc")
def resolve(self, script_name, path_info):
"""Return a _DAVResource object for the path (None, if not found).
`path_info`: is a URL relative to this object.
"""
if path_info in ("", "/"):
return self
assert path_info.startswith("/")
name, rest = util.pop_path(path_info)
res = self.get_member(name)
if res is None or rest in ("", "/"):
return res
return res.resolve(util.join_uri(script_name, name), rest)
def get_member(self, name):
# raise NotImplementedError
return self.provider.get_resource_inst(
util.join_uri(self.path, name), self.environ
)
def get_member(self, name):
# Handle visible categories and also /by_key/...
if name in self._validMemberNames:
return CategoryTypeCollection(join_uri(self.path, name), self.environ)
return None
def create_collection(self, name):
"""Create a new collection as member of self.
See DAVResource.create_collection()
"""
assert "/" not in name
if self.provider.readonly:
raise DAVError(HTTP_FORBIDDEN)
path = util.join_uri(self.path, name)
fp = self.provider._loc_to_file_path(path, self.environ)
os.mkdir(fp)
MySQLBrowserResource(
self.provider,
util.join_uri(self.path, name),
True,
self.environ,
)
)
elif primKey is None:
pri_key = self.provider._find_primary_key(conn, tableName)
if pri_key is not None:
retlist = self.provider._list_fields(conn, tableName, pri_key)
for name in retlist:
members.append(
MySQLBrowserResource(
self.provider,
util.join_uri(self.path, name),
False,
self.environ,
)
)
members.insert(
0,
MySQLBrowserResource(
self.provider,
util.join_uri(self.path, "_ENTIRE_CONTENTS"),
False,
self.environ,
),
)
finally:
conn.close()
return members
def get_member(self, name):
doc = self.coll.find_one(ObjectId(name))
return DocResource(join_uri(self.path, name), self.environ, doc)
def get_member(self, name):
"""Return child resource with a given name (None, if not found).
This method COULD be overridden by a derived class, for performance
reasons.
This default implementation calls self.provider.get_resource_inst().
"""
assert self.is_collection
return self.provider.get_resource_inst(
util.join_uri(self.path, name), self.environ
)