예제 #1
0
파일: convert.py 프로젝트: pombredanne/PJs
def _classdef(node, scope):
    imports = []
    dct = {}
    dct['left'] = do_left(ast.Name(node.name, {}), scope)
    dct['name'] = node.name;
    dct['rname'] = resolve(node.name, scope);
    dct['bases'] = ', '.join(resolve(name.id, scope) for name in node.bases)

    dct['dec_front'] = ''
    dct['dec_back'] = ''
    for dec in node.decorator_list:
        js = convert_node(dec, scope)
        dct['dec_front'] += js+'('
        dct['dec_back'] += ')'

    scope = new_scope(scope)
    scope['exp locals'] = True

    text = convert_block(node.body, scope)
    prefix = local_prefix(scope)
    for name in scope['locals']:
        text = re.sub('{:undef:' + name + ':[^:]*:}', prefix + name, text)
    dct['contents'] = text
    dct['lnum'] = len(scope['parent locals'])

    text = TEMPLATES['class'] % dct
    return text
예제 #2
0
파일: atomic.py 프로젝트: b2ornot2b/PJs
def attribute(conv, node, scope):
    if node.attr in utils.reserved_words:
        raise SyntaxError("Sorry, '%s' is a reserved word in javascript." % node.attr)
    js = conv.convert_node(node.value, scope)
    if js == 'js':
        return 'js.%s' % (utils.resolve(node.attr, scope))
    return "%s.%s" % (js, node.attr)
예제 #3
0
파일: convert.py 프로젝트: pombredanne/PJs
def _attribute(node, scope):
    if node.attr in reserved_words:
        raise PJsException("Sorry, '%s' is a reserved word in javascript." % node.attr)
    js = convert_node(node.value, scope)
    if js == 'js':
        return 'js.%s' % (resolve(node.attr, scope))
    return "%s.%s" % (js, node.attr)
예제 #4
0
파일: nodes.py 프로젝트: mgill25/tortoise
 def resolve_in_expression(self, expr, ctx):
     expr_type, expr = eval_expression(expr)
     if expr_type == 'name' and expr:
         resolved = resolve(expr, ctx)
         return eval_expression(resolved)[1] if resolved else None
     elif expr_type == 'literal':
         return expr
예제 #5
0
 def render(self, context):
     kwargs = dict(self.kwargs)
     kwargs = utils.resolve(kwargs, context)
     #print repr(kwargs)
     context.update(kwargs)
     result = self.nodelist.render(context)
     context.pop()
     return result
예제 #6
0
파일: convert.py 프로젝트: pombredanne/PJs
def _functiondef(node, scope):
    dct = {}
    dct['left'] = do_left(ast.Name(node.name, []), scope)
    dct['name'] = node.name
    dct['lineno'] = node.lineno
    try:
        dct['rname'] = resolve(node.name, scope);
    except PJsNameError, e:
        print scope
        raise PJsException('UndefinedNameError: %s on line %d' % (e, node.lineno))
예제 #7
0
def main():
    define('host', default='127.0.0.1', help='run on the given host', type=str)
    define('port', default=8000, help='run on the given port', type=int)
    define('debug', default=False, help='enable debug mode', type=bool)
    parse_command_line()

    settings = {
        'debug': options.debug,
        'cookie_secret': os.urandom(32),
        'template_path': resolve('./templates'),
        'static_path': resolve('./static'),
    }

    application = Application(routes, **settings)
    application.listen(options.port, options.host, xheaders=True)

    asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
    IOLoop.configure('tornado.platform.asyncio.AsyncIOLoop')
    print('» listen to http://%s:%s' % (options.host, options.port))
    IOLoop.instance().start()
예제 #8
0
파일: scoping.py 프로젝트: b2ornot2b/PJs
def classdef(conv, node, scope):
    imports = []
    dct = {
        'name':  node.name,
        
        'bases': ', '.join(utils.resolve(base.id, scope) for base in node.bases),
        'left':  utils.lhand_assign(node.name, scope),
        'rname': utils.resolve(node.name, scope),
    }

    dct['dec_front'] = ''
    dct['dec_back'] = ''
    for dec in node.decorator_list:
        dct['dec_front'] += conv.convert_node(dec, scope) + '('
        dct['dec_back'] += ')'

    scope = scope.copy()
    scope.explicit_locals = True

    dct['contents'] = utils.fix_undef(conv.convert_block(node.body, scope), scope)

    dct['lnum'] = len(scope.parent_locals)

    return CLASS_TEMPLATE % dct
예제 #9
0
파일: nodes.py 프로젝트: mgill25/tortoise
    def render(self, context):
        if self._iter[0] == 'literal':
            items = self._iter[1]
        elif self._iter[0] == 'name':
            items = resolve(self._iter[1], context)

        # Since Py2.x can't mutate parent scope variables,
        # we use a dictionary to pass in the index to the function below.
        nonlocals = {'index': 0}

        def render_item(item):
            # Add the current item to be rendered into the context.
            context[self._loop_var] = item
            context['index'] = nonlocals['index']
            nonlocals['index'] += 1
            return self.render_children(context, self.children)

        return ''.join(map(render_item, items))
