• pacco

    Hi all,

    Pythonista 2.0 has finally arrived and there is much rejoicing!

    For me, Pythonista was initially a quick and easy way to become more proficient with the language -- it allowed tinkering and experimenting at odd moments from wherever I happened to be. Later, it provided an easy way to explore much of the Python standard library. Even later, I began to use it to prototype utility scripts for backend servers and simple network security testing.

    My point is that (like many of you), Pythonista has become one of my more/most important apps on my device and I'm very happy that Pythonista 2.0 is finally here.

    I also have to believe that there are many of us here who gladly would have paid for version 2.0 (either as an IAP or as a completely separate app).[1] Since omz has graciously chosen not to do either with this release, I have a modest proposal for any who feel that he deserves a show of appreciation for all his efforts on version 2.0:

    • Consider gifting the app to a new user through iTunes.

    While simply buying another copy of Pythonista with another iTunes account would accomplish the same thing, how about gifting it toward someone who you think just might be interested in learning programming? Maybe one of your kids, a spouse, a coworker? (And if you're feeling especially generous, maybe include a copy of a Python book to get them started. e.g., 'Python for Kids', 'Hello! Python', 'Learn Python the Hard Way', etc. or whatever helped you first learn the language) While some of you may have started programming in school or even on the job, I'd hazard to guess that many of us are developers today because someone else took the time to introduce us to the concept and provided the proper degree of encouragement. Why not use this as an opportunity to pass that on?

    Anyhow, it's simply a suggestion for those of us who feel we've gotten way more out of this app than the modest price it was purchased for. I understand that not everyone reading this may feel the same way. However, you still might consider another way to help omz and Pythonista that will cost you nothing: If you haven't already done so, why not post a detailed and honest review of Pythonista in the App Store?

    Thanks,
    Pacco
    [Who has no relationship with Pythonista, nor its developer]

    [1] While major app updates like this are a great deal to existing customers (free upgrades for the life of the original app), it's also been acknowledged that it can make sustained development for the App Store difficult as revenue comes solely from new purchases.

    posted in Pythonista read more
  • pacco

    Yep! (Or at least it's in the US Apps Store)

    Updating now.

    Thanks omz for all your hard work and effort behind this new version! I'm also impressed that you decided to offer it as a free/upgrade as there are a significant changes to the app. [more comments about this in another post]

    I realize over the years Apple has gradually relaxed a number restrictions on what is accepted to be published on the App Store, but to some degree I'm still amazed at what Pythonista is able to achieve on a non-JB device. Greatly looking forward to exploring the new features (e.g., ctypes!)

    Another quick note: I'm also just paranoid enough that immediately after updating the app, I'm going to sync to iTunes so I can keep a safe copy of the v2.0 Pythonista.ipa file. (Just in case Apple changes their mind on this release, for whatever reason. Sadly, there is some historical precedent in their allowing certain apps into the AppStore then later deciding they violate policy and pulling them).

    posted in Pythonista read more
  • pacco

    Agreed -- my point was simply that there are often a collection of different methods for detection, depending on the nature of the JB. Some of those techniques rely on positive as well as negative test results.

    Whatever the case, that's a neat script you came up with!

    posted in Pythonista read more
  • pacco

    Neat! (Of course, I don't have any JB devices to actually test it on at the moment...)

    A lot of MDM vendors will do these types of tests in their software agents as many institutions using their products won't allow jailbroken devices (even BYOD) to be enrolled.

    Another similar jailbreak test I've read about was to write a dummy file to certain normally-protected parts of the filesystem. If the write succeeded, then the device was likely jailbroken.

    posted in Pythonista read more
  • pacco

    Apologies -- I'm not actually running the Pythonista beta. However, I did want to add that I've been seeing this behavior ('Copy' and other commands missing from selected/contextual popup) in several other apps ever since upgrading to iOS9 -- so I assume it's either a outright iOS bug or Apple made a subtle change in one of their APIs that only triggers the problem in certain situations.

    posted in Pythonista read more
  • pacco

    @tony, that's awesome!

    If I weren't in the middle of such a heavy work week, I'd definitely ask about the details. For now, I just have this link to pass along. (Caveat: I haven't actually tried it).

    http://stackoverflow.com/questions/7664189/how-to-recompile-the-python-2-5-bytecode-to-2-7

    posted in Pythonista read more
  • pacco

    Specifically:

    I've been writing small test servers in Pythonista and connect to them using Safari or some other client app on the same device. I've noticed that network performance of the server is impacted pretty heavily if it tries to print anything to the console while it's running in the background. While one obvious solution is to just write all messages to a logfile instead of the console, I was wondering if there are any iOS methods surfaced in Pythonista to tell if it's running in the foreground/background?

    Thanks,<br>
    Pacco

    posted in Pythonista read more
  • pacco

    @ccc -- you're right, of course. I was thinking of the OpenSSL wrapper module that some of these proxy servers depend on. (I believe it wraps the external openssl binary, which isn't an option for Pythonista for the obvious reasons)<br>

    @Tizzy -- I still haven't gotten proxpy working, but I realized I'd forgotten to install the local proxpy root CA on the iOS device I was testing with. (It installs under Settings app->Profiles, like any other mobileconfig). Will continue messing with it as time allows...

    posted in Pythonista read more
  • pacco

    Thanks for the feedback all. I even appreciate omz chiming in -- I did suspect it might take some ctypes-fu to determine an app's state but thought there might have been an easier way.

    Clearly, this isn't a high-priority issue as I suspect running server apps on Pythonista isn't a huge use case. But it does make me wonder why console printing would slow things down? Is it simply because the app is in a backgrounded state or is it because it's offscreen? (i.e., console output has to be written to some sort of image backing store that's slower than a live render, etc)

    Thanks,<br>
    Pacco

    posted in Pythonista read more
  • pacco

    What an incredible coincidence! I was just playing with various Python-based http proxies the day before (which also relates to a recent question on this forum about running server apps in the background). I've found several several http (tcp/80) proxies that work ok with Pythonista:

    <blockquote>
    https://evilzone.org/scripting-languages/(python)-proxy-server-19-lines-of-code!/<br>
    http://infomesh.net/2002/bproxy<br>
    http://python-proxy.googlecode.com/svn/trunk/PythonProxy.py<br>
    https://gist.github.com/voorloopnul/415cb75a3e4f766dc590#file-proxy-py<br>
    </blockquote>

    But haven't been able to get any SSL-based ones working either. The one I'm currently looking at is <a href="http://code.google.com/p/proxpy/">proxpy</a> but I suspect it has a dependency on OpenSSL (either the lib or a binary) which clearly is not available in Pythonista. If you make any progress with mitmproxy (or any other) please update this thread -- I'm very interested in this as well.

    Sidenote: One interesting discovery made while playing with the proxy servers -- iOS (8.3 anyway) uses this URL http://mesu.apple.com/assets/com_apple_MobileAsset_SoftwareUpdate/com_apple_MobileAsset_SoftwareUpdate.xml to check if any new OS updates are available. It's also interesting/depressing to see just how many apps on your device call home using various analytic frameworks...

    Edit: Fixed bad markdown for URLs.

    posted in Pythonista read more
  • pacco

    @tony -- that's great to hear. Although it was only a few months back, I can't quite recall if I assembled the example using Papaya with Pythonista or on a completely different platform and then copied just the bytecode data over. The value of doing the latter would have reinforced (to me anyway) the proof that Pythonista was loading and executing pure bytecode data.

    I will admit to wondering if something like <a href="https://github.com/whymirror/unholy">this</a> (the Python bytecode generation part) could produce a .pyc that was usable by Pythonista. I haven't had the time to give it a try. (Hey, Python friends -- sorry for bringing up something related to R*** -- but we all have to come from <i>somewhere</i> right? :-)

    posted in Pythonista read more
  • pacco

    Apologies as this isn't quite on-topic, but I thought I'd post a <a href="https://omz-forums.appspot.com/pythonista/post/5817769727623168">link</a> of an experiment to get Pythonista to execute externally-compiled Python bytecode binaries (.pyc). (Anyone searching the forum under the topic of bytecode VMs are more likely to come across this thread than the one that post was attached to)

    posted in Pythonista read more
  • pacco

    So I know this isn't the same workflow as sideloading data in/out of Pythonista's document folder via tethered access, but just a reminder that another method that still works fine with iOS8.3 (and Pythonista 1.5 at least) is to spin up a pure python mini-fileserver.

    For instance, I regularly use the mini WebDAV server that wolf71 posted <a href="https://omz-forums.appspot.com/pythonista/post/5862818263859200">here</a> a while back. (In that thread I have a post that describes how I use it to transfer content locally between GoodReader on the same device by using it as a WebDAV client. i.e. connect via local loopback). I tend to use GoodReader as my central 'hub'# on my iPad, and haven't ever tested Wolf71's mini-server against the native WebDAV client capability in OSX or Win. But the GitHub page states that it does support Win/OSX/iOS clients. Might be worth exploring if the direct access method doesn't come back.

    Thanks,<br>
    Pacco

    # I do most external file transfers with it

    posted in Pythonista read more
  • pacco

    The problem occured whenever using Pythonista with an external keyboard. If your code brought up a text field using console.input_alert(), it wouldn't accept text without first tapping the field.

    I was told a while back this actually was an iOS issue. Sure enough, today's iOS8 upgrade fixed it. (At least on my iPad Air2 with Logitecth Type+ folio keyoard)

    Just thought others might want to know.

    posted in Pythonista read more
  • pacco

    Nice. Here's some UI-goodness wrapped around. (Caveat: Suffers from known bug that doesn't focus the alert input fields and I agree -- still not as nice as Editorial's builtin message-sender).

    import clipboard, webbrowser,console,sys
    msg = 'I am texting you through pythonista!'
    tel='' 
    try:
        tel=console.input_alert('Text Sender','Enter Tel #/AppleID',tel)
        msg=console.input_alert('Text Sender','Enter Msg text',msg).strip()
    #   if len(msg) > 128:
    #       console.hud_alert('Warning: SMS messages may be truncated)','error',2.00)
    except Exception as e:
        sys.exit()
    clipboard.set(msg)       # once iMessage opens, do a Paste into the message body
    webbrowser.open('sms:' + tel)
    

    posted in Pythonista read more
  • pacco

    Apologies for continuing the 'contamination' of this thread (ostensibly about iPad keyboards!)

    Below is something I used to convince myself that Pythonista could run 'bytecode binaries' (i.e., .pyc) files even if it didn't produce them. It's a short .pyc file created using a mini-assembler that emits Python bytecode. So in effect, yes -- if someone were sufficiently motivated they could conceivably write another language compiler to emit bytecode files that Pythonista could execute. (Much like how the JVM or CLR allows this as mentioned in my earlier comment). I'm not sure what the point would be from a practical perspective. But some things are fun simply because they're possible, I suppose.

    Anyway, apologies again if this isn't exactly news to the experienced Python hackers here. As I've said before, I'm new to this language and cobbling together snippets of test code has always been my preferred way of learning.

    Thanks,<br>
    Pacco

    Reminder: The Pythonista file navigator doesn't display .pyc files. Use shellista or some other tool to see them.

    <pre><code>

    A proof-of-concept to illustrate that Pythonista can call/run bytecode (.pyc) files

    that have been precompiled (no surprise) or even created using other tools.

    Pacco 20150114

    import os,base64

    A bytecode binary created using the bytecode assembler [https://github.com/pib/papaya]

    and patched to use Pythonista 1.5's identifier [03f3] in first two bytes.

    [http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html]

    This is just the Fibonacci (fib.pya) example included with the Papaya assembler

    pycbin=base64.b64decode(
    'A/MNCr7JtlRjAAAAAAAAAAABAAAAQAAAAHMNAAAAZAEAhAAAWgAAZAAAUygCAAAATmMBAAAAAQAAAAQA'+
    'AABDAAAAcz4AAAB8AABkAQBrAgBvEABkAQBTAXwAAGQCAGsCAG8hAGQCAFMBdAAAfAAAZAIAGIMBAHQA'+
    'AHwAAGQDABiDAQAXUygEAAAATmkAAAAAaQEAAABpAgAAACgBAAAAdAMAAABmaWIoAQAAAHQBAAAAbigA'+
    'AAAAKAAAAABzBwAAAGZpYi5weWFSAAAAAAQAAABzMgAAAAMBAwEDAQMBAwEBBAEBAwEDAQMBAwEDAQEE'+
    'AQEDAQMBAwEBAQMCAwEDAQMBAQEDAQECKAEAAABSAAAAACgAAAAAKAAAAAAoAAAAAHMHAAAAZmliLnB5'+
    'YXMIAAAAPG1vZHVsZT4CAAAAcwgAAAADJQMBAwEDAQ=='
    )

    write it to a .pyc file

    pycfile='fib0.pyc'
    with open(pycfile,'wb') as f:
    f.write(pycbin)

    Now load and call a function in the binary

    import imp

    try:
    ourpyc=imp.load_compiled('Test Module',pycfile)
    print ourpyc.fib(10) # call a function in our loaded pyc file
    except Exception as e:
    print "Error:",e

    clean up .pyc afterwards to be neat

    if os.path.isfile(pycfile): os.remove(pycfile)

    </code></pre>

    posted in Pythonista read more
  • pacco

    On the original keyboard thread: I also had a Zagg Folio that I bought about the same time as my new iPad. Nice keyboard, athough not quite as sturdy as the ClamCase. However, it had a standard key layout, a hinged design (that gave it the laptop-like formfactor I'm fond of) and it came in black!

    Unfortunately, after about two months of use it broke and literally split apart at the hinge area. This wasn't entirely a suprise as I hadn't been too impressed with the build quality (i.e., it felt flimsy) when I got it.

    In all fairness, I should add that I'm a pretty heavy iPad user and probably opened/closed that case at least a dozen times daily, for those two months.


    @dgelessus : Yes, thanks -- those were some of the projects I was alluding to. Another is Emscripten, an C-to-JS compiler. Amazingly, there is a project that ported DOSBox to JS using this tool. I'm too new to the Python world to know if something like this has been attempted/possible with this language, but I'll admit to wondering if other compilers could be built to generate compatible bytecode that Pythonisa could execute. (Much like the way the JVM and CLR supports multiple languages).

    posted in Pythonista read more
  • pacco

    @dgelessus: You probably have seen this, but if not: Check about Fabrice Bellard's jslinux page. He wrote an <a href="http://bellard.org/jslinux/">entire x86 hardware emulator</a> in Javascript(!)...that boots an embedded Linux Kernel. He even includes gcc so technically one could compile C on the ipad by having the jslinux VM running in a local WebView in Pythonista or something, but that's just being silly :-). At this stage it's really more of a curiosity and a toy, but there are more than a couple of C-to-JS compiler projects out there that basically treats JS as sort of a machine-instruction layer.

    On a semi-related note: Has anyone gotten PyEmu to run successfully under Pythonista? (It isn't a full system emulator for booting an OS or anything -- it's primary an x86 emulator for debugging/stepping through routines for reverse-engineering/analyzing malware, etc.). It appears to have a dependency on a disassembler module that must be compiled but I'm wondering if another pure-python disasm module could be dropped in.

    And just so I'm contributing to the original spirit of the thread. The best BT iPad keyboard I've ever used was a ClamCase Pro with my iPad 4th gen (iPad2 will also fit perfectly). But with my new iPad Air 2 I really wanted a black case that was lightweight (the ClamCase is only available in white and nearly doubles the weight of the iPad). This time I went with a Logitech Type+ which is proving to be a great choice. Hint: Be sure to check for standard key placement (if that's important to you). I was looking at a couple of other popular iPad keyboards but they had funky key placements (with the Ctrl or semicolon key placed to the right of the spacebar, etc) which immediately disqualified them for my use.

    posted in Pythonista read more
  • pacco

    Like Gerzer's suggestion, this isn't a Pythonista-specific method.

    If you don't have a Mac (or do but aren't running Yosemite) and are willing to spend a modest amount on a 3rd party solution, you could use one of the few apps out there that turns your Mac/PC into an Airplay receiver. At least one of the apps has a recording feature built in. Or just combine it with your own screen-recording app such as Camtasia, et al.

    Just google 'airplay mirror app' for more hint.

    posted in Pythonista read more
  • pacco

    Just a fyi.

    I initially wrote the archive script so I'd have a quick way to backup my entire Pythonista library without requiring an iTunes sync or needing a network connection to an external server.

    I recently came across <a href="https://omz-forums.appspot.com/pythonista/post/5862818263859200">wolf71's mini-webdav server here</a>.

    If you combine this mini-server with an app like GoodReader (which connects to webdav servers) you now have a really easy way to transfer your files in/out of Pythonista.

    Thanks,<br>
    Pacco

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!