diff --git a/README.md b/README.md index 634eb4b..93b7a23 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,13 @@ The main idea of PRET is to facilitate the communication between the end-user an ### Installation -PRET only requires a Python2 interpreter. For colored output and SNMP support however, third party modules need to be installed: +PRET only requires a Python3 interpreter. For colored output and SNMP support however, third party modules need to be installed: - # pip install colorama pysnmp + # pip3 install colorama pysnmp If running on a Windows console and Unicode characters are not displayed correctly, install the *win_unicode_console* module: - # pip install win_unicode_console + # pip3 install win_unicode_console For experimental, ‘driverless’ printing (see print command), ImageMagick and GhostScript need to be installed: diff --git a/capabilities.py b/capabilities.py index b19d5fd..860cf56 100644 --- a/capabilities.py +++ b/capabilities.py @@ -4,10 +4,7 @@ # python standard library import re, os, sys #, urllib.error, urllib.parse -try: - import urllib.request as urllib_request -except ImportError: - import urllib as urllib_request +import requests # local pret classes from helper import output, item @@ -67,9 +64,11 @@ def ipp(self, host, lang): body = ("\x01\x01\x00\x0b\x00\x01\xab\x10\x01G\x00\x12attributes-charset\x00\x05utf-8H" + "\x00\x1battributes-natural-language\x00\x02enE\x00\x0bprinter-uri\x00\x14ipp:" + "//localhost/ipp/D\x00\x14requested-attributes\x00\x13printer-description\x03").encode() - request = urllib_request.Request("http://" + host + ":631/", + + response = requests.post("http://" + host + ":631/", data=body, headers={'Content-type': 'application/ipp'}) - response = urllib_request.urlopen(request, timeout=self.timeout).read().decode() + response = response.text + # get name of device model = item(re.findall("MDL:(.+?);", response)) # e.g. MDL:hp LaserJet 4250 # get language support @@ -86,7 +85,7 @@ def http(self, host): try: # poor man's way get http title sys.stdout.write("Checking for HTTP support: ") - html = urllib_request.urlopen("http://" + host, timeout=self.timeout).read().decode() + html = requests.get("http://" + host).text # cause we are to parsimonious to import BeautifulSoup ;) title = re.findall("\n?(.+?)\n?", html, re.I|re.M|re.S) # get name of device diff --git a/helper.py b/helper.py index 2169aad..19ba8fd 100644 --- a/helper.py +++ b/helper.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from __future__ import print_function + # python standard library from socket import socket diff --git a/lpd/lpdprint.py b/lpd/lpdprint.py index 30ac2e4..e4ac267 100755 --- a/lpd/lpdprint.py +++ b/lpd/lpdprint.py @@ -27,7 +27,7 @@ def usage(): data = f.read() f.close() except IOError as e: - print "Cannot read from file: " + str(e) + print(("Cannot read from file: " + str(e))) sys.exit() # ---------------------------------------------------------------------- @@ -35,7 +35,7 @@ def usage(): # get lpd acknowledgement def check_acknowledgement(): if s.recv(4096) != "\000": - print "Negative acknowledgement" + print("Negative acknowledgement") s.send("\001\n") # [ RFC 1179 | 6.1 01 - Abort job ] s.close() sys.exit() diff --git a/lpd/lpdtest.py b/lpd/lpdtest.py index 69afd43..8f2ffa7 100755 --- a/lpd/lpdtest.py +++ b/lpd/lpdtest.py @@ -108,34 +108,34 @@ def getFilequeueList(aFilename): if args.mode == 'get': getname = args.argument data += " If you can read this, the test failed." - print("[get] Trying to print file " + args.argument) + print(("[get] Trying to print file " + args.argument)) elif args.mode == 'put': ctrlfile = args.argument datafile = args.argument - print("[put] Trying to write to file " + args.argument) + print(("[put] Trying to write to file " + args.argument)) elif args.mode == 'rm': delname = args.argument - print("[rm] Trying to delete file " + args.argument) + print(("[rm] Trying to delete file " + args.argument)) elif args.mode == 'in': hostname = username = ctrlfile = datafile = delname = jobname \ = srcfile = jobtitle = classname = mailname = args.argument - print("[in] Trying to send user input '" + args.argument + "'") + print(("[in] Trying to send user input '" + args.argument + "'")) elif args.mode == 'mail': try: mailname = args.argument.split('@', 1)[0] hostname = args.argument.split('@', 1)[1] except Exception as e: - print("Bad argument" + str(e)) + print(("Bad argument" + str(e))) sys.exit() - print("[mail] Trying to send job information to " + args.argument) + print(("[mail] Trying to send job information to " + args.argument)) elif args.mode == 'brute': bruteQueueNameFile = args.argument - print("[brute] Trying to brute force queue file " + args.argument) + print(("[brute] Trying to brute force queue file " + args.argument)) # --------[ RFC 1179 | 6.2 02 - Receive control file ]------------------ @@ -174,7 +174,7 @@ def getFilequeueList(aFilename): continue else : - print("Printer found:",queueName) + print(("Printer found:",queueName)) break diff --git a/pjl.py b/pjl.py index 1256a1b..4857de2 100644 --- a/pjl.py +++ b/pjl.py @@ -393,7 +393,7 @@ def do_pagecount(self, arg): def do_display(self, arg): "Set printer's display message: display " if not arg: - arg = eval(input("Message: ")) + arg = input("Message: ") arg = arg.strip('"') # remove quotes self.chitchat("Setting printer's display message to \"" + arg + "\"") self.cmd('@PJL RDYMSG DISPLAY="' + arg + '"', False) diff --git a/pret.py b/pret.py index dec5493..5d4dab6 100644 --- a/pret.py +++ b/pret.py @@ -1,7 +1,7 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- -from __future__ import print_function + # python standard library import os, sys, argparse