Beispiel #1
0
 def operator_ior(size):
     a = Array(size, 'int32')
     b = Array(size, 'int32')
     for i in range(size):
         a[i] = nb_types.int32(i)
         b[i] = nb_types.int32(size-i-1)
     operator.ior(a, b)
     return a
Beispiel #2
0
 def test_inplace(self):
     #operator = self.module
     class C(object):
         def __iadd__     (self, other): return "iadd"
         def __iand__     (self, other): return "iand"
         def __ifloordiv__(self, other): return "ifloordiv"
         def __ilshift__  (self, other): return "ilshift"
         def __imod__     (self, other): return "imod"
         def __imul__     (self, other): return "imul"
         def __ior__      (self, other): return "ior"
         def __ipow__     (self, other): return "ipow"
         def __irshift__  (self, other): return "irshift"
         def __isub__     (self, other): return "isub"
         def __itruediv__ (self, other): return "itruediv"
         def __ixor__     (self, other): return "ixor"
         def __getitem__(self, other): return 5  # so that C is a sequence
     c = C()
     self.assertEqual(operator.iadd     (c, 5), "iadd")
     self.assertEqual(operator.iand     (c, 5), "iand")
     self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
     self.assertEqual(operator.ilshift  (c, 5), "ilshift")
     self.assertEqual(operator.imod     (c, 5), "imod")
     self.assertEqual(operator.imul     (c, 5), "imul")
     self.assertEqual(operator.ior      (c, 5), "ior")
     self.assertEqual(operator.ipow     (c, 5), "ipow")
     self.assertEqual(operator.irshift  (c, 5), "irshift")
     self.assertEqual(operator.isub     (c, 5), "isub")
     self.assertEqual(operator.itruediv (c, 5), "itruediv")
     self.assertEqual(operator.ixor     (c, 5), "ixor")
     self.assertEqual(operator.iconcat  (c, c), "iadd")
Beispiel #3
0
 def put_(self, args):
     """PUT: Put a sprite on the screen."""
     if self._mode.is_text_mode:
         raise error.BASICError(error.IFC)
     x0, y0 = (values.to_single(_arg).to_value() for _arg in islice(args, 2))
     array_name, operation_token = args
     array_name = self._memory.complete_name(array_name)
     operation_token = operation_token or tk.XOR
     if array_name not in self._memory.arrays:
         raise error.BASICError(error.IFC)
     elif array_name[-1:] == values.STR:
         raise error.BASICError(error.TYPE_MISMATCH)
     x0, y0 = self._get_window_physical(x0, y0)
     self._last_point = x0, y0
     packed_sprite = self._memory.arrays.view_full_buffer(array_name)
     sprite = self._mode.sprite_builder.unpack(packed_sprite)
     x1, y1 = x0 + sprite.width - 1, y0 + sprite.height - 1
     # the whole sprite must fit or it's IFC
     error.throw_if(not self.graph_view.contains(x0, y0))
     error.throw_if(not self.graph_view.contains(x1, y1))
     # apply the sprite to the screen
     if operation_token == tk.PSET:
         rect = sprite
     elif operation_token == tk.PRESET:
         rect = sprite ^ (2**self._mode.bitsperpixel - 1)
     elif operation_token == tk.AND:
         # we use in-place operations as we'll assign back anyway
         rect = operator.iand(self.graph_view[y0:y1+1, x0:x1+1], sprite)
     elif operation_token == tk.OR:
         rect = operator.ior(self.graph_view[y0:y1+1, x0:x1+1], sprite)
     elif operation_token == tk.XOR:
         rect = operator.ixor(self.graph_view[y0:y1+1, x0:x1+1], sprite)
     self.graph_view[y0:y1+1, x0:x1+1] = rect
def get_permission_mask(*args) -> Optional[int]:
    p_masks = []
    for arg in args:
        if type(arg) == str and PMask.has_key(arg.upper()):
            p_masks.append(arg.upper())
        else:
            return
    return functools.reduce(lambda a, b: operator.ior(a, PMask[b]), p_masks, 0)
Beispiel #5
0
 def register_poller(self, zmq_socket, sock_fd, poll_type, callback):
     self.poller_handler.setdefault(zmq_socket, {})[poll_type] = callback
     if sock_fd in self.__registered:
         self.poller.modify(
             zmq_socket,
             operator.ior(*self.poller_handler[zmq_socket].keys()))
     else:
         self.poller.register(zmq_socket, poll_type)
         self.__registered.add(sock_fd)
Beispiel #6
0
 	def tune(self, lowByte):
     	print "\nTuning........."
     	self.i2c.writeList(self.WB_TUNE_FREQ,[0x00, self.freqHighByte, lowByte])
     	time.sleep(self.TUNE_DELAY)
     	#print hex(self.intStatus), hex(self.INTAVL)
     	self.intStatus = operator.ior(self.intStatus, self.INTAVL)
     	#print hex(self.intStatus)
     	self.getTuneStatus(self.INTACK)
     	return
