本文整理汇总了Python中fom.session.Fluid类的典型用法代码示例。如果您正苦于以下问题:Python Fluid类的具体用法?Python Fluid怎么用?Python Fluid使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Fluid类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTags
class TestTags(unittest.TestCase):
def setUp(self):
endpoint = os.environ.get('FLUIDDB_ENDPOINT', 'http://localhost:9000')
username = os.environ.get('FLUIDDB_ADMIN_USERNAME', 'fluiddb')
password = os.environ.get('FLUIDDB_ADMIN_PASSWORD', 'secret')
self.fluiddb = Fluid(endpoint)
self.fluiddb.login(username, password)
self.fluiddb.bind()
def testPOSTNewTagUnderUnicodeNamespace(self):
"""
There shouldn't be a problem creating a tag under a namespace whose
name is expressed in non-ascii characters.
See the following bug:
https://bugs.edge.launchpad.net/fluiddb/+bug/762779
"""
# Use the testuser1 root namespace.
ns = Namespace('testuser1')
# Create an interestingly named namespace
quran = u'\ufe8e\ufee0\ufed7\ufead\ufe81'
quranNS = ns.create_namespace(quran, 'For the purposes of testing')
# Attempt to create a new tag underneath
newTag = False
try:
# just check it can be created
newTag = quranNS.create_tag('foo', 'This is a test', False)
expectedPath = u'testuser1/' + quran + '/foo'
self.assertEqual(expectedPath, newTag.path)
finally:
if newTag:
newTag.delete()
quranNS.delete()
def testPOSTNewUnicodeTagUnderUnicodeNamespace(self):
"""
There shouldn't be a problem creating a tag under a namespace whose
name is expressed in non-ascii characters.
See the following bug:
https://bugs.edge.launchpad.net/fluiddb/+bug/762779
"""
# Use the testuser1 root namespace.
ns = Namespace('testuser1')
# Create an interestingly named namespace
quran = u'\ufe8e\ufee0\ufed7\ufead\ufe81'
quranNS = ns.create_namespace(quran, 'For the purposes of testing')
# Attempt to create a new tag underneath
newTag = False
try:
# just check it can be created
sura = u'\ufeb1\ufeed\ufead'
newTag = quranNS.create_tag(sura, 'This is a test', False)
expectedPath = u'testuser1/' + quran + '/' + sura
self.assertEqual(expectedPath, newTag.path)
finally:
if newTag:
newTag.delete()
quranNS.delete()
示例2: __init__
class TestRunner:
def __init__(self):
endpoint = os.environ['FLUIDDB_ENDPOINT']
username = os.environ['FLUIDDB_ADMIN_USERNAME']
password = os.environ['FLUIDDB_ADMIN_PASSWORD']
self.solrURL = os.environ['FLUIDDB_INDEXING_SERVER_URL']
self.fluiddb = Fluid(endpoint)
self.fluiddb.login(username, password)
def solrCommit(self):
request = HTTPRequest()
url = urljoin(self.solrURL, 'update')
request.POST(url, '<commit />')
def __call__(self):
fluiddb = self.fluiddb
testNamespace = 'fluiddb/testing'
# CREATE
objectId = objects.createRandomObject(fluiddb)
aboutValue = about.createRandomObject(fluiddb)
namespace = namespaces.createRandomNamespace(fluiddb, testNamespace)
tag = tags.createRandomTag(fluiddb, testNamespace)
self.solrCommit()
#UPDATE
objects.setRandomTagValueString(fluiddb, objectId, tag)
about.setRandomTagValueString(fluiddb, aboutValue, tag)
namespaces.updateNamespaceWithRandomDescription(fluiddb, namespace)
tags.UpdateTagWithRandomDescription(fluiddb, tag)
# READ
objects.simpleEqualsQuery(fluiddb, aboutValue)
objects.simpleMatchesQuery(fluiddb, aboutValue)
objects.getObjectInfo(fluiddb, objectId)
objects.getTagValue(fluiddb, objectId, tag)
objects.hasTagValue(fluiddb, objectId, tag)
about.getObjectInfo(fluiddb, aboutValue)
about.getTagValue(fluiddb, aboutValue, tag)
about.hasTagValue(fluiddb, aboutValue, tag)
namespaces.getNamespaces(fluiddb, namespace)
tags.getTagInfo(fluiddb, tag)
#DELETE
objects.deleteTagValue(fluiddb, objectId, tag)
about.deleteTagValue(fluiddb, aboutValue, tag)
namespaces.deleteNamespace(fluiddb, namespace)
tags.deleteTag(fluiddb, tag)
示例3: test_user
def test_user(self):
"Check if fluiddb user exists"
fdb = Fluid(self.url)
try:
ret = fdb.__call__('GET', '/users/fluiddb')
if ret[0] == 200:
return (True,
'%s instance is now reachable' % self.shortname.capitalize(),
ret[1]['id'])
except socket.error:
return (False, '%s instance is unreachable' % self.shortname.capitalize())
except:
pass
return (False, 'Wrong thing happends on %s instance' % self.shortname)
示例4: Login
def Login(username, password):
instance = session.get('instance', 'fluiddb')
flogin = Fluid(get_instance_url(instance, ssl=False))
flogin.login(username, password)
try:
flogin.namespaces[username].get()
session['logged'] = True
session['username'] = username
session['password'] = password
return {'success': True}
except:
return {'success': False}
示例5: setUp
def setUp(self):
endpoint = os.environ.get('FLUIDDB_ENDPOINT', 'http://localhost:9000')
username = os.environ.get('FLUIDDB_ADMIN_USERNAME', 'fluiddb')
password = os.environ.get('FLUIDDB_ADMIN_PASSWORD', 'secret')
self.fluiddb = Fluid(endpoint)
self.fluiddb.login(username, password)
self.fluiddb.bind()
示例6: generateData
def generateData(username, password, endpoint):
"""Worker function creates random data.
Requests to create namespaces, tags and values are continuously generated.
This function never returns.
@param username: The username to connect as.
@param password: The password to use.
@param endpoint: The Fluidinfo API endpoint to make requests against.
"""
fluidinfo = Fluid(endpoint)
fluidinfo.login(username, password)
fluidinfo.bind()
while True:
try:
generateNamespaceData(username)
except StandardError, e:
logQueue.put(('ERROR %s' % str(e), ()))
示例7: TestPUT
class TestPUT(unittest.TestCase):
def setUp(self):
endpoint = os.environ.get('FLUIDDB_ENDPOINT', 'http://localhost:9000')
self.username = os.environ.get('FLUIDDB_ADMIN_USERNAME', 'fluiddb')
password = os.environ.get('FLUIDDB_ADMIN_PASSWORD', 'secret')
self.fluiddb = Fluid(endpoint)
self.fluiddb.login(self.username, password)
self.fluiddb.bind()
def testChangesTakeEffect(self):
"""
When PUTting updated values for a user's password, email or full-name
make sure the changes propogate to the database for later retrieval.
"""
newName = 'Kathpakalaxmikanthan'
body = {'name': newName}
response = self.fluiddb.db('PUT', ['users', 'testuser1'], body)
userID = self.fluiddb.users['testuser1'].get().value['id']
response = self.fluiddb.objects[userID]['fluiddb/users/name'].get()
self.assertEqual(newName, response.value)
示例8: Clipboard
class Clipboard(object):
"""
Get/set/clear a clipboard tag in Fluidinfo.
"""
_username = 'USERNAME' # Your Fluidinfo username.
_password = 'PASSWORD' # Your Fluidinfo password.
_tag = _username + '/clipboard'
def __init__(self):
self._fdb = Fluid()
self._fdb.login(self._username, self._password)
def get(self):
"""
Return the value of the user's clipboard tag if any, else C{None}.
"""
try:
result = self._fdb.values.get('has ' + self._tag, [self._tag])
except FluidError, e:
print 'Error:', e.args[0].response
raise
else:
示例9: __init__
def __init__(self):
self._fdb = Fluid()
self._fdb.login(self._username, self._password)
示例10: setUp
def setUp(self):
# sort out FluidDB
fdb = Fluid('https://sandbox.fluidinfo.com')
fdb.bind()
fdb.login('test', 'test')
示例11: len
from fom.session import Fluid
from json import loads
import os
import sys
if len(sys.argv) != 1:
print >>sys.stderr, 'Usage: %s < manifest.json' % sys.argv[0]
sys.exit(1)
APP_ID = 'kaagoiiakipocenbkhmcmbnldkbphcbn'
codebase = (
'https://fluiddb.fluidinfo.com/about/open-it-later/fluidinfo.com/chrome.crx')
version = loads(sys.stdin.read())['version']
fdb = Fluid('https://fluiddb.fluidinfo.com')
password = os.environ['FLUIDDB_FLUIDINFO_DOT_COM_PASSWORD']
fdb.login('fluidinfo.com', password)
about = 'open-it-later'
tag = 'fluidinfo.com/chrome-update.xml'
data = '''<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='%(id)s'>
<updatecheck codebase='%(codebase)s' version='%(version)s' />
</app>
</gupdate>
''' % {
'codebase': codebase,
'id': APP_ID,
示例12: Fluid
#!/usr/bin/env python
from json import dumps
import os
from fom.session import Fluid
fdb = Fluid()
fdb.login('telegraph.co.uk', os.environ['FLUDINFO_TELEGRAPH_PASSWORD'])
datasets = [
{
'about': [
'abu qatada',
'http://www.guardian.co.uk/commentisfree/2012/apr/17/abu-qatada-taking-the-righton-line',
'http://www.guardian.co.uk/commentisfree/2012/apr/17/abu-qatada-taking-the-righton-line?INTCMP=SRCH',
'http://www.guardian.co.uk/commentisfree/cartoon/2012/apr/17/abu-qatada-uk-security-cartoon',
'http://www.guardian.co.uk/commentisfree/cartoon/2012/apr/17/abu-qatada-uk-security-cartoon?INTCMP=SRCH',
'http://www.guardian.co.uk/commentisfree/cartoon/2012/apr/19/steve-bell-may-abu-qatada',
'http://www.guardian.co.uk/commentisfree/cartoon/2012/apr/19/steve-bell-may-abu-qatada?INTCMP=SRCH',
'http://www.guardian.co.uk/law/2012/apr/19/abu-qatada-deadline-appeal-strasbourg',
'http://www.guardian.co.uk/law/2012/apr/19/abu-qatada-deadline-appeal-strasbourg?INTCMP=SRCH',
'http://www.guardian.co.uk/law/2012/apr/19/brighton-abu-qatada-strasbourg',
'http://www.guardian.co.uk/law/2012/apr/19/brighton-abu-qatada-strasbourg?INTCMP=SRCH',
'http://www.guardian.co.uk/politics/2012/apr/19/theresa-may-sketch-abu-qatada',
'http://www.guardian.co.uk/politics/2012/apr/19/theresa-may-sketch-abu-qatada?INTCMP=SRCH',
'http://www.guardian.co.uk/politics/2012/apr/23/lords-reform-cameron-downplays-referendum',
'http://www.guardian.co.uk/politics/2012/apr/23/lords-reform-cameron-downplays-referendum?INTCMP=SRCH',
'http://www.guardian.co.uk/world/2009/feb/19/abu-qatada-profile',
'http://www.guardian.co.uk/world/2009/feb/19/abu-qatada-profile?INTCMP=SRCH',
'http://www.guardian.co.uk/world/2012/apr/17/abu-qatada-to-be-deported',
示例13: execute
def execute():
"""
Grab a bunch of args from the command line, verify and get the show on the
road
"""
parser = OptionParser(version="%prog " + flimp.VERSION)
parser.add_option('-f', '--file', dest='filename',
help='The FILE to process (valid filetypes: %s)' %
', '.join(VALID_FILETYPES.keys()), metavar="FILE")
parser.add_option('-d', '--dir', dest='directory',
help="The root directory for a filesystem import into"\
" FluidDB")
parser.add_option('-u', '--uuid', dest="uuid", default="",
help="The uuid of the object to which the filesystem"\
" import is to attach its tags")
parser.add_option('-a', '--about', dest="about", default="",
help="The about value of the object to which the"\
" filesystem import is to attach its tags")
parser.add_option('-p', '--preview', action="store_true", dest="preview",
help="Show a preview of what will happen, don't import"\
" anything", default=False)
parser.add_option('-i', '--instance', dest='instance',
default="https://fluiddb.fluidinfo.com",
help="The URI for the instance of FluidDB to use")
parser.add_option('-l', '--log', dest='log', default="flimp.log",
help="The log file to write to (defaults to flimp.log)")
parser.add_option('-v', '--verbose', dest='verbose', default=False,
action="store_true", help="Display status messages to"\
" console")
parser.add_option('-c', '--check', dest='check', default=False,
action="store_true", help="Validate the data file"\
" containing the data to import into FluidDB - don't"\
" import anything")
options, args = parser.parse_args()
# Some options validation
if not (options.filename or options.directory):
parser.error("You must supply either a source file or root directory"\
" to import.")
if options.filename and options.directory:
parser.error("You may only supply either a source file OR root"\
" directory to import (not both).")
if options.uuid and options.about:
parser.error("You may only supply either an object's uuid OR its"\
" about tag value (not both).")
# Setup logging properly
logger = logging.getLogger("flimp")
logger.setLevel(logging.DEBUG)
logfile_handler = logging.FileHandler(options.log)
logfile_handler.setLevel(logging.DEBUG)
log_format = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logfile_handler.setFormatter(log_format)
logger.addHandler(logfile_handler)
# verbose..?
if options.verbose:
# console handler
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
ch.setFormatter(log_format)
logger.addHandler(ch)
if options.check:
# No need to get information from the user if we're just validating
# the file. A bit hacky!
username = password = root_path = name = desc = about = ""
else:
# In the same way that sphinx interrogates the user using q&a we need to
# assemble some more data that is probably not so easy to grab from the
# arguments of the command
username = get_argument('FluidDB username')
password = get_argument('FluidDB password', password=True)
root_path = get_argument('Absolute Namespace path (under which imported'\
' namespaces and tags will be created)')
if options.filename:
name = get_argument('Name of dataset (defaults to filename)',
os.path.basename(options.filename).split('.')[0])
about = get_argument('Key field for about tag value (if none given,'\
' will use anonymous objects)', required=False)
else:
name = get_argument('Name of dataset')
desc = get_argument('Description of the dataset')
# Dump the recently collected information into the log file
logger.info('FluidDB instance: %r' % options.instance)
logger.info('Username: %r' % username)
logger.info('Absolute Namespace path: %r' % root_path)
logger.info('Dataset name: %r' % name)
logger.info('Dataset description: %r' % desc)
# Log into FluidDB
fdb = Fluid(options.instance)
fdb.bind()
fdb.login(username, password)
# Process the file or directory
try:
print "Working... (this might take some time, why not: tail -f the"\
" log?)"
if options.filename:
#.........这里部分代码省略.........
示例14: URL
default=False,
help='If True, open the current URL (default %default).')
args, opt = opts.parse_args()
# Check that any custom URL suffix is legal as a Fluidinfo tag name.
if args.custom:
if not re.match('^[\:\.\-\w/]+$', args.custom, re.UNICODE):
print >>sys.stderr, ('Custom suffixes can only contain letters, '
'digits, dot, hyphen, colon, and slash.')
sys.exit(1)
args.custom = '-' + args.custom.replace('/', '-')
# Get an instance of fom.session.Fluid and provide it with credentials,
# if we have been given a password to use.
fdb = Fluid()
if args.password:
if not args.user:
print >>sys.stderr, 'Please use --user USERNAME.'
sys.exit(1)
if not args.password:
print >>sys.stderr, 'Please use --password PASSWORD.'
sys.exit(1)
fdb.login(args.user, args.password)
# The Fluidinfo tag that will be acted on.
tag = '%s/lastpage%s' % (args.user, args.custom)
# Prepend 'http://' if it looks like we can be helpful.
if args.url and not args.url.startswith('http'):
args.url = 'http://' + args.url
示例15: len
#!/usr/bin/env python
from fom.session import Fluid
import os
import sys
if len(sys.argv) != 2:
print >> sys.stderr, "Usage: %s extension-file.crx" % sys.argv[0]
sys.exit(1)
crxFile = sys.argv[1]
data = open(crxFile).read()
fdb = Fluid("https://fluiddb.fluidinfo.com")
password = os.environ["FLUIDDB_FLUIDINFO_DOT_COM_PASSWORD"]
fdb.login("fluidinfo.com", password)
about = "open-it-later"
tag = "fluidinfo.com/chrome.crx"
fdb.about[about][tag].put(data, "application/x-chrome-extension")
print "Uploaded %s to https://fluiddb.fluidinfo.com/about/%s/%s" % (crxFile, about, tag)