Merge PR #162 into dev-1.2.x
Michael Teo
3 years ago
0 | ||
1 | 0 | import os, sys, socket, urllib.request, urllib.error, urllib.parse, mimetypes, email, tempfile |
2 | 1 | from urllib.parse import (unwrap, unquote, splittype, splithost, quote, |
3 | 2 | splitport, splittag, splitattr, splituser, splitpasswd, splitvalue) |
25 | 24 | port = int(port) |
26 | 25 | |
27 | 26 | # username/password handling |
27 | ||
28 | 28 | user, host = splituser(host) |
29 | ||
29 | 30 | if user: |
30 | 31 | user, passwd = splitpasswd(user) |
31 | 32 | else: |
32 | 33 | passwd = None |
34 | ||
33 | 35 | host = unquote(host) |
34 | 36 | user = user or '' |
35 | 37 | |
40 | 42 | passwd = passwd or '' |
41 | 43 | myname = MACHINE_NAME or self.generateClientMachineName() |
42 | 44 | |
43 | n = NetBIOS() | |
44 | names = n.queryIPForName(host) | |
45 | if names: | |
46 | server_name = names[0] | |
47 | else: | |
48 | raise urllib.error.URLError('SMB error: Hostname does not reply back with its machine name') | |
45 | server_name,host = host.split(',') if ',' in host else [None,host] | |
46 | ||
47 | if server_name is None: | |
48 | n = NetBIOS() | |
49 | ||
50 | names = n.queryIPForName(host) | |
51 | if names: | |
52 | server_name = names[0] | |
53 | else: | |
54 | raise urllib.error.URLError('SMB error: Hostname does not reply back with its machine name') | |
49 | 55 | |
50 | 56 | path, attrs = splitattr(req.selector) |
51 | 57 | if path.startswith('/'): |