Beispiel #7
0
    def test_inplace(self):
        #operator = self.module
        class C(object):
            def __iadd__(self, other):
                return "iadd"

            def __iand__(self, other):
                return "iand"

            def __ifloordiv__(self, other):
                return "ifloordiv"

            def __ilshift__(self, other):
                return "ilshift"

            def __imod__(self, other):
                return "imod"

            def __imul__(self, other):
                return "imul"

            def __ior__(self, other):
                return "ior"

            def __ipow__(self, other):
                return "ipow"

            def __irshift__(self, other):
                return "irshift"

            def __isub__(self, other):
                return "isub"

            def __itruediv__(self, other):
                return "itruediv"

            def __ixor__(self, other):
                return "ixor"

            def __getitem__(self, other):
                return 5  # so that C is a sequence

        c = C()
        self.assertEqual(operator.iadd(c, 5), "iadd")
        self.assertEqual(operator.iand(c, 5), "iand")
        self.assertEqual(operator.ifloordiv(c, 5), "ifloordiv")
        self.assertEqual(operator.ilshift(c, 5), "ilshift")
        self.assertEqual(operator.imod(c, 5), "imod")
        self.assertEqual(operator.imul(c, 5), "imul")
        self.assertEqual(operator.ior(c, 5), "ior")
        self.assertEqual(operator.ipow(c, 5), "ipow")
        self.assertEqual(operator.irshift(c, 5), "irshift")
        self.assertEqual(operator.isub(c, 5), "isub")
        self.assertEqual(operator.itruediv(c, 5), "itruediv")
        self.assertEqual(operator.ixor(c, 5), "ixor")
        self.assertEqual(operator.iconcat(c, c), "iadd")
Beispiel #8
0
 def tune(self, lowByte):
     print "\nTuning........."
     self.i2c.writeList(self.WB_TUNE_FREQ,
                        [0x00, self.freqHighByte, lowByte])
     time.sleep(self.TUNE_DELAY)
     #print hex(self.intStatus), hex(self.INTAVL)
     self.intStatus = operator.ior(self.intStatus, self.INTAVL)
     #print hex(self.intStatus)
     self.getTuneStatus(self.INTACK)
     return
Beispiel #9
0
    def getProperty(self, prop):
        value = 0x0000

        self.i2c.write16(self.GET_PROPERTY, prop)

        self.response = self.i2c.readList(0, 3)

        value = operator.ior(value, self.response[2] << 8 | self.response[3])

        return value
Beispiel #10
0
    	def getProperty(self, prop):
        	value = 0x0000

        	self.i2c.write16(self.GET_PROPERTY, prop);

        	self.response = self.i2c.readList(0,3);

        	value = operator.ior(value, self.response[2] << 8 | self.response[3])

        	return value
Beispiel #11
0
    def __init__(self, *args):

        # if only one argument is provided and it's not a feature-value,
        # assume it's a container of values.
        if len(args) == 1 and not isinstance(args[0], value):
            args = args[0]

        self._features = {}
        self._delayed = []
        self._conditionals = []
        reduce(lambda s, a: ior(s, a), args, self)
Beispiel #12
0
def user_list(order_by='last_name', or_clause=None, **and_clause):

    and_clause.update({'profile__pk__isnull': False})

    l1 = [Q(**{k: v}) for k, v in and_clause.items()]
    if or_clause:
        l2 = [Q(**{k: v}) for k, v in or_clause.items()]
        filter = ior(reduce(iand, l1), reduce(iand, l2))
    else:
        filter = reduce(iand, l1)

    return [serialize(user) for user in User.objects.filter(filter).order_by(order_by)]
Beispiel #13
0
    def sameRead(self):
        value = 0x00

        if (self.rxBufferIndex < self.rxBufferLength):
            value = self.rxBuffer[self.rxBufferIndex]
            self.rxBufferIndex += 1

        else:
            self.rxBufferIndex, self.rxBufferLength = 0
            self.msgStatus = operator.ior(self.msgStatus, self.MSGUSD)

        return chr(value)
Beispiel #14
0
    	def sameRead(self):
        	value = 0x00

        	if (self.rxBufferIndex < self.rxBufferLength):
            		value = self.rxBuffer[self.rxBufferIndex]
			self.rxBufferIndex += 1

        	else:
            		self.rxBufferIndex, self.rxBufferLength = 0
            		self.msgStatus = operator.ior(self.msgStatus, self.MSGUSD)

        	return chr(value)
    def test_class_binary_inplace_operators(self):
        class WithLotsOfOperators(Class):
            def __iadd__(self, other):
                return (self, "iadd", other)

            def __isub__(self, other):
                return (self, "isub", other)

            def __imul__(self, other):
                return (self, "imul", other)

            def __imod__(self, other):
                return (self, "imod", other)

            def __itruediv__(self, other):
                return (self, "itruediv", other)

            def __ifloordiv__(self, other):
                return (self, "ifloordiv", other)

            def __ilshift__(self, other):
                return (self, "ilshift", other)

            def __irshift__(self, other):
                return (self, "irshift", other)

            def __ior__(self, other):
                return (self, "ior", other)

            def __iand__(self, other):
                return (self, "iand", other)

            def __ixor__(self, other):
                return (self, "ixor", other)

            def __imatmul__(self, other):
                return (self, "imatmul", other)

        c = WithLotsOfOperators()

        self.assertEqual(operator.iadd(c, 0), (c, "iadd", 0))
        self.assertEqual(operator.isub(c, 0), (c, "isub", 0))
        self.assertEqual(operator.imul(c, 0), (c, "imul", 0))
        self.assertEqual(operator.imod(c, 0), (c, "imod", 0))
        self.assertEqual(operator.itruediv(c, 0), (c, "itruediv", 0))
        self.assertEqual(operator.ifloordiv(c, 0), (c, "ifloordiv", 0))
        self.assertEqual(operator.ilshift(c, 0), (c, "ilshift", 0))
        self.assertEqual(operator.irshift(c, 0), (c, "irshift", 0))
        self.assertEqual(operator.ior(c, 0), (c, "ior", 0))
        self.assertEqual(operator.iand(c, 0), (c, "iand", 0))
        self.assertEqual(operator.ixor(c, 0), (c, "ixor", 0))
        self.assertEqual(operator.imatmul(c, 0), (c, "imatmul", 0))
