コード例 #1
0
def pg_type_info(typ):
    value = None
    if isinstance(typ, dict):
        value = typ["value"]
        typ = typ["type"]

    data = py_types.get(typ)
    if data == None:
        raise NotSupportedError("type %r not mapped to pg type" % typ)

    # permit the type data to be determined by the value, if provided
    inspect_func = data.get("inspect")
    if value != None and inspect_func != None:
        data = inspect_func(value)

    type_oid = data.get("typeoid")
    if type_oid == None:
        raise InternalError("type %r has no type_oid" % typ)
    elif type_oid == -1:
        # special case: NULL values
        return type_oid, 0

    # prefer bin, but go with whatever exists
    if data.get("bin_out"):
        format = 1
    elif data.get("txt_out"):
        format = 0
    else:
        raise InternalError("no conversion fuction for type %r" % typ)

    return type_oid, format
コード例 #2
0
    def __init__(self, y=0, x=0):

        if not isinstance(y, int) or not isinstance(x, int):
            raise InternalError("Point expected two integers (y,x)")
        self.y = y
        self.x = x
        self.normalise()
コード例 #3
0
    def __init__(self, where=None, color=curses.A_REVERSE):

        if not isinstance(where, Rect):
            raise InternalError('Expected \'where\' to be a Rect')

        self.where = where
        self.color = color
コード例 #4
0
    def moveto(where=Point(0, 0)):

        if not isinstance(where, Point):
            raise InternalError('Expected \'where\' to be a Point')

        if where:
            self.where.move(where)
コード例 #5
0
 def unwrap(self, depth=1):
     if isinstance(self.inner, TypePointer):
         return self.inner.unwrap(depth + 1)
     elif isinstance(self.inner, TypePrim):
         return f'{self.inner.kind}{depth * "$"}'
     else:
         raise InternalError('pointer to something other than primary type')
コード例 #6
0
def pg_value(value, fc, **kwargs):
    typ = type(value)
    data = py_types.get(typ)
    if data == None:
        raise NotSupportedError("type %r not mapped to pg type" % typ)

    # permit the type conversion to be determined by the value, if provided
    inspect_func = data.get("inspect")
    if value != None and inspect_func != None:
        data = inspect_func(value)

    # special case: NULL values
    if data.get("typeoid") == -1:
        return None

    if fc == 0:
        func = data.get("txt_out")
    elif fc == 1:
        func = data.get("bin_out")
    else:
        raise InternalError("unrecognized format code %r" % fc)
    if func == None:
        raise NotSupportedError("type %r, format code %r not supported" %
                                (typ, fc))
    return func(value, **kwargs)
コード例 #7
0
class Executioner(Backend):

    def create_context(self, ccache=None, client_ip=None):
        """
        client_ip: The IP address of the remote client.
        """

        if ccache is not None:
            os.environ["KRB5CCNAME"] = ccache

        if self.env.in_server:
            self.Backend.ldap2.connect(ccache=ccache)
        else:
            self.Backend.rpcclient.connect(verbose=self.env.verbose,
                fallback=self.env.fallback, delegate=self.env.delegate)
        if client_ip is not None:
            setattr(context, "client_ip", client_ip)

    def destroy_context(self):
        destroy_context()

    def execute(self, _name, *args, **options):
        error = None
        try:
            if _name not in self.Command:
                raise CommandError(name=_name)
            result = self.Command[_name](*args, **options)
        except PublicError, e:
            error = e
        except StandardError, e:
            self.exception(
                'non-public: %s: %s', e.__class__.__name__, str(e)
            )
            error = InternalError()
コード例 #8
0
ファイル: app.py プロジェクト: fans656-deprecated/auth
 def wrapped(*args, **kwargs):
     try:
         resp = viewfunc(*args, **kwargs)
         return resp
     except Error as e:
         return e.resp
     except Exception:
         traceback.print_exc()
         return InternalError().resp
コード例 #9
0
 def add_children(self, *children):
     for child in children:
         if not child:
             pass  # ignore
         elif type(child) == list:
             for ch in child:
                 self.add_children(ch)
         elif isinstance(child, Node):
             child.parent = self
         else:
             raise InternalError('bad child')
