remove static native_str()

This commit is contained in:
Alexandre Detiste 2024-02-28 01:25:06 +01:00
parent 2243ce3187
commit f47b45ac1a
7 changed files with 22 additions and 33 deletions

View File

@ -4,7 +4,6 @@ Ported to Python 3.
from __future__ import annotations
from future.utils import native_str
from six import ensure_str
import os, time, weakref, itertools
@ -165,7 +164,7 @@ class HelperUploadResults(Copyable, RemoteCopy):
# package/module/class name
#
# Needs to be native string to make Foolscap happy.
typeToCopy = native_str("allmydata.upload.UploadResults.tahoe.allmydata.com")
typeToCopy = "allmydata.upload.UploadResults.tahoe.allmydata.com"
copytype = typeToCopy
# also, think twice about changing the shape of any existing attribute,

View File

@ -6,8 +6,6 @@ Ported to Python 3.
Note that for RemoteInterfaces, the __remote_name__ needs to be a native string because of https://github.com/warner/foolscap/blob/43f4485a42c9c28e2c79d655b3a9e24d4e6360ca/src/foolscap/remoteinterface.py#L67
"""
from future.utils import native_str
from typing import Dict
from zope.interface import Interface, Attribute
@ -111,7 +109,7 @@ ReadData = ListOf(ShareData)
class RIStorageServer(RemoteInterface):
__remote_name__ = native_str("RIStorageServer.tahoe.allmydata.com")
__remote_name__ = "RIStorageServer.tahoe.allmydata.com"
def get_version():
"""
@ -2767,7 +2765,7 @@ UploadResults = Any() #DictOf(bytes, bytes)
class RIEncryptedUploadable(RemoteInterface):
__remote_name__ = native_str("RIEncryptedUploadable.tahoe.allmydata.com")
__remote_name__ = "RIEncryptedUploadable.tahoe.allmydata.com"
def get_size():
return Offset
@ -2783,7 +2781,7 @@ class RIEncryptedUploadable(RemoteInterface):
class RICHKUploadHelper(RemoteInterface):
__remote_name__ = native_str("RIUploadHelper.tahoe.allmydata.com")
__remote_name__ = "RIUploadHelper.tahoe.allmydata.com"
def get_version():
"""
@ -2796,7 +2794,7 @@ class RICHKUploadHelper(RemoteInterface):
class RIHelper(RemoteInterface):
__remote_name__ = native_str("RIHelper.tahoe.allmydata.com")
__remote_name__ = "RIHelper.tahoe.allmydata.com"
def get_version():
"""

View File

