X-Git-Url: https://code.delx.au/dotfiles/blobdiff_plain/fc6814be8f52c34705d000045a4527a67551f1de..673bbacda0823171b5aa39f8c1133170fb0c89b0:/.pythonrc.py diff --git a/.pythonrc.py b/.pythonrc.py index 5d8a274..fe74d41 100644 --- a/.pythonrc.py +++ b/.pythonrc.py @@ -1,18 +1,43 @@ #!/usr/bin/env python -# Useful things to have from __future__ import division -from math import * -import math -import os -import re + import sys -import array -import cgi -from datetime import datetime, timedelta +#################################### +# Python2 compatibility for urllib # +#################################### + +try: + import urllib + import urllib2 + import urlparse + + class dummy_urllib_module: + parse = urlparse + request = urllib2 + sys.modules["urllib"] = dummy_urllib_module + sys.modules["urllib.parse"] = dummy_urllib_module.parse + sys.modules["urllib.request"] = dummy_urllib_module.request + dummy_urllib_module.parse.urlencode = urllib.urlencode + +except ImportError: + pass + + +################## +# Useful imports # +################## + +import base64 +import collections +import datetime import hashlib +import io import json +import math +import os +import pickle import random import re import socket @@ -20,43 +45,41 @@ import struct import subprocess import tempfile import time -import traceback import urllib +import urllib.parse +import urllib.request -# Not available in Python3 -try: - import StringIO - import urllib2 - import urlparse -except ImportError: - pass -# Readline completion of everything :) -import rlcompleter, readline, atexit -defaultCompleter = rlcompleter.Completer() +####################### +# Readline completion # +####################### -historyPath = os.path.expanduser("~/.pyhistory") +def setup_readline_completion(): + import atexit + import readline + import rlcompleter -def myCompleter(text, state): - if text.strip() == "": - if state == 0: - return text + "\t" - else: - return None - else: - return defaultCompleter.complete(text, state) + history_path = os.path.expanduser("~/.python_history") -def save_history(historyPath=historyPath): - import readline - readline.write_history_file(historyPath) + default_completer = rlcompleter.Completer() -readline.set_completer(myCompleter) -readline.parse_and_bind("tab: complete") + readline.parse_and_bind("tab: complete") -if os.path.exists(historyPath): - readline.read_history_file(historyPath) + if os.path.exists(history_path): + readline.read_history_file(history_path) -atexit.register(save_history) + def my_completer(text, state): + if text.strip() == "": + if state == 0: + return text + "\t" + else: + return None + else: + return default_completer.complete(text, state) + readline.set_completer(my_completer) -del rlcompleter, readline, atexit + def save_history(history_path=history_path): + readline.write_history_file(history_path) + atexit.register(save_history) +setup_readline_completion()