Beispiel #16
0
def list_all_datasets(request, *args, **kwargs):
    user, profile = user_and_profile(request)
    # Réservé aux référents ou administrateurs IDGO
    roles = profile.get_roles()
    if roles['is_admin']:
        QuerySet = Dataset.default.all()
    elif roles['is_referent']:
        kwargs = {'profile': profile, 'validated_on__isnull': False}
        organisation__in = set(instance.organisation for instance
                               in LiaisonsReferents.objects.filter(**kwargs))
        filter = ior(Q(editor=user), Q(organisation__in=organisation__in))
        QuerySet = Dataset.default.filter(filter)
    else:
        raise Http404()
    context = handle_context(
        QuerySet, request.GET, target='all')
    return render_with_info_profile(
        request, 'idgo_admin/dataset/datasets.html', status=200, context=context)
Beispiel #17
0
    def scan(self):
        i = 0
        best_channel = 0
        best_rssi = 0x00

        self.setMute(self.ON)

        for i in range(0, 7):
            self.currentFreq = i
            self.tune(self.freqLowByte[i])

        if (self.rssi > best_rssi):
            best_rssi = self.rssi
            best_channel = i

        self.currentFreq = best_channel
        self.tune(self.freqLowByte[best_channel])
        self.setMute(self.OFF)
        self.intStatus = operator.ior(self.intStatus, self.INTAVL)
Beispiel #18
0
    	def scan(self):
        	i = 0
        	best_channel = 0
        	best_rssi = 0x00

        	self.setMute(self.ON);

        	for i in range(0,7):
            		self.currentFreq = i
            		self.tune(self.freqLowByte[i]);

            	if (self.rssi > best_rssi):
                	best_rssi = self.rssi
                	best_channel = i

        	self.currentFreq = best_channel
        	self.tune(self.freqLowByte[best_channel]);
        	self.setMute(self.OFF);
        	self.intStatus  = operator.ior(self.intStatus,self.INTAVL)
Beispiel #19
0
def list_all_datasets(request, *args, **kwargs):
    user = request.user
    # Réservé aux référents ou administrateurs métiers
    roles = user.profile.get_roles()
    if roles['is_admin']:
        QuerySet = Dataset.default.all()
    elif roles['is_referent']:
        organisation__in = Organisation.extras.get_subordinated_organisations(
            user.profile)
        filter = ior(Q(editor=request.user),
                     Q(organisation__in=organisation__in))
        QuerySet = Dataset.default.filter(filter)
    else:
        raise Http404()
    context = handle_context(QuerySet, request.GET, target='all')
    return render(request,
                  'idgo_admin/dataset/datasets.html',
                  status=200,
                  context=context)
Beispiel #20
0
def iadd(a: Accumulatable, b: Accumulatable) -> Accumulatable:
    """Add two accumulatables together, assuming the first is mutable"""
    if isinstance(a, Addable) and isinstance(b, Addable):
        return operator.iadd(a, b)
    elif isinstance(a, MutableSet) and isinstance(b, MutableSet):
        return operator.ior(a, b)
    elif isinstance(a, MutableMapping) and isinstance(b, MutableMapping):
        if not isinstance(b, type(a)):
            raise ValueError(
                f"Cannot add two mappings of incompatible type ({type(a)} vs. {type(b)})"
            )
        lhs, rhs = set(a), set(b)
        for key in lhs & rhs:
            a[key] = iadd(a[key], b[key])
        for key in rhs - lhs:
            a[key] = copy.deepcopy(b[key])
        return a
    raise ValueError(
        f"Cannot add accumulators of incompatible type ({type(a)} vs. {type(b)})"
    )
Beispiel #21
0
 def update_event(self, inp=-1):
     self.set_output_val(0, operator.ior(self.input(0), self.input(1)))
