PrivateBin CLI on python 3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
626 B

import json, ntpath, os
8 years ago
class PBinCLIException(Exception):
pass
def path_leaf(path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
8 years ago
def check_readable(f):
# Checks if path exists and readable
8 years ago
if not os.path.exists(f) or not os.access(f, os.R_OK):
raise PBinCLIException("Error accessing path: {}".format(f))
8 years ago
def check_writable(f):
# Checks if path is writable
8 years ago
if not os.access(os.path.dirname(f) or ".", os.W_OK):
raise PBinCLIException("Path is not writable: {}".format(f))
8 years ago
def json_encode(s):
return json.dumps(s, separators=(',',':')).encode()