Example #1
0
def parsing(message):
    global entered
    global answered
    global gaming
    global user
    global iteration

    if not gaming:

        if message.text == "/signup" and not entered:
            user = register(message.chat.id, message.date)  # message.from_user.username
            entered = True
            bot.send_message(message.chat.id, "Вы залогинены!")
            # что-то там с юзернеймом

        elif message.text == "/game" and entered:
            gaming = True
            answered = True
            iteration = 0

        elif message.text == "/exit" and entered:
            user.save()
            entered = False
            gaming = False
            bot.send_message(message.chat.id,
                             str(user.username) + ", Вы завершили игру c " + str(user.score) + " очками!")

    if gaming and iteration < 4:

        points = get_points()
        if answered:
            bot.send_message(message.chat.id, points[iteration].question,
                             reply_markup=generate_markup(points, iteration))
            answered = False
        else:
            if message.text == points[iteration].r_answ:
                bot.send_message(message.chat.id,
                                 "Правильно!" + " Вы получаете " + str(points[iteration].score) + " очков",
                                 reply_markup=next_markup())
                user.score += points[iteration].score
            else:
                bot.send_message(message.chat.id, "Неравильно:(", reply_markup=next_markup())
            answered = True
            iteration += 1
    elif gaming and iteration > 3:
        user.save()
        entered = False
        gaming = False
        bot.send_message(message.chat.id,
                         message.from_user.username + ", Вы завершили игру c " + str(user.score) + " очками!")
Example #2
0
		# which is set when we are posting (but not when
		# we are previewing).
		# It is possible to lose comment permissions partway
		# through writing a comment (after you have text and
		# before you hit post). If this happens we fall through
		# to the normal non-post case, which already must handle
		# this; this is somewhat friendlier.
		#
		# If the previous IP address prefix in the POST fails
		# to match, we don't generate any explicit errors; we
		# just fall through to another preview pass.
		#
		#X#   verify_ip_prefix(self.context) and \
		if self.context.getviewvar("post") and \
		   self.context.page.comment_ok(self.context):
			if not post(self.context, self.response):
				# hand-crafted bad request
				self.error("badrequest", 403)
			else:
				setCommentCookie(self.context,
						 self.response)
		else:
			# We actually want 100% generic handling here,
			# surprisingly enough.
			super(WriteCommentView, self).render()

views.register('showcomments', views.TemplateView)
views.register('writecomment', WriteCommentView, canPOST = True,
	       postParams = ('comment', 'previp', 'post', 'dopref', 'name',
			     'whois', 'whourl', ))
Example #3
0
        # to match, we don't generate any explicit errors; we
        # just fall through to another preview pass.
        #
        #X#   verify_ip_prefix(self.context) and \
        if self.context.getviewvar("post") and \
           self.context.page.comment_ok(self.context):
            if not post(self.context, self.response):
                # hand-crafted bad request
                self.error("badrequest", 403)
            else:
                setCommentCookie(self.context, self.response)
        else:
            # We actually want 100% generic handling here,
            # surprisingly enough.
            super(WriteCommentView, self).render()


views.register('showcomments', views.TemplateView)
views.register('writecomment',
               WriteCommentView,
               canPOST=True,
               postParams=(
                   'comment',
                   'previp',
                   'post',
                   'dopref',
                   'name',
                   'whois',
                   'whourl',
               ))
Example #4
0
	hlist.sort()
	res = []
	res.append("<ul>\n")
	for path in hlist:
		res.append("<li>")
		res.append(htmlrends.makelink(path,
					      context.web.url_from_path(path)))
		res.append("\n")
	res.append("</ul>\n")
	return ''.join(res)
htmlrends.register("search::display", display_results)

# View registration.

#
# Search view is always a view on the root, so it can't be redirected
# off the root.
class SearchView(views.TemplateView):
	def render(self):
		if not can_search(self.context):
			self.error("badaccess")
		else:
			super(SearchView, self).render()
	def redirect_root(self):
		return False

# In theory you can use ?search=... on anything, although we only
# generate it on the root.
# We do not POST to search, so this is actually disallowed.
views.register("search", SearchView, getParams = ("search",), onDir = True)
Example #5
0
import derrors
import views
import pageranges

# By convention we import all HTML view renderers, thereby forcing
# their registration.
__pychecker__ = "no-import"
import htmlrends, wikirend, histview, blogdir, comments, search, atomgen
import interjections, sitemaps, htmlauth, conditions
__pychecker__ = ""
import htmlerr

# Our views.
# Most are registered elsewhere, in the files that implement them, but
# these views are so basic that we register them here, in the core.
views.register('history', views.TemplateView)
views.register('normal', views.TemplateView, onDir=True, pubDir=True)
views.register('source', views.SourceView)


#
# This implementation serves straight URLs under a rooturl,
# with views indicated by '?<view>' at the end. The rooturl is a
# directory, not just a raw prefix.
#
def pub_dir_views():
    return views.pub_dir_views()


class WebServices:
    def __init__(self, cfg, model):