Beispiel #22
0
    def getSameStatus(self, mode):
        i = 0

        markChar = 0

        self.i2c.writeList(self.WB_SAME_STATUS, [mode, 0x00])
        self.response = self.i2c.readList(0, 4)

        self.sameStatus = self.response[1]
        self.sameState = self.response[2]
        self.sameLength = self.response[3]

        if (not (self.sameStatus & self.HDRRDY)):
            return  #  If no HDRRDY, return.

        #TIMER1_START();                #  Start/Re-start the 6 second timer.

        self.sameHeaderCount += 1
        #print self.sameHeaderCount

        if (
                self.sameHeaderCount >= 3
        ):  #  If this is the third Header, set msgStatus to show that it needs to be purged after usage.
            #self.msgStatus = operator.ior(self.msgStatus, self.MSGAVL)
            self.msgStatus = operator.ior(self.msgStatus, self.MSGPUR)

        if (self.sameLength < self.SAME_MIN_LENGTH):
            return  #  Don't process messages that are too short to be valid.

        for i in range(0, self.sameLength, 8):
            self.i2c.writeList(self.WB_SAME_STATUS, [self.CHECK, i])

            self.response = self.i2c.readList(0, 14)

            self.sameConf[0] = (self.response[5] & self.SAME_STATUS_OUT_CONF0
                                ) >> self.SAME_STATUS_OUT_CONF0_SHFT
            self.sameConf[1] = (self.response[5] & self.SAME_STATUS_OUT_CONF1
                                ) >> self.SAME_STATUS_OUT_CONF1_SHFT
            self.sameConf[2] = (self.response[5] & self.SAME_STATUS_OUT_CONF2
                                ) >> self.SAME_STATUS_OUT_CONF2_SHFT
            self.sameConf[3] = (self.response[5] & self.SAME_STATUS_OUT_CONF3
                                ) >> self.SAME_STATUS_OUT_CONF3_SHFT
            self.sameConf[4] = (self.response[4] & self.SAME_STATUS_OUT_CONF4
                                ) >> self.SAME_STATUS_OUT_CONF4_SHFT
            self.sameConf[5] = (self.response[4] & self.SAME_STATUS_OUT_CONF5
                                ) >> self.SAME_STATUS_OUT_CONF5_SHFT
            self.sameConf[6] = (self.response[4] & self.SAME_STATUS_OUT_CONF6
                                ) >> self.SAME_STATUS_OUT_CONF6_SHFT
            self.sameConf[7] = (self.response[4] & self.SAME_STATUS_OUT_CONF7
                                ) >> self.SAME_STATUS_OUT_CONF7_SHFT

            self.sameData[0] = self.response[6]
            self.sameData[1] = self.response[7]
            self.sameData[2] = self.response[8]
            self.sameData[3] = self.response[9]
            self.sameData[4] = self.response[10]
            self.sameData[5] = self.response[11]
            self.sameData[6] = self.response[12]
            self.sameData[7] = self.response[13]
            j = 0
            for j in range(0, 8):
                self.rxBuffer[j + i] = self.sameData[j]
                self.rxConfidence[j + i] = self.sameConf[j]

                if (self.rxBuffer[j + i] == 47):  # "/" symbol in callsign
                    markChar = 1

                if ((self.rxBuffer[j + i] == 45) and (markChar)):
                    self.sameLength = (j + i)
                    break

        self.msgStatus = operator.ior(self.msgStatus, self.MSGAVL)

        i = 0

        for i in range(0, self.sameLength):

            if (self.rxConfidence[i] < self.SAME_CONFIDENCE_THRESHOLD):
                self.msgStatus = operator.iand(self.msgStatus, ~self.MSGAVL)

        if (not (self.msgStatus & self.MSGAVL)):
            return

        self.rxBufferIndex = 0
        self.rxBufferLength = self.sameLength
        print ' '
        for i in range(0, self.rxBufferLength):
            sys.stdout.write(chr(self.rxBuffer[i])),

        confStr = '\n'
        for i in range(0, self.rxBufferLength):
            confStr += str(self.rxConfidence[i])

        print confString
Beispiel #23
0
a = 3
b = 2
print(operator.ipow(a, b))

"""9.iand() :- This function is used to assign and bitwise and the current value. This operation does “a &= b” operation. Assigning is not performed in case of
immutable containers, such as strings, numbers and tuples"""

a = 1
b = 1
print(operator.iand(a, b))

"""10.ior()-  This function is used to assign and bitwise or the current value. This operation does “a |=b ” operation. Assigning is not performed in case of
immutable containers, such as strings, numbers and tuples."""
a = 5
b = 1
print(operator.ior(a, b))

"""11.ilshift()-This function is used to assign and bitwise leftshift the current value by second argument. This operation does “a <<=b ” operation. Assigning is not
performed in case of immutable containers, such as strings, numbers and tuples."""

a = 3
b = 2
print(operator.ilshift(a, b))

"""12.irshift()- This function is used to assign and bitwise rightshift the current value by second argument. This operation does “a >>=b ” operation. Assigning is not
performed in case of immutable containers, such as strings, numbers and tuples."""

a = 4
b = 1
print(operator.irshift(a, b))
Beispiel #24
0
 def bitwise_ior_usecase(x, y):
     return operator.ior(x, y)
print(li)
operator.delitem(li, slice(1, 4))
print(li)
print(operator.getitem(li, slice(0, 2)))
s1 = "testing "
s2 = "operator"
print(operator.concat(s1, s2))
if (operator.contains(s1, s2)):
    print("Contains")
else:
    print("It doesn't")
a = 1
b = 0
print(operator.and_(a, b))
print(operator.or_(a, b))
print(operator.invert(a))

x = 10
y = 5
print(operator.iadd(x, y))
print(operator.isub(x, y))
print(operator.iconcat(s1, s2))
print(operator.imul(x, y))
print(operator.itruediv(x, y))
print(operator.imod(x, y))
print(operator.ixor(x, y))
print(operator.ipow(x, y))
print(operator.iand(x, y))
print(operator.ior(x, y))
print(operator.ilshift(x, y))
print(operator.irshift(x, y))
Beispiel #26
0
 def bitwise_ior_usecase(x, y):
     return operator.ior(x, y)
Beispiel #27
0
a = 9
b = operator.itruediv(a, 2)
print a
print b

#将与自身的值相与的值赋给自身 同 &=
#但是不改变自身的值,返回值返回相与的结果
a = 8
b = operator.iand(a, 1)
print a
print b

#将与自身的值相或的值赋给自身 同 |=
#但是不改变自身的值,返回值返回相或的结果
a = 8
b = operator.ior(a, 1)
print a
print b

#将与自身的值相异或的值赋给自身 同 ^=
#但是不改变自身的值,返回值返回相异或的结果
a = 8
b = operator.ixor(a, 1)
print a
print b

