Permalink
Browse files

retab Python scripts according to PEP8

Recent Vim sets sts=4 for Python files by default. Might as well follow
it already, I guess. Use `git show -w` for this one.
  • Loading branch information...
1 parent 781ecaa commit 992046f082a6235f1ec3fc9eeff6ff4cc3eee9e3 @grawity committed Nov 21, 2013
Showing with 5,536 additions and 5,559 deletions.
  1. +4 −4 lib/python/nullroute/__init__.py
  2. +150 −154 lib/python/nullroute/authorized_keys.py
  3. +25 −25 lib/python/nullroute/clipboard.py
  4. +254 −257 lib/python/nullroute/irc.py
  5. +147 −147 lib/python/nullroute/mp3tags.py
  6. +374 −376 lib/python/nullroute/sexp.py
  7. +50 −50 lib/python/nullroute/tests.py
  8. +200 −200 lib/python/nullroute/windows/firewall.py
  9. +7 −7 lib/python/nullroute/windows/io.py
  10. +63 −63 lib/python/nullroute/windows/registry.py
  11. +9 −9 lib/python/nullroute/windows/util.py
  12. +57 −57 misc/bthkeys.py
  13. +117 −118 misc/dupes
  14. +7 −8 misc/ldifunwrap
  15. +103 −103 misc/putty-hostalias.py
  16. +75 −75 misc/sony-ericsson-screenshot
  17. +40 −40 misc/zlib
  18. +103 −103 music/id3-cover
  19. +66 −66 music/id3-lyrics
  20. +1 −1 music/id3-purge-priv
  21. +3 −3 music/id3-sync-rg
  22. +8 −9 music/rg-copytags
  23. +2 −4 net/freenet-monitor.py
  24. +40 −43 net/obml-parser
  25. +211 −211 net/old-protocols/in.rfingerd
  26. +101 −101 net/scrape-reddit-comment
  27. +144 −144 net/unixify
  28. +63 −63 net/update-etchosts.py
  29. +419 −420 security/git-credential-lib
  30. +81 −81 security/gpg-sync-keyrings
  31. +100 −100 security/ssh-duphosts
  32. +474 −475 security/ssh-publickeyd
  33. +79 −79 security/update-k5login
  34. +194 −194 security/win32-cred.py
  35. +19 −20 system/envcp
  36. +206 −207 system/ldmissing
  37. +77 −77 system/systemd-coredump-extract
  38. +358 −361 term/xterm-color-chooser
  39. +204 −206 win32/df.py
  40. +53 −51 win32/fingerd.py
  41. +73 −72 win32/fw.py
  42. +363 −363 win32/identd/win32-identd.py
  43. +145 −146 win32/pathed.py
  44. +2 −2 win32/powermonitor/actions.py.example
  45. +71 −71 win32/powermonitor/powermonitor.py
  46. +194 −193 win32/ts.py