コード例 #10
0
    def timeout(self, milliseconds):

        scr = self.screen

        if type(milliseconds) != int:
            raise InternalError('timeout expected integer milliseconds')

        self.timeout = milliseconds

        if not debug and scr:
            scr.timeout(milliseconds)
コード例 #11
0
 def print(self, title, obj):
     if isinstance(obj, Node):
         self.print_node(title, obj)
     elif isinstance(obj, list):
         self.print_array(title, obj)
     elif isinstance(obj, Token):
         self.print_token(title, obj)
     elif not obj:
         self.print_single(title, 'NULL')
     else:
         raise InternalError(f'bad argument {obj.__class__.__name__}')
コード例 #12
0
 def check_types(self):
     if self.lit.type == 'LIT_INT':
         return TYPE_INT
     elif self.lit.type == 'LIT_FLOAT':
         return TYPE_FLOAT
     elif self.lit.type in ['KW_TRUE', 'KW_FALSE']:
         return TYPE_BOOL
     elif self.lit.type == 'LIT_CHAR':
         return TYPE_CHAR
     elif self.lit.type == 'LIT_STR':
         return TYPE_STRING
     else:
         raise InternalError('Bad ExprLit token')
コード例 #13
0
def py_type_info(description):
    type_oid = description['type_oid']
    data = pg_types.get(type_oid)
    if data == None:
        raise NotSupportedError("type oid %r not mapped to py type" % type_oid)
    # prefer bin, but go with whatever exists
    if data.get("bin_in"):
        format = 1
    elif data.get("txt_in"):
        format = 0
    else:
        raise InternalError("no conversion fuction for type oid %r" % type_oid)
    return format
コード例 #14
0
 def wrapped(*args, **kwargs):
     try:
         resp = viewfunc(*args, **kwargs)
         if not resp:
             return ''
         elif isinstance(resp, dict):
             return json.dumps(resp)
         else:
             return resp
     except Error as e:
         return e.resp
     except Exception:
         traceback.print_exc()
         return InternalError().resp
コード例 #15
0
def unify(type_0, type_1):
    # def unify_types(type_0, type_1, token=None):
    # todo error?
    if not type_0 or not type_1:
        return 0
    elif type_0.__class__ != type_1.__class__:
        return 1
    # cia jau zinome kad klases sutampa (TypePrim?)
    elif isinstance(type_0, TypePointer) and isinstance(type_1, TypePointer):
        return unify(type_0.inner, type_1.inner)
    elif isinstance(type_0, TypePrim) and isinstance(type_1, TypePrim):
        if type_0.kind != type_1.kind:
            return 2
        else:
            return 0
    else:
        raise InternalError('unreachable')
コード例 #16
0
ファイル: app.py プロジェクト: fans656-deprecated/auth
def do_register(username, password):
    validate_username(username)
    validate_password(password)

    if dbutil.get_user(username):
        raise Error('user already exists')

    salt = generate_salt()
    hashed_password = hash_password(password, salt)
    user = {
        'username': username,
        'ctime': utc_now_as_str(),
        'salt': salt,
        'hashed_password': hashed_password,
    }
    if not dbutil.create_user(user):
        raise InternalError()

    return token_response(dbutil.get_user_for_token(username))
コード例 #17
0
    def check_types(self):
        target_type = None

        # todo jei exprunary nebutinai targetnode type
        if self.target_node:
            target_type = self.lhs.check_types()
            # target_type = @target.type
        # print(target_type.inner.kind)
        value_type = self.value.check_types(
        )  # jis visada kazkoks bus, nereik tikrint kasd jis su void bus

        # todo return?
        # target_node jau prisyreme vardu rez metu
        # unifyt_types(@target_node&.type, value_type)
        # cia jei target_type nera, tai nil paduoti, ir viduj jau error gausim
        if target_type:
            if self.op != "EQUALS" and not target_type.is_arithmetic():
                semantic_error3(
                    f'cannot perform arithmetic assign operation with this type: {target_type.kind}',
                    self.lhs.name)
            unify_types(target_type, value_type, self.value.get_token())
        else:
            raise InternalError("no target type")
コード例 #18
0
#
# __main__
#
#---

