Example #1
0
        def _test_url(self):
                args=[u'*****@*****.**', u'file%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4']
		url = RequestUtils.getUrl(args)
                self.assertEquals(False,RequestUtils.checkUrl(url));
                args=[u'*****@*****.**', u'chrome%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4']
		url = RequestUtils.getUrl(args)
                self.assertEquals(False,RequestUtils.checkUrl(url));
                args=[u'*****@*****.**', u'about%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4']
		url = RequestUtils.getUrl(args)
                self.assertEquals(False,RequestUtils.checkUrl(url));
                args=[u'*****@*****.**', u'ed2k%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4']
		url = RequestUtils.getUrl(args)
                self.assertEquals(False,RequestUtils.checkUrl(url));
                args=[u'*****@*****.**', u'liberator%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4']
		url = RequestUtils.getUrl(args)
                self.assertEquals(False,RequestUtils.checkUrl(url));
                args=[u'*****@*****.**', u'irc%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4']
		url = RequestUtils.getUrl(args)
                self.assertEquals(False,RequestUtils.checkUrl(url));
                args=[u'*****@*****.**', u'chrome-extension%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4']
		url = RequestUtils.getUrl(args)
                self.assertEquals(False,RequestUtils.checkUrl(url));
                args=[u'*****@*****.**', u'http%3A%2F%2Fuk.gizmodo.com%2F5805875%2Fthe-knock%2Bdown-drag%2Bout-fight-over-the-next-generation-of-batteries', u'The%20Knock-Down%2C%20Drag-Out%20Fight%20Over%20the%20Next%20Generation%20of%20Batteries', u'0.4.0.4']
		url = RequestUtils.getUrl(args)
                self.assertEquals(True,RequestUtils.checkUrl(url));
Example #2
0
	def post(self):

		ud, args = RequestUtils.parse_request(self.request.body)

		logging.info('Received args:%s' % args)
                client = RequestUtils.getClient(args)
		user=RequestUtils.getUser(ud,args)
		url=RequestUtils.getUrl(args)
		domain=RequestUtils.getDomain(url)
                title = RequestUtils.getTitle(args, client)
                version = RequestUtils.getVersion(args)
                selection = RequestUtils.getSelection(args)
		share_mode = RequestUtils.getShareMode(args)

                if not RequestUtils.checkUrl(url):
                        logging.info('skipping since url is not good!')
			self.response.out.write('{"message":"Bad url"}')
                        return
                user_agent = self.request.headers['User-agent']
                if user is None or len(user) == 0:
                        logging.info('skipping since user is not defined ( client %s )' % client )
			from google.appengine.api import mail
			if ENVIRONMENT == 'http://www.instaright.com':
	                        mail.send_mail(sender='*****@*****.**', to='*****@*****.**', subject='Bad request!', html='Request: args = %s <br> ud: %s' %( args, ud), body='Request: args = %s <br> ud: %s' %( args, ud))
			self.response.out.write('{"message":"User not defined"}')
                        return
                logging.info('request has been made from valid user %s' % user)
                try:
			taskqueue.add(queue_name='link-queue', url='/article/task', params={'user': user, 'url': url, 'domain': domain, 'title': title, 'version': version,'client': client, 'selection': selection, 'user_agent': user_agent, 'share_mode': share_mode})
                except TransientError:
			taskqueue.add(queue_name='link-queue', url='/article/task', params={'user': user, 'url': url, 'domain': domain, 'title': title, 'version': version,'client': client, 'selection': selection, 'user_agent': user_agent, 'share_mode': share_mode})

		if client == 'bookmarklet':
		        logging.info('bookmarklet specific response')
			self.response.out.write('{"close_html":"Link successfully marked"}')
			return
                cachedBadge = memcache.get('badge_'+user)
                logging.info('looking for badge %s' % 'badge_'+user)
                if cachedBadge is not None:
                        logging.info('response badge %s' %cachedBadge)
                        self.response.out.write(cachedBadge)
                else:
                        logging.info('no badge found, using default')
                        self.response.out.write('')