Jump to content

[Python] Code Translator 2 to 3


Recommended Posts

  • Forum Moderator

M2 Download Center

This is the hidden content, please
( Internal )

This is the hidden content, please
( GitHub )

Python-Code-Translator-2-to-3

Is a Python program that reads Python 2.x source code and applies a series of fixers to transform it into valid Python 3.x code that works on all versions (py2.x - py3.x).

The standard library contains a rich set of fixers that will handle almost all code. A flexible and generic library, so it is possible to write your own fixers based on your purposes.

Warning: This tool purpose wasn't for doing the transition to python3, is just for the IDE purpose.

INSTALLATION
USING
  • Add your .py scripts to the modules folder.
  • Run main.bat
  • Take the output files and move them into your application.
FIXERS
print
  • Converts the print statement to the print() function.
  • Matching multiple formats, comments, and more.
Exception handling
  • Convert except to except BaseException, since BaseException is the base class for all built-in exceptions.
  • Converts except X, T to except X as T.
xrange
  • Renames xrange() to range() and wraps existing range() calls with list.
has_key
  • Changed dict.has_key(key) to dict..contains__(key)
dict
  • Fixes dictionary iteration methods. dict.iteritems() is converted to dict.items(), dict.iterkeys() to dict.keys(), and dict.itervalues() to dict.values(). Similarly, dict.viewitems(), dict.viewkeys() and dict.viewvalues() are converted respectively to dict.items(), dict.keys() and dict.values(). It also wraps existing usages of dict.items(), dict.keys(), and dict.values() in a call to list.
exec - TODO
  • Converts the exec statement to the exec() function.
apply - TODO
  • Removes usage of apply(). For example apply(function, *args, **kwargs) is converted to function(*args, **kwargs).
raise - TODO
  • Converts raise E, V to raise E(V), and raise E, V, T to raise E(V).with_traceback(T). If E is a tuple, the translation will be incorrect because substituting tuples for exceptions has been removed in 3.0.

 

You can use it together with Skeleton of Python modules for IDE, from @Takuma.

 

Download:

This is the hidden content, please

  • Metin2 Dev 43
  • Eyes 1
  • Dislove 1
  • Not Good 1
  • Confused 1
  • Good 24
  • Love 7
  • Love 38
Link to comment
Share on other sites

  • 1 month later...
  • Forum Moderator

Update

  • implementation of the TODO tasks (exec/apply/raise, [...])
  • added the pip environment
  • added a library used for encoding detection of the python script files

Thanks to @ServerCommandParser for contributions.

 

 

 

  • Good 1
  • Love 3
Link to comment
Share on other sites

  • 3 months later...

Hey ! Sorry, i'm late, but I just tought about it because I'm upgradding my client to Py3. I think you fourgot something (And I have one in my system.py).

In python2 you can specifie a numeric type for numer like :

my_numeric = 0L

But it is no longer supported in Python3, and we need juse use :

my_numeric = 0

Same with 0j.

(Source: PEP 237)

Edited by Takuma
  • Metin2 Dev 4
  • Love 1
Link to comment
Share on other sites

  • 3 months later...
  • Management

Hey, found some issues while using your translator.

They're all related to raise Exception, present in stringcommander.py, consolemodule.py and uidragonsoul.py

On stringcommander.py, in function Run in class Analyzer.

On consolemodule.py, there are 4 raise's "alone", without Exception, which makes the following functions bug.

On uidragonsoul.py, in function __SetItem in class DragonSoulRefineWindow.

Replacing all this raise's with the python 2 version they work fine.

  • Metin2 Dev 1

raw

raw

Link to comment
Share on other sites

  • Forum Moderator

I will update the repo when I will have some free time, right now I'm very busy with the university and the job.
For those who want to contribute to it, you can do a pull request in the GitHub repository.

  • Love 1
Link to comment
Share on other sites



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.