#将与自身相除取整的值赋给自身 同 /=
#但是不改变自身的值,返回值返回相除的结果
a = 9
b = operator.idiv(a, 4)
print a
Beispiel #28
0
    	def getSameStatus(self, mode):
        	i = 0
		
		markChar = 0

        	self.i2c.writeList(self.WB_SAME_STATUS,[mode, 0x00])
        	self.response = self.i2c.readList(0, 4)

        	self.sameStatus = self.response[1]
        	self.sameState  = self.response[2]
        	self.sameLength = self.response[3]


        	if (not(self.sameStatus & self.HDRRDY)):
			return                  #  If no HDRRDY, return.

        	#TIMER1_START();                #  Start/Re-start the 6 second timer.

        	self.sameHeaderCount += 1
                #print self.sameHeaderCount
        	
		if (self.sameHeaderCount >= 3): #  If this is the third Header, set msgStatus to show that it needs to be purged after usage.
			#self.msgStatus = operator.ior(self.msgStatus, self.MSGAVL)
			self.msgStatus = operator.ior(self.msgStatus,self.MSGPUR)

        	if (self.sameLength < self.SAME_MIN_LENGTH):
			return  #  Don't process messages that are too short to be valid.

        	for i in range(0, self.sameLength, 8):
			self.i2c.writeList(self.WB_SAME_STATUS, [self.CHECK, i])

            		self.response = self.i2c.readList(0, 14)


            		self.sameConf[0] = (self.response[5] & self.SAME_STATUS_OUT_CONF0) >> self.SAME_STATUS_OUT_CONF0_SHFT
			self.sameConf[1] = (self.response[5] & self.SAME_STATUS_OUT_CONF1) >> self.SAME_STATUS_OUT_CONF1_SHFT
            		self.sameConf[2] = (self.response[5] & self.SAME_STATUS_OUT_CONF2) >> self.SAME_STATUS_OUT_CONF2_SHFT
            		self.sameConf[3] = (self.response[5] & self.SAME_STATUS_OUT_CONF3) >> self.SAME_STATUS_OUT_CONF3_SHFT
            		self.sameConf[4] = (self.response[4] & self.SAME_STATUS_OUT_CONF4) >> self.SAME_STATUS_OUT_CONF4_SHFT
            		self.sameConf[5] = (self.response[4] & self.SAME_STATUS_OUT_CONF5) >> self.SAME_STATUS_OUT_CONF5_SHFT
            		self.sameConf[6] = (self.response[4] & self.SAME_STATUS_OUT_CONF6) >> self.SAME_STATUS_OUT_CONF6_SHFT
            		self.sameConf[7] = (self.response[4] & self.SAME_STATUS_OUT_CONF7) >> self.SAME_STATUS_OUT_CONF7_SHFT

            		self.sameData[0] = self.response[6]
            		self.sameData[1] = self.response[7]
            		self.sameData[2] = self.response[8]
            		self.sameData[3] = self.response[9]
            		self.sameData[4] = self.response[10]
            		self.sameData[5] = self.response[11]
            		self.sameData[6] = self.response[12]
            		self.sameData[7] = self.response[13]
            		j = 0
            		for j in range (0,8):
                		self.rxBuffer[j + i] = self.sameData[j]
                		self.rxConfidence[j + i] = self.sameConf[j]

                		if (self.rxBuffer[j + i] == 47): # "/" symbol in callsign
					markChar = 1
				
				if ((self.rxBuffer[j + i] == 45) and (markChar)):
					self.sameLength = (j + i)
                    			break
                
        	self.msgStatus = operator.ior(self.msgStatus, self.MSGAVL)
		
        	i = 0 
                  
        
        	for i in range(0,self.sameLength):
            		
        		if (self.rxConfidence[i] < self.SAME_CONFIDENCE_THRESHOLD):
                      		self.msgStatus = operator.iand(self.msgStatus, ~self.MSGAVL)
				                                         


        	if (not(self.msgStatus & self.MSGAVL)):
			return

        	self.rxBufferIndex = 0
        	self.rxBufferLength = self.sameLength
                print ' '
                for i in range(0, self.rxBufferLength):
                        sys.stdout.write (chr(self.rxBuffer[i])), 
                
                confStr = '\n'
                for i in range(0, self.rxBufferLength):
                        confStr += str(self.rxConfidence[i])
				
		print confString
Beispiel #29
0
# using ixor() to exclusive or and assign value
x = operator.ixor(x, y)
print("The value after xoring and assigning : ", end="")
print(x)

# using ipow() to exponentiate and assign value
x = 5
y = 4
x = operator.ipow(x, y)
print("The value after exponentiating and assigning : ", end="")
print(x)

# using ior() to or, and assign value
x = 10
y = 5
x = operator.ior(x, y)
print("The value after bitwise or, and assigning : ", end="")
print(x)

x = 5
y = 4
x = operator.iand(x, y)
print("The value after bitwise and, and assigning : ", end="")
print(x)

#%%
''' ilshift() :- This function is used to assign and bitwise 
    leftshift the current value by second argument.'''

import operator
Beispiel #30
0
a = 9
b = operator.itruediv(a,2)
print a
print b

#将与自身的值相与的值赋给自身 同 &=
#但是不改变自身的值,返回值返回相与的结果
a = 8
b = operator.iand(a,1)
print a
print b

#将与自身的值相或的值赋给自身 同 |=
#但是不改变自身的值,返回值返回相或的结果
a = 8
b = operator.ior(a,1)
print a
print b

#将与自身的值相异或的值赋给自身 同 ^=
#但是不改变自身的值,返回值返回相异或的结果
a = 8
b = operator.ixor(a,1)
print a
print b

#将与自身相除取整的值赋给自身 同 /=
#但是不改变自身的值,返回值返回相除的结果
a = 9
b = operator.idiv(a,4)
print a
Beispiel #31
0
 def __ior__(self, other):
     return operator.ior(self._wrapped(), other)
