Esempio n. 1
0
 def __init__(self):
     self.MODES = common.enum(GET_CONTENT=1,
                              GET_VOD=2,
                              GET_LIVE=3,
                              GET_EPISODES_LIST=4,
                              GET_CAMERAS=5,
                              PLAY_VIDEO=6)
def get_impl(operator):
    args_list = common.enum(operator.params[1:])
    tmpl_args = []
    if not operator.closed:
        tmpl_args += ['typename ToType']
    tmpl_args += ['typename T']
    tmpl_args += ['typename A{}'.format(i[0]) for i in args_list \
                  if i[1] not in ['v', 'l']]
    tmpl_args = ', '.join(tmpl_args)

    def arg_type(arg):
        if arg[1] in ['v', 'l']:
            return 'T a{}'.format(arg[0])
        else:
            return 'A{i} a{i}'.format(i=arg[0])

    args = [arg_type(i) for i in args_list]
    varis = ['a{}'.format(a[0]) for a in args_list]
    varis += ['ToType()', 'T()'] if not operator.closed else ['T()']
    varis = ', '.join(varis)
    returns = '' if operator.params[0] == '_' else 'return '
    return_typ = 'ToType' if not operator.closed else 'T'
    template = '''template <{tmpl_args}>
                  {return_typ} {op_name}({{args}}) {{{{
                    {returns}{op_name}({varis}, cpu());
                  }}}}'''. \
                  format(tmpl_args=tmpl_args, return_typ=return_typ,
                         op_name=operator.name, args=', '.join(args),
                         returns=returns, varis=varis)
    ret = template.format(args=', '.join(args))
    if not operator.closed:
        args = ['ToType'] + args
        ret += '\n\n' + template.format(args=', '.join(args))
    if operator.cxx_operator != '' and operator.cxx_operator != None and \
       (operator.params == ['v', 'v', 'v'] or \
        operator.params == ['l', 'v', 'v']):
        ret += \
        '''

        template <typename T, int N, typename SimdExt, typename S>
        pack{l}<T, N, SimdExt> {cxx_op}(pack<T, N, SimdExt> const &v, S s) {{
          return {op_name}(v, pack<T, N, SimdExt>(T(s)));
        }}

        template <typename S, typename T, int N, typename SimdExt>
        pack{l}<T, N, SimdExt> {cxx_op}(S s, pack<T, N, SimdExt> const &v) {{
          return {op_name}(pack<T, N, SimdExt>(T(s)), v);
        }}'''.format(l='l' if operator.params[0] == 'l' else '',
                     cxx_op=operator.cxx_operator, op_name=operator.name)

    return ret
Esempio n. 3
0
 def __init__(self):
     self.MODES = common.enum(GET_SERIES_LIST=1, GET_EPISODES_LIST=2)
Esempio n. 4
0
 def __init__(self):
     self.MODES = common.enum(GET_GENRE=1, GET_SERIES_LIST=2, GET_EPISODES_LIST=3, SHOW_EPISODES=4)
Esempio n. 5
0
from binascii import hexlify

import common
import network_data

CommandType = common.enum(LINK_REQUEST=0,
                          LINK_ACCEPT=1,
                          LINK_ACCEPT_AND_REQUEST=2,
                          LINK_REJECT=3,
                          ADVERTISEMENT=4,
                          UPDATE=5,
                          UPDATE_REQUEST=6,
                          DATA_REQUEST=7,
                          DATA_RESPONSE=8,
                          PARENT_REQUEST=9,
                          PARENT_RESPONSE=10,
                          CHILD_ID_REQUEST=11,
                          CHILD_ID_RESPONSE=12,
                          CHILD_UPDATE_REQUEST=13,
                          CHILD_UPDATE_RESPONSE=14,
                          ANNOUNCE=15,
                          DISCOVERY_REQUEST=16,
                          DISCOVERY_RESPONSE=17
                          )

