[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Removing stem.util.system.is_relative_path()
commit 809b34159067c25730d71b35460ba2e0fbf9a815
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Apr 8 14:34:59 2012 -0700
Removing stem.util.system.is_relative_path()
Why did I make this function again? Python already has os.path.isabs()...
---
stem/connection.py | 2 +-
stem/util/system.py | 17 +----------------
test/unit/util/system.py | 11 -----------
3 files changed, 2 insertions(+), 28 deletions(-)
diff --git a/stem/connection.py b/stem/connection.py
index 76099bf..0fd2017 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -667,7 +667,7 @@ def _expand_cookie_path(protocolinfo_response, pid_resolver, pid_resolution_arg)
"""
cookie_path = protocolinfo_response.cookie_path
- if cookie_path and stem.util.system.is_relative_path(cookie_path):
+ if cookie_path and not os.path.isabs(cookie_path):
try:
tor_pid = pid_resolver(pid_resolution_arg)
if not tor_pid: raise IOError("pid lookup failed")
diff --git a/stem/util/system.py b/stem/util/system.py
index 16d1832..6ecc0aa 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -11,7 +11,6 @@ get_pid_by_port - gets the pid for a process listening to a given port
get_pid_by_open_file - gets the pid for the process with an open file
get_cwd - provides the current working directory for a given process
get_bsd_jail_id - provides the BSD jail id a given process is running within
-is_relative_path - checks if a given path can be expanded by expand_path
expand_path - expands relative paths and ~ entries
call - runs the given system command and provides back the results
"""
@@ -489,20 +488,6 @@ def get_bsd_jail_id(pid):
return 0
-def is_relative_path(path):
- """
- Checks if the path can be expanded by the expand_path function.
-
- Returns:
- bool that's True if the path is relative or begins with an expandable home,
- False otherwise
- """
-
- if platform.system() == "Windows":
- return False # TODO: implement
- else:
- return path and not path.startswith("/")
-
def expand_path(path, cwd = None):
"""
Provides an absolute path, expanding tildas with the user's home and
@@ -523,7 +508,7 @@ def expand_path(path, cwd = None):
else:
relative_path = path
- if not path or path[0] == "/":
+ if not path or os.path.isabs(path):
# empty or already absolute - nothing to do
pass
elif path.startswith("~"):
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index b09dca7..397ba7d 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -284,17 +284,6 @@ class TestSystem(unittest.TestCase):
expected_response = 1 if test_input == "1111" else 0
self.assertEquals(expected_response, system.get_bsd_jail_id(test_input))
- def test_is_relative_path_unix(self):
- """
- Tests the is_relative_path function.
- """
-
- mocking.mock(platform.system, mocking.return_value("Linux"))
- self.assertTrue(system.is_relative_path("hello/world"))
- self.assertTrue(system.is_relative_path("~/hello/world"))
- self.assertTrue(system.is_relative_path("~user/hello/world"))
- self.assertFalse(system.is_relative_path("/tmp/hello/world"))
-
def test_expand_path_unix(self):
"""
Tests the expand_path function. This does not exercise home directory
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits