Exemple #1
0
 def post(self):
         self.response.headers['Content-Type'] = 'text/html'
         user = users.get_current_user()
         newword = self.request.get('addword')
         lexico_order=''.join(sorted(set(newword)))
         userid=users.get_current_user().email()
         userid = hashlib.sha1('%s' % (userid)).hexdigest()
         key = ndb.Key('MyList', lexico_order+userid)
         my_list = key.get()
         if my_list==None:
             my_list=MyList(id=lexico_order+userid)
             my_list.put()
         key = ndb.Key('MyList', lexico_order+userid)
         my_list = key.get()
         action=self.request.get('button')
         if action == 'Submit':
             string = self.request.get('addword')
             if string == None or string == '':
                 self.redirect('/')
                 return
             my_list.list_of_words.append(newword)
             my_list.lexicographical=lexico_order
             my_list.word_count=len(my_list.list_of_words)
             my_list.letter_count=len(my_list.lexicographical)
             my_list.user_id=userid
         my_list.put()
         self.redirect('/add')
Exemple #2
0
 def post(self):
     self.response.headers['Content-Type'] = 'text/html'
     user = users.get_current_user()
     string = self.request.get('input')
     string7 = ''.join(k for k, g in groupby(sorted(string)))
     emailsample = users.get_current_user().email()
     key = ndb.Key('MyList', string7 + emailsample)
     my_list = key.get()
     if my_list == None:
         my_list = MyList(id=string7 + emailsample)
         my_list.put()
     key = ndb.Key('MyList', string7 + emailsample)
     my_list = key.get()
     action = self.request.get('button')
     if action == 'add':
         string = self.request.get('input')
         if string == None or string == '':
             self.redirect('/')
             return
         my_list.strings.append(string)
         my_list.lexographical = string7
         my_list.wordcount = len(my_list.strings)
         my_list.lettercount = len(my_list.lexographical)
         my_list.email = emailsample
     my_list.put()
     self.redirect('/add')
def test_contains(alist: list):
    from_list = MyList(list(alist))
    from_alist = MyList(alist)
    from_mylist = MyList(MyList(alist))
    for element in alist:
        assert element in from_alist
        assert element in from_list
        assert element in from_mylist
    for idx, element in enumerate(alist):
        assert element == from_alist[idx]
        assert element == from_list[idx]
        assert element == from_mylist[idx]
Exemple #4
0
def start():
    try:
        mlist = MyList()
        mlist.fill_list()

        for value in mlist.mylist:
            print value

        mlist.mylist.append(60)
        if 60 in mlist.mylist:
            end("This is over!")
    except MyListError as lerr:
        print lerr
Exemple #5
0
def test_min_max():
    from mylist import MyList
    test_input_list = [[-1, 5, 8, 100], [5, -8, 9, 45, 88, 34, 65],
                       [-5, 8.234, -99023, 342, 9.452]]
    test_output_values = ((100, -1), (88, -8), (342, -99023))

    for count, elem in enumerate(test_input_list):
        test = MyList(test_input_list[count])
        assert test.output_min_max == test_output_values[count]
        assert isinstance(test.output_min_max, tuple)  # should be true

    with pytest.raises(TypeError):
        MyList(['string', 'why'])
    with pytest.raises(ValueError):
        MyList([])
Exemple #6
0
def test_max_diff():
    from mylist import MyList
    test_input_list = [[10, 8, 5, 17, 16], [2, -7, 1.5]]
    test_output_value = [12, 9]
    for n, t in enumerate(test_input_list):
        test = MyList(test_input_list[n])
        assert test.output_max_diff == test_output_value[n]

    with pytest.raises(ImportError):  # Test ImportError?
        import scipy
    with pytest.raises(TypeError):  # Type error when None inputted
        MyList()
        MyList(['sing'])
    with pytest.raises(ValueError):  # ValueError can occur when only 1 # given
        max([])  # This is where it fails in return_max_difference
Exemple #7
0
 def get(self):
     self.response.headers['Content-Type'] = 'text/html'
     email = users.get_current_user().email()
     query = MyList.query(MyList.email == users.get_current_user().email())
     template_values = {'query': query}
     template = JINJA_ENVIRONMENT.get_template('show.html')
     self.response.write(template.render(template_values))
Exemple #8
0
	def __add__(self, otherlist):
		self.countadd += 1
		MyListSub.count += 1
		self.outcount()
		if isinstance(otherlist, MyListSub):
			otherlist = otherlist.data
		return MyListSub(MyList.__add__(self, otherlist))
Exemple #9
0
 def get(self):
     self.response.headers['Content-Type'] = 'text/html'
     userid = users.get_current_user().email()
     userid = hashlib.sha1('%s' % (userid)).hexdigest()
     query = MyList.query(MyList.user_id == userid)
     template_values = {'query': query}
     template = JINJA_ENVIRONMENT.get_template('uanagram.html')
     self.response.write(template.render(template_values))
Exemple #10
0
 def post(self):
     self.response.headers['Content-Type'] = 'text/html'
     user = users.get_current_user().email()
     textfile = self.request.get("myFile")
     textfile = textfile.split()
     for x in textfile:
         line = ''.join(k for k, g in groupby(sorted(x)))
         key = ndb.Key('MyList', line + user)
         my_list = key.get()
         if my_list == None:
             my_list = MyList(id=line + user)
             my_list.put()
         key = ndb.Key('MyList', line + user)
         my_list = key.get()
         my_list.strings.append(x)
         my_list.lexographical = line
         my_list.wordcount = len(my_list.strings)
         my_list.lettercount = len(my_list.lexographical)
         my_list.email = user
         my_list.put()
     self.redirect('/')
Exemple #11
0
 def post(self):
     self.response.headers['Content-Type'] = 'text/html'
     userid = users.get_current_user().email()
     userid = hashlib.sha1('%s' % (userid)).hexdigest()
     textfile = self.request.get("myFile")
     textfile = textfile.split()
     for x in textfile:
         line=''.join(sorted(set(x)))
         key = ndb.Key('MyList', line+userid)
         my_list = key.get()
         if my_list==None:
             my_list=MyList(id=line+userid)
             my_list.put()
         key = ndb.Key('MyList', line+userid)
         my_list = key.get()
         my_list.list_of_words.append(x)
         my_list.lexicographical=line
         my_list.word_count=len(my_list.list_of_words)
         my_list.letter_count=len(my_list.lexicographical)
         my_list.user_id=userid
         my_list.put()
     self.redirect('/')
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        url = ''
        url_string = ''
        welcome = 'Welcome back'
        my_list = None
        d = []
        user = users.get_current_user()
        if user:
            url = users.create_logout_url(self.request.uri)
            url_string = 'logout'
            key = ndb.Key('MyList', user.user_id())
            email = users.get_current_user().email()
            email = hashlib.sha1('%s' % (email)).hexdigest()
            word = self.request.get('searchword')
            lexicoword = ''.join(k for k, g in groupby(sorted(word)))
            query = MyList.query(MyList.user_id == email)

            string8 = None
            my_list1 = None
            for i in query:
                if i.lexicographical in lexicoword:
                    if i.lexicographical == lexicoword:
                        pass
                    else:
                        string8 = i.lexicographical
                        if string8 == None:
                            pass
                        else:
                            key1 = ndb.Key('MyList', string8 + email)
                            my_list1 = key1.get()
                            d.append(my_list1)
            key = ndb.Key('MyList', lexicoword + email)
            my_list = key.get()
        else:
            url = users.create_login_url(self.request.uri)
            url_string = 'login'

        template_values = {
            'url': url,
            'url_string': url_string,
            'user': user,
            'welcome': welcome,
            'my_list': my_list,
            'my_list': my_list,
            'd': d
        }
        template = JINJA_ENVIRONMENT.get_template('main.html')
        self.response.write(template.render(template_values))
Exemple #13
0
 def __init__ (self, poll, is_blocking=True, debug=True):
     """ 
     sock:   sock to listen
         """
     self._debug = debug
     self._sock_dict = dict ()
     self._locker = threading.Lock ()
     self._lock = self._locker.acquire
     self._unlock = self._locker.release
     self._poll = poll
     self._cbs = MyList () # (handler, handler_args)
     self._pending_fd_ops = MyList () # (handler, conn)
     self._checktimeout_inv = 0
     self.get_time = time.time
     self.is_blocking = is_blocking
    def get(self):
        self.response.headers['Content-Type'] = 'text/html'
        url = ''
        url_string = ''
        welcome = 'Welcome back'
        my_list = None
        a = []
        user = users.get_current_user()
        if user:
            url = users.create_logout_url(self.request.uri)
            url_string = 'logout'
            key = ndb.Key('MyList', user.user_id())
            email = users.get_current_user().email()
            string = self.request.get('input77')
            string7 = ''.join(k for k, g in groupby(sorted(string)))
            query = MyList.query(
                MyList.email == users.get_current_user().email())

            string8 = None
            my_list1 = None
            for i in query:
                if i.lexographical in string7:
                    if i.lexographical == string7:
                        pass
                    else:
                        string8 = i.lexographical
                        if string8 == None:
                            pass
                        else:
                            key1 = ndb.Key('MyList', string8 + email)
                            my_list1 = key1.get()
                            a.append(my_list1)
            key = ndb.Key('MyList', string7 + email)
            my_list = key.get()
        else:
            url = users.create_login_url(self.request.uri)
            url_string = 'login'
        template_values = {
            'url': url,
            'url_string': url_string,
            'user': user,
            'welcome': welcome,
            'my_list': my_list,
            'my_list': my_list,
            'a': a
        }
        template = JINJA_ENVIRONMENT.get_template('main.html')
        self.response.write(template.render(template_values))
Exemple #15
0
 def get(self):
     self.response.headers['Content-Type'] = 'text/html'
     email = users.get_current_user().email()
     string = self.request.get('input77')
     string7 = ''.join(k for k, g in groupby(sorted(string)))
     action = self.request.get('button')
     e = []
     d = []
     if action == 'search':
         if string7 == None or '':
             pass
         else:
             c = []
             query = MyList.query(
                 MyList.email == users.get_current_user().email())
             for i in query:
                 for j in i.lexographical:
                     if j in string7:
                         c.append(i.lexographical)
                     else:
                         break
                         break
             z = 0
             m = []
             s = 0
             for i in query:
                 z = len(i.lexographical)
                 s = c.count(i.lexographical)
                 if z == s:
                     m.append(i.lexographical)
                 else:
                     pass
             if string7 in m:
                 m.remove(string7)
             for i in m:
                 key1 = ndb.Key('MyList', i + email)
                 my_list1 = key1.get()
                 d.append(my_list1)
     key = ndb.Key('MyList', string7 + email)
     my_list = key.get()
     template_values = {'my_list': my_list, 'd': d}
     template = JINJA_ENVIRONMENT.get_template('search.html')
     self.response.write(template.render(template_values))
Exemple #16
0
def test_sum():
    from mylist import MyList
    list1 = MyList([1, 3, 5, 7, 9])
    list2 = MyList([-2, -5, -6, -1])
    list3 = MyList([4, -6, 9, -1])
    list4 = MyList([2.2, 5.1, 9.1, 1.2])
    list5 = MyList([-1.1, -5.2, -1.4, -3.8])
    list6 = MyList([-1.1, 2.2, -3.1])
    assert list1.output_sum == 25
    assert list2.output_sum == -14
    assert list3.output_sum == 6
    assert list4.output_sum == pytest.approx(17.6)
    assert list5.output_sum == pytest.approx(-11.5)
    assert list6.output_sum == pytest.approx(-2)
    with pytest.raises(TypeError):
        np.sum(['hello', 'hi'])
    with pytest.raises(ValueError):
        MyList([])
Exemple #17
0
 def __init__(self, start):
     self.adds = 0
     MyList.__init__(self, start)
