# Path: yql/storage.py
# class FileTokenStore(BaseTokenStore):
#     """A simple filesystem based token store
# 
#     Note: this is more intended as an example rather than
#     something for heavy duty production usage.
# 
#     """
# 
#     def __init__(self, dir_path, secret=None):
#         """Initialize token storage"""
# 
#         if not os.path.exists(dir_path):
#             raise TokenStoreError("Path is not valid")
# 
#         self.base_dir = dir_path
#         self.secret = secret or SECRET
# 
#     def get_filepath(self, name):
#         """Build filepath"""
# 
#         filename = md5("%s%s" % (name, self.secret)).hexdigest()
#         filepath = os.path.join(self.base_dir, filename)
# 
#         return filepath
# 
#     def set(self, name, token):
#         """Write a token to file"""
# 
#         if hasattr(token, 'key'):
#             token = YahooToken.to_string(token)
# 
#         if token:
#             filepath = self.get_filepath(name)
#             f_handle = open(filepath, 'w')
#             f_handle.write(token)
#             f_handle.close()
# 
#     def get(self, name):
#         """Get a token from the filesystem"""
# 
#         filepath = self.get_filepath(name)
# 
#         if os.path.exists(filepath):
#             f_handle = open(filepath, 'r')
#             token = f_handle.read()
#             f_handle.close()
# 
#             token = YahooToken.from_string(token)
#             return token


import os
import sys
import yql
from time import time
from unittest import TestCase
from nose.plugins.skip import SkipTest
from yql.storage import FileTokenStore
    from secrets import *
            token_store.set('foo', token)
        else:
            # Check access_token is within 1hour-old and if not refresh it
            # and stash it
            token = y.check_token(stored_token)
            if token != stored_token:
                token_store.set('foo', token)

        res = y.execute(query, token=token)
        assert res.rows[0] == "ok"
        new_query = """select message from social.profile.status where guid=me"""
        res = y.execute(new_query, token=token)
        assert res.rows[0].get("message") == "Using YQL. %s Update" % timestamp


    def test_check_env_var(self):
        """Testing env variable"""
        y = yql.Public()
        env = "http://datatables.org/alltables.env"
        query = "SHOW tables;"
        res = y.execute(query, env=env)
        assert res.count >= 800

    def test_xpath_works(self):
        y = yql.Public()
        query = """SELECT * FROM html
                   WHERE url='http://google.co.uk'
                   AND xpath="//input[contains(@name, 'q')]"
                   LIMIT 10"""
        res = y.execute(query)

# Path: yql/storage.py
# class FileTokenStore(BaseTokenStore):
#     """A simple filesystem based token store
# 
#     Note: this is more intended as an example rather than
#     something for heavy duty production usage.
# 
#     """
# 
#     def __init__(self, dir_path, secret=None):
#         """Initialize token storage"""
# 
#         if not os.path.exists(dir_path):
#             raise TokenStoreError("Path is not valid")
# 
#         self.base_dir = dir_path
#         self.secret = secret or SECRET
# 
#     def get_filepath(self, name):
#         """Build filepath"""
# 
#         filename = md5("%s%s" % (name, self.secret)).hexdigest()
#         filepath = os.path.join(self.base_dir, filename)
# 
#         return filepath
# 
#     def set(self, name, token):
#         """Write a token to file"""
# 
#         if hasattr(token, 'key'):
#             token = YahooToken.to_string(token)
# 
#         if token:
#             filepath = self.get_filepath(name)
#             f_handle = open(filepath, 'w')
#             f_handle.write(token)
#             f_handle.close()
# 
#     def get(self, name):
#         """Get a token from the filesystem"""
# 
#         filepath = self.get_filepath(name)
# 
#         if os.path.exists(filepath):
#             f_handle = open(filepath, 'r')
#             token = f_handle.read()
#             f_handle.close()
# 
#             token = YahooToken.from_string(token)
#             return token


# Path: yql/tests/test_live_services.py
import os
import sys
import yql
from time import time
from unittest import TestCase
from nose.plugins.skip import SkipTest
from yql.storage import FileTokenStore
    from secrets import *

            token_store.set('foo', token)
        else:
            # Check access_token is within 1hour-old and if not refresh it
            # and stash it
            token = y.check_token(stored_token)
            if token != stored_token:
                token_store.set('foo', token)

        res = y.execute(query, token=token)
        assert res.rows[0] == "ok"
        new_query = """select message from social.profile.status where guid=me"""
        res = y.execute(new_query, token=token)
        assert res.rows[0].get("message") == "Using YQL. %s Update" % timestamp


    def test_check_env_var(self):
        """Testing env variable"""
        y = yql.Public()
        env = "http://datatables.org/alltables.env"
        query = "SHOW tables;"
        res = y.execute(query, env=env)
        assert res.count >= 800

    def test_xpath_works(self):
        y = yql.Public()
        query = """SELECT * FROM html
                   WHERE url='http://google.co.uk'
                   AND xpath="//input[contains(@name, 'q')]"
                   LIMIT 10"""
        res = y.execute(query)

        assert res.rows[0].get("title") == "Google Search"