示例#1
0
 def _fromJson(cls, s):
     u"""
     If s evaluates to a list, then assume that the contents are dictionaries, which all convert to a single
     state. If s evaluates to a dict, then create a single state.
     """
     assert isinstance(s, basestring)
     return cls._fromObject(cjson.encode(s))
示例#2
0
    def setCookie(self, value=None, expires=None, url="/", name=None, **args):
        u"""
        The <code>setCookie</code> method saves the cookie indicated by <attr>name</attr> with <attr>value</attr>,
        using the <attr>expires</attr> and <attr>url</attr> attributes.
        """

        import datetime, urllib

        if not name:
            name = self.COOKIENAME

        # allow expires to be specified as number of days
        if expires and not isinstance(expires, basestring):
            try:
                days = int(expires)
                if days > 0:
                    expiry = datetime.datetime.now() + datetime.timedelta(days=days)
                    expires = expiry.strftime("%a, %d %b %Y %H:%M:%S GMT")
            except:
                expires = None

        # encode python objects into string
        value = urllib.quote(cjson.encode(value))

        self.request.addCookie(name, value, expires=expires, path=url, **args)

        # and just make sure it's available to the rest of this request
        self.request.received_cookies[name] = value
示例#3
0
 def _fromJson(cls, s):
     u"""
     If s evaluates to a list, then assume that the contents are dictionaries, which all convert to a single
     state. If s evaluates to a dict, then create a single state.
     """
     assert isinstance(s, basestring)
     return cls._fromObject(cjson.encode(s))
示例#4
0
    def setCookie(self, value=None, expires=None, url='/', name=None, **args):
        u"""
        The ``setCookie`` method saves the cookie indicated by ``name`` with ``value``,
        using the ``expires`` and ``url`` attributes.
        """

        import datetime, urllib

        if not name:
            name = self.COOKIENAME

        # allow expires to be specified as number of days
        if expires and not isinstance(expires, basestring):
            try:
                days = int(expires)
                if days > 0:
                    expiry = datetime.datetime.now() + datetime.timedelta(
                        days=days)
                    expires = expiry.strftime("%a, %d %b %Y %H:%M:%S GMT")
            except:
                expires = None

        # encode python objects into string
        value = urllib.quote(cjson.encode(value))

        self.request.addCookie(name, value, expires=expires, path=url, **args)

        # and just make sure it's available to the rest of this request
        self.request.received_cookies[name] = value
示例#5
0
文件: task.py 项目: thongnv/Xierpa3
 def post(self, builder, priority=999999, order=0, args=None):
     u"""
     The <code>post</code> method adds <code>self</code> task to the scheduled tasks,
     if the <code>builder.USE_MULTIPROCESSING</code> is <code>True</code>. Other wise the
     task is immediately executed. This direct execution is required for servers running
     Python2.5 or older (that don’s support multiprocessing) of for debugging in Eclipse.
     Due to a deep bug, the Python application of the split process crashes when in debug mode.
     """
     print '... Post task', self.name
     if builder.USE_MULTIPROCESSING:
         self.name = self.getTaskName(priority, order)
         self.arguments = args if isinstance(args, dict) else {}
         f = open(self.PATH_SCHEDULERTASKS + '/' + self.name, 'wb')
         f.write(cjson.encode(self.getValues()))
         f.close()
     else:
         # In case multiprocessing is off, execute the task immediately
         self.execute(builder)
示例#6
0
 def post(self, builder, priority=999999, order=0, args=None):
     u"""
     The <code>post</code> method adds <code>self</code> task to the scheduled tasks,
     if the <code>builder.USE_MULTIPROCESSING</code> is <code>True</code>. Other wise the
     task is immediately executed. This direct execution is required for servers running
     Python2.5 or older (that don’s support multiprocessing) of for debugging in Eclipse.
     Due to a deep bug, the Python application of the split process crashes when in debug mode.
     """
     print '... Post task', self.name
     if builder.USE_MULTIPROCESSING:
         self.name = self.getTaskName(priority, order)
         self.arguments = args if isinstance(args, dict) else {}
         f = open(self.PATH_SCHEDULERTASKS + '/' + self.name, 'wb')
         f.write(cjson.encode(self.getValues()))
         f.close()
     else:
         # In case multiprocessing is off, execute the task immediately
         self.execute(builder)
示例#7
0
 def buildAjax(self, site):
     u"""Answer the json of the ajax dict generated by the site. This method gets
     called if there is a "/ajax" parameter in the url."""
     return cjson.encode(site.buildAjaxDict()), self.C.MIMETYPE_JSON