TlvType = common.enum(SOURCE_ADDRESS=0,
                      MODE=1,
                      TIMEOUT=2,
                      CHALLENGE=3,
                      RESPONSE=4,
Esempio n. 6
0
HEADERS = {
    'User-Agent':
    '%s/%s' % (common.APPLICATION_NAME.replace(' ', ''), common.VERSION)
}
KEYRING_SERVICE = 'ontheday.net'
QSETTINGS_GROUP = 'ontheday'
QSETTINGS_KEY_USERNAME = '******'

POLLING_INTERVAL_SECS = 15


class OnTheDayException(BaseException):
    """Exceptions generated by this module."""


ResultStatus = common.enum(Ok=0, Rejected=1)


def check_auth(auth):
    """Check that the authenticator is good.

    For this, we can do a simple transaction and make sure it comes back with
    something.
    """
    return len(get_race_list(auth)) > 0


def get_race_list(auth):
    """Gets the list of races that are visible from a particular authentication.

    The returned race records are of the following form:
Esempio n. 7
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from whoosh.index import create_in, open_dir, exists_in
from common import get_project_root
from common.terminal import statuses
from datetime import datetime
from shutil import rmtree
from common import enum
import os

Index_Types = enum(
	Source  = 0,
	Crisees = 1)

class Indexer(object):
	
	def __init__(self, schema, name, index_type):
		self.schema = schema
		self.name = name
		self.index_type = index_type
		
		self.index = self.open_index()
	
	def open_index(self):
		path_to_index = os.path.join(get_project_root(), 'index/whoosh')
		
		if self.index_type == Index_Types.Source:
			path_to_index = os.path.join(path_to_index, ('sources/%s.whoosh' % self.name))
		elif self.index_type == Index_Types.Crisees:
			path_to_index = os.path.join(path_to_index, ('crisees/%s.whoosh' % self.name))
Esempio n. 8
0
 def __init__(self):
     self.MODES = common.enum(GET_CATEGORIES=1, GET_SERIES_LIST=2, GET_EPISODES_LIST=3, PLAY_ITEM=4)
Esempio n. 9
0
import appindicator
import gtk

import aboutdlg
import prefdlg
import screencapper
import uploader

from common import enum

cmd = enum("CAPTURE_AREA", "CAPTURE_ACTIVE_WINDOW", "CAPTURE_SCREEN", "SHOW_PREFERENCES", "SHOW_ABOUT", "EXIT")


class LookitIndicator:
    def __init__(self):
        self.indicator = appindicator.Indicator("lookit-indicator", "lookit", appindicator.CATEGORY_APPLICATION_STATUS)
        self.indicator.set_status(appindicator.STATUS_ACTIVE)

        try:
            # Check for special Ubuntu themes.
            # This is an ugly, ugly hack
            theme = gtk.gdk.screen_get_default().get_setting("gtk-icon-theme-name")
            if theme == "ubuntu-mono-dark":
                self.indicator.set_icon("lookit-dark")
            elif theme == "ubuntu-mono-light":
                self.indicator.set_icon("lookit-light")
            # Oh god, it hurt to even type that, I need to find
            # a better solution, but it won't see the icons if I
            # install them manually whhhaaarrgggbbbbllll
        except ValueError:
            # Couldn't find the setting, probably not running gnome
Esempio n. 10
0
 def __init__(self):
     self.MODES = common.enum(GET_CATEGORIES=1,
                              GET_SERIES_LIST=2,
                              GET_EPISODES_LIST=3,
                              PLAY_ITEM=4)
Esempio n. 11
0
import io
import ipaddress
import struct
import sys

import common
import ipv6
import lowpan
import mac802154
import mle


MessageType = common.enum("MLE",
                          "COAP",
                          "ICMP",
                          "ACK",
                          "BEACON",
                          "DATA")


class Message(object):

    def __init__(self):
        self._type = None
        self._channel = None
        self._mac_header = None
        self._ipv6_packet = None
        self._mle = None
        self._icmp = None

    def _extract_udp_datagram(self, udp_datagram):
Esempio n. 12
0
DEFAULT_REVIEW_INFO_URL = "http://code.oa.com/tcr-qs/t/tcr/web/endpoint/c/request/getRequestById?requestId="

DEFAULT_REVIEW_URL = "http://code.oa.com/v2/user/request/"

_EXT_IGNORES = frozenset([
    '.bak',
    '.diff',
    '.log',
    '.new',
    '.old',
    '.orig',
    '.tmp',
])

_ISSUE_STATE = common.enum(UNDERREVIEW=30, PASSED=45, CLOSED=50, SUBMITED=70)


class SvnInfo(object):
    def __init__(self, path):
        info = run_command_in_english(["svn", "info", path])
        self.svn_info = "\n".join(info.split("\n")[1:])

    def get_remote_path(self):
        for i in self.svn_info.split("\n"):
            if i.startswith("URL: "):
                return i[5:].strip()
        return ""

    def get_revision(self):
        for i in self.svn_info.split("\n"):
Esempio n. 13
0
import common
from common import db
from core.player import Player
import core.cards as cards
from core.gamestate import GameState
import db.stats as stats


# Constants and global variables
WINNING_SCORE = 11
STARTING_HAND_SIZE = 9
NUM_TEAMS = 2
TEAM_SIZE = 2
NUM_PLAYERS = NUM_TEAMS * TEAM_SIZE
GAME_MODE = common.enum(PLAY=1, BID=2)
MAX_HANDS = 16 # Not part of game rules; intended to prevent AI problems.
               # Can be modified later if actual gameplay is trending longer.

# Bid constants
BID = common.enum(PASS=0, CINCH=5)


class Game:
    """Define object for Game object with instance variables:

        stack_deck (bool): fixed hands for testing purposes.
        deck_seed (float)[0..1]: used to seed if stack_deck is True
        id (integer): unique id for game object
        mode (integer): setting for game mode
        players (list): array of Player objects for players in game
Esempio n. 14
0
kLowTgtHCenter  = kLowEdgeHeight + kLowHeight/2.0

kLowInnerRatio  = kLowHeight/kLowWidth                                    # 0.827586206897 
kLowOuterRatio  = (kLowHeight + kTapeWidth*2)/(kLowWidth + kTapeWidth*2)  # 0.864864864865

kOptimumVerticalPosition = 0.5      # percent from top
kOptimumHorizontalPosition = 0.5    # percent from left

kThresholdV = 2.0
kThresholdH = 2.0

# target location types
location = common.enum(TOP=0, 
                       LMIDDLE=3,   # left of top
                       RMIDDLE=4,   # right of top
                       MIDDLE=1,    # unknown middle
                       LOW=2,
                       UNKNOWNL=5,
                       UNKNOWNR=6)

class Target(object):
    
    def __init__(self, x, y, w, h, polygon, location, ratio, rotation):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.cx = int(x + w/2.0)    # center x
        self.cy = int(y + h/2.0)    # center y
        self.polygon = polygon
        self.location = location
Esempio n. 15
0
from django.http import HttpResponse, HttpResponseForbidden, HttpResponseBadRequest, HttpResponseNotFound, HttpResponseServerError
from common import enum
import simplejson
import datetime

API_VERSION = '1.0'
DT_HANDLER = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime
                                                       ) else None

