[Pkg-privacy-commits] [pyptlib] 76/136: deprecate util.checkClientMode in favour of a much simpler config.checkClientMode

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:11 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository pyptlib.

commit ee80c0e61227b5f4b0b3e67bc9946f12a7e9d819
Author: Ximin Luo <infinity0 at gmx.com>
Date:   Thu Aug 15 15:22:31 2013 +0100

    deprecate util.checkClientMode in favour of a much simpler config.checkClientMode
---
 pyptlib/config.py        |  5 +++++
 pyptlib/util/__init__.py | 15 +++------------
 sphinx/API.rst           |  2 +-
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/pyptlib/config.py b/pyptlib/config.py
index ca31465..31e0fd6 100644
--- a/pyptlib/config.py
+++ b/pyptlib/config.py
@@ -153,3 +153,8 @@ class EnvError(Exception):
     Thrown when the environment is incomplete or corrupted.
     """
     pass
+
+def checkClientMode():
+    if 'TOR_PT_CLIENT_TRANSPORTS' in os.environ: return True
+    if 'TOR_PT_SERVER_TRANSPORTS' in os.environ: return False
+    raise EnvError('neither TOR_PT_{SERVER,CLIENT}_TRANSPORTS set')
diff --git a/pyptlib/util/__init__.py b/pyptlib/util/__init__.py
index 9966625..c724c4e 100644
--- a/pyptlib/util/__init__.py
+++ b/pyptlib/util/__init__.py
@@ -8,19 +8,10 @@ Utility functions.
 import re
 import socket
 
-from pyptlib.config import Config, EnvError
+# Deprecated; use pyptlib.config.checkClientMode() instead.
+# TODO(infinity0): remove this when all downstream migrates to new API
+from pyptlib.config import checkClientMode
 
-def checkClientMode(): # XXX WTF!???! This also exists in config.py.
-    """
-    Check whether Tor wants us to run as a client or as a server.
-
-    :returns: bool -- True if Tor wants us to run as a client.
-    """
-    try:
-        c = Config()
-        return c.checkClientMode()
-    except EnvError:
-        return False
 
 # This code is borrowed from flashproxy. Thanks David!
 def parse_addr_spec(spec, defhost = None, defport = None, resolve = False):
diff --git a/sphinx/API.rst b/sphinx/API.rst
index 7287a3b..5915273 100644
--- a/sphinx/API.rst
+++ b/sphinx/API.rst
@@ -27,7 +27,7 @@ Detailed API Overview
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 An application using pyptlib should start by calling
-:func:`pyptlib.util.checkClientMode` to learn whether Tor wants it
+:func:`pyptlib.config.checkClientMode` to learn whether Tor wants it
 to run as a client or as a server.
 
 1) Get transport information from Tor

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/pyptlib.git



More information about the Pkg-privacy-commits mailing list