def retry_after(cls, response, default):
        """Compute next `poll` time based on response ``Retry-After`` header.

        :param response: Response from `poll`.
        :type response: `requests.Response`

        :param int default: Default value (in seconds), used when
            ``Retry-After`` header is not present or invalid.

        :returns: Time point when next `poll` should be performed.
        :rtype: `datetime.datetime`

        """
        retry_after = response.headers.get('Retry-After', str(default))
        try:
            seconds = int(retry_after)
        except ValueError:
            # pylint: disable=no-member
            decoded = werkzeug.parse_date(retry_after)  # RFC1123
            if decoded is None:
                seconds = default
            else:
                return decoded

        return datetime.datetime.now() + datetime.timedelta(seconds=seconds)
Exemple #2
0
    def test_session_expiration(self):
        permanent = True
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'
        @app.route('/')
        def index():
            flask.session['test'] = 42
            flask.session.permanent = permanent
            return ''

        @app.route('/test')
        def test():
            return unicode(flask.session.permanent)

        client = app.test_client()
        rv = client.get('/')
        assert 'set-cookie' in rv.headers
        match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
        expires = parse_date(match.group())
        expected = datetime.utcnow() + app.permanent_session_lifetime
        assert expires.year == expected.year
        assert expires.month == expected.month
        assert expires.day == expected.day

        rv = client.get('/test')
        assert rv.data == 'True'

        permanent = False
        rv = app.test_client().get('/')
        assert 'set-cookie' in rv.headers
        match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
        assert match is None
Exemple #3
0
    def test_session_expiration(self):
        permanent = True
        app = flask.Flask(__name__)
        app.secret_key = "testkey"

        @app.route("/")
        def index():
            flask.session["test"] = 42
            flask.session.permanent = permanent
            return ""

        @app.route("/test")
        def test():
            return unicode(flask.session.permanent)

        client = app.test_client()
        rv = client.get("/")
        assert "set-cookie" in rv.headers
        match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])
        expires = parse_date(match.group())
        expected = datetime.utcnow() + app.permanent_session_lifetime
        assert expires.year == expected.year
        assert expires.month == expected.month
        assert expires.day == expected.day

        rv = client.get("/test")
        assert rv.data == "True"

        permanent = False
        rv = app.test_client().get("/")
        assert "set-cookie" in rv.headers
        match = re.search(r"\bexpires=([^;]+)", rv.headers["set-cookie"])
        assert match is None
Exemple #4
0
    def test_session_expiration(self):
        permanent = True
        app = flask.Flask(__name__)
        app.secret_key = 'testkey'
        @app.route('/')
        def index():
            flask.session['test'] = 42
            flask.session.permanent = permanent
            return ''

        @app.route('/test')
        def test():
            return unicode(flask.session.permanent)

        client = app.test_client()
        rv = client.get('/')
        assert 'set-cookie' in rv.headers
        match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
        expires = parse_date(match.group())
        expected = datetime.utcnow() + app.permanent_session_lifetime
        assert expires.year == expected.year
        assert expires.month == expected.month
        assert expires.day == expected.day

        rv = client.get('/test')
        assert rv.data == 'True'

        permanent = False
        rv = app.test_client().get('/')
        assert 'set-cookie' in rv.headers
        match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])
        assert match is None
Exemple #5
0
 def __init__(self, result):
     self.text = Markup(result['text']).unescape()
     self.user = result['from_user']
     self.via = Markup(Markup(result['source']).unescape())
     self.pub_date = parse_date(result['created_at'])
     self.profile_image = result['profile_image_url']
     self.type = result['metadata']['result_type']
     self.retweets = result['metadata'].get('recent_retweets') or 0
Exemple #6
0
 def twitter_date(date):
     return parse_date(date)
Exemple #7
0
 def twitter_date(date):
     return parse_date(date)