Changeset 2f0a5d9 in trunk
- Timestamp:
- 2020-10-27T20:58:46Z (5 years ago)
- Branches:
- master
- Children:
- 91c055a
- Parents:
- 874bfa72 (diff), b79504a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - git-author:
- Itamar Turner-Trauring <itamar@…> (2020-10-27 20:58:46)
- git-committer:
- GitHub <noreply@…> (2020-10-27 20:58:46)
- Files:
-
- 1 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified nix/tahoe-lafs.nix ¶
r874bfa72 r2f0a5d9 5 5 , service-identity, pyyaml, magic-wormhole, treq, appdirs 6 6 , beautifulsoup4, eliot, autobahn, cryptography, netifaces 7 , html5lib, pyutil, distro 7 , html5lib, pyutil, distro, configparser 8 8 }: 9 9 python.pkgs.buildPythonPackage rec { … … 47 47 service-identity pyyaml magic-wormhole treq 48 48 eliot autobahn cryptography netifaces setuptools 49 future pyutil distro 49 future pyutil distro configparser 50 50 ]; 51 51 -
TabularUnified setup.py ¶
r874bfa72 r2f0a5d9 135 135 # Linux distribution detection: 136 136 "distro >= 1.4.0", 137 138 # Backported configparser for Python 2: 139 "configparser ; python_version < '3.0'", 137 140 ] 138 141 -
TabularUnified src/allmydata/client.py ¶
r874bfa72 r2f0a5d9 3 3 from functools import partial 4 4 from errno import ENOENT, EPERM 5 try: 6 from ConfigParser import NoSectionError 7 except ImportError: 8 from configparser import NoSectionError 5 6 # On Python 2 this will be the backported package: 7 from configparser import NoSectionError 9 8 10 9 from foolscap.furl import ( … … 36 35 yamlutil, configutil, 37 36 ) 38 from allmydata.util.encodingutil import (get_filesystem_encoding, 39 from_utf8_or_none) 37 from allmydata.util.encodingutil import get_filesystem_encoding 40 38 from allmydata.util.abbreviate import parse_abbreviated_size 41 39 from allmydata.util.time_format import parse_duration, parse_date … … 720 718 def init_stats_provider(self): 721 719 gatherer_furl = self.config.get_config("client", "stats_gatherer.furl", None) 720 if gatherer_furl: 721 # FURLs should be bytes: 722 gatherer_furl = gatherer_furl.encode("utf-8") 722 723 self.stats_provider = StatsProvider(self, gatherer_furl) 723 724 self.stats_provider.setServiceParent(self) … … 807 808 config_storedir = self.get_config( 808 809 "storage", "storage_dir", self.STOREDIR, 809 ) .decode('utf-8')810 ) 810 811 storedir = self.config.get_config_path(config_storedir) 811 812 … … 935 936 if helper_furl in ("None", ""): 936 937 helper_furl = None 938 939 # FURLs need to be bytes: 940 if helper_furl is not None: 941 helper_furl = helper_furl.encode("utf-8") 937 942 938 943 DEP = self.encoding_params … … 1044 1049 from allmydata.webish import WebishServer 1045 1050 nodeurl_path = self.config.get_config_path("node.url") 1046 staticdir_config = self.config.get_config("node", "web.static", "public_html") .decode("utf-8")1051 staticdir_config = self.config.get_config("node", "web.static", "public_html") 1047 1052 staticdir = self.config.get_config_path(staticdir_config) 1048 1053 ws = WebishServer(self, webport, nodeurl_path, staticdir) … … 1051 1056 def init_ftp_server(self): 1052 1057 if self.config.get_config("ftpd", "enabled", False, boolean=True): 1053 accountfile = from_utf8_or_none( 1054 self.config.get_config("ftpd", "accounts.file", None)) 1058 accountfile = self.config.get_config("ftpd", "accounts.file", None) 1055 1059 if accountfile: 1056 1060 accountfile = self.config.get_config_path(accountfile) … … 1064 1068 def init_sftp_server(self): 1065 1069 if self.config.get_config("sftpd", "enabled", False, boolean=True): 1066 accountfile = from_utf8_or_none( 1067 self.config.get_config("sftpd", "accounts.file", None)) 1070 accountfile = self.config.get_config("sftpd", "accounts.file", None) 1068 1071 if accountfile: 1069 1072 accountfile = self.config.get_config_path(accountfile) 1070 1073 accounturl = self.config.get_config("sftpd", "accounts.url", None) 1071 1074 sftp_portstr = self.config.get_config("sftpd", "port", "8022") 1072 pubkey_file = from_utf8_or_none(self.config.get_config("sftpd", "host_pubkey_file"))1073 privkey_file = from_utf8_or_none(self.config.get_config("sftpd", "host_privkey_file"))1075 pubkey_file = self.config.get_config("sftpd", "host_pubkey_file") 1076 privkey_file = self.config.get_config("sftpd", "host_privkey_file") 1074 1077 1075 1078 from allmydata.frontends import sftpd -
TabularUnified src/allmydata/frontends/ftpd.py ¶
r874bfa72 r2f0a5d9 1 from six import ensure_str 1 2 2 3 from types import NoneType … … 334 335 335 336 f = ftp.FTPFactory(p) 337 # strports requires a native string. 338 ftp_portstr = ensure_str(ftp_portstr) 336 339 s = strports.service(ftp_portstr, f) 337 340 s.setServiceParent(self) -
TabularUnified src/allmydata/node.py ¶
r874bfa72 r2f0a5d9 4 4 """ 5 5 from past.builtins import unicode 6 from six import ensure_str 6 7 7 8 import datetime … … 10 11 import types 11 12 import errno 12 from io import StringIO13 13 import tempfile 14 14 from base64 import b32decode, b32encode 15 15 16 # Python 2 compatibility 17 from six.moves import configparser 18 from future.utils import PY2 19 if PY2: 20 from io import BytesIO as StringIO # noqa: F811 16 # On Python 2 this will be the backported package. 17 import configparser 21 18 22 19 from twisted.python import log as twlog … … 188 185 # (try to) read the main config file 189 186 config_fname = os.path.join(basedir, "tahoe.cfg") 190 parser = configparser.SafeConfigParser()191 187 try: 192 188 parser = configutil.get_config(config_fname) … … 194 190 if e.errno != errno.ENOENT: 195 191 raise 192 # The file is missing, just create empty ConfigParser. 193 parser = configutil.get_config_from_string(u"") 196 194 197 195 configutil.validate_config(config_fname, parser, _valid_config) … … 210 208 _valid_config = _common_valid_config() 211 209 210 if isinstance(config_str, bytes): 211 config_str = config_str.decode("utf-8") 212 212 213 # load configuration from in-memory string 213 parser = configparser.SafeConfigParser() 214 parser.readfp(StringIO(config_str)) 214 parser = configutil.get_config_from_string(config_str) 215 215 216 216 fname = "<in-memory>" … … 640 640 location = ",".join(new_locations) 641 641 642 # Lacking this, Python 2 blows up in Foolscap when it is confused by a 643 # Unicode FURL. 644 location = location.encode("utf-8") 645 642 646 return tubport, location 643 647 … … 687 691 else: 688 692 port_or_endpoint = port 693 # Foolscap requires native strings: 694 if isinstance(port_or_endpoint, (bytes, unicode)): 695 port_or_endpoint = ensure_str(port_or_endpoint) 689 696 tub.listenOn(port_or_endpoint) 690 697 tub.setLocation(location) … … 840 847 if lgfurl: 841 848 # this is in addition to the contents of log-gatherer-furlfile 849 lgfurl = lgfurl.encode("utf-8") 842 850 self.log_tub.setOption("log-gatherer-furl", lgfurl) 843 851 self.log_tub.setOption("log-gatherer-furlfile", -
TabularUnified src/allmydata/scripts/common.py ¶
r874bfa72 r2f0a5d9 9 9 if PY2: 10 10 from future.builtins import str # noqa: F401 11 from six.moves.configparser import NoSectionError 11 12 # On Python 2 this will be the backported package: 13 from configparser import NoSectionError 12 14 13 15 from twisted.python import usage -
TabularUnified src/allmydata/storage_client.py ¶
r874bfa72 r2f0a5d9 32 32 33 33 import re, time, hashlib 34 try: 35 from ConfigParser import ( 36 NoSectionError, 37 ) 38 except ImportError: 39 from configparser import NoSectionError 34 35 # On Python 2 this will be the backport. 36 from configparser import NoSectionError 37 40 38 import attr 41 39 from zope.interface import ( -
TabularUnified src/allmydata/test/test_configutil.py ¶
r874bfa72 r2f0a5d9 155 155 ) 156 156 self.assertIn("section [node] contains unknown option 'invalid'", str(e)) 157 158 def test_duplicate_sections(self): 159 """ 160 Duplicate section names are merged. 161 """ 162 fname = self.create_tahoe_cfg('[node]\na = foo\n[node]\n b = bar\n') 163 config = configutil.get_config(fname) 164 self.assertEqual(config.get("node", "a"), "foo") 165 self.assertEqual(config.get("node", "b"), "bar") -
TabularUnified src/allmydata/test/test_connections.py ¶
r874bfa72 r2f0a5d9 169 169 tor_provider.get_tor_handler() 170 170 self.assertIn( 171 "invalid literal for int() with base 10: 'kumquat'", 171 "invalid literal for int()", 172 str(ctx.exception) 173 ) 174 self.assertIn( 175 "kumquat", 172 176 str(ctx.exception) 173 177 ) -
TabularUnified src/allmydata/test/test_node.py ¶
r874bfa72 r2f0a5d9 152 152 153 153 config = read_config(basedir, "") 154 self.failUnlessEqual(config.get_config("node", "nickname") .decode('utf-8'),154 self.failUnlessEqual(config.get_config("node", "nickname"), 155 155 u"\u2621") 156 156 -
TabularUnified src/allmydata/util/configutil.py ¶
r874bfa72 r2f0a5d9 2 2 Read/write config files. 3 3 4 Configuration is returned as native strings.4 Configuration is returned as Unicode strings. 5 5 6 6 Ported to Python 3. … … 13 13 from future.utils import PY2 14 14 if PY2: 15 # We don't do open(), because we want files to read/write native strs when 16 # we do "r" or "w". 17 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 15 from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401 18 16 19 if PY2: 20 # In theory on Python 2 configparser also works, but then code gets the 21 # wrong exceptions and they don't get handled. So just use native parser 22 # for now. 23 from ConfigParser import SafeConfigParser 24 else: 25 from configparser import SafeConfigParser 17 # On Python 2 we use the backport package; that means we always get unicode 18 # out. 19 from configparser import ConfigParser 26 20 27 21 import attr … … 37 31 38 32 def get_config(tahoe_cfg): 39 """Load the config, returning a SafeConfigParser.33 """Load the config, returning a ConfigParser. 40 34 41 Configuration is returned as native strings.35 Configuration is returned as Unicode strings. 42 36 """ 43 config = SafeConfigParser() 44 with open(tahoe_cfg, "r") as f: 45 # On Python 2, where we read in bytes, skip any initial Byte Order 46 # Mark. Since this is an ordinary file, we don't need to handle 47 # incomplete reads, and can assume seekability. 48 if PY2 and f.read(3) != b'\xEF\xBB\xBF': 49 f.seek(0) 50 config.readfp(f) 51 return config 37 # Byte Order Mark is an optional garbage code point you sometimes get at 38 # the start of UTF-8 encoded files. Especially on Windows. Skip it by using 39 # utf-8-sig. https://en.wikipedia.org/wiki/Byte_order_mark 40 with open(tahoe_cfg, "r", encoding="utf-8-sig") as f: 41 cfg_string = f.read() 42 return get_config_from_string(cfg_string) 43 44 45 def get_config_from_string(tahoe_cfg_string): 46 """Load the config from a string, return the ConfigParser. 47 48 Configuration is returned as Unicode strings. 49 """ 50 parser = ConfigParser(strict=False) 51 parser.read_string(tahoe_cfg_string) 52 return parser 53 52 54 53 55 def set_config(config, section, option, value): -
TabularUnified src/allmydata/webish.py ¶
r874bfa72 r2f0a5d9 1 from six import ensure_str 2 1 3 import re, time 2 4 … … 187 189 if re.search(r'^\d', webport): 188 190 webport = "tcp:"+webport # twisted warns about bare "0" or "3456" 191 # strports must be native strings. 192 webport = ensure_str(webport) 189 193 s = strports.service(webport, self.site) 190 194 s.setServiceParent(self)
Note: See TracChangeset
for help on using the changeset viewer.