@@ -1,11 +1,11 @@
import sys
def warn(*args):
- print("\033[1;33mwarning:\033[m", *args, file=sys.stderr)
+ print("\033[1;33mwarning:\033[m", *args, file=sys.stderr)
def err(*args):
- print("\033[1;31merror:\033[m", *args, file=sys.stderr)
+ print("\033[1;31merror:\033[m", *args, file=sys.stderr)
def die(*args):
- err(*args)
- sys.exit(1)
+ err(*args)
+ sys.exit(1)
@@ -1,9 +1,5 @@
-#!/usr/bin/env python
+# parser for OpenSSH authorized_keys files
# vim: ft=python
-
-# State-machine-based parser for OpenSSH authorized_keys files.
-# (c) 2011 Mantas M. <grawity@gmail.com>
-# Released under WTFPL v2 <http://sam.zoy.org/wtfpl/>
#
# for line in open("authorized_keys"):
# if line and not line.startswith("#"):
@@ -13,156 +9,156 @@
import hashlib
class PublicKeyOptions(list):
- def __str__(self):
- o = []
- for k, v in self:
- if v is True:
- o.append(k)
- else:
- o.append("%s=%s" % (k, v))
- return ",".join(o)
-
- @classmethod
- def parse(klass, text):
- keys = []
- values = []
- current = ""
- state = "key"
-
- for char in text:
- if state == "key":
- if char == ",":
- keys.append(current)
- values.append(True)
- current = ""
- elif char == "=":
- keys.append(current)
- current = ""
- state = "value"
- else:
- current += char
- elif state == "value":
- if char == ",":
- values.append(current)
- current = ""
- state = "key"
- elif char == "\"":
- current += char
- state = "value dquote"
- else:
- current += char
- elif state == "value dquote":
- if char == "\"":
- current += char
- state = "value"
- elif char == "\\":
- current += char
- state = "value dquote escape"
- else:
- current += char
- elif state == "value dquote escape":
- current += char
- state = "value dquote"
-
- if current:
- if state == "key":
- keys.append(current)
- values.append(True)
- else:
- values.append(current)
-
- return klass(zip(keys, values))
+ def __str__(self):
+ o = []
+ for k, v in self:
+ if v is True:
+ o.append(k)
+ else:
+ o.append("%s=%s" % (k, v))
+ return ",".join(o)
+
+ @classmethod
+ def parse(klass, text):
+ keys = []
+ values = []
+ current = ""
+ state = "key"
+
+ for char in text:
+ if state == "key":
+ if char == ",":
+ keys.append(current)
+ values.append(True)
+ current = ""
+ elif char == "=":
+ keys.append(current)
+ current = ""
+ state = "value"
+ else:
+ current += char
+ elif state == "value":
+ if char == ",":
+ values.append(current)
+ current = ""
+ state = "key"
+ elif char == "\"":
+ current += char
+ state = "value dquote"
+ else:
+ current += char
+ elif state == "value dquote":
+ if char == "\"":
+ current += char
+ state = "value"
+ elif char == "\\":
+ current += char
+ state = "value dquote escape"
+ else:
+ current += char
+ elif state == "value dquote escape":
+ current += char
+ state = "value dquote"
+
+ if current:
+ if state == "key":
+ keys.append(current)
+ values.append(True)
+ else:
+ values.append(current)
+
+ return klass(zip(keys, values))
class PublicKey(object):
- def __init__(self, line=None):
- if line:
- tokens = self.parse(line)
- else:
- tokens = ["", None, None, None]
-
- self.prefix, self.algo, self.blob, self.comment = tokens
-
- self.options = PublicKeyOptions.parse(self.prefix)
-
- def __repr__(self):
- return "<PublicKey prefix=%r algo=%r comment=%r>" % \
- (self.prefix, self.algo, self.comment)
-
- def __str__(self):
- options = self.options
- blob = base64.b64encode(self.blob).decode("utf-8")
- comment = self.comment
- k = [self.algo, blob]
- if len(options):
- k.insert(0, str(options))
- if len(comment):
- k.append(comment)
- return " ".join(k)
-
- def fingerprint(self, alg=None, hex=False):
- if alg is None:
- alg = hashlib.md5
- m = alg()
- m.update(self.blob)
- return m.hexdigest() if hex else m.digest()
-
- @classmethod
- def parse(self, line):
- tokens = []
- current = ""
- state = "normal"
-
- for char in line:
- old = state
- if state == "normal":
- if char in " \t":
- tokens.append(current)
- current = ""
- elif char == "\"":
- current += char
- state = "dquote"
- else:
- current += char
- elif state == "dquote":
- if char == "\"":
- current += char
- state = "normal"
- elif char == "\\":
- current += char
- state = "dquote escape"
- else:
- current += char
- elif state == "dquote escape":
- current += char
- state = "dquote"
-
- if current:
- tokens.append(current)
-
- if tokens[0] in {"ssh-rsa", "ssh-dss", "ecdsa-sha2-nistp256",
- "ecdsa-sha2-nistp384", "ecdsa-sha2-nistp521"}:
- prefix = ""
- else:
- prefix = tokens.pop(0)
- algo = tokens[0]
- blob = tokens[1]
- blob = base64.b64decode(blob.encode("utf-8"))
- comment = " ".join(tokens[2:])
-
- return prefix, algo, blob, comment
+ def __init__(self, line=None):
+ if line:
+ tokens = self.parse(line)
+ else:
+ tokens = ["", None, None, None]
+
+ self.prefix, self.algo, self.blob, self.comment = tokens
+
+ self.options = PublicKeyOptions.parse(self.prefix)
+
+ def __repr__(self):
+ return "<PublicKey prefix=%r algo=%r comment=%r>" % \
+ (self.prefix, self.algo, self.comment)
+
+ def __str__(self):
+ options = self.options
+ blob = base64.b64encode(self.blob).decode("utf-8")
+ comment = self.comment
+ k = [self.algo, blob]
+ if len(options):
+ k.insert(0, str(options))
+ if len(comment):
+ k.append(comment)
+ return " ".join(k)
+
+ def fingerprint(self, alg=None, hex=False):
+ if alg is None:
+ alg = hashlib.md5
+ m = alg()
+ m.update(self.blob)
+ return m.hexdigest() if hex else m.digest()
+
+ @classmethod
+ def parse(self, line):
+ tokens = []
+ current = ""
+ state = "normal"
+
+ for char in line:
+ old = state
+ if state == "normal":
+ if char in " \t":
+ tokens.append(current)
+ current = ""
+ elif char == "\"":
+ current += char
+ state = "dquote"
+ else:
+ current += char
+ elif state == "dquote":
+ if char == "\"":
+ current += char
+ state = "normal"
+ elif char == "\\":
+ current += char
+ state = "dquote escape"
+ else:
+ current += char
+ elif state == "dquote escape":
+ current += char
+ state = "dquote"
+
+ if current:
+ tokens.append(current)
+
+ if tokens[0] in {"ssh-rsa", "ssh-dss", "ecdsa-sha2-nistp256",
+ "ecdsa-sha2-nistp384", "ecdsa-sha2-nistp521"}:
+ prefix = ""
+ else:
+ prefix = tokens.pop(0)
+ algo = tokens[0]
+ blob = tokens[1]
+ blob = base64.b64decode(blob.encode("utf-8"))
+ comment = " ".join(tokens[2:])
+
+ return prefix, algo, blob, comment
if __name__ == "__main__":
- import os
-
- path = os.path.expanduser("~/.ssh/authorized_keys")
-
- for line in open(path, "r"):
- line = line.strip()
- if line and not line.startswith("#"):
- key = PublicKey(line)
- print("key = %r" % key)
- print("prefix = %r" % key.prefix)
- print("algo = %r" % key.algo)
- print("comment = %r" % key.comment)
- print("options = %r" % key.options)
- print()
+ import os
+
+ path = os.path.expanduser("~/.ssh/authorized_keys")
+
+ for line in open(path, "r"):
+ line = line.strip()
+ if line and not line.startswith("#"):
+ key = PublicKey(line)
+ print("key = %r" % key)
+ print("prefix = %r" % key.prefix)
+ print("algo = %r" % key.algo)
+ print("comment = %r" % key.comment)
+ print("options = %r" % key.options)
+ print()
@@ -1,30 +1,30 @@
import sys
def get():
- if sys.platform == "win32":
- import win32clipboard as clip
- clip.OpenClipboard()
- # TODO: what type does this return?
- data = clip.GetClipboardData(clip.CF_UNICODETEXT)
- #print("clipboard.get =", repr(data))
- clip.CloseClipboard()
- return data
- else:
- raise RuntimeError("Unsupported platform")
+ if sys.platform == "win32":
+ import win32clipboard as clip
+ clip.OpenClipboard()
+ # TODO: what type does this return?
+ data = clip.GetClipboardData(clip.CF_UNICODETEXT)
+ #print("clipboard.get =", repr(data))
+ clip.CloseClipboard()
+ return data
+ else:
+ raise RuntimeError("Unsupported platform")
def put(data):
- if sys.platform == "win32":
- import win32clipboard as clip
- clip.OpenClipboard()
- clip.EmptyClipboard()
- clip.SetClipboardText(data, clip.CF_UNICODETEXT)
- clip.CloseClipboard()
- elif sys.platform.startswith("linux"):
- import subprocess
- proc = subprocess.Popen(("xsel", "-i", "-b", "-l", "/dev/null"),
- stdin=subprocess.PIPE)
- proc.stdin.write(data.encode("utf-8"))
- proc.stdin.close()
- proc.wait()
- else:
- raise RuntimeError("Unsupported platform")
+ if sys.platform == "win32":
+ import win32clipboard as clip
+ clip.OpenClipboard()
+ clip.EmptyClipboard()
+ clip.SetClipboardText(data, clip.CF_UNICODETEXT)
+ clip.CloseClipboard()
+ elif sys.platform.startswith("linux"):
+ import subprocess
+ proc = subprocess.Popen(("xsel", "-i", "-b", "-l", "/dev/null"),
+ stdin=subprocess.PIPE)
+ proc.stdin.write(data.encode("utf-8"))
+ proc.stdin.close()
+ proc.wait()
+ else:
+ raise RuntimeError("Unsupported platform")
Oops, something went wrong.

0 comments on commit 992046f

Please sign in to comment.