These are chat archives for pybee/general

13th
Mar 2017
Deepankar Agrawal
@deep110
Mar 13 2017 01:02

@cflee Can you tell me which tool do you use to decompile java bytecode to java classes, asm doesn't seem to be working for me. Thanks

Also, if you want I can paste my asm.sh script.

Russell Keith-Magee
@freakboy3742
Mar 13 2017 01:03
@deep110 There are two options: javap and VOC itself.
if you run python -m voc.java <path to class file> it will dump the class file contents.
Deepankar Agrawal
@deep110
Mar 13 2017 01:04
yes, but it shows bytecode, I want to see .java class, Actually was trying to see how to handle static methods, and currently what does voc produce
Chiang Fong Lee
@cflee
Mar 13 2017 01:05
@deep110 I use javap -c <path_to_file.class>
Elias Dorneles
@eliasdorneles
Mar 13 2017 01:05
There is no intermediate .java generated
Chiang Fong Lee
@cflee
Mar 13 2017 01:06
or sometimes I use JD-GUI, which tries to reconstruct source from bytecode, but…. it’s hit or miss. since it’s literally reverse engineering and guessing from the bytecode.
Elias Dorneles
@eliasdorneles
Mar 13 2017 01:06
@deep110 VOC converts Python code straight to Java bytecode
Btw, nice to know about python -m voc.java -- hadn't seen that one before, that's cool! :smile:
Deepankar Agrawal
@deep110
Mar 13 2017 01:08
@eliasdorneles yes, I know that, actually I was asking is there a way to see java classes from .class files, because some java decompilers does that, so I wanted to ask which to use
Chiang Fong Lee
@cflee
Mar 13 2017 01:10
I suppose by “java classes" you mean “java source code”?
Deepankar Agrawal
@deep110
Mar 13 2017 01:10
yes, sorry for wrong word usage :sweat_smile:
Chiang Fong Lee
@cflee
Mar 13 2017 01:11
just trying to figure it out together :) I think we got a little confused
Alan Velasco
@alanbato
Mar 13 2017 01:15
@freakboy3742 You mentioned an email you sent someone about contributing something besides Java/JS stuff that you wanted preserved in something along the lines of a possible http://pybee.org/contributing/how/first-time/what/ouroboros page, right? Is there any way I could read it?
Deepankar Agrawal
@deep110
Mar 13 2017 01:19
@eliasdorneles @freakboy3742 I was trying to fix pybee/voc#352, seems that constructor of KeyError or ValueError needs to be modified or a new one added for python args and kwargs, but signatures doesn't not work on constructors. Is it built that way, or that needs a fix.
And adding one for single python object seem only a temporary fix, because CPython one can take Tuple as input, so here also needs to be same. Any suggestions?
Alan Velasco
@alanbato
Mar 13 2017 01:21
Thanks! I'll get back to you (or another member) asking for feedback of the draft sometime soon if time permits.
Shivendra Kumar
@bitdumper1
Mar 13 2017 02:51
on python 3.4
'"".split(5)
TypeError: Can't convert 'int' object to str implicitly'
on python 3.6

"".split(5)
TypeError: must be str or None, not int

and there is no way I can get the version of the python

How can I resolve the issue
Alan Velasco
@alanbato
Mar 13 2017 02:55
@bitdumper1 You can import sys and use sys.version_info to get the version of the python running your script :)
Then check if sys.version_info == (3, 4) or sys.version_info == (3, 6)
Shivendra Kumar
@bitdumper1
Mar 13 2017 03:02
Got it.
Shivendra Kumar
@bitdumper1
Mar 13 2017 03:16
I forgot about the function😌
Alan Velasco
@alanbato
Mar 13 2017 03:18
No problem, glad I could help :)
Jonas Schell
@Ocupe
Mar 13 2017 13:41
@freakboy3742 Do you know how to hook into a NSMenuItem action/callback when I click on the ‘Preferences’ menu item on mac OS? I try to open a settings window from there.
Ashutosh Saboo
@ashutoshsaboo
Mar 13 2017 13:43
Hi, can someone tell me, where can I find all the python functions that are accepted as of now? As in, in case if I want to add a new python standard library method, then where should I add it?
@eliasdorneles ^ ?
Elias Dorneles
@eliasdorneles
Mar 13 2017 15:45
@ashutoshsaboo you can search for NotImplementedError in python/common/org/Python.java
Ashutosh Saboo
@ashutoshsaboo
Mar 13 2017 15:46
Hi @eliasdorneles ! I figured it out. Thanks for your help! :smile:
I just pushed this PR - pybee/voc#413 . Could you please review it!
Elias Dorneles
@eliasdorneles
Mar 13 2017 15:52
@deep110 About fixing #352, I discussed it recently with @Deepanshu2017 here: https://gitter.im/pybee/general?at=58bbbdb0f1a33b6275800329
You shouldn't need to add a new constructor for the exceptions, the existing one with the args and kwargs should be enough
Ashutosh Saboo
@ashutoshsaboo
Mar 13 2017 16:03
@eliasdorneles Should this be the output when you just do raise ValueError() in the python script, and then use voc to compile it, and then run it?-:
Exception in thread "main" ValueError: 
    at python.example.__init__.module$import(example.py:8)
    at python.example.__init__.main(example.py)
