本文整理汇总了Python中fom.session.Fluid.bind方法的典型用法代码示例。如果您正苦于以下问题:Python Fluid.bind方法的具体用法?Python Fluid.bind怎么用?Python Fluid.bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fom.session.Fluid
的用法示例。
在下文中一共展示了Fluid.bind方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTags
# 需要导入模块: from fom.session import Fluid [as 别名]
# 或者: from fom.session.Fluid import bind [as 别名]
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: generateData
# 需要导入模块: from fom.session import Fluid [as 别名]
# 或者: from fom.session.Fluid import bind [as 别名]
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), ()))
示例3: TestPUT
# 需要导入模块: from fom.session import Fluid [as 别名]
# 或者: from fom.session.Fluid import bind [as 别名]
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)
示例4: setUp
# 需要导入模块: from fom.session import Fluid [as 别名]
# 或者: from fom.session.Fluid import bind [as 别名]
def setUp(self):
# sort out FluidDB
fdb = Fluid('https://sandbox.fluidinfo.com')
fdb.bind()
fdb.login('test', 'test')
示例5: open
# 需要导入模块: from fom.session import Fluid [as 别名]
# 或者: from fom.session.Fluid import bind [as 别名]
print "Commiting:",sAbout
fdb.values.put( query='fluiddb/about = "'+sAbout+'"',values=dictTags)
if __name__ == "__main__":
#############################
# Bind to FluidInfo instance
fileCredentials = open(os.path.expanduser('~/.fluidDBcredentials'), 'r')
username = fileCredentials.readline().strip()
password = fileCredentials.readline().strip()
fileCredentials.close()
# fdb = Fluid('https://sandbox.fluidinfo.com') # The sandbox instance
fdb = Fluid() # The main instance
fdb.login(username, password)
fdb.bind()
nsUser = Namespace(username)
sUserNS = nsUser.path # Ugly use of a global, I know. :-)
dictObjects = dict()
fRequest = urllib2.urlopen(urlISOcodeListing)
# Get enconding of raw listing.
# This should usually be UTF-8, but it could change and cause a big headache!
# sEncoding = fRequest.headers['content-type'].split('charset=')[-1]
# ^^^^This is not working, since http://loc.org is not specifying the encoding. Dammit!
# fRequest.headers['content-type'] = 'text/plain'
# instead of:
# fRequest.headers['content-type'] = 'text/html; charset=utf-8'
示例6: TestGET
# 需要导入模块: from fom.session import Fluid [as 别名]
# 或者: from fom.session.Fluid import bind [as 别名]
class TestGET(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 testQueryWithUnicodeTagName(self):
"""
Make sure that a query using a tag whose name contains non-ASCII
unicode characters works correctly.
See https://bugs.edge.launchpad.net/fluiddb/+bug/681354 for the reason
this is tested.
"""
# Use the testuser1 root namespace.
ns = Namespace('testuser1')
# Umlauts FTW!
tag_name = u'C\xfc\xe4h'
# Create the tag.
tag = ns.create_tag(tag_name, 'Used for testing purposes', False)
try:
# Run a query that uses the tag. If we haven't fixed the bug,
# FluidDB will hang at this point.
result = Object.filter('has testuser1/%s' % tag_name)
# Check the result is an empty list (i.e., no results found).
self.assertEqual([], result)
finally:
# Clean up the tag.
tag.delete()
def testTagValueTypeHeaderInt(self):
"""
When requesting a primitive tag value using a GET or HEAD request to
/objects/id/namespace/tag, the response should put an X-FluidDB-Type
header indicating the type of the response. This particular test
checks header values for the int type.
"""
# Create and object and add one tag.
id = self.fluiddb.objects.post().value['id']
self.fluiddb.objects[id]['fluiddb/testing/test1'].put(1)
try:
response = self.fluiddb.objects[id]['fluiddb/testing/test1'].get()
self.assertEqual('int',
response.response.headers.get('x-fluiddb-type'))
response = self.fluiddb.objects[id]['fluiddb/testing/test1'].head()
self.assertEqual('int',
response.response.headers.get('x-fluiddb-type'))
finally:
self.fluiddb.objects[id]['fluiddb/testing/test1'].delete()
def testTagValueTypeHeaderFloat(self):
"""
When requesting a primitive tag value using a GET or HEAD request to
/objects/id/namespace/tag, the response should put an X-FluidDB-Type
header indicating the type of the response. This particular test
checks header values for the float type.
"""
# Create and object and add one tag.
id = self.fluiddb.objects.post().value['id']
self.fluiddb.objects[id]['fluiddb/testing/test1'].put(1.1)
try:
response = self.fluiddb.objects[id]['fluiddb/testing/test1'].get()
self.assertEqual('float',
response.response.headers.get('x-fluiddb-type'))
response = self.fluiddb.objects[id]['fluiddb/testing/test1'].head()
self.assertEqual('float',
response.response.headers.get('x-fluiddb-type'))
finally:
self.fluiddb.objects[id]['fluiddb/testing/test1'].delete()
def testTagValueTypeHeaderString(self):
"""
When requesting a primitive tag value using a GET or HEAD request to
/objects/id/namespace/tag, the response should put an X-FluidDB-Type
header indicating the type of the response. This particular test
checks header values for the string type.
"""
# Create and object and add one tag.
id = self.fluiddb.objects.post().value['id']
self.fluiddb.objects[id]['fluiddb/testing/test1'].put('hello')
try:
response = self.fluiddb.objects[id]['fluiddb/testing/test1'].get()
self.assertEqual('string',
response.response.headers.get('x-fluiddb-type'))
response = self.fluiddb.objects[id]['fluiddb/testing/test1'].head()
self.assertEqual('string',
response.response.headers.get('x-fluiddb-type'))
finally:
self.fluiddb.objects[id]['fluiddb/testing/test1'].delete()
#.........这里部分代码省略.........
示例7: TestGETHEAD
# 需要导入模块: from fom.session import Fluid [as 别名]
# 或者: from fom.session.Fluid import bind [as 别名]
class TestGETHEAD(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 testTagValueTypeHeaderFloat(self):
"""
When requesting a primitive tag value using a GET or HEAD request to
/objects/id/namespace/tag, the response should put an X-FluidDB-Type
header indicating the type of the response. This particular test
checks header values for the float type.
"""
# Create and object and add one tag.
self.fluiddb.about.post('about').value['id']
path = 'fluiddb/testing/test1'
self.fluiddb.about['about'][path].put(1.1)
try:
response = self.fluiddb.about['about'][path].get()
self.assertEqual('float',
response.response.headers.get('x-fluiddb-type'))
response = self.fluiddb.about['about'][path].head()
self.assertEqual('float',
response.response.headers.get('x-fluiddb-type'))
finally:
self.fluiddb.about['about'][path].delete()
def testTagValueTypeHeaderString(self):
"""
When requesting a primitive tag value using a GET or HEAD request to
/objects/id/namespace/tag, the response should put an X-FluidDB-Type
header indicating the type of the response. This particular test
checks header values for the string type.
"""
# Create and object and add one tag.
self.fluiddb.about.post('about').value['id']
path = 'fluiddb/testing/test1'
self.fluiddb.about['about'][path].put('hello')
try:
response = self.fluiddb.about['about'][path].get()
self.assertEqual('string',
response.response.headers.get('x-fluiddb-type'))
response = self.fluiddb.about['about'][path].head()
self.assertEqual('string',
response.response.headers.get('x-fluiddb-type'))
finally:
self.fluiddb.about['about'][path].delete()
def testTagValueTypeHeaderBool(self):
"""
When requesting a primitive tag value using a GET or HEAD request to
/objects/id/namespace/tag, the response should put an X-FluidDB-Type
header indicating the type of the response. This particular test
checks header values for the bool type.
"""
# Create and object and add one tag.
self.fluiddb.about.post('about').value['id']
path = 'fluiddb/testing/test1'
self.fluiddb.about['about'][path].put(True)
try:
response = self.fluiddb.about['about'][path].get()
self.assertEqual('boolean',
response.response.headers.get('x-fluiddb-type'))
response = self.fluiddb.about['about'][path].head()
self.assertEqual('boolean',
response.response.headers.get('x-fluiddb-type'))
finally:
self.fluiddb.about['about'][path].delete()
def testTagValueTypeHeaderNull(self):
"""
When requesting a primitive tag value using a GET or HEAD request to
/objects/id/namespace/tag, the response should put an X-FluidDB-Type
header indicating the type of the response. This particular test
checks header values for the none type.
"""
# Create and object and add one tag.
self.fluiddb.about.post('about').value['id']
path = 'fluiddb/testing/test1'
self.fluiddb.about['about'][path].put(None)
try:
response = self.fluiddb.about['about'][path].get()
self.assertEqual('null',
response.response.headers.get('x-fluiddb-type'))
response = self.fluiddb.about['about'][path].head()
self.assertEqual('null',
response.response.headers.get('x-fluiddb-type'))
finally:
#.........这里部分代码省略.........
示例8: execute
# 需要导入模块: from fom.session import Fluid [as 别名]
# 或者: from fom.session.Fluid import bind [as 别名]
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:
#.........这里部分代码省略.........