# Status codes used within the API.
# Uses the enum imitator defined in the common module.
Status_Codes = enum(
    OK=200,
    FORBIDDEN=403,
    BAD_REQUEST=400,
    NOT_FOUND=404,
    SERVER_ERROR=500,
)


# Generates a Django HttpResponse object based on the information provided.
def generate_response(response_dict, status=Status_Codes.OK):
    api_dict = {
        'api_version': API_VERSION,
    }
    joined_dict = dict(list(api_dict.items()) + list(response_dict.items()))

    if status == Status_Codes.FORBIDDEN:
        return HttpResponseForbidden(simplejson.dumps(joined_dict,
                                                      default=DT_HANDLER),
Esempio n. 16
0
from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotFound, HttpResponseServerError
from httplib2 import Http
from urllib import urlencode
from common import enum
import simplejson

COMPATIBLE_VERSION = '1.0'
API_BASE_URL = 'http://127.0.0.1:8001/'
DT_HANDLER = lambda obj: obj.isoformat() if isinstance(obj, datetime.datetime
                                                       ) else None
http_object = Http()

Methods = enum(
    GET='GET',
    POST='POST',
    DELETE='DELETE',
)

Status_Codes = enum(
    OK=200,
    FORBIDDEN=403,
    BAD_REQUEST=400,
    NOT_FOUND=404,
    SERVER_ERROR=500,
    NO_API_CONNECTION=598,
    INCOMPATIABLE_API=599,
)


def get_response(api_path, method, data={}, recreate=False):