Elias Dorneles
@eliasdorneles
Mar 13 2017 16:04
yes
So, I'm trying to use a custom view class for Android.
This is the minimal app code:
import android
from android.util import Log
from android.widget import LinearLayout
import android.view


class DrawingView(extends=android.view.View):
    def DrawingView(self, context: android.content.Context) -> void:
        print('hello from constructor thing')
        super().View(context)

    def __init__(self):
        print('hello from init')


class MyApp:
    def __init__(self):
        self._activity = None

    def link(self, activity):
        self._activity = activity
        print('linked activity', self._activity)

    def onCreate(self):
        print('onCreate, activity is', self._activity)
        parent_layout = LinearLayout(self._activity)
        self.drawing = DrawingView(self._activity)
        parent_layout.addView(self.drawing)
        self._activity.setContentView(parent_layout)


print('starting app...')
app = MyApp()
activity = android.PythonActivity.setListener(app)
app.link(activity)
And I keep getting:
RuntimeError: java.lang.IllegalAccessError: Method 'void android.view.View.<init>()' is inaccessible to class 'org.eliasdorneles.drawingapp.app.DrawingView' (declaration of 'org.eliasdorneles.drawingapp.app.DrawingView' appears in /data/app/org.eliasdorneles-1/base.apk)
E/AndroidRuntime( 3631):     at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 3631):     at java.lang.reflect.Method.invoke(Method.java:372)
E/AndroidRuntime( 3631):     at org.python.types.Function.invoke(Function.java:388)
E/AndroidRuntime( 3631):     at org.python.types.Method.invoke(Method.java:47)
E/AndroidRuntime( 3631):     at android.PythonActivity.invoke_app_method(PythonActivity.java:90)
E/AndroidRuntime( 3631):     at android.PythonActivity.onCreate(PythonActivity.java:71)
E/AndroidRuntime( 3631):     at android.app.Activity.performCreate(Activity.java:5990)
Ashutosh Saboo
@ashutoshsaboo
Mar 13 2017 16:09
Why does it print the line numbers, and other details here @eliasdorneles ?-:
Exception in thread "main" ValueError: 
    at python.example.__init__.module$import(example.py:8)
    at python.example.__init__.main(example.py)
Elias Dorneles
@eliasdorneles
Mar 13 2017 16:10
@ashutoshsaboo isn't that what you would expect when you raise an exception? getting a stack trace, showing which code was being called and in which line the exception was raised?
Ashutosh Saboo
@ashutoshsaboo
Mar 13 2017 16:11
I see. Just got a bit confused. nvm! :smile:
@freakboy3742 Could you please review pybee/voc#413 ?
Elias Dorneles
@eliasdorneles
Mar 13 2017 16:11
We get notifications for all PRs, no need to ping here :)
Ashutosh Saboo
@ashutoshsaboo
Mar 13 2017 16:12
I just thought, I must inform the org admin. Thanks! :smile:
Elias Dorneles
@eliasdorneles
Mar 13 2017 16:21
No need to, as I said, all maintainers get notifications for each PRs
Elias Dorneles
@eliasdorneles
Mar 13 2017 16:27
Can anyone help me clarify what is the android/view/View."<init>":()V method?
This is what I see in the bytecode:
  public org.eliasdorneles.drawingapp.app.DrawingView(org.python.Object[], java.util.Map);
    Code:
       0: aconst_null
       1: astore_3
       2: aload_0
       3: dup
       4: invokespecial #131                // Method android/view/View."<init>":()V
       7: invokestatic  #132                // Method org/python/types/Type.toPython:(Ljava/lang/Object;)Lorg/python/Object;
      10: ldc_w         #115                // String __init__
      13: invokeinterface #136,  2          // InterfaceMethod org/python/Object.__getattribute_null:(Ljava/lang/String;)Lorg/python/Object;
      18: dup
      19: ifnull        32
      22: checkcast     #140                // class org/python/Callable
      25: aload_1
      26: aload_2
      27: invokeinterface #142,  3          // InterfaceMethod org/python/Callable.invoke:([Lorg/python/Object;Ljava/util/Map;)Lorg/python/Object;
      32: pop
      33: return
