[Pkg-privacy-commits] [onionshare] 02/53: Add some missing docstrings.
Ulrike Uhlig
u-guest at moszumanska.debian.org
Wed Dec 30 00:20:10 UTC 2015
This is an automated email from the git hooks/post-receive script.
u-guest pushed a commit to branch debian
in repository onionshare.
commit 7fada800f3e455cb27a4da01eab93c0084ab2b45
Author: Lazlo Westerhof <github at lazlo.me>
Date: Thu Jun 25 21:55:29 2015 +0200
Add some missing docstrings.
---
onionshare/helpers.py | 23 +++++++++++++++++++++++
onionshare/strings.py | 7 +++++++
onionshare_gui/common.py | 6 ++++++
3 files changed, 36 insertions(+)
diff --git a/onionshare/helpers.py b/onionshare/helpers.py
index 8c30c2e..279cb56 100644
--- a/onionshare/helpers.py
+++ b/onionshare/helpers.py
@@ -27,6 +27,9 @@ sys.setdefaultencoding("utf-8")
def get_platform():
+ """
+ Returns the platform OnionShare is running on.
+ """
p = platform.system()
if p == 'Linux' and platform.uname()[0:2] == ('Linux', 'amnesia'):
p = 'Tails'
@@ -40,14 +43,22 @@ if get_platform() == 'Darwin':
else:
osx_resources_dir = None
+
def get_onionshare_dir():
+ """
+ Returns the OnionShare directory.
+ """
if get_platform() == 'Darwin':
onionshare_dir = os.path.dirname(__file__)
else:
onionshare_dir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
return onionshare_dir
+
def get_html_path(filename):
+ """
+ Returns the path of the html files.
+ """
p = platform.system()
if p == 'Darwin':
prefix = os.path.join(osx_resources_dir, 'html')
@@ -57,6 +68,9 @@ def get_html_path(filename):
def constant_time_compare(val1, val2):
+ """
+ Compares two values in constant time.
+ """
_builtin_constant_time_compare = getattr(hmac, 'compare_digest', None)
if _builtin_constant_time_compare is not None:
return _builtin_constant_time_compare(val1, val2)
@@ -74,6 +88,9 @@ def constant_time_compare(val1, val2):
def random_string(num_bytes, output_len=None):
+ """
+ Returns a random string with a specified number of bytes.
+ """
b = os.urandom(num_bytes)
h = hashlib.sha256(b).digest()[:16]
s = base64.b32encode(h).lower().replace('=', '')
@@ -83,6 +100,9 @@ def random_string(num_bytes, output_len=None):
def human_readable_filesize(b):
+ """
+ Returns filesize in a human readable format.
+ """
thresh = 1024.0
if b < thresh:
return '{0:.1f} B'.format(b)
@@ -96,6 +116,9 @@ def human_readable_filesize(b):
def is_root():
+ """
+ Returns if user is root.
+ """
return os.geteuid() == 0
diff --git a/onionshare/strings.py b/onionshare/strings.py
index fe4fc0e..6e2521b 100644
--- a/onionshare/strings.py
+++ b/onionshare/strings.py
@@ -24,6 +24,10 @@ strings = {}
def load_strings(default="en"):
+ """
+ Loads translated strings and fallback to English
+ if the translation does not exist.
+ """
global strings
p = helpers.get_platform()
@@ -55,6 +59,9 @@ def load_strings(default="en"):
def translated(k, gui=False):
+ """
+ Returns a translated string.
+ """
if gui:
return strings[k].encode("utf-8").decode('utf-8', 'replace')
else:
diff --git a/onionshare_gui/common.py b/onionshare_gui/common.py
index 60212f0..5caedfb 100644
--- a/onionshare_gui/common.py
+++ b/onionshare_gui/common.py
@@ -21,6 +21,9 @@ import os, sys, inspect, platform
from onionshare import helpers
def get_onionshare_gui_dir():
+ """
+ Returns the OnionShare gui directory.
+ """
p = helpers.get_platform()
if p == 'Darwin':
onionshare_gui_dir = os.path.dirname(__file__)
@@ -32,6 +35,9 @@ onionshare_gui_dir = get_onionshare_gui_dir()
def get_image_path(filename):
+ """
+ Returns the OnionShare image path.
+ """
p = helpers.get_platform()
if p == 'Linux' or p == 'Tails':
prefix = os.path.join(sys.prefix, 'share/onionshare/images')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git
More information about the Pkg-privacy-commits
mailing list