1. Список говнокодов пользователя american_idiot

    Всего: 3

  2. Python / Говнокод #17098

    −101

    1. 1
    self.exclude = list(set(list(self.exclude or []) + ['str1', 'str2']))

    american_idiot, 12 Ноября 2014

    Комментарии (14)
  3. Python / Говнокод #16926

    −97

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    def constant_time_compare(val1, val2):
        """
        Returns True if the two strings are equal, False otherwise.
    
        The time taken is independent of the number of characters that match.
        """
        if len(val1) != len(val2):
            return False
        result = 0
        for x, y in zip(val1, val2):
            result |= ord(x) ^ ord(y)
        return result == 0

    Django.utils.crypto в Django 1.4

    american_idiot, 24 Октября 2014

    Комментарии (36)
  4. Python / Говнокод #16916

    −106

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    def parse_check_response(response_status, response_body, service):
        """
        :param response_status: код
        :type response_status: int
    
        :param response_body: ответ
        :type response_body: HTTPResponse
    
        :param service_: определяет каким пользователям разрешена проверка (зарегестрированным или новым)
        :type service_: str
    
        Проверяет http ответ возвращаемый `` code_check``.
        Если в ответе содержится ошибка то в ``resp['error']``  и ``resp['status']``
        добавляется статус ошибки и её сообщение.
        Примеры ошибок которые могут быть в ответе:
          * Неверный код
          * Срок действия кода истёк
          * Данный код уже был использован
          * ...
        """
        if response_status != CHECK_STATUS_FOUND:
            if not response_status == CHECK_STATUS_BAD_DATA and not response_status == CHECK_STATUS_NOT_FOUND:
                raise CodeResponseException
    
            return {
                'status': response_status,
                'error': EC_ERR_NOT_VALID
            }
    
        response_body_dict = json.loads(response_body)
        resp = {'status': ERR_OK}
    
        allowed_users = response_body_dict["codeset"]["allowed_users"]
        if (
            service == 'registration' and allowed_users == REGISTERED_USERS
            or service == 'personal' and allowed_users == NEW_USERS
        ):
            resp['status'] = EC_FORBIDDEN
            resp['error'] = EC_ERR_NOT_VALID
    
        if not response_body_dict['is_valid']:
            error_code = response_body_dict['error_code']
            if error_code in EC_NOT_VALID_GROUP:
                resp['status'] = EC_NOT_VALID
                resp['error'] = EC_ERR_NOT_VALID
            elif error_code in EC_EXPIRED_GROUP:
                resp['status'] = EC_EXPIRED
                resp['error'] = EC_ERR_NOT_VALID
            elif error_code in [EC_CANCELED, EC_NOT_FOUND, EC_UNKNOWN_REGION, EC_LIMIT_EXHAUSTED, EC_FORBIDDEN]:
                resp['status'] = error_code
                resp['error'] = EC_ERR_NOT_VALID
            # If error_code == EC_FORBIDDEN we already
            # have status and error message
            elif error_code != EC_NO_ERRORS:
                resp['status'] = EC_NOT_VALID
                resp['error'] = EC_ERR_NOT_VALID
    
        resp['response_data'] = response_body
    
        return resp

    PHP-style Python

    american_idiot, 23 Октября 2014

    Комментарии (9)