Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted from python2 to python3. #67

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
13 changes: 6 additions & 7 deletions capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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("<title.*?>\n?(.+?)\n?</title>", html, re.I|re.M|re.S)
# get name of device
Expand Down
2 changes: 1 addition & 1 deletion helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from __future__ import print_function


# python standard library
from socket import socket
Expand Down
4 changes: 2 additions & 2 deletions lpd/lpdprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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()

# ----------------------------------------------------------------------

# 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()
Expand Down
16 changes: 8 additions & 8 deletions lpd/lpdtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]------------------

Expand Down Expand Up @@ -174,7 +174,7 @@ def getFilequeueList(aFilename):
continue

else :
print("Printer found:",queueName)
print(("Printer found:",queueName))
break


Expand Down
2 changes: 1 addition & 1 deletion pjl.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def do_pagecount(self, arg):
def do_display(self, arg):
"Set printer's display message: display <message>"
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)
Expand Down
4 changes: 2 additions & 2 deletions pret.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down