if __name__ == '__main__':

    if 1:

        if len(sys.argv) == 2:
            tinfo = terminfo(sys.argv[1])
        elif len(sys.argv) == 1:
            tinfo = terminfo()
        else:
            print(
                InternalError("Expected only 1 argument, got %d" %
                              (len(sys.argv) - 1)))
            sys.exit(1)

        # Display tinfo...
        print('\n\nterminfo for %s...' % tinfo['termname'])
        keys = list(tinfo.keys())
        keys.sort()

        maxkey = 0
        for key in keys:
            maxkey = max(maxkey, len(key))

        for key in keys:
            val = tinfo[key]
            vallen = 0 if type(val) != str else len(val)
            print('  %s:%s (%d) = %s' %
コード例 #19
0
def terminfo(termname=os.environ['TERM']):

    lines = os.popen('infocmp -1 -E %s' % repr(termname)).read().split('\n')

    if 'infocmp: ' in lines[0]:
        raise InternalError(lines[0])

    # Strip leading and trailing spaces from lines...
    for lineno in range(0, len(lines)):
        line = lines[lineno].strip()
        if line.endswith(','):
            line = line[:-1]
        lines[lineno] = line

    tinfo = {}
    c_name = ''

    for lineno in range(0, len(lines)):

        line = lines[lineno]

        # Handle ..._alias_data
        if '_alias_data[]' in line:
            lookfor = 'static char '
            pos1 = line.find(lookfor) + len(lookfor)
            pos2 = line.find('_alias_data')
            c_name = line[pos1:pos2]
            pos1 = line.find('[] = "') + 6
            pos2 = line.find('";')
            alias_data = line[pos1:pos2]
            tinfo['alias_data'] = alias_data
            tinfo['termname'] = termname
            tinfo['c_name'] = c_name
            continue

        if not c_name:
            continue

        # Handle escape formats...
        lookfor = 'static char ' + c_name + '_s_'
        pos1 = line.find(lookfor)
        if pos1 >= 0:
            line = line[pos1 + len(lookfor):]
            pos2 = line.find('[] =')
            key = line[:pos2]
            pos3 = pos2 + 5
            pos4 = line.find('";')
            evalstr = line[pos3:pos4 + 1]
            val = eval(evalstr)
            tinfo[key] = val
            continue

        # Handle boolean and numeric values...
        if '/*' in line and '*/' in line:
            pos1 = line.find(': ') + 2
            pos2 = line[pos1:].find(' ') + pos1
            key = line[pos1:pos2]
            pos1 = line.find('*/') + 2
            line = line[pos1:]
            pos2 = line.find(',') + pos1
            val = line[:pos2]
            while val and val[0] in ' \t':
                val = val[1:]
            if val == 'ABSENT_NUMERIC':
                continue
            elif val == 'FALSE':
                val = False
            elif val == 'TRUE':
                val = True
            elif isInt(val):
                val = int(val)
            else:
                raise InternalError('Unexpected format at line %d: %s' %
                                    (lineno + 1, repr(line)))
            tinfo[key] = val
            continue

        # Finished if we've got to the pointers...
        if 'static char * ' in line:
            break

    return DotDict(tinfo)
コード例 #20
0
 def resolve_names(self, scope):
     # raise NotImplementedError.new
     raise InternalError(
         f'resolve names not implemented for: {self.__class__.__name__}')
コード例 #21
0
 def check_types(self):
     # raise NotImplementedError
     raise InternalError(
         f'check_types not implemented for {self.__class__}')
コード例 #22
0
ファイル: cli.py プロジェクト: AvidehST/freeipa
    textui,
    console,
    help,
    show_mappings,
)


def run(api):
    error = None
    try:
        (options, argv) = api.bootstrap_with_global_options(context='cli')
        for klass in cli_plugins:
            api.register(klass)
        api.load_plugins()
        api.finalize()
        if not 'config_loaded' in api.env:
            raise NotConfiguredError()
        sys.exit(api.Backend.cli.run(argv))
    except KeyboardInterrupt:
        print ''
        api.log.info('operation aborted')
    except PublicError, e:
        error = e
    except StandardError, e:
        api.log.exception('%s: %s', e.__class__.__name__, str(e))
        error = InternalError()
    if error is not None:
        assert isinstance(error, PublicError)
        api.log.error(error.strerror)
        sys.exit(error.rval)