masklinn avatar masklinn committed 1930d5e

Namespace for API helpers looks like shit after all. Use prefix to names

Comments (0)

Files changed (3)

 
 These are functions provided to implement ``py`` objects which can be
 used within a ``py.js`` evaluation, they're essentially ``py.js``'s
-version of the Python C API. They live in a ``py`` sub-namespace (and
-are thus accessible via ``py.py.[function]``)
+version of the Python C API. They are prefixed with ``PY_``
 
-.. function:: py.py.parseArgs(arguments, format)
+.. function:: py.PY_parseArgs(arguments, format)
 
     Arguments parser converting from the :ref:`user-defined calling
     conventions <calling-conventions-python>` to a JS object mapping
     :raises: ``TypeError`` if the provided arguments don't match the
              format
 
-    Examples::
+.. class:: py.PY_def(fn)
 
-        py.py.parseArgs(arguments, [])
+    Type wrapping javascript functions into py.js callables. The
+    wrapped function follows :ref:`the py.js calling conventions
+    <calling-conventions-python>`
+
+    :param Function fn: the javascript function to wrap
+    :returns: a callable py.js object
 
 Implementation details
 ----------------------
         case 'string':
             return new py.str(val);
         case 'function':
-            return new py.def(val);
+            return new py.PY_def(val);
         }
 
         switch(val.constructor) {
     // types
     py.py = {};
 
-    py.py.parseArgs = function PY_parseArgs(argument, format) {
+    py.PY_parseArgs = function PY_parseArgs(argument, format) {
         var out = {};
         var args = argument[0], kwargs = argument[1];
         var name = function (spec) {
             this._store[key.__hash__()] = [key, value];
         },
         get: function () {
-            var args = py.py.parseArgs(arguments, ['k', ['d', py.None]]);
+            var args = py.PY_parseArgs(arguments, ['k', ['d', py.None]]);
             var h = args.k.__hash__();
             if (!(h in this._store)) {
                 return args.d;
             return out;
         }
     });
-    py.def = py.type(function def(nativefunc) {
+    py.PY_def = py.type(function def(nativefunc) {
         this._inst = null;
         this._func = nativefunc;
     }, py.object, {
         // could also use bind?
         this._inst = instance;
         this._func = nativefunc;
-    }, py.def, {});
+    }, py.PY_def, {});
 
-    py.issubclass = new py.def(function issubclass() {
-        var args = py.py.parseArgs(arguments, ['C', 'B']);
+    py.issubclass = new py.PY_def(function issubclass() {
+        var args = py.PY_parseArgs(arguments, ['C', 'B']);
         if (args.C === args.B || args.C.prototype instanceof args.B) {
             return py.True;
         }
 describe('Utility functions', function () {
     describe("Arguments parser", function () {
         it('should return an object', function () {
-            expect(py.py.parseArgs([[], {}], []))
+            expect(py.PY_parseArgs([[], {}], []))
                 .to.be.an(Object);
         });
         it('should assert the number of arguments', function () {
             expect(function () {
-                py.py.parseArgs([[1, 2], {}], []);
+                py.PY_parseArgs([[1, 2], {}], []);
             }).to.throwException(/^TypeError/);
             expect(function () {
-                py.py.parseArgs([[], {a: 3}], []);
+                py.PY_parseArgs([[], {a: 3}], []);
             }).to.throwException(/^TypeError/);
             expect(function () {
-                py.py.parseArgs([[], {}], ['a']);
+                py.PY_parseArgs([[], {}], ['a']);
             }).to.throwException(/^TypeError/);
             expect(function () {
-                py.py.parseArgs([[], {}], ['*', 'a']);
+                py.PY_parseArgs([[], {}], ['*', 'a']);
             }).to.throwException(/^TypeError/);
         });
         it('should prevent arguments conflicts', function () {
             expect(function () {
-                py.py.parseArgs([[1], {foo: 1}], ['foo']);
+                py.PY_parseArgs([[1], {foo: 1}], ['foo']);
             }).to.throwException(/^TypeError/);
         });
         it('should not require optional arguments', function () {
             var val = new py.float(3);
-            expect(py.py.parseArgs([[], {}], [['foo', val]]))
+            expect(py.PY_parseArgs([[], {}], [['foo', val]]))
                 .to.eql({
                     foo: val
                 });
-            expect(py.py.parseArgs([[], {}], ['*', ['foo', val]]))
+            expect(py.PY_parseArgs([[], {}], ['*', ['foo', val]]))
                 .to.eql({
                     foo: val
                 });
             var def = new py.float(3);
             var val = new py.float(4);
 
-            expect(py.py.parseArgs([[val], {}], [['foo', def]]))
+            expect(py.PY_parseArgs([[val], {}], [['foo', def]]))
                 .to.eql({
                     foo: val
                 });
-            expect(py.py.parseArgs([[], {foo: val}], [['foo', def]]))
+            expect(py.PY_parseArgs([[], {foo: val}], [['foo', def]]))
                 .to.eql({
                     foo: val
                 });
     });
     it("should work with functions", function () {
         var o = new py.object();
-        o.bar = new py.def(function () {
+        o.bar = new py.PY_def(function () {
             return new py.str("ok");
         });
         expect(py.eval('foo.bar()', {foo: o})).to.be('ok');
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.