Beispiel #32
0
    def sameParse(self):
        self.finalMsg = []

        i = 0
        for i in range(0, self.sameLength):
            self.finalMsg.append(chr(self.rxBuffer[i]))
            time.sleep(0.02)

        if (not (self.msgStatus
                 & self.MSGAVL)):  #  If no message is Available, return
            return

        self.samePlusIndex = int(0)
        self.sameLocations = int(0)
        self.sameDuration = int(0)
        self.sameDay = int(0)
        self.sameTime = int(0)

        i = 0

        self.sameOriginatorName[0] = chr(self.rxBuffer[i + 1])
        self.sameOriginatorName[1] = chr(self.rxBuffer[i + 2])
        self.sameOriginatorName[2] = chr(self.rxBuffer[i + 3])
        self.sameOriginatorName[3] = chr(32)

        self.sameEventName[0] = chr(self.rxBuffer[i + 5])
        self.sameEventName[1] = chr(self.rxBuffer[i + 6])
        self.sameEventName[2] = chr(self.rxBuffer[i + 7])
        self.sameEventName[3] = chr(32)

        for i in range(0, len(self.rxBuffer)):  #  Look for the Plus Sign.
            if (self.rxBuffer[i] == 43):
                self.samePlusIndex = i  #  Found it.

                if (self.rxBuffer[i] >= 0x30 and self.rxBuffer[i] <= 0x39
                    ):  #  If the value is ascii, strip off the upper bits.
                    self.rxBuffer[i] = self.rxBuffer[i] & 0x0F

        #print "Found + sign:", self.samePlusIndex
        if (self.samePlusIndex == 0):
            return  #  No Plus Sign found.

        self.sameLocationCodes = []
        for i in range(
                6, self.samePlusIndex
        ):  #  There are no sameLocationCodes past the samePlusIndex.
            if (self.rxBuffer[i] == 45):
                self.tempLocation = [None
                                     ] * 7  #  Clear out any remaining data.
                self.tempLocation[0] = chr(self.rxBuffer[i + 1])
                self.tempLocation[1] = chr(self.rxBuffer[i + 2])
                self.tempLocation[2] = chr(self.rxBuffer[i + 3])
                self.tempLocation[3] = chr(self.rxBuffer[i + 4])
                self.tempLocation[4] = chr(self.rxBuffer[i + 5])
                self.tempLocation[5] = chr(self.rxBuffer[i + 6])
                self.tempLocation[6] = chr(32)
                self.sameLocationCodes.append(''.join(self.tempLocation))
                self.sameLocations += 1

                if (self.sameLocations > self.SAME_LOCATION_CODES
                    ):  #  SAME_LOCATION_CODES (31) is the maximum allowed.
                    break

        self.sameDuration = [None] * 5
        self.sameDuration[0] = chr(self.rxBuffer[self.samePlusIndex + 1])
        self.sameDuration[1] = chr(self.rxBuffer[self.samePlusIndex + 2])
        self.sameDuration[2] = chr(self.rxBuffer[self.samePlusIndex + 3])
        self.sameDuration[3] = chr(self.rxBuffer[self.samePlusIndex + 4])
        self.sameDuration[4] = chr(32)

        self.sameDay = [None] * 4
        self.sameDay[0] = chr(self.rxBuffer[self.samePlusIndex + 6])
        self.sameDay[1] = chr(self.rxBuffer[self.samePlusIndex + 7])
        self.sameDay[2] = chr(self.rxBuffer[self.samePlusIndex + 8])
        self.sameDay[3] = chr(32)

        self.sameTime = [None] * 5
        self.sameTime[0] = chr(self.rxBuffer[self.samePlusIndex + 9])
        self.sameTime[1] = chr(self.rxBuffer[self.samePlusIndex + 10])
        self.sameTime[2] = chr(self.rxBuffer[self.samePlusIndex + 11])
        self.sameTime[3] = chr(self.rxBuffer[self.samePlusIndex + 12])
        self.sameTime[4] = chr(32)

        i = 0

        for i in range(0, 9):
            if (self.rxBuffer[i + self.samePlusIndex + 14] == 45):
                self.sameCallSign[i] = chr(32)
                self.endMsgFlag = int(i + self.samePlusIndex + 14)
            else:
                self.sameCallSign[i] = chr(
                    self.rxBuffer[i + self.samePlusIndex + 14])

        self.msgStatus = operator.ior(
            self.msgStatus,
            (self.MSGUSD | self.MSGPAR
             ))  # Set the status to show the message was successfully Parsed.

        return