Example #6
0
            return True

        # We should only be valid on directories, so we can just
        # go here.
        ip = self.page.child("__index")
        if ip and ip.is_redirect():
            # Code smell: duplicated with the core view.
            res = ip.redirect_target()
            if not res or res[0] == 'page' and not res[1]:
                self.error('nopage')
                return True
            if res[0] != 'page':
                url = res[1]
            else:
                url = self.context.uri(res[1])
            self.response.redirect(url)
            return True
        # We do not try to redirect to the regular view of this
        # directory if there is no __index file, because we would
        # have to go through gyrations to insure that we aren't
        # redirecting to something with a default index view.
        # If you ask for an index view of a directory without an
        # __index, you get whatever the view template says you
        # should get.

        # Nothing special.
        return False


views.register("index", IndexView, onDir=True, onFile=False, pubDir=True)
Example #7
0
	def redirect_page(self):
		if super(IndexView, self).redirect_page():
			return True

		# We should only be valid on directories, so we can just
		# go here.
		ip = self.page.child("__index")
		if ip and ip.is_redirect():
			# Code smell: duplicated with the core view.
			res = ip.redirect_target()
			if not res or res[0] == 'page' and not res[1]:
				self.error('nopage')
				return True
			if res[0] != 'page':
				url = res[1]
			else:
				url = self.context.uri(res[1])
			self.response.redirect(url)
			return True
		# We do not try to redirect to the regular view of this
		# directory if there is no __index file, because we would
		# have to go through gyrations to insure that we aren't
		# redirecting to something with a default index view.
		# If you ask for an index view of a directory without an
		# __index, you get whatever the view template says you
		# should get.

		# Nothing special.
		return False
views.register("index", IndexView, onDir = True, onFile = False, pubDir = True)
Example #8
0
		# a nice error (and fall back to a much less nice one if
		# we really have to).
		if res:
			setUserCookie(self.context, self.response)
			send_location(self.context, self.response)
		else:
			loginerror(self.context, self.response)

# We inherit the default post vars of 'page'.
class LogoutView(views.PostView):
	def post(self):
		destroyUserCookie(self.context, self.response)
		self.context.logout()
		send_location(self.context, self.response)

views.register('login', LoginView, canPOST = True, canGET = False,
	       postParams = ('login', 'password', 'page',))
views.register('logout', LogoutView, canPOST = True, canGET = False,
	       postParams = ('page',))

	       
# As a convenience, spit out the encoded version of the passwords on the
# command line.
# If we are given no arguments, read 20 bytes of /dev/urandom and barf
# them out in base64 to serve as a decent global-authseed value.
if __name__ == "__main__":
	import sys
	if len(sys.argv) < 2:
		fp = open("/dev/urandom", "rb")
		buf = fp.read(20)
		print buf.encode("base64")[:-1]
	else:
Example #9
0
		# see it.
		if np.type == "file":
			dp = np.parent()
			if dp not in dirs:
				dirs[dp] = True
				ustr = genurlent(context, dp, dir_pri)
				res.append(ustr)

		# Generate a reference to the show-comments page if
		# there are comments. Note that this skips comments
		# on undisplayable pages, because of how get_commentlist
		# behaves.
		# If comments-in-normal is set, comments are already
		# shown in the default page view.
		if "comments-in-normal" not in context and \
		   context.model.get_commentlist(np):
			res.append(genviewurlent(context, np, comment_pri,
						 'showcomments'))
	return "".join(res)

htmlrends.register("sitemap::minurlset", minurlset)

# Register the 'sitemap' view.
# Google doesn't say what content-type their sitemap should be
# returned in, so we pick application/xml since, well, it's an
# XML file. The sitemap view is only valid on directories.
class XMLView(views.AltType):
	content_type = "application/xml"

views.register('sitemap', XMLView, onDir = True, onFile = False)
Example #10
0
            dp = np.parent()
            if dp not in dirs:
                dirs[dp] = True
                ustr = genurlent(context, dp, dir_pri)
                res.append(ustr)

        # Generate a reference to the show-comments page if
        # there are comments. Note that this skips comments
        # on undisplayable pages, because of how get_commentlist
        # behaves.
        # If comments-in-normal is set, comments are already
        # shown in the default page view.
        if "comments-in-normal" not in context and \
           context.model.get_commentlist(np):
            res.append(genviewurlent(context, np, comment_pri, 'showcomments'))
    return "".join(res)


htmlrends.register("sitemap::minurlset", minurlset)


# Register the 'sitemap' view.
# Google doesn't say what content-type their sitemap should be
# returned in, so we pick application/xml since, well, it's an
# XML file. The sitemap view is only valid on directories.
class XMLView(views.AltType):
    content_type = "application/xml"


views.register('sitemap', XMLView, onDir=True, onFile=False)
Example #11
0
import derrors
import views
import pageranges

# By convention we import all HTML view renderers, thereby forcing
# their registration.
__pychecker__ = "no-import"
import htmlrends, wikirend, histview, blogdir, comments, search, atomgen
import interjections, sitemaps, htmlauth, conditions
__pychecker__ = ""
import htmlerr

# Our views.
# Most are registered elsewhere, in the files that implement them, but
# these views are so basic that we register them here, in the core.
views.register('history', views.TemplateView)
views.register('normal', views.TemplateView, onDir = True, pubDir = True)
views.register('source', views.SourceView)