예제 #10
0
파일: scoping.py 프로젝트: b2ornot2b/PJs
def functiondef(conv, node, scope):
    dct = {
        'name':    node.name,
        'lineno':  node.lineno,

        'special': function_special(conv, node, scope),
        'left':    utils.lhand_assign(node.name, scope),
        'rname':   utils.resolve(node.name, scope),
    }
    args = function_args(conv, node, scope)
    dct['args'] = ', '.join(args)

    dct['dec_front'] = ''
    dct['dec_back'] = ''
    for dec in node.decorator_list:
        dct['dec_front'] += conv.convert_node(dec, scope) + '('
        dct['dec_back'] += ')'

    scope = scope.copy()
    scope.explicit_locals = False
    scope.locals += args

    dct['contents'] = utils.fix_undef(conv.convert_block(node.body, scope), scope)
    return FUNC_TEMPLATE % dct
예제 #11
0
import sqlite3

from utils import resolve


class IntegrityError(sqlite3.IntegrityError):
    pass


DATABASE = resolve('../database.sqlite')
conn = sqlite3.connect(DATABASE, isolation_level=None)
conn.execute('PRAGMA journal_mode=WAL')
conn.executescript('''
CREATE TABLE IF NOT EXISTS shorten (
    id INTEGER PRIMARY KEY NOT NULL ON CONFLICT ROLLBACK,
    datetime INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL ON CONFLICT ROLLBACK,
    code TEXT UNIQUE NOT NULL ON CONFLICT ROLLBACK,
    url TEXT NOT NULL ON CONFLICT ROLLBACK
);
CREATE INDEX IF NOT EXISTS idx_shorten ON shorten (code);

CREATE TABLE IF NOT EXISTS pastebin (
    id INTEGER PRIMARY KEY NOT NULL ON CONFLICT ROLLBACK,
    datetime INTEGER DEFAULT CURRENT_TIMESTAMP NOT NULL ON CONFLICT ROLLBACK,
    code TEXT UNIQUE NOT NULL ON CONFLICT ROLLBACK,
    data BLOB NOT NULL ON CONFLICT ROLLBACK
);
CREATE INDEX IF NOT EXISTS idx_pastebin ON pastebin (code);
''')

예제 #12
0
from PyQt4.QtGui import QPixmap
from PyQt4.QtCore import QSettings
from PyQt4 import uic

import resources_rc

import utils

FORM_CLASS, FORM_BASE = uic.loadUiType(utils.resolve("settingsdialog.ui"))


class SettingsDialog(FORM_BASE, FORM_CLASS):
    def __init__(self, parent=None):
        super(SettingsDialog, self).__init__(parent)
        self.setupUi(self)
        self.settings = QSettings()

    def value(self, key, type=str):
        try:
            return self.settings.value(key, type=type)
        except TypeError:
            return None

    def showEvent(self, event):
        serviceUrl = self.value("plugins/Earthmine/serviceUrl")
        baseDataUrl = self.value("plugins/Earthmine/baseDataUrl", type=str)
        apiKey = self.value("plugins/Earthmine/apiKey", type=str)
        secretKey = self.value("plugins/Earthmine/secretKey", type=str)
        viewerUrl = self.value("plugins/Earthmine/viewerUrl", type=str)
        if not viewerUrl:
            viewerUrl = "http://qgis.mapsolutions.com.au/qgis/earthmine/view.html"
예제 #13
0
파일: convert.py 프로젝트: pombredanne/PJs
def _name(node, scope):
    try:
        return resolve(node.id, scope)
    except PJsNameError, e:
        print scope
        raise PJsException('UndefinedNameError: %s on line %d' % (e, node.lineno))
예제 #14
0
파일: nodes.py 프로젝트: mgill25/tortoise
 def render(self, context):
     return resolve(self.token.clean(), context)
예제 #15
0
파일: small.py 프로젝트: b2ornot2b/PJs
def _name(conv, node, scope):
    return utils.resolve(node.id, scope)
예제 #16
0
 def render(self, context):
     kwargs = dict(self.kwargs)
     kwargs = utils.resolve(kwargs, context)
     for key,value in kwargs.items():
         context[key] = value
     return ''
예제 #17
0
import json
import functools

from PyQt4.QtWebKit import QWebView, QWebSettings
from PyQt4.QtCore import QUrl, Qt, QObject, pyqtSlot, pyqtSignal
from PyQt4.QtGui import QToolBar, QIcon, QWidget, QLabel, QSizePolicy, QActionGroup, QComboBox, QCheckBox
from PyQt4 import uic

from qgis.gui import QgsMapLayerComboBox, QgsMapLayerProxyModel
from qgis.core import QgsMapLayer, QGis, QgsGeometry, QgsDistanceArea

import resources_rc

import utils

ViewerClass, ViewerBase = uic.loadUiType(utils.resolve('viewer.ui'))
MeasureClas, MeasureBase = uic.loadUiType(utils.resolve('measure.ui'))


class EarthmineAPI(object):
    """
    Convenience class to allows calling JS methods as Python attributes.
    """
    def __init__(self, frame):
        """
        frame -- The QWebFrame to evel the JS in
        """
        self.frame = frame

    def __getattr__(self, item):
        return functools.partial(self._jscall, item)