I'm guessing this is the constructor that's being called for self.drawing = DrawingView(self._activity)
Nimish Singhal
@ASP1234
Mar 13 2017 16:58
public FrozenSet() {
        super();
        this.value = new java.util.HashSet<org.python.Object>();
    }
Trying to implement frozenset constructors but getting no python compatible constructors found
@cflee anything I need to do apart from this?
Elias Dorneles
@eliasdorneles
Mar 13 2017 17:21
@ASP1234 you need to annotate the constructor with the proper signature (see: http://voc.readthedocs.io/en/latest/internals/signatures.html)
you can also check Dict.java for an example
Nimish Singhal
@ASP1234
Mar 13 2017 17:22
Thanks! Hopefully it should work now. Also, are there any leads for min max?
Elias Dorneles
@eliasdorneles
Mar 13 2017 17:25

Also, are there any leads for min max?

Sorry, I don't follow, what do you mean?

Nimish Singhal
@ASP1234
Mar 13 2017 17:26
Like anyone doing the not implemented part of max min
Elias Dorneles
@eliasdorneles
Mar 13 2017 17:31
There is PR pybee/voc#402 for max
Nimish Singhal
@ASP1234
Mar 13 2017 17:31
Cool
Ashutosh Saboo
@ashutoshsaboo
Mar 13 2017 18:14
How do I get the value at the 0th index of a tuple ? Since tuple[0] doesn't seem to work like it must work for Python.
Deepankar Agrawal
@deep110
Mar 13 2017 18:32
@ashutoshsaboo you can use tuple.__getitem__(index)
Nimish Singhal
@ASP1234
Mar 13 2017 18:54
Implemented frozenset constructors and len() is finished
Passing the tests
PR sent
Elias Dorneles
@eliasdorneles
Mar 13 2017 19:16
@ashutoshsaboo __getitem__ will require passing a Python int, if you're doing this in Java side you can do tuple.value.get(0)
Ashutosh Saboo
@ashutoshsaboo
Mar 13 2017 19:17
Yes sure. I'll use it, after this pybee/voc#415 gets reviewed once! Thanks! :smile:
Dima Tisnek
@dimaqq
Mar 13 2017 19:34

What are the rules for publishing selectors implemented in Python?
For example, I have:

UITapGestureRecognizer.alloc().initWithTarget_action_(self, get_selector("tap:"))
...
@objc_method
def tap_(self, rec):

And that works, but also works (and receives argument correctly) for get_selector("tap") / def tap(self, rec): ...

dgelessus
@dgelessus
Mar 13 2017 19:42
You're right, there is nothing in the Objective-C runtime that forces you to put colons in the right places in selectors. It's just a result of the Objective-C language syntax.
This is similar to how you can't use foo-bar as an attribute name in Python code, but nothing stops you from saying setattr(self, "foo-bar", 42).
Dima Tisnek
@dimaqq
Mar 13 2017 19:58
Cool, thanks
I'm trying send_message(UIView, b"transitionFromView:toView:duration:options:completion:", old, new, 3, 1, None)
Surely there's more elegant way to call class methods, right?
dgelessus
@dgelessus
Mar 13 2017 20:05
UIView.transitionFromView_toView_duration_options_completion_(old, new, 3, 1, None) should work, right?
Dima Tisnek
@dimaqq
Mar 13 2017 20:06
does not for me... crashes:
  File "rubicon/objc/objc.py", line 817, in get_prototype
    return CFUNCTYPE(self.restype, *self.argtypes)
TypeError: CFUNCTYPE() argument after * must be an iterable, not NoneType
though perhaps, it just doesn't auto-convert, e.g. None?
There's No argtypes encoding for b'transitionFromView:toView:duration:options:completion:' ([b'@', b':', b'@', b'@', b'd', b'Q', b'@?']) in the log
Or... perhaps I have to create NSTimeInterval manually, and not try to smuggle 3 in...
dgelessus
@dgelessus
Mar 13 2017 20:09
Yeah, that means there's an unsupported type in the method signature. I'm planning to do something about that at some point...
For now you need to use send_message.
Dima Tisnek
@dimaqq
Mar 13 2017 20:16
Cool; turns out send_message plus cast 3 to NSTimeInterval
Thanks, I got unblocked!
dgelessus
@dgelessus
Mar 13 2017 20:21
Ah, right. send_message doesn't look at the signature, so it doesn't know what types the arguments need to be. So all arguments need to be cast to the right types, or you need to manually pass the signature using the restype and argtypes kwargs.