Exemple #18
0
 def __add__(self, other):
     MyListSub.calls += 1
     self.adds += 1
     return MyList.__add__(self, other)
Exemple #19
0
	def __init__(self, start):
		self.adds = 0
		MyList.__init__(self,start)
Exemple #20
0
 def __add__(self, other):
     print('add: ' + str(other))
     MyListSub.calls += 1  # Class-wide counter
     self.adds += 1  # Per-instance counts
     return MyList.__add__(self, other)
Exemple #21
0
 def __init__(self, start):
     self.adds = 0  # Varies in each instance
     MyList.__init__(self, start)
 def __init__(self, start):
     self.adds = 0                              # Varies in each instance
     MyList.__init__(self, start)
 def __add__(self, other):
     print('add: ' + str(other))
     MyListSub.calls += 1                       # Class-wide counter
     self.adds += 1                             # Per-instance counts
     return MyList.__add__(self, other)
Exemple #24
0
	def __add__(self, other):
		MyListSub.calls += 1
		self.adds += 1
		return MyList.__add__(self,other)
Exemple #25
0
 def __add__(self, other):
     MyListSub.calls = MyListSub.calls + 1  # Class-wide counter
     self.adds = self.adds + 1              # Per instance counts
     return MyList.__add__(self, other)
import pytest

sys.path.append('.')
from mylist import MyList

lists = [
    [1, 2, 3, 4],
    [4, 3, 2, 1],
    ['a', 'b', 'c', 'd'],
    [1, 2, 'a', 'b']]

lists_ids = [str(element) for element in lists]

alist = lists[0]
from_list = MyList(list(alist))
from_alist = MyList(alist)
from_mylist = MyList(MyList(alist))


def test_repr():
    assert str(from_alist) == str(from_alist.data)
    assert str(from_mylist) == str(from_mylist.data)
    assert str(from_list) == str(from_list.data)


def test_init():
    assert type(from_mylist.data) == type(from_list.data)
    assert from_mylist.data == from_list.data
    assert from_mylist.data == from_alist.data
Exemple #27
0
 def __add__(self, other):
     print 'add:',str(other)
     MyListSub.calls += 1
     self.adds += 1
     return MyList.__add__(self, other)
