Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
15fb7f7d
Commit
15fb7f7d
authored
May 29, 2013
by
Guillaume Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve hostname detection and use hostname:port format
parent
b149a2fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
printcore.py
printcore.py
+14
-3
No files found.
printcore.py
View file @
15fb7f7d
...
...
@@ -108,11 +108,22 @@ class printcore():
self
.
baud
=
baud
if
self
.
port
is
not
None
and
self
.
baud
is
not
None
:
# Connect to socket if "port" is an IP, device if not
p
=
re
.
compile
(
"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])
\
.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
)
if
p
.
match
(
port
):
host_regexp
=
re
.
compile
(
"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])
\
.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$|^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9
\
-]*[a-zA-Z0-9])
\
.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9
\
-]*[A-Za-z0-9])$"
)
is_serial
=
True
if
":"
in
port
:
bits
=
port
.
split
(
":"
)
if
len
(
bits
)
==
2
:
hostname
=
bits
[
0
]
try
:
port
=
int
(
bits
[
1
])
if
host_regexp
.
match
(
hostname
)
and
1
<=
port
<=
65535
:
is_serial
=
False
except
:
pass
if
not
is_serial
:
self
.
printer
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
timeout
=
0.25
self
.
printer
.
connect
((
port
,
baud
))
self
.
printer
.
connect
((
hostname
,
port
))
else
:
disable_hup
(
self
.
port
)
self
.
printer
=
Serial
(
port
=
self
.
port
,
baudrate
=
self
.
baud
,
timeout
=
0.25
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment