equal
deleted
inserted
replaced
15 |
15 |
16 from i18n import _ |
16 from i18n import _ |
17 import error, osutil, encoding |
17 import error, osutil, encoding |
18 import errno, re, shutil, sys, tempfile, traceback |
18 import errno, re, shutil, sys, tempfile, traceback |
19 import os, stat, time, calendar, textwrap, unicodedata, signal |
19 import os, stat, time, calendar, textwrap, unicodedata, signal |
20 import imp |
20 import imp, socket |
21 |
21 |
22 # Python compatibility |
22 # Python compatibility |
23 |
23 |
24 def sha1(s): |
24 def sha1(s): |
25 return _fastsha1(s) |
25 return _fastsha1(s) |
1412 """ |
1412 """ |
1413 fn = fn or (lambda s: s) |
1413 fn = fn or (lambda s: s) |
1414 r = re.compile(r'%s(%s)' % (prefix, '|'.join(mapping.keys()))) |
1414 r = re.compile(r'%s(%s)' % (prefix, '|'.join(mapping.keys()))) |
1415 return r.sub(lambda x: fn(mapping[x.group()[1:]]), s) |
1415 return r.sub(lambda x: fn(mapping[x.group()[1:]]), s) |
1416 |
1416 |
|
1417 def getport(port): |
|
1418 """Return the port for a given network service. |
|
1419 |
|
1420 If port is an integer, it's returned as is. If it's a string, it's |
|
1421 looked up using socket.getservbyname(). If there's no matching |
|
1422 service, util.Abort is raised. |
|
1423 """ |
|
1424 try: |
|
1425 return int(port) |
|
1426 except ValueError: |
|
1427 pass |
|
1428 |
|
1429 try: |
|
1430 return socket.getservbyname(port) |
|
1431 except socket.error: |
|
1432 raise Abort(_("no port number associated with service '%s'") % port) |