Skip to content

Commit

Permalink
Add bit shifting magic methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkeene committed Jun 30, 2014
1 parent 5219a78 commit 624574d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 8 additions & 0 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,11 @@ def it_ors(self, response):
def it_xors(self, response):
assert response ^ 4 == 8
assert 8 ^ response == 4

def it_lshifts(self, response):
assert response << 3 == 96
assert 1 << response == 4096

def it_rshifts(self, response):
assert response >> 2 == 3
assert 8192 >> response == 2
17 changes: 12 additions & 5 deletions ubersmith/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,19 @@ def __xor__(self, other):
return self.data ^ other
__rxor__ = __xor__

# TODO: need to add all these methods to emulate numeric type
# __lshift__(self, other)
# __rlshift__(self, other)
# __rshift__(self, other)
# __rrshift__(self, other)
def __lshift__(self, other):
return self.data << other

def __rlshift__(self, other):
return other << self.data

def __rshift__(self, other):
return self.data >> other

def __rrshift__(self, other):
return other >> self.data

# TODO: need to add all these methods to emulate numeric type
# __pos__(self)
# __invert__(self)
# __complex__(self)
Expand Down

0 comments on commit 624574d

Please sign in to comment.