Esempio n. 1
0
 def input(self, strip=True):
     if self.params is not None:
         return self.params
     self.params = {}
     for k, v in self.request.arguments.iteritems():
         self.params[util.unicode_to_utf8(k)] = util.unicode_to_utf8(strip and v[-1].strip() or v[-1])
     return self.params
Esempio n. 2
0
    def trade_push(self, actv, member, code_info):
        '''推送'''
        customer_id = member['customer_id']
        appid, hj_appid = self.get_appid()
        try:
            p = {}
            p['appid'] = appid
            # 获取openid
            p['openid'] = thrift_callex(config.OPENUSER_SERVER, OpenUser,
                                        'get_openids_by_user_ids', hj_appid, [
                                            customer_id,
                                        ])[0]

            # 店铺名
            user = apcli_ex('findUserBriefById', int(self.user.userid))
            p['shopname'] = user.shopname if user else ''
            p['exchange_num'] = member['exchange_num'] + 1
            p['exchange_pt'] = actv['exchange_pt']
            p['obtain_amt'] = actv['obtain_amt']
            p['busicd'] = 'card_actv_exchange'
            p['goods_amt'] = actv['goods_amt']
            p['goods_name'] = actv['goods_name']
            p['code'] = code_info['code']
            p['customer_id'] = hids.encode(customer_id)
            p['activity_id'] = actv['id']
            p['card_id'] = member['id']
            p = {
                unicode_to_utf8(k): unicode_to_utf8(v)
                for k, v in p.iteritems()
            }

            HttpClient(config.TRADE_PUSH_SERVER).post('/push/v2/push',
                                                      params=p)
        except:
            log.warn('error:%s' % traceback.format_exc())
Esempio n. 3
0
    def GET(self):
        # use openid get userid
        userid = openid2userid(self.openid)

        # skip url
        skip_url = url_add_query(
            self._d.get('redirect_url', config.DEFAULT_REDIRECT_URL),
            {'_swx': self.swx})

        # 跳转到绑定页面
        if not userid:
            return self.redirect(config.OP_BIND_URL % urllib.quote(skip_url))

        return self.redirect(unicode_to_utf8(skip_url))
Esempio n. 4
0
File: api_util.py Progetto: quru/qis
def create_api_error_dict(exc):
    """
    Returns an API standard response dict for the given exception.
    If the exception has an 'api_data' attribute, this will be returned in
    the response's data value, otherwise the data value will be None.
    """
    err_no = API_CODES.INTERNAL_ERROR
    exc_val = '(none)' if exc is None else unicode_to_utf8(unicode(exc))

    if isinstance(exc, errors.ParameterError):
        err_no = API_CODES.INVALID_PARAM
    elif isinstance(exc, errors.AlreadyExistsError):
        err_no = API_CODES.ALREADY_EXISTS
    elif isinstance(exc, errors.DoesNotExistError):
        err_no = API_CODES.NOT_FOUND
    elif isinstance(exc, errors.AuthenticationError):
        err_no = API_CODES.REQUIRES_AUTH
    elif isinstance(exc, errors.ImageError):
        err_no = API_CODES.IMAGE_ERROR
    elif isinstance(exc, errors.SecurityError):
        err_no = API_CODES.UNAUTHORISED
    elif isinstance(exc, errors.ServerTooBusyError):
        err_no = API_CODES.TOO_BUSY

    # Log interesting errors
    if err_no == API_CODES.INVALID_PARAM:
        logger.error('API Parameter error (' + str(exc) + ')')
    elif err_no == API_CODES.UNAUTHORISED:
        logger.error('API Security error (' + str(exc) + ')')
    elif err_no == API_CODES.INTERNAL_ERROR:
        logger.error('API ' + traceback.format_exc())

    return create_api_dict(
        err_no,
        API_MESSAGES[err_no] + ' (' + exc_val + ')',
        getattr(exc, 'api_data', None)
    )
 def load_from_json(self, file_name):
     self.__dict__.update(
         util.unicode_to_utf8(json.load(open(file_name, 'rb'))))
Esempio n. 6
0
File: views.py Progetto: quru/qis
def make_image_response(image_wrapper, is_original, stats=None, as_attachment=None, xref=None):
    """
    Returns a Flask response object for the given image and response options,
    handles the tracking ID if there is one, and writes view statistics for the
    image.

    image_wrapper - An ImageWrapper containing the image data to return.
    is_original - Whether to count this response as a "download original" function.
                  If True, logs download statistics instead of a view.
    stats - Optional override for whether to enable or disable image statistics.
            Uses the setting in image_wrapper when None.
    as_attachment - Optional override for whether to provide the
                    Content-Disposition HTTP header (with filename).
                    Uses the setting in image_wrapper when None.
    xref - Optional external URL to call.
    """
    image_attrs = image_wrapper.attrs()

    # Process xref if there is one
    if xref:
        handle_image_xref(xref)

    # Create the HTTP response
    if _USE_SENDFILE:
        response = send_file(
            StringIO.StringIO(image_wrapper.data()),
            image_attrs.mime_type()
        )
    else:
        response = make_response(image_wrapper.data())
        response.mimetype = image_attrs.mime_type()

    # Set the browser caching headers
    _add_http_caching_headers(
        response,
        image_attrs,
        image_wrapper.last_modified_time(),
        image_wrapper.client_expiry_time()
    )

    # Set custom cache info header
    response.headers['X-From-Cache'] = str(image_wrapper.is_from_cache())

    # URL attachment param overrides what the returned object wants
    attach = as_attachment if (as_attachment is not None) else \
             image_wrapper.is_attachment()
    if is_original or attach:
        fname = image_attrs.filename(with_path=False, replace_format=True)
        fname = unicode_to_utf8(fname)
        cd_type = 'attachment' if attach else 'inline'
        response.headers['Content-Disposition'] = cd_type + '; filename="' + fname + '"'

    if app.config['DEBUG']:
        logger.debug(
            'Sending ' + str(len(image_wrapper.data())) + ' bytes for ' + str(image_attrs)
        )

    _log_stats(
        image_attrs.database_id(),
        len(image_wrapper.data()),
        is_original,
        image_wrapper.is_from_cache(),
        image_wrapper.record_stats() if stats is None else stats
    )
    return response