text
stringlengths 0
828
|
---|
To test if a table exists in a database: |
.. code-block:: python |
from fundamentals.mysql import table_exists |
exists = table_exists( |
dbConn=dbConn, |
log=log, |
dbTableName=""stupid_named_table"" |
) |
print exists |
# OUTPUT: False |
"""""" |
log.debug('starting the ``table_exists`` function') |
sqlQuery = u"""""" |
SELECT count(*) |
FROM information_schema.tables |
WHERE table_name = '%(dbTableName)s' |
"""""" % locals() |
tableExists = readquery( |
log=log, |
sqlQuery=sqlQuery, |
dbConn=dbConn, |
quiet=False |
) |
if tableExists[0][""count(*)""] == 0: |
tableExists = False |
else: |
tableExists = True |
log.debug('completed the ``table_exists`` function') |
return tableExists" |
4896,"def __handle_request(self, request, *args, **kw): |
"""""" Intercept the request and response. |
This function lets `HttpStatusCodeError`s fall through. They |
are caught and transformed into HTTP responses by the caller. |
:return: ``HttpResponse`` |
"""""" |
self._authenticate(request) |
self._check_permission(request) |
method = self._get_method(request) |
data = self._get_input_data(request) |
data = self._clean_input_data(data, request) |
response = self._exec_method(method, request, data, *args, **kw) |
return self._process_response(response, request)" |
4897,"def _exec_method(self, method, request, data, *args, **kw): |
"""""" Execute appropriate request handler. """""" |
if self._is_data_method(request): |
return method(data, request, *args, **kw) |
else: |
return method(request, *args, **kw)" |
4898,"def _process_response(self, response, request): |
"""""" Process the response. |
If the response is ``HttpResponse``, does nothing. Otherwise, |
serializes, formats and validates the response. |
:param response: resource's response. This can be |
- ``None``, |
- django's ``HttpResponse`` |
- devil's ``Response`` |
- dictionary (or list of dictionaries) |
- object (or list of objects) that are first serialized into dict |
using ``self.factory``. |
- plaintext |
:returns: Django's ``HttpResponse`` |
"""""" |
def coerce_response(): |
"""""" Coerce the response object into devil structure. """""" |
if not isinstance(response, Response): |
return Response(0, response) |
return response |
if isinstance(response, HttpResponse): |
# we don't do anything if resource returns django's http response |
return response |
devil_res = coerce_response() |
if devil_res.content and devil_res.get_code_num() in (0, 200, 201): |
# serialize, format and validate |
serialized_res = devil_res.content = self._serialize_object(devil_res.content, request) |
formatted_res = self._format_response(request, devil_res) |
self._validate_output_data(response, serialized_res, formatted_res, request) |
else: |
# no data -> format only |
formatted_res = self._format_response(request, devil_res) |
return formatted_res" |
4899,"def _format_response(self, request, response): |
"""""" Format response using appropriate datamapper. |
Take the devil response and turn it into django response, ready to |
be returned to the client. |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.