Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Implementation of x-callback-url (Inter app communication) on macOS using Python

NotificationsYou must be signed in to change notification settings

robwalton/python-xcall

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Pythonx-callback-url client for bi-directionalcommunication with x-callback-url enabled macOS applications. python-xcall supports callbacks from appplications. It wraps the handyxcall command line tool.

It is used by:

Software compatability

Requires:

  • macOS
  • python 2.7
  • Usesxcall (included).
  • Needs pytest and mock for testing

Installation

Check it out:

$ git clone https://github.com/robwalton/python-xcall.gitCloning into'python-xcall'...

Basic use

Call a scheme (ulysses) with an action (get-version):

>>>importxcall>>>xcall.xcall('ulysses','get-version'){u'apiVersion':u'2',u'buildNumber':u'33542'}

An x-success reply will be utf-8 un-encoded, then url unquoted, and then un-marshaled using json into Python objects and returned.

A dictionary of action parameters can also be provided (each value is utf-8encoded and then url quoted before sending):

>>>xcall.xcall('ulysses','new-sheet', {'text':'My new sheet','index':'2'})

If the application calls back with an x-error, anXCallbackError will be raised:

>>>xcall.xcall('ulysses','an-invalid-action')Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>...XCallbackError:x-errorcallback:'{"errorMessage" : "Invalid Action",  "errorCode" : "100"}' (inresponsetourl:'ulysses://x-callback-url/an-invalid-action')

More control

For more control create an instance ofxcall.XCallClient, specifying the scheme to use, whether responses should be un-marshaled using json, and an x-error handler. For example:

classUlyssesError(XCallbackError):passdefulysses_xerror_handler(xerror,requested_url):error_message=eval(xerror)['errorMessage']error_code=eval(xerror)['errorCode']raiseUlyssesError(        ("%(error_message)s. Code=%(error_code)s. ""In response to sending the url '%(requested_url)s'")%locals())ulysses_client=XCallClient('ulysses',on_xerror_handler=ulysses_xerror_handler,json_decode_success=True)

Make calls using:

>>>ulysses_client.xcall('get-version')

or just:

>>>ulysses_client('get-version')

Logging

As logger output just goes directly to the terminal, it is disabled by default. To enable more verbose logging use:

>>>importxcall>>>xcall.enable_verbose_logging()

On thread/process safety

Call to this module areprobably not thread/process safe. An attempt is madeto ensure thatxcall is not already running, but there is 20-30ms window in whichmultiple calls to this module will result in multiple xcall processes runningand the chance of replies being mixed up.

Testing

Running the tests requires thepytest andmock packages. Some optional integrationtests currently requireUlysses. Code youraccess-token into the top oftest_calls.py. Obtain the access token string by removing the @skipmarker fromtest_authorise() intest_calls.py and running the tests.

From the root package folder call:

MacBook:python-xcall walton$ pytest...

Licensing & Thanks

The code and the documentation are released under the MIT and Creative CommonsAttribution-NonCommercial licences respectively.

Thanks to:

Todo

  • Upload PyPi after working out how distrubute the lib folder containing xcall.app.
  • Logs could go somewhere more sensible that stdout.

About

Implementation of x-callback-url (Inter app communication) on macOS using Python

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp