Here are the examples of the python api django.utils.encoding.smart_str taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
144 Examples
3
Source : memcache.py
with GNU Affero General Public License v3.0
from Abstract-Tech
with GNU Affero General Public License v3.0
from Abstract-Tech
def cleaned_string(val):
"""
Converts `val` to unicode and URL-encodes special characters
(including quotes and spaces)
"""
return six.moves.urllib.parse.quote_plus(smart_str(val))
def safe_key(key, key_prefix, version):
3
Source : views.py
with MIT License
from adfinis-sygroup
with MIT License
from adfinis-sygroup
def retrieve(self, request, **kwargs):
template = self.get_object()
mime_type, _ = mimetypes.guess_type(template.template.name)
extension = mimetypes.guess_extension(mime_type)
content_type = mime_type or "application/force-download"
response = HttpResponse(content_type=content_type)
response["Content-Disposition"] = 'attachment; filename="%s"' % smart_str(
template.slug + extension
)
response["Content-Length"] = template.template.size
response.write(template.template.read())
return response
3
Source : string.py
with MIT License
from ambient-innovation
with MIT License
from ambient-innovation
def slugify_file_name(file_name: str, length: int = 40) -> str:
"""
Slugify the given file name
"""
name, ext = os.path.splitext(file_name)
name = smart_str(slugify(name).replace('-', '_'))
ext = smart_str(slugify(ext))
result = '%s%s%s' % (name[:length], "." if ext else "", ext)
return result
def smart_truncate(text: str, max_length: int = 100, suffix: str = '...') -> str:
3
Source : snippet.py
with Apache License 2.0
from dockerizeme
with Apache License 2.0
from dockerizeme
def add(self, key, value, timeout=None, min_compress_len=MIN_COMPRESS_LEN):
if isinstance(value, unicode):
value = value.encode('utf-8')
if timeout is None:
timeout = self.default_timeout
return self._cache.add(smart_str(key), value, timeout, min_compress_len)
def set(self, key, value, timeout=None, min_compress_len=MIN_COMPRESS_LEN):
3
Source : snippet.py
with Apache License 2.0
from dockerizeme
with Apache License 2.0
from dockerizeme
def set(self, key, value, timeout=None, min_compress_len=MIN_COMPRESS_LEN):
if isinstance(value, unicode):
value = value.encode('utf-8')
if timeout is None:
timeout = self.default_timeout
self._cache.set(smart_str(key), value, timeout)
def set_many(self, data, timeout=None, min_compress_len=MIN_COMPRESS_LEN):
3
Source : snippet.py
with Apache License 2.0
from dockerizeme
with Apache License 2.0
from dockerizeme
def set_many(self, data, timeout=None, min_compress_len=MIN_COMPRESS_LEN):
safe_data = {}
for key, value in data.items():
if isinstance(value, unicode):
value = value.encode('utf-8')
safe_data[smart_str(key)] = value
if timeout is None:
timeout = self.default_timeout
self._cache.set_multi(safe_data, timeout, min_compress_len=min_compress_len)
3
Source : snippet.py
with Apache License 2.0
from dockerizeme
with Apache License 2.0
from dockerizeme
def to_python(self, value):
if not isinstance(value, basestring):
return value
try:
return pickle.loads(smart_str(value))
except (EOFError, IndexError, KeyError, ValueError):
return value
# Make able to store Django model objects in ``PickleField``
def picklefield(func):
3
Source : serializers.py
with Apache License 2.0
from dylanleigh
with Apache License 2.0
from dylanleigh
def to_internal_value(self, data):
try:
return self.get_queryset().get_or_create(**{self.slug_field: data})[0]
except ObjectDoesNotExist:
self.fail('does_not_exist', slug_name=self.slug_field, value=smart_str(data))
except (TypeError, ValueError):
self.fail('invalid')
class IngredientSerializer(serializers.HyperlinkedModelSerializer):
3
Source : generic.py
with GNU General Public License v3.0
from foonsun
with GNU General Public License v3.0
from foonsun
def get_checkbox_object_name(self):
if self.checkbox_object_name:
return self.checkbox_object_name
return smart_str(self.model._meta.object_name.lower())
def get_error_url(self, request):
3
Source : hive_metastore_server.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _encode_struct_attr(struct, attr):
try:
unival = getattr(struct, attr)
except AttributeError:
return struct
val = smart_str(unival, strings_only=True)
setattr(struct, attr, val)
return struct
3
Source : tests.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _make_query(client, query, submission_type="Execute",
udfs=None, settings=None, resources=[],
wait=False, name=None, desc=None, local=True,
is_parameterized=True, max=30.0, database='default', email_notify=False, params=None, server_name='beeswax', **kwargs):
res = make_query(client, query, submission_type,
udfs, settings, resources,
wait, name, desc, local, is_parameterized, max, database, email_notify, params, server_name, **kwargs)
# Should be in the history if it's submitted.
if submission_type == 'Execute':
if is_parameterized and params:
query = substitute_variables(query, dict(params))
fragment = collapse_whitespace(smart_str(escape(query[:20])))
verify_history(client, fragment=fragment, server_name=server_name)
return res
def random_generator(size=8, chars=string.ascii_uppercase + string.digits):
3
Source : api.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def getRows(self, cluster, tableName, columns, startRowKey, numRows, prefix=False):
client = self.connectCluster(cluster)
if prefix == False:
scanner = client.scannerOpen(tableName, smart_str(startRowKey), columns, None, doas=self.user.username)
else:
scanner = client.scannerOpenWithPrefix(tableName, smart_str(startRowKey), columns, None, doas=self.user.username)
data = client.scannerGetList(scanner, numRows, doas=self.user.username)
client.scannerClose(scanner, doas=self.user.username)
return data
def getAutocompleteRows(self, cluster, tableName, numRows, query):
3
Source : api.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def getAutocompleteRows(self, cluster, tableName, numRows, query):
query = smart_str(query)
try:
client = self.connectCluster(cluster)
scan = get_thrift_type('TScan')(startRow=query, stopRow=None, timestamp=None, columns=[], caching=None, filterString="PrefixFilter('" + query + "') AND ColumnPaginationFilter(1,0)", batchSize=None)
scanner = client.scannerOpenWithScan(tableName, scan, None, doas=self.user.username)
return [result.row for result in client.scannerGetList(scanner, numRows, doas=self.user.username)]
except Exception as e:
LOG.error('Autocomplete error: %s' % smart_str(e))
return []
def getRow(self, cluster, tableName, columns, startRowKey):
3
Source : api.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def getRow(self, cluster, tableName, columns, startRowKey):
row = self.getRows(cluster, tableName, columns, smart_str(startRowKey), 1)
if len(row) > 0:
return row[0]
return None
def getRowsFull(self, cluster, tableName, startRowKey, numRows):
3
Source : api.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def getRowFull(self, cluster, tableName, startRowKey, numRows):
row = self.getRowsFull(cluster, tableName, smart_str(startRowKey), 1)
if len(row) > 0:
return row[0]
return None
def getRowPartial(self, cluster, tableName, rowKey, offset, number):
3
Source : api.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def deleteColumns(self, cluster, tableName, row, columns):
client = self.connectCluster(cluster)
Mutation = get_thrift_type('Mutation')
mutations = [Mutation(isDelete = True, column=smart_str(column)) for column in columns]
return client.mutateRow(tableName, smart_str(row), mutations, None, doas=self.user.username)
def deleteColumn(self, cluster, tableName, row, column):
3
Source : api.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def putRow(self, cluster, tableName, row, data):
client = self.connectCluster(cluster)
mutations = []
Mutation = get_thrift_type('Mutation')
for column in list(data.keys()):
value = smart_str(data[column]) if data[column] is not None else None
mutations.append(Mutation(column=smart_str(column), value=value)) # must use str for API, does thrift coerce by itself?
return client.mutateRow(tableName, smart_str(row), mutations, None, doas=self.user.username)
def putColumn(self, cluster, tableName, row, column, value=None):
3
Source : api.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def putUpload(self, cluster, tableName, row, column, value):
client = self.connectCluster(cluster)
Mutation = get_thrift_type('Mutation')
return client.mutateRow(tableName, smart_str(row), [Mutation(column=smart_str(column), value=value.file.read(value.size))], None, doas=self.user.username)
def getRowQuerySet(self, cluster, tableName, columns, queries):
3
Source : tests.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _make_query(client, query, submission_type="Execute",
udfs=None, settings=None, resources=[],
wait=False, name=None, desc=None, local=True,
is_parameterized=True, max=30.0, database='default', email_notify=False, **kwargs):
"""Wrapper around the real make_query"""
res = make_query(client, query, submission_type,
udfs, settings, resources,
wait, name, desc, local, is_parameterized, max, database, email_notify, **kwargs)
# Should be in the history if it's submitted.
if submission_type == 'Execute':
fragment = collapse_whitespace(smart_str(query[:20]))
verify_history(client, fragment=fragment)
return res
class TestApi():
3
Source : workflows.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def _assign_workflow_properties(workflow, root, namespace):
namespaces = {
'n': namespace
}
global_config = root.xpath('n:global', namespaces=namespaces)
if global_config:
_global_configuration(workflow, global_config[0], namespace)
LOG.debug("Finished assigning properties to workflow %s" % smart_str(workflow.name))
def _save_links(workflow, root):
3
Source : models.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def compress(self, mapping=None, fp=string_io()):
metadata = {
'version': Bundle.METADATA_FORMAT_VERSION,
'attributes': {
'description': self.description,
'deployment_dir': self.deployment_dir
}
}
xml = self.to_xml(mapping=mapping)
zfile = zipfile.ZipFile(fp, 'w')
zfile.writestr("bundle.xml", smart_str(xml))
zfile.writestr("bundle-metadata.json", smart_str(json.dumps(metadata)))
zfile.close()
return fp
@classmethod
3
Source : exception.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def handle_rest_exception(e, msg):
parent_ex = e.get_parent_ex()
reason = None
if hasattr(parent_ex, 'reason'):
reason = parent_ex.reason
if isinstance(reason, socket.error):
LOG.error(smart_str('Could not connect to sqoop server: %s (%s)' % (reason[0], reason[1])))
return {
'status': -1,
'errors': [_('Could not connect to sqoop server. %s (%s)') % (reason[0], reason[1])]
}
else:
LOG.error(smart_str(msg))
LOG.error(smart_str(e.message))
return {
'status': 1,
'errors': [msg],
'exception': str(e)
}
3
Source : views.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def sync_ldap_users_and_groups(connection, is_ensuring_home_directory=False, fs=None, failed_users=None):
try:
users = sync_ldap_users(connection, failed_users=failed_users)
groups = sync_ldap_groups(connection, failed_users=failed_users)
except (ldap.LDAPError, LdapBindException) as e:
LOG.error("LDAP Exception: %s" % smart_str(e))
raise PopupException(smart_str(_('There was an error when communicating with LDAP: %s')) % str(e))
# Create home dirs for every user sync'd
if is_ensuring_home_directory:
for user in users:
try:
ensure_home_directory(fs, user)
except (IOError, WebHdfsException) as e:
raise PopupException(_("The import may not be complete, sync again."), detail=e)
def import_ldap_users(connection, user_pattern, sync_groups, import_by_dn, server=None, failed_users=None):
3
Source : views.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def sync_ldap_users(connection, failed_users=None):
"""
Syncs LDAP user information. This will not import new
users from LDAP. It is also not possible to import both a user and a
group at the same time. Each must be a separate operation. If neither a user,
nor a group is provided, all users and groups will be synced.
"""
users = User.objects.filter(userprofile__creation_method=UserProfile.CreationMethod.EXTERNAL.name).all()
for user in users:
_import_ldap_users(connection, smart_str(user.username), failed_users=failed_users)
return users
def sync_ldap_groups(connection, failed_users=None):
3
Source : export_csvxls.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def encode_row(row, encoding=None, make_excel_links=False):
encoded_row = []
encoding = encoding or i18n.get_site_encoding()
for cell in row:
if isinstance(cell, six.string_types):
cell = re.sub(ILLEGAL_CHARS, '?', cell)
if make_excel_links:
cell = re.compile('^(https?://.+)', re.IGNORECASE).sub(r'=HYPERLINK("\1")', cell)
cell = nullify(cell)
if not isinstance(cell, numbers.Number):
cell = smart_str(cell, encoding, strings_only=True, errors='replace')
encoded_row.append(cell)
return encoded_row
def dataset(headers, data, encoding=None):
3
Source : i18n.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def smart_str(s, strings_only=False, errors='strict'):
"""
Wrapper around Django's version, while supplying our configured encoding.
Encode unicode into char array.
"""
return django.utils.encoding.smart_str(
s, get_site_encoding(), strings_only, errors)
_CACHED_ENV = None
3
Source : engine.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def redact(self, message):
"""
Perform the message redaction. If the message does not contain the
`trigger` string then it will return the original string unmodified.
"""
if message and (self.trigger is None or self.trigger.search(message)):
return self.regex.sub(smart_str(self.replace), message)
else:
return message
def __repr__(self):
3
Source : tests.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def test_unicode_strings(self):
path = get_path('real-1.json')
policy = parse_redaction_policy_from_file(path)
messages = [
("äöüß 123-45-6789", "äöüß XXX-XX-XXXX"),
("你好阿基尔 1234234534654576", "你好阿基尔 XXXXXXXXXXXXXXXX"),
("ã 你好 1234,2345,3456,4576", "ã 你好 XXXX-XXXX-XXXX-XXXX"),
]
for message, redacted_message in messages:
message_to_redact = smart_str(message)
self.logger.debug("Message to redact : %s " % message_to_redact)
self.logger.debug("Message after redact : %s " % policy.redact(message_to_redact))
assert_equal(redacted_message, policy.redact(message_to_redact))
def test_huge_rules(self):
3
Source : webhdfs.py
with Apache License 2.0
from gethue
with Apache License 2.0
from gethue
def rename(self, old, new):
"""rename(old, new)"""
old = self.strip_normpath(old)
if not self.is_absolute(new):
new = Hdfs.join(Hdfs.dirname(old), new)
new = self.strip_normpath(new)
params = self._getparams()
params['op'] = 'RENAME'
# Encode `new' because it's in the params
params['destination'] = smart_str(new)
headers = self._getheaders()
result = self._root.put(old, params, headers=headers)
if not result['boolean']:
raise IOError(_("Rename failed: %s -> %s") % (smart_str(old, errors='replace'), smart_str(new, errors='replace')))
def rename_star(self, old_dir, new_dir):
3
Source : utils.py
with MIT License
from guidovranken
with MIT License
from guidovranken
def test_smart_str(inp):
try:
smart_str(inp)
except:
pass
def test_forms_BooleanField(inp):
3
Source : integration.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_not_logged_browse_private_list(client, messages):
'''Test that an unauthenticated user cannot access private list
browse views
'''
message = Message.objects.filter(email_list__name='private').first()
url = reverse('archive_search') + '?email_list=private&index={}'.format(message.hashcode.strip('='))
response = client.get(url)
assert 'No results found' in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : integration.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_odd_queries(client, messages):
'Test some odd queries'
# search with no params
url = reverse('archive_search')
response = client.get(url)
assert response.status_code == 200
# search with only hyphen
url = url + '?q=-'
response = client.get(url, follow=True)
assert response.status_code == 200
assert 'Invalid search' in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : integration.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_queries_two_periods(client, messages):
'''Test that range operator (two periods) doesn't cause error'''
url = reverse('archive_search') + '?q=spec...)'
response = client.get(url, follow=True)
assert response.status_code == 200
assert 'Invalid search' in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : models.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_attachment_get_sub_message(client, attachment_messages_no_index):
attachment = Attachment.objects.first()
sub = attachment.get_sub_message()
assert sub.get_content_type() == 'text/plain'
assert get_filename(sub) == 'skip32.c'
print(type(sub.get_payload(decode=True)))
assert 'unsigned' in smart_str(sub.get_payload(decode=True))
def test_is_attachment():
3
Source : views.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_admin_menu(client, admin_client):
url = reverse('archive')
response = client.get(url)
assert 'id="navbar-admin"' not in smart_str(response.content)
response = admin_client.get(url)
assert 'id="navbar-admin"' in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : views.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_browse_static(client, messages):
url = reverse('archive_browse_static')
response = client.get(url)
assert response.status_code == 200
msg = messages.filter(email_list__private=False).first()
assert msg.email_list.name in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : views.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_browse_static_small_year_month(client, static_list, settings):
settings.STATIC_INDEX_YEAR_MINIMUM = 20
url = reverse('archive_browse_static_date', kwargs={'list_name': static_list.name, 'date': '2015-06'})
response = client.get(url)
assert response.status_code == 200
assert 'http-equiv="refresh"' in smart_str(response.content)
assert 'public/2015' in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : views.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_browse_static_small_year_current(client, settings):
settings.STATIC_INDEX_YEAR_MINIMUM = 20
today = datetime.datetime.today()
current_year = today.year
elist = EmailListFactory.create()
message = MessageFactory.create(email_list=elist, date=today)
url = reverse('archive_browse_static_date', kwargs={'list_name': elist.name, 'date': '{}-{:02d}'.format(today.year, today.month)})
response = client.get(url)
assert response.status_code == 200
assert message.subject in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : views.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_browse_static_big_year_year(client, static_list, settings):
settings.STATIC_INDEX_YEAR_MINIMUM = 20
url = reverse('archive_browse_static_date', kwargs={'list_name': static_list.name, 'date': '2017'})
response = client.get(url)
assert response.status_code == 200
assert 'http-equiv="refresh"' in smart_str(response.content)
assert 'public/2017-12' in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : views.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_detail(client):
elist = EmailListFactory.create()
msg = MessageFactory.create(email_list=elist)
url = reverse('archive_detail', kwargs={'list_name': elist.name, 'id': msg.hashcode})
response = client.get(url)
assert response.status_code == 200
assert ' < title>{} < /title>'.format(msg.subject) in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : views.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_attachment(client, attachment_messages_no_index):
message = Message.objects.get(msgid='attachment')
attachment = message.attachment_set.first()
url = reverse('archive_attachment', kwargs={'list_name': attachment.message.email_list.name,
'id': attachment.message.hashcode,
'sequence': attachment.sequence})
response = client.get(url)
assert response.status_code == 200
assert response['Content-Type'] == 'text/plain'
assert response['Content-Disposition'] == 'attachment; filename=skip32.c'
assert 'unsigned' in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : views.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_attachment_folded_name(client, attachment_messages_no_index):
message = Message.objects.get(msgid='attachment.folded.name')
attachment = message.attachment_set.first()
url = reverse('archive_attachment', kwargs={'list_name': attachment.message.email_list.name,
'id': attachment.message.hashcode,
'sequence': attachment.sequence})
response = client.get(url)
assert response.status_code == 200
assert response['Content-Type'] == 'text/plain'
assert response['Content-Disposition'] == 'attachment; filename=this_is_a really_long filename'
assert 'unsigned' in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : views.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_export_limit(admin_client, messages, settings):
settings.EXPORT_LIMIT = 0
url = reverse('archive_browse_list', kwargs={'list_name': 'pubone'})
response = admin_client.get(url)
# print(response.content)
print(type(response.content))
assert response.status_code == 200
assert 'Export is limited to 0 messages.' in smart_str(response.content)
q = PyQuery(response.content)
assert len(q('.export-link.disabled')) == 3
url = reverse('archive_export', kwargs={'type': 'mbox'}) + '?email_list=pubone'
response = admin_client.get(url)
assert response.status_code == 302
def test_help(client):
3
Source : view_funcs.py
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
with BSD 3-Clause "New" or "Revised" License
from ietf-tools
def test_get_export_url(messages):
url = '%s?%s' % (reverse('archive_export', kwargs={'type': 'url'}), 'q=message')
request = get_request(url=url)
search = get_search()
search = search.query('term', email_list='pubone')
response = get_export(search, 'url', request)
assert response.status_code == 200
search_response = search.execute()
apply_objects(search_response.hits)
assert search_response[0].object.get_absolute_url() in smart_str(response.content)
@pytest.mark.django_db(transaction=True)
3
Source : tests.py
with Apache License 2.0
from lumanjiao
with Apache License 2.0
from lumanjiao
def _make_query(client, query, submission_type="Execute",
udfs=None, settings=None, resources=[],
wait=False, name=None, desc=None, local=True,
is_parameterized=True, max=30.0, database='default', email_notify=False, params=None, server_name='beeswax', **kwargs):
res = make_query(client, query, submission_type,
udfs, settings, resources,
wait, name, desc, local, is_parameterized, max, database, email_notify, params, server_name, **kwargs)
# Should be in the history if it's submitted.
if submission_type == 'Execute':
fragment = collapse_whitespace(smart_str(escape(query[:20])))
verify_history(client, fragment=fragment, server_name=server_name)
return res
def get_csv(client, result_response):
3
Source : api.py
with Apache License 2.0
from lumanjiao
with Apache License 2.0
from lumanjiao
def getAutocompleteRows(self, cluster, tableName, numRows, query):
query = smart_str(query)
try:
client = self.connectCluster(cluster)
scan = get_thrift_type('TScan')(startRow=query, stopRow=None, timestamp=None, columns=[], caching=None, filterString="PrefixFilter('" + query + "') AND ColumnPaginationFilter(1,0)", batchSize=None)
scanner = client.scannerOpenWithScan(tableName, scan, None, doas=self.user.username)
return [result.row for result in client.scannerGetList(scanner, numRows, doas=self.user.username)]
except Exception, e:
LOG.error('Autocomplete error: %s' % smart_str(e))
return []
def getRow(self, cluster, tableName, columns, startRowKey):
3
Source : api.py
with Apache License 2.0
from lumanjiao
with Apache License 2.0
from lumanjiao
def putRow(self, cluster, tableName, row, data):
client = self.connectCluster(cluster)
mutations = []
Mutation = get_thrift_type('Mutation')
for column in data.keys():
value = smart_str(data[column]) if data[column] is not None else None
mutations.append(Mutation(column=smart_str(column), value=value)) # must use str for API, does thrift coerce by itself?
return client.mutateRow(tableName, smart_str(row), mutations, None, doas=self.user.username)
def putColumn(self, cluster, tableName, row, column, value=None):
3
Source : tests.py
with Apache License 2.0
from lumanjiao
with Apache License 2.0
from lumanjiao
def _make_query(client, query, submission_type="Execute",
udfs=None, settings=None, resources=[],
wait=False, name=None, desc=None, local=True,
is_parameterized=True, max=30.0, database='default', email_notify=False, **kwargs):
"""Wrapper around the real make_query"""
res = make_query(client, query, submission_type,
udfs, settings, resources,
wait, name, desc, local, is_parameterized, max, database, email_notify, **kwargs)
# Should be in the history if it's submitted.
if submission_type == 'Execute':
fragment = collapse_whitespace(smart_str(query[:20]))
verify_history(client, fragment=fragment)
return res
class TestMetastoreWithHadoop(BeeswaxSampleProvider):
3
Source : models.py
with Apache License 2.0
from lumanjiao
with Apache License 2.0
from lumanjiao
def compress(self, mapping=None, fp=StringIO.StringIO()):
metadata = {
'version': Bundle.METADATA_FORMAT_VERSION,
'attributes': {
'description': self.description,
'deployment_dir': self.deployment_dir
}
}
xml = self.to_xml(mapping=mapping)
zfile = zipfile.ZipFile(fp, 'w')
zfile.writestr("bundle.xml", smart_str(xml))
zfile.writestr("bundle-metadata.json", smart_str(json.dumps(metadata)))
zfile.close()
return fp
@classmethod
3
Source : backend.py
with Apache License 2.0
from lumanjiao
with Apache License 2.0
from lumanjiao
def _bind_as(self, bind_dn, bind_password, sticky=False):
"""
Binds to the LDAP server with the given credentials. This does not trap
exceptions.
If sticky is True, then we will consider the connection to be bound for
the life of this object. If False, then the caller only wishes to test
the credentials, after which the connection will be considered unbound.
"""
self._get_connection().simple_bind_s(force_str(bind_dn),
force_str(bind_password))
self._connection_bound = sticky
def _get_connection(self):
See More Examples