#
# This implementation serves straight URLs under a rooturl,
# with views indicated by '?<view>' at the end. The rooturl is a
# directory, not just a raw prefix.
#
def pub_dir_views():
	return views.pub_dir_views()

class WebServices:
	def __init__(self, cfg, model):
		self.cfg = cfg
		self.model = model
Example #12
0
				rl.append("\n</td> </tr>\n")
			rl.append("<tr> <td> %s: </td> <td>\n" % \
				  link_to_tm(context, t, plain))
			lday = plain
		else:
			# If we are the second or later entry for a
			# given day, we must put a <br> between ourselves
			# and the previous entry.
			rl.append("<br>\n")

		# As usual, we must work in a new context.
		nc = context.clone_to_page(np)
		ltitle = rfunc(nc)
		if not ltitle:
			ltitle = httputil.quotehtml(path[len(rootpath)+1:])
		# We can't use htmlrends.makelink() because that would
		# quote the live HTML in real titles.
		rl.append('    <a href="%s">%s</a>' % \
			  (context.nurl(np), ltitle))
		context.newtime(nc.modtime)
	# Done all; close off the <table>
	rl.append('\n</td></tr></table>\n')
	return ''.join(rl)
htmlrends.register("blog::titles", titleindex)

# View registration.
views.register('blog', views.TemplateView, onDir = True, onFile = False,
	       pubDir = True)
views.register('blogdir', views.TemplateView, onDir = True, onFile = False,
	       pubDir = True)
Example #13
0
            rl.append("<br>\n")

        # As usual, we must work in a new context.
        nc = context.clone_to_page(np)
        ltitle = rfunc(nc)
        if not ltitle:
            ltitle = httputil.quotehtml(path[len(rootpath) + 1:])
        # We can't use htmlrends.makelink() because that would
        # quote the live HTML in real titles.
        rl.append('    <a href="%s">%s</a>' % \
           (context.nurl(np), ltitle))
        context.newtime(nc.modtime)
    # Done all; close off the <table>
    rl.append('\n</td></tr></table>\n')
    return ''.join(rl)


htmlrends.register("blog::titles", titleindex)

# View registration.
views.register('blog',
               views.TemplateView,
               onDir=True,
               onFile=False,
               pubDir=True)
views.register('blogdir',
               views.TemplateView,
               onDir=True,
               onFile=False,
               pubDir=True)
Example #14
0
            return r
        tp = true_atom_page(self.context, True)
        if tp == self.page:
            return False
        self.response.redirect(self.context.uri(tp, self.view))
        return True


# Generating an RSS 2.0 feed is a huge hack. We do not advertise it in
# page tools or anything else; it exists only for a few RSS2-only
# consumers that Chris (now) cares about and because existing feed
# conversion services either don't do it right or are undependable (in
# the long term) or both. It is deliberate that there is no RSS 2.0
# comments feed. RSS 2.0 feeds are just like Atom feeds and obey all
# of the same restrictions.
#
# All of the magic happens in renderers. We need a separate class here
# only to change the content-type.
class RestrictedRss2View(AtomView):
    # This is allegedly the right content-type. RSS being RSS,
    # there are apparently variations.
    content_type = "application/rss+xml"


# An atom view cannot be applied to a file, only a directory.
# Atom comments can be applied to anything.
views.register('atom', RestrictedAtomView, onDir=True, onFile=False)
views.register('atomcomments', AtomView, onDir=True)

views.register('rss2', RestrictedRss2View, onDir=True, onFile=False)
Example #15
0
		r = super(AtomView, self).redirect_page()
		if r or not self._restrictable(()):
			return r
		tp = true_atom_page(self.context, True)
		if tp == self.page:
			return False
		self.response.redirect(self.context.uri(tp, self.view))
		return True

# Generating an RSS 2.0 feed is a huge hack. We do not advertise it in
# page tools or anything else; it exists only for a few RSS2-only
# consumers that Chris (now) cares about and because existing feed
# conversion services either don't do it right or are undependable (in
# the long term) or both. It is deliberate that there is no RSS 2.0
# comments feed. RSS 2.0 feeds are just like Atom feeds and obey all
# of the same restrictions.
#
# All of the magic happens in renderers. We need a separate class here
# only to change the content-type.
class RestrictedRss2View(AtomView):
	# This is allegedly the right content-type. RSS being RSS,
	# there are apparently variations.
	content_type = "application/rss+xml"

# An atom view cannot be applied to a file, only a directory.
# Atom comments can be applied to anything.
views.register('atom', RestrictedAtomView, onDir = True, onFile = False)
views.register('atomcomments', AtomView, onDir = True)

views.register('rss2', RestrictedRss2View, onDir = True, onFile = False)
 def test_register_with_post_method(self, mock_serve_post_response, mock_get_user):
     mock_get_user.return_value = self.ureporter
     request = self.factory.post('/register/')
     register(request)
     mock_serve_post_response.assert_called_once_with(request, self.uuid, self.ureporter)
Example #17
0
 def test_views_register(self):
     views.register();