[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

python 2 to 3 converter

On Tue, Dec 10, 2019 at 5:05 AM songbird <songbird at anthive.com> wrote:
> jfong at ms4.hinet.net wrote:
> ...
> > Even string is hard to be handled by the AI:-)
> >
> > Quoted from https://portingguide.readthedocs.io/en/latest/strings.html
> > " ... This means that you need to go through the entire codebase, and decide which value is what type. Unfortunately, this process generally cannot be automated."
>   i don't agree.  if the language is already parsed then
> you have the strings.  the contents of the strings will
> have to be finite if they are fixed strings.  so to convert
> a fixed string you can choose a type for the value and run
> a test to see if it works.  if it does then you've picked
> the correct type, if it doesn't you pick the next type.
> there are only a finite number of types.

Here's an example piece of code.

sock = socket.socket(...)
name = input("Enter your username: ")
code = input("Enter the base64 code: ")
code = base64.b64decode(code)
sock.write("""GET /foo HTTP/1.0
Authentication: Demo %s/%s

""" % (name, code))
match = re.search(r"#[A-Za-z0-9]+#", sock.read())
if match: print("Response: " + match.group(0))

Your challenge: Figure out which of those strings should be a byte
string and which should be text. Or alternatively, prove that this is
a hard problem. There are only a finite number of types - two, to be
precise - so by your argument, this should be straightforward, right?