Beispiel #33
0
    def handle(self, request, *args, **kwargs):

        user = request.user
        if user.is_anonymous:
            profile = None
        else:
            try:
                profile = get_object_or_404(Profile, user=user)
            except Exception:
                raise ProfileHttp404

        qs = request.POST or request.GET

        outputformat = qs.get('format')
        if not outputformat or outputformat not in ('odl', 'datasud'):
            raise Http404()

        if outputformat == 'odl':
            annotate = OrderedDict((
                ('COLL_NOM', COLL_NOM),
                ('COLL_SIRET', COLL_SIRET),
                ('ID', ID),
                ('TITRE', TITRE),
                ('DESCRIPTION', DESCRIPTION),
                ('THEME', THEME),
                # ('DIFFUSEUR', DIFFUSEUR),
                ('PRODUCTEUR_NOM', PRODUCTEUR_NOM),
                ('PRODUCTEUR_SIRET', PRODUCTEUR_SIRET),
                ('COUV_SPAT_MAILLE', COUV_SPAT_MAILLE),
                ('COUV_SPAT_NOM', COUV_SPAT_NOM),
                ('COUV_TEMP_DEBUT', COUV_TEMP_DEBUT),
                ('COUV_TEMP_FIN', COUV_TEMP_DEBUT),
                ('DATE_PUBL', DATE_PUBL),
                ('FREQ_MAJ', FREQ_MAJ),
                ('DATE_MAJ', DATE_MAJ),
                ('MOTS_CLES', MOTS_CLES),
                ('LICENCE', LICENCE),
                ('NOMBRE_RESSOURCES', NOMBRE_RESSOURCES),
                ('FORMAT_RESSOURCES', FORMAT_RESSOURCES),
                # ('PROJECTION', PROJECTION),
                # ('LANG', LANG),
                ('URL', URL)))
        else:
            annotate = OrderedDict((
                ('COLL_NOM', COLL_NOM),
                ('COLL_SIRET', COLL_SIRET),
                ('ID', ID),
                ('TITRE', TITRE),
                ('DESCRIPTION', DESCRIPTION),
                ('THEME', THEME),
                ('PRODUCTEUR_NOM', PRODUCTEUR_NOM),
                ('PRODUCTEUR_SIRET', PRODUCTEUR_SIRET),
                ('COUV_SPAT_MAILLE', COUV_SPAT_MAILLE),
                ('COUV_SPAT_NOM', COUV_SPAT_NOM),
                ('COUV_TEMP_DEBUT', COUV_TEMP_DEBUT),
                ('COUV_TEMP_FIN', COUV_TEMP_DEBUT),
                ('DATE_PUBL', DATE_PUBL),
                ('FREQ_MAJ', FREQ_MAJ),
                ('DATE_MAJ', DATE_MAJ),
                ('MOTS_CLES', MOTS_CLES),
                ('LICENCE', LICENCE),
                ('NOMBRE_RESSOURCES', NOMBRE_RESSOURCES),
                ('FORMAT_RESSOURCES', FORMAT_RESSOURCES),
                ('URL', URL),
                ('DATASUD_ID', DATASUD_ID),
                # ('DATASUD_MOT_CLES', DATASUD_MOT_CLES),
                # ('DATASUD_ORGA', DATASUD_ORGA),
                ('DATASUD_ORGA_ID', DATASUD_ORGA_ID),
                ('DATASUD_ORGA_URL', DATASUD_ORGA_URL),
                ('DATASUD_PRODUCTEUR_NOM', DATASUD_PRODUCTEUR_NOM),
                # ('DATASUD_PRODUCTEUR_EMAIL', DATASUD_PRODUCTEUR_EMAIL),
                ('DATASUD_DIFFUSEUR_NOM', DATASUD_DIFFUSEUR_NOM),
                # ('DATASUD_DIFFUSEUR_EMAIL', DATASUD_DIFFUSEUR_EMAIL),
                ('DATASUD_COUV_TERR', DATASUD_COUV_TERR),
                # ('DATASUD_INSPIRE', DATASUD_INSPIRE),
                # ('DATASUD_DATASET_URL', DATASUD_DATASET_URL),
                # ('DATASUD_INSPIRE_URL', DATASUD_INSPIRE_URL),
                ('DATASUD_DATE_CREATION', DATASUD_DATE_CREATION),
                # ('DATASUD_RESSOURCE_URLS', DATASUD_RESSOURCE_URLS),
                # ('DATASUD_RESSOURCE_TAILLE', DATASUD_RESSOURCE_TAILLE),
                ('DATASUD_RESSOURCE_TYPES', DATASUD_RESSOURCE_TYPES),
                ('DATASUD_DATASET_VUES', DATASUD_DATASET_VUES),
                ('DATASUD_RESSOURCES_TELECHARGEMENT',
                 DATASUD_RESSOURCES_TELECHARGEMENT),
                ('DATASUD_DATASET_NOTE', DATASUD_DATASET_NOTE),
                ('DATASUD_DATASET_NB_NOTES', DATASUD_DATASET_NB_NOTES),
                ('DIFFUSEUR', DIFFUSEUR),
                ('PROJECTION', PROJECTION),
                ('LANG', LANG),
            ))

        values = list(annotate.keys())

        if not profile:
            ids = qs.get('ids', '').split(',')
            datasets = Dataset.objects.filter(
                ckan_id__in=[UUID(id) for id in ids])
        elif 'mode' in qs:
            mode = qs.get('mode')
            if mode == 'all':
                roles = profile.get_roles()
                if roles['is_admin']:
                    QuerySet = Dataset.default.all()
                elif roles['is_referent']:
                    kwargs = {
                        'profile': profile,
                        'validated_on__isnull': False
                    }
                    organisation__in = set(
                        instance.organisation
                        for instance in LiaisonsReferents.objects.filter(
                            **kwargs))
                    filter = ior(Q(editor=user),
                                 Q(organisation__in=organisation__in))
                    QuerySet = Dataset.default.filter(filter)
            elif mode == 'mine':
                QuerySet = Dataset.default.filter(editor=user)
            elif mode == 'ckan_harvested':
                QuerySet = Dataset.harvested_ckan
            elif mode == 'csw_harvested':
                QuerySet = Dataset.harvested_csw
            else:
                raise Http404()
            datasets = get_filtered_datasets(QuerySet, qs)

        response = HttpResponse(content_type='text/csv')
        response[
            'Content-Disposition'] = 'attachment; filename=dataset_export.csv'
        response['Cache-Control'] = 'no-cache'

        writer = unicodecsv.writer(response,
                                   encoding='utf-8',
                                   quoting=csv.QUOTE_ALL,
                                   delimiter=',',
                                   quotechar='"')
        writer.writerow(values)
        for row in datasets.annotate(**annotate).values(*values):
            if not outputformat == 'odl':
                package = CkanHandler.get_package(str(row['ID']),
                                                  include_tracking=True)

                dataset_view = 0
                if 'tracking_summary' in package:
                    dataset_view = package['tracking_summary'].get('total')
                row['DATASUD_DATASET_VUES'] = dataset_view

                resources_dl = 0
                for resource in package.get('resources'):
                    if 'tracking_summary' in resource:
                        resources_dl += int(
                            resource['tracking_summary'].get('total'))
                row['DATASUD_RESSOURCES_TELECHARGEMENT'] = resources_dl
                row['DATASUD_DATASET_NOTE'] = package.get('rating')
                row['DATASUD_DATASET_NB_NOTES'] = package.get('ratings_count')

            writer.writerow([row[value] for value in values])

        return response
