This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: [doc] xdrlib.Packer().pack_fstring throws a TypeError when called with a str()
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: docs@python Nosy List: arnoldp, benjamin.peterson, docs@python, eric.araujo, gruszczy, hnhn, iritkatriel, mark.dickinson, petri.lehtinen, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2010-08-09 05:51 by arnoldp, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
9544.patch gruszczy, 2011-03-27 10:43 review
issue9544.patch petri.lehtinen, 2012-06-06 18:29 Doc patch review
issue9544.2.patch hnhn, 2017-05-30 09:37 review
Messages (15)
msg113386 - (view) Author: Paul Arnold (arnoldp) Date: 2010-08-09 05:51
In Python 3.1, xdrlib.Packer().pack_fstring() throws a TypeError if called with a str() (an encoded string bytes() works just fine).

>>> xdrlib.Packer().pack_fstring(6, "foobar")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.1/xdrlib.py", line 81, in pack_fstring
    data = data + (n - len(data)) * b'\0'
TypeError: Can't convert 'bytes' object to str implicitly
msg113387 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-09 05:53
Thanks for the report. Can you tell if it applies to 3.2? Also, is the doc unclear on this point?
msg113388 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-08-09 05:54
Editing type. (FYI, you can follow the link to see some descriptions.)
msg113390 - (view) Author: Paul Arnold (arnoldp) Date: 2010-08-09 06:09
It will apply to 3.2 also, checking in SVN there have been no changes to xdrlib.py for a couple of years.

The documentation makes no mention of the need to encode strings.
msg132306 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-03-27 10:43
Here is a simple patch with a test. Depending o bytes in this library seems strange, maybe it should be changed somehow? Anyway, this simple patch should be a quick fix to the problem.
msg133700 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-04-13 22:05
This doesn't really make sense, since XDR doesn't seem to say anything about unicode strings, just bytes.
msg133719 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-04-14 10:19
Actually documentation doesn't say that it supports only bytes, but:

"The following methods support packing strings, bytes, and opaque data:"

Also under python2 you can easily do this:

In [1]: import xdrlib

In [2]: p = xdrlib.Packer()

In [3]: p.pack_string('some str')

In [4]: p.pack_string(u'some str')

So to conclude I believe either docs for python3 should be changed to say that only bytes are allowed or it should be changed to work as in python2. It's clear that in python2 some unicode string are accepted and I think we should allow such strings to be accepted in python3 too.
msg133735 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-04-14 13:03
2011/4/14 Filip Gruszczyński <report@bugs.python.org>:
>
> Filip Gruszczyński <gruszczy@gmail.com> added the comment:
>
> Actually documentation doesn't say that it supports only bytes, but:
>
> "The following methods support packing strings, bytes, and opaque data:"
>
> Also under python2 you can easily do this:
>
> In [1]: import xdrlib
>
> In [2]: p = xdrlib.Packer()
>
> In [3]: p.pack_string('some str')
>
> In [4]: p.pack_string(u'some str')

I doubt u"美", will, though.
msg133736 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-04-14 13:11
I am well aware of this, Benjamin. I am not trying to force any solution, but rather trying to point out, that current documentation is misleading. There might be no need for patching the code, but rather updating the docs to say, that only bytes are allowed and that will be sufficient.
msg133737 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2011-04-14 13:15
2011/4/14 Filip Gruszczyński <report@bugs.python.org>:
>
> Filip Gruszczyński <gruszczy@gmail.com> added the comment:
>
> I am well aware of this, Benjamin. I am not trying to force any solution, but rather trying to point out, that current documentation is misleading. There might be no need for patching the code, but rather updating the docs to say, that only bytes are allowed and that will be sufficient.

Yes, I think a doc patch is the correct thing to do.
msg133739 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-04-14 13:22
I'll provide docs patch.
msg162419 - (view) Author: Petri Lehtinen (petri.lehtinen) * (Python committer) Date: 2012-06-06 18:28
Attached a patch against 3.2. It reflects the facts that pack_fstring and pack_fopaque are the same methd, and pack_string, pack_opaque and pack_bytes are the same method.
msg294700 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-05-29 16:17
issue9544.patch LGTM as the first step. There are other mentions of strings in the documentation.
msg294746 - (view) Author: Jan Hnatek (hnhn) * Date: 2017-05-30 09:37
Attached an updated patch against 3.7 fixing the remaining mentions of string.
msg415051 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-13 17:21
xdrlib is deprecated as per PEP 594, so there won't be further enhancements to it.
History
Date User Action Args
2022-04-11 14:57:05adminsetgithub: 53753
2022-03-13 17:21:41iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg415051

resolution: wont fix
stage: needs patch -> resolved
2021-12-03 23:42:33iritkatrielsettitle: xdrlib.Packer().pack_fstring throws a TypeError when called with a str() -> [doc] xdrlib.Packer().pack_fstring throws a TypeError when called with a str()
versions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.5, Python 3.6, Python 3.7
2017-05-30 09:37:36hnhnsetfiles: + issue9544.2.patch

messages: + msg294746
2017-05-29 16:18:16serhiy.storchakalinkissue30216 superseder
2017-05-29 16:17:47serhiy.storchakasetversions: + Python 3.5, Python 3.6, Python 3.7, - Python 3.2, Python 3.3
nosy: + serhiy.storchaka

messages: + msg294700

stage: needs patch
2017-05-29 14:37:52hnhnsetnosy: + hnhn
2012-06-06 18:29:37petri.lehtinensetfiles: + issue9544.patch
2012-06-06 18:28:44petri.lehtinensetmessages: + msg162419
versions: + Python 3.2, Python 3.3, - Python 3.1
2012-06-01 08:23:46petri.lehtinensetnosy: + petri.lehtinen
2011-04-14 13:22:05gruszczysetnosy: + docs@python
messages: + msg133739

assignee: docs@python
components: + Documentation, - None
2011-04-14 13:15:39benjamin.petersonsetmessages: + msg133737
2011-04-14 13:11:55gruszczysetmessages: + msg133736
2011-04-14 13:03:46benjamin.petersonsetmessages: + msg133735
2011-04-14 10:19:42gruszczysetmessages: + msg133719
2011-04-13 22:05:24benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg133700
2011-03-28 16:19:48gruszczysetnosy: + mark.dickinson
2011-03-27 10:43:15gruszczysetfiles: + 9544.patch

nosy: + gruszczy
messages: + msg132306

keywords: + patch
2010-08-09 06:09:12arnoldpsetmessages: + msg113390
2010-08-09 05:54:46eric.araujosettype: crash -> behavior
messages: + msg113388
2010-08-09 05:53:34eric.araujosetnosy: + eric.araujo
messages: + msg113387
2010-08-09 05:51:25arnoldpcreate