@ -2,9 +2,6 @@
Ported to Python 3.
"""
from future.utils import native_str
from zope.interface import Interface
from foolscap.api import StringConstraint, SetOf, DictOf, Any, \
RemoteInterface, Referenceable
@ -34,7 +31,7 @@ FURL = StringConstraint(1000)
Announcement_v2 = Any()
class RIIntroducerSubscriberClient_v2(RemoteInterface):
__remote_name__ = native_str("RIIntroducerSubscriberClient_v2.tahoe.allmydata.com")
__remote_name__ = "RIIntroducerSubscriberClient_v2.tahoe.allmydata.com"
def announce_v2(announcements=SetOf(Announcement_v2)):
"""I accept announcements from the publisher."""
@ -47,11 +44,14 @@ class RIIntroducerPublisherAndSubscriberService_v2(RemoteInterface):
announcement message. I will deliver a copy to all connected subscribers.
To hear about services, connect to me and subscribe to a specific
service_name."""
__remote_name__ = native_str("RIIntroducerPublisherAndSubscriberService_v2.tahoe.allmydata.com")
__remote_name__ = "RIIntroducerPublisherAndSubscriberService_v2.tahoe.allmydata.com"
def get_version():
return DictOf(bytes, Any())
def publish_v2(announcement=Announcement_v2, canary=Referenceable):
return None
def subscribe_v2(subscriber=RIIntroducerSubscriberClient_v2,
service_name=bytes, subscriber_info=SubscriberInfo):
"""Give me a subscriber reference, and I will call its announce_v2()

View File

@ -3,7 +3,6 @@ Ported to Python 3.
"""
from future.utils import bchr
from future.builtins import str as future_str
import os
import sys
@ -64,13 +63,13 @@ def run_cli_native(verb, *args, **kwargs):
:param runner.Options options: The options instance to use to parse the
given arguments.
:param native_str verb: The command to run. For example,
:param str verb: The command to run. For example,
``"create-node"``.
:param [native_str] args: The arguments to pass to the command. For
:param [str] args: The arguments to pass to the command. For
example, ``("--hostname=localhost",)``.
:param [native_str] nodeargs: Extra arguments to pass to the Tahoe
:param [str] nodeargs: Extra arguments to pass to the Tahoe
executable before ``verb``.
:param bytes|unicode stdin: Text or bytes to pass to the command via stdin.
@ -165,7 +164,7 @@ def run_cli_unicode(verb, argv, nodeargs=None, stdin=None, encoding=None):
if nodeargs is None:
nodeargs = []
precondition(
all(isinstance(arg, future_str) for arg in [verb] + nodeargs + argv),
all(isinstance(arg, str) for arg in [verb] + nodeargs + argv),
"arguments to run_cli_unicode must be unicode",
verb=verb,
nodeargs=nodeargs,
@ -229,13 +228,9 @@ def flip_one_bit(s, offset=0, size=None):
class ReallyEqualMixin(object):
def failUnlessReallyEqual(self, a, b, msg=None):
self.assertEqual(a, b, msg)
# Make sure unicode strings are a consistent type. Specifically there's
# Future newstr (backported Unicode type) vs. Python 2 native unicode
# type. They're equal, and _logically_ the same type, but have
# different types in practice.
if a.__class__ == future_str:
if a.__class__ == str:
a = str(a)
if b.__class__ == future_str:
if b.__class__ == str:
b = str(b)
self.assertEqual(type(a), type(b), "a :: %r (%s), b :: %r (%s), %r" % (a, type(a), b, type(b), msg))

View File

@ -5,7 +5,7 @@ functionality.
Ported to Python 3.
"""
from future.utils import native_str, native_str_to_bytes
from future.utils import native_str_to_bytes
from six import ensure_str
import attr
@ -40,7 +40,7 @@ from allmydata.util.jsonbytes import (
class RIDummy(RemoteInterface):
__remote_name__ = native_str("RIDummy.tahoe.allmydata.com")
__remote_name__ = "RIDummy.tahoe.allmydata.com"
def just_some_method():
"""

View File

@ -8,9 +8,6 @@ Once Python 2 support is dropped, most of this module will obsolete, since
Unicode is the default everywhere in Python 3.
"""
from future.utils import native_str
from future.builtins import str as future_str
from past.builtins import unicode
from six import ensure_str
@ -124,7 +121,7 @@ def unicode_to_argv(s):
# According to unicode_to_argv above, the expected type for
# cli args depends on the platform, so capture that expectation.
argv_type = (future_str, native_str) if sys.platform == "win32" else native_str
argv_type = (str,)
"""
The expected type for args to a subprocess
"""

View File

@ -104,7 +104,7 @@ def get_local_addresses_sync():
on the local system.
"""
return list(
native_str(address[native_str("addr")])
native_str(address["addr"])
for iface_name
in interfaces()
for address
@ -161,7 +161,7 @@ def _foolscapEndpointForPortNumber(portnum):
# approach is error prone for the reasons described on
# https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2787
portnum = allocate_tcp_port()
return (portnum, native_str("tcp:%d" % (portnum,)))
return (portnum, "tcp:%d" % portnum)
@implementer(IStreamServerEndpoint)
@ -210,7 +210,7 @@ def listenOnUnused(tub, portnum=None):
"""
portnum, endpoint = _foolscapEndpointForPortNumber(portnum)
tub.listenOn(endpoint)
tub.setLocation(native_str("localhost:%d" % (portnum,)))
tub.setLocation("localhost:%d" % portnum)
return portnum