1. Python / Говнокод #16596

    −101

    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
    class ImageAsset(Asset):
     
        def to_xml(self):  
            if self.asset_type == self.VIDEO:
                return self.videoasset.to_xml()
            element = etree.Element("imageAsset")
            if self.mask_key:
                element.set("maskId", self.mask_key)
            if self.image_x:
                element.set("imageX", str(self.image_x))
            if self.image_y:
                element.set("imageY", str(self.image_y))
            if self.image_width:
                element.set("imageWidth", str(self.image_width))
            if self.image_height:
                element.set("imageHeight", str(self.image_height))
            self.set_xml_attrs(element)
            return element
    
    class VideoAsset(ImageAsset):
     
        def to_xml(self):  
            element = etree.Element("videoAsset")
            if self.mask_key:
                element.set("maskId", self.mask_key)
            if self.image_x:
                element.set("imageX", str(self.image_x))
            if self.image_y:
                element.set("imageY", str(self.image_y))
            if self.image_width:
                element.set("imageWidth", str(self.image_width))
            if self.image_height:
                element.set("imageHeight", str(self.image_height))
            self.set_xml_attrs(element)
            return element

    Полиморфизм это вам не шубу в трусы заправлять!

    wvxvw, 26 Августа 2014

    Комментарии (0)
  2. Python / Говнокод #16528

    −88

    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
    class DataModel(dict):
        _SCHEME_VERSION = 0
        _transform = dict()
        _additional = dict()
        _migration = None
    
        def __init__(self, data=None, network=None, conf=None):
            if network and conf:
                _scheme = map(lambda x: x.strip(), conf.get(network).keys())
                _map =  map(lambda x: x.strip(), conf.get(network).values())
    
                self._scheme = int(conf._scheme)
    
                map(lambda x: setattr(self, x[0], data.get(x[1], None)),
                    [(_scheme[i], _map[i]) for i in xrange(0,len(_map))])
    
                if self._transform.get(network, False):
                    map(lambda x: setattr(self, x, getattr(self._transform[network], x)(getattr(self, x))),
                        [k for k in self._transform[network].__dict__.keys() if not k.startswith('__')])
            else:
                dict.__init__(self, data)
    
            if self.get('_scheme', 0)<self._SCHEME_VERSION and self._migration is not None:
                k = [int(k.split('_')[1]) for k in self._migration.__dict__.keys() if not k.startswith('__')]
                k.sort()
                [k.remove(x) for x in k if x<=self.get('_scheme', 0)]
                map(lambda x: getattr(self._migration, 'scheme_%s' % x)(self), k)
                self._scheme = self._SCHEME_VERSION
    
            map(lambda x: setattr(self, x, getattr(self._additional, x)(self)),
                [k for k in self._additional.__dict__.keys() if not k.startswith('__')])
    
        def __setattr__(self, name, val):
            if name in self.__dict__:
                self.__dict__[name]= val
            else:
                self[name] = val
    
        def __getattr__(self, name):
            if name in self.__dict__:
                return self.__dict__[name]
            else:
                return self[name]

    Mongo migration, written in Python, for human beings.

    vaxxxa, 14 Августа 2014

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

    −89

    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
    6. 6
    7. 7
    8. 8
    9. 9
    def mayakovsky(string):
        splitted = string.split('\n')
        l = [splitted[0]]
        lastSpaces = 0
        
        for i in range(1, len(splitted)):
            l += [' '*(lastSpaces + len(splitted[i - 1]) + 1) + splitted[i]]
            lastSpaces += len(splitted[i - 1]) + 1
        return '\n'.join(l)

    Лол.

    gost, 12 Августа 2014

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

    −102

    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
    def _registerCommands(self, mapping=None, dataMapping=None, commandUpdates=None, dataUpdates=None):
                ...
            for (cmdName, cmdClass) in cMap.iteritems():
                ...
                self._setCommand(cmdObj)
    
        def _setCommand(self, cmdObj):
            if cmdObj.__class__.__name__.find("_") != -1:
                name = unicode(cmdObj.__class__.__name__.split("_", 1)[1])
            else:
                name = unicode(cmdObj.__class__.__name__).lower()
            setattr(self, name.lower(), cmdObj)
            ...

    Fedora, pykickstart. Посоны регистрируют команды в парсере...

    solo1h, 25 Июля 2014

    Комментарии (0)
  5. Python / Говнокод #16390

    −94

    1. 1
    list(zip_longest(*[iter(('0'+str(bin(int(time.time())))[2:]).replace('0', '_').replace('1', '*'))]*4))

    увидел у в скрипте на подобии archey3

    rob_vigna, 20 Июля 2014

    Комментарии (18)
  6. Python / Говнокод #16358

    −422

    1. 1
    2. 2
    3. 3
    4. 4
    import math
    print math.pow(2,64) //1.84467440737e+19
    print pow(2,64)         //18446744073709551616
    print 2**64               //18446744073709551616

    http://ideone.com/kmGrBa
    http://ideone.com/otSgCP

    Говно в обоих версиях калькулятора.

    3.14159265, 16 Июля 2014

    Комментарии (58)
  7. Python / Говнокод #16298

    −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
    13. 13
    def load_library():
        requests = []
        class Handler(object):
            pass
        Handler.errors = 0
        def handler(request):
            print "failed to load: %s" % request.url
            Handler.errors += 1
        for node in res:
            for url in filter(lambda x: x, map(node.prop, names)):
                requests.append(grequests.get(url))
        gmap(tuple(requests), exception_handler = handler)
        print "total failures: %s" % Handler.errors

    Ля-ля-ля, замыкания!

    wvxvw, 10 Июля 2014

    Комментарии (211)
  8. Python / Говнокод #16250

    −96

    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
    import random
    
    while 0<1:
        inn_d=str(random.randint(100000000,999999999))
        a=int(inn_d[:1])*2
        b=int(inn_d[1:2])*4
        c=int(inn_d[2:3])*10
        d=int(inn_d[3:4])*3
        e=int(inn_d[4:5])*5
        f=int(inn_d[5:6])*9
        g=int(inn_d[6:7])*4
        l=int(inn_d[7:8])*6
        m=int(inn_d[8:9])*8
        x=a+b+c+d+e+f+g+l+m
        y=x%11
        if y%11==10:
            y=0
        print str(inn_d)+str(y)

    Такой вот генератор ИННов

    pl7ofit, 28 Июня 2014

    Комментарии (11)
  9. Python / Говнокод #16203

    −100

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    #Было
    def extract_brand(x):
                    x = x[0].lower()
                    for brand in brands:
                        if x.count(brand):
                            return brand
    il.brand_out = extract_brand
    
    #Стало после кодревью
    il.brand_in = lambda x: [brand for brand in brands if brand.lower() in x[0].lower()]

    Кто то смог прочитать второй вариант?

    kyzi007, 22 Июня 2014

    Комментарии (90)
  10. Python / Говнокод #16145

    −99

    1. 1
    2. 2
    3. 3
    def dict_to_tuple(d):
        """Converts an ordered dict into a tuple."""
        return tuple(dict_to_list(d))

    hugr, 11 Июня 2014

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