Exemple #28
0
class SocketEngine (object):

    sock = None
    _poll = None
    _lock = None
    _sock_dict = None
    logger = None
    _rw_timeout = 0
    _idle_timeout = 0
    _last_checktimeout = None
    _checktimeout_inv = 0
    
    def __init__ (self, poll, is_blocking=True, debug=True):
        """ 
        sock:   sock to listen
            """
        self._debug = debug
        self._sock_dict = dict ()
        self._locker = threading.Lock ()
        self._lock = self._locker.acquire
        self._unlock = self._locker.release
        self._poll = poll
        self._cbs = MyList () # (handler, handler_args)
        self._pending_fd_ops = MyList () # (handler, conn)
        self._checktimeout_inv = 0
        self.get_time = time.time
        self.is_blocking = is_blocking

    def set_timeout (self, rw_timeout, idle_timeout):
        self._rw_timeout = rw_timeout
        self._idle_timeout = idle_timeout
        self._last_checktimeout = time.time ()
        temp_timeout = []
        if self._rw_timeout:
            temp_timeout.append (self._rw_timeout)
        if self._idle_timeout:
            temp_timeout.append (self._idle_timeout)
        if len(temp_timeout):
            self._checktimeout_inv = float (min (temp_timeout)) / 2
        else:
            self._checktimeout_inv = 0

    def set_logger (self, logger):
        self.logger = logger

    def log_error (self, msg):
        if self.logger:
            self.logger.warning (msg, bt_level=1)
        else:
            print msg

    def log_exception (self, e):
        if self.logger:
            self.logger.exception (e)
        else:
            print e

    def put_sock (self, sock, readable_cb, readable_cb_args=(), idle_timeout_cb=None, stack=True):
        return self._put_sock (sock, readable_cb, readable_cb_args, idle_timeout_cb, lock=True)

    def _put_sock (self, sock, readable_cb, readable_cb_args=(), idle_timeout_cb=None, stack=True, lock=False):
        conn = Connection (sock,
                readable_cb=readable_cb, readable_cb_args=readable_cb_args, 
                idle_timeout_cb=idle_timeout_cb)
        if stack and self._debug:
            conn.putsock_tb = traceback.extract_stack()[0:-1]
        if lock:
            self.watch_conn (conn)
        else:
            self._watch_conn (conn)
        return conn


    def watch_conn (self, conn):
        """ assume conn is already manage by server, register into poll """
        assert isinstance (conn, Connection)
        self._lock ()
        self._pending_fd_ops.append ((self._watch_conn, conn))
        self._unlock ()

    def _watch_conn (self, conn):
        self._sock_dict[conn.fd] = conn
        conn.last_ts = self.get_time ()
        conn.status = ConnState.IDLE
        if conn.sign == 'r':
            self._poll.register (conn.fd, 'r', conn.readable_cb, (conn, ) + conn.readable_cb_args)


    def remove_conn (self, conn):
        """ remove conntion from server """
        self._lock ()
        self._pending_fd_ops.append ((self._remove_conn, conn))
        self._unlock ()

    def _remove_conn (self, conn):
        conn.status = ConnState.EXTENDED_USING
        fd = conn.fd
        self._poll.unregister (fd)
        try:
            del self._sock_dict[fd]
        except KeyError:
            pass

    def close_conn (self, conn):
        """ remove an close connection """
        self._lock ()
        self._pending_fd_ops.append ((self._close_conn, conn))
        self._unlock ()

    def _close_conn (self, conn):
        fd = conn.fd
        self._poll.unregister (fd)
        try:
            del self._sock_dict[fd]
        except KeyError:
            pass
        conn.close ()

    def _accept_conn (self, sock, readable_cb, readable_cb_args, idle_timeout_cb, new_conn_cb):
        """ socket will set FD_CLOEXEC upon accepted """
        _accept = sock.accept
        _put_sock = self._put_sock
        while True: 
        # have to make sure the socket is non-block, so we can accept multiple connection
            try:
                (csock, addr) = _accept ()
                try:
                    flags = fcntl.fcntl(csock, fcntl.F_GETFD)
                    fcntl.fcntl(csock, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
                except IOError, e:
                    self.log_error ("cannot set FD_CLOEXEC on accepted socket fd, %s" % (str(e)))

                if self.is_blocking:
                    csock.settimeout (self._rw_timeout or None)
                else:
                    csock.setblocking (0)


                if callable (new_conn_cb):
                    csock = new_conn_cb (csock, *readable_cb_args)
                    if not csock:
                        continue
                _put_sock (csock, readable_cb=readable_cb, readable_cb_args=readable_cb_args, 
                        idle_timeout_cb=idle_timeout_cb, stack=False, lock=False)
            except socket.error, e:
                if e[0] == errno.EAGAIN:
                    return #no more
                if e[0] != errno.EINTR:
                    msg = "accept error (unlikely): " + str(e)
                    self.log_error (msg)
Exemple #29
0
from drone import Drone
from robot import Robot
from mylist import MyList

def execute(robot):
    try:
        lista.append(robot.detect_object("red"))
        if lista[0][2] >   300:
            robot.move("forward", 1)
        
    except KeyboardInterrupt:
        raise

if __name__ == '__main__':
    mylist=MyList()
    if len(sys.argv) == 2:
        path = os.getcwd()
        open_path = path[:path.rfind('src')] + 'cfg/'
        filename = sys.argv[1]

    else:
        sys.exit("ERROR: Example:python my_generated_script.py cfgfile.yml")

    # loading the ICE and ROS parameters
    cfg = config.load(open_path + filename)
    stream = open(open_path + filename, "r")
    yml_file = yaml.load(stream)

    for section in yml_file:
        if section == 'drone':
Exemple #30
0
	def __init__(self, listin = []):
		self.countadd = 0
		MyList.__init__(self, listin)