Beispiel #34
0
    	def sameParse(self):
        	self.finalMsg = []
        	
		i = 0
        	for i in range(0, self.sameLength):
			self.finalMsg.append(chr(self.rxBuffer[i]))
            		time.sleep(0.02)

        	if (not(self.msgStatus & self.MSGAVL)):       #  If no message is Available, return
			return

        	self.samePlusIndex = int(0)
        	self.sameLocations = int(0)
        	self.sameDuration = int(0)
        	self.sameDay = int(0)
        	self.sameTime = int(0)

        	i = 0
        	
        	self.sameOriginatorName[0] = chr(self.rxBuffer[i + 1])
        	self.sameOriginatorName[1] = chr(self.rxBuffer[i + 2])
        	self.sameOriginatorName[2] = chr(self.rxBuffer[i + 3])
        	self.sameOriginatorName[3] = chr(32)
        	
        	self.sameEventName[0] = chr(self.rxBuffer[i + 5])
        	self.sameEventName[1] = chr(self.rxBuffer[i + 6])
        	self.sameEventName[2] = chr(self.rxBuffer[i + 7])
        	self.sameEventName[3] = chr(32)
        	
        	for i in range (0, len(self.rxBuffer)):#  Look for the Plus Sign.
			if (self.rxBuffer[i] == 43):
				self.samePlusIndex = i #  Found it.


				if (self.rxBuffer[i] >= 0x30 and self.rxBuffer[i] <= 0x39):  #  If the value is ascii, strip off the upper bits.
					self.rxBuffer[i] = self.rxBuffer[i] & 0x0F

        	#print "Found + sign:", self.samePlusIndex
        	if (self.samePlusIndex == 0):
			return        #  No Plus Sign found.

        	
        	
        	self.sameLocationCodes = [] 
        	for i in range(6, self.samePlusIndex): #  There are no sameLocationCodes past the samePlusIndex.
            		if (self.rxBuffer[i] == 45):
                		self.tempLocation = [None] * 7  #  Clear out any remaining data.
                		self.tempLocation[0] = chr(self.rxBuffer[i + 1])
                		self.tempLocation[1] = chr(self.rxBuffer[i + 2])
                		self.tempLocation[2] = chr(self.rxBuffer[i + 3])
                		self.tempLocation[3] = chr(self.rxBuffer[i + 4])
                		self.tempLocation[4] = chr(self.rxBuffer[i + 5])
                		self.tempLocation[5] = chr(self.rxBuffer[i + 6])
				self.tempLocation[6] = chr(32)
                		self.sameLocationCodes.append(''.join(self.tempLocation))
                		self.sameLocations += 1

                		if (self.sameLocations > self.SAME_LOCATION_CODES): #  SAME_LOCATION_CODES (31) is the maximum allowed.
                        		break


        	self.sameDuration = [None] * 5
        	self.sameDuration[0] = chr(self.rxBuffer[self.samePlusIndex + 1])
        	self.sameDuration[1] = chr(self.rxBuffer[self.samePlusIndex + 2])
        	self.sameDuration[2] = chr(self.rxBuffer[self.samePlusIndex + 3])
        	self.sameDuration[3] = chr(self.rxBuffer[self.samePlusIndex + 4])
		self.sameDuration[4] = chr(32)

        	self.sameDay = [None] * 4
        	self.sameDay[0] = chr(self.rxBuffer[self.samePlusIndex + 6])
        	self.sameDay[1] = chr(self.rxBuffer[self.samePlusIndex + 7])
        	self.sameDay[2] = chr(self.rxBuffer[self.samePlusIndex + 8])
		self.sameDay[3] = chr(32)

        	self.sameTime = [None] * 5
        	self.sameTime[0] = chr(self.rxBuffer[self.samePlusIndex + 9])
        	self.sameTime[1] = chr(self.rxBuffer[self.samePlusIndex + 10])
        	self.sameTime[2] = chr(self.rxBuffer[self.samePlusIndex + 11])
        	self.sameTime[3] = chr(self.rxBuffer[self.samePlusIndex + 12])
		self.sameTime[4] = chr(32)

        	i = 0
        	
        	for i in range(0, 9):
			if (self.rxBuffer[i + self.samePlusIndex + 14] == 45):
                		self.sameCallSign[i] = chr(32)
                		self.endMsgFlag = int(i + self.samePlusIndex + 14)
            		else:
                		self.sameCallSign[i] = chr(self.rxBuffer[i + self.samePlusIndex + 14])

        	self.msgStatus = operator.ior(self.msgStatus,(self.MSGUSD | self.MSGPAR))     # Set the status to show the message was successfully Parsed.
        	
        	return
Beispiel #35
0
# using ixor() to exclusive or and assign value
x = operator.ixor(10, 5)

print("The value after xoring and assigning : ")
print(x)

# using ipow() to exponentiate and assign value
x = operator.ipow(5, 4)
print("The value after exponentiating and assigning : ")
print(x)

# Python code to demonstrate the working of
# ior() and iand()

# using ior() to or, and assign value
x = operator.ior(10, 5)
print("The value after bitwise or and assigning : ")
print(x)

# using iand() to and , and assign value
x = operator.iand(5, 4)
print("The value after bitwise and, and assigning : ")
print(x)

# Python code to demonstrate the working of
# ilshift() and irshift()

# using ilshift() to bitwise left shift and assign value
x = operator.ilshift(8, 2)
print("The value after bitwise left shift and assigning : ")
print(x)