Example #1
0
def sys_argv_errors():
    _reload_module(sys)
    try:
        # Fix for Python 2.7
        sys.setdefaultencoding('utf8')
    except AttributeError:
        pass
    for i in xrange(len(sys.argv)):
        # Check for illegal (non-console) quote characters.
        if len(sys.argv[i]) > 1 and all(
                ord(_) in xrange(0x2018, 0x2020)
                for _ in ((sys.argv[i].split('=', 1)[-1].strip() or ' ')[0],
                          sys.argv[i][-1])):
            err_msg = "Illegal (non-console) quote characters ('" + sys.argv[
                i] + "')."
            print(print_critical_msg(err_msg))
            raise SystemExit()
        # Check for illegal (non-console) comma characters.
        elif len(sys.argv[i]) > 1 and u"\uff0c" in sys.argv[i].split('=',
                                                                     1)[-1]:
            err_msg = "Illegal (non-console) comma character ('" + sys.argv[
                i] + "')."
            print(print_critical_msg(err_msg))
            raise SystemExit()
        # Check for potentially miswritten (illegal '=') short option.
        elif re.search(r"\A-\w=.+", sys.argv[i]):
            err_msg = "Potentially miswritten (illegal '=') short option detected ('" + sys.argv[
                i] + "')."
            print(print_critical_msg(err_msg))
            raise SystemExit()
Example #2
0
else:
    try:
        import readline
        if getattr(readline, '__doc__',
                   '') is not None and 'libedit' in getattr(
                       readline, '__doc__', ''):
            import gnureadline as readline
    except ImportError:
        try:
            import gnureadline as readline
        except ImportError:
            readline_error = True
pass

# Set default encoding
_reload_module(sys)
#sys.setdefaultencoding(settings.DEFAULT_ENCODING)

if settings.IS_WINDOWS:
    import codecs
    # Reference: https://github.com/nodejs/node/issues/12786#issuecomment-298652440
    codecs.register(lambda name: codecs.lookup("utf-8")
                    if name == "cp65001" else None)
    # Use Colorama to make Termcolor work on Windows too :)
    init()
"""
Define HTTP User-Agent header.
"""


def user_agent_header():