Ejemplo n.º 1
0
    def test_dedent_preserve_margin_tabs(self):
        text = "  hello there\n\thow are you?"
        self.assertUnchanged(text)

        # same effect even if we have 8 spaces
        text = "        hello there\n\thow are you?"
        self.assertUnchanged(text)

        # dedent() only removes whitespace that can be uniformly removed!
        text = "\thello there\n\thow are you?"
        expect = "hello there\nhow are you?"
        self.assertEqual(expect, dedent(text))

        text = "  \thello there\n  \thow are you?"
        self.assertEqual(expect, dedent(text))

        text = "  \t  hello there\n  \t  how are you?"
        self.assertEqual(expect, dedent(text))

        text = "  \thello there\n  \t  how are you?"
        expect = "hello there\n  how are you?"
        self.assertEqual(expect, dedent(text))

        # test margin is smaller than smallest indent
        text = "  \thello there\n   \thow are you?\n \tI'm fine, thanks"
        expect = " \thello there\n  \thow are you?\n\tI'm fine, thanks"
        self.assertEqual(expect, dedent(text))
Ejemplo n.º 2
0
    def test_dedent_uneven(self):
        # Lines indented unevenly.
        text = '''\
        def foo():
            while 1:
                return foo
        '''
        expect = '''\
def foo():
    while 1:
        return foo
'''
        self.assertEqual(expect, dedent(text))

        # Uneven indentation with a blank line.
        text = "  Foo\n    Bar\n\n   Baz\n"
        expect = "Foo\n  Bar\n\n Baz\n"
        self.assertEqual(expect, dedent(text))

        # Uneven indentation with a whitespace-only line.
        text = "  Foo\n    Bar\n \n   Baz\n"
        expect = "Foo\n  Bar\n\n Baz\n"
        self.assertEqual(expect, dedent(text))

        # Uneven indentation with declining indent level,
        # requiring downward re-estimation of margin.
        text = "     Foo\n    Bar\n"  # 5 spaces, then 4
        expect = " Foo\nBar\n"
        self.assertEqual(expect, dedent(text))
Ejemplo n.º 3
0
    def test_dedent_preserve_internal_tabs(self):
        text = "  hello\tthere\n  how are\tyou?"
        expect = "hello\tthere\nhow are\tyou?"
        self.assertEqual(expect, dedent(text))

        # make sure that it preserves tabs when it's not making any
        # changes at all
        self.assertEqual(expect, dedent(expect))
Ejemplo n.º 4
0
    def test_dedent_even(self):
        # All lines indented by two spaces.
        text = "  Hello there.\n  How are ya?\n  Oh good."
        expect = "Hello there.\nHow are ya?\nOh good."
        self.assertEqual(expect, dedent(text))

        # Same, with blank lines.
        text = "  Hello there.\n\n  How are ya?\n  Oh good.\n"
        expect = "Hello there.\n\nHow are ya?\nOh good.\n"
        self.assertEqual(expect, dedent(text))

        # Now indent one of the blank lines.
        text = "  Hello there.\n  \n  How are ya?\n  Oh good.\n"
        expect = "Hello there.\n\nHow are ya?\nOh good.\n"
        self.assertEqual(expect, dedent(text))
Ejemplo n.º 5
0
def main():
    available_commands = dedent('''
    available subcommands:
    \tclean              clean files out
    \trename             rename files
    '''.expandtabs(2))
    parser = argparse.ArgumentParser(prog='ficl', description='batch file transformer.', 
        epilog=available_commands, formatter_class=RawDescriptionHelpFormatter)
    
    parser.add_argument('subcommand', type=str, help='subcommand to run')
    parser.add_argument('path', type=str, help='path to target directory')

    parser.add_argument('-v', '--verbose', 
                        action='store_true', help='increase output verbosity')
    parser.add_argument('-r', '--recursively', 
                        action='store_true', help='include subdirectories')
    parser.add_argument('-n', '--no-special-files', 
                        action='store_false', help='exclude files that start with a dot')
    parser.add_argument('-p', '--prefix', metavar='',
                        type=str, help='filename prefix')
    parser.add_argument('-t', '--postfix', metavar='',
                        type=str, help='filename postfix')

    args = parser.parse_args()

    try:
        globals()[args.subcommand](args)
    except KeyError:
        print('Unrecognized command. Use -h flag to see usage tips.')
        return
Ejemplo n.º 6
0
 def _add_enum(self, FeatureName, feature, enumObj):
     values = OrderedDict()
     for enumValObj in enumObj.values:
         values[enumValObj.name] = enumValObj.value
     enum = ArsdkEnum(enumObj.name, names=values)
     enum.__doc__ = string_from_arsdkxml(enumObj.doc)
     for enumvalue, enumvalueobj in zip(enum, enumObj.values):
         enumvalue.__doc__ = string_from_arsdkxml(enumvalueobj.doc)
     bitfield = enum._bitfield_type_
     self._enums_feature[enum] = feature.name
     self._enums_source[enum] = textwrap.dedent("""
         class {}(ArsdkEnum):
             {}
             {}
         """.format(
         enumObj.name, '"""{}"""'.format(enum.__doc__),
         "\n".join(map(lambda v: (v._name_ + " = " + str(v._value_)),
                       enum))))
     self._enums[FeatureName][enum.__name__] = enum
     self._bitfields[FeatureName][bitfield.__name__] = bitfield
     self._by_feature[feature.name][enum.__name__] = enum
     self._by_feature[feature.name][bitfield.__name__] = bitfield
     for class_name in feature.classesByName:
         prefix = class_name + "_"
         if enum.__name__.startswith(prefix):
             enum.__name__ = enum.__name__[len(prefix):]
             self._enums[FeatureName][enum.__name__] = enum
             self._by_feature[feature.name][class_name][
                 enum.__name__] = enum
             self._by_feature[feature.name][class_name][
                 bitfield.__name__] = bitfield
             break
Ejemplo n.º 7
0
 def post(self, request, *args, **kwargs):
     form = self.form_class(request.POST)
     if form.is_valid():
         response_text = textwrap.dedent('''\
             <html>
             <head>
             <title>Issue Creada</title>
             </head>
             <body bgcolor="#E6E6FA">
             ''' + form.cleaned_data['nomUsuari'] + '''
             ''' + form.cleaned_data['clauUsuari'] + '''
             </body>
             </html>
           ''')
         return HttpResponse(response_text)
     else:
         return render(request, self.template_name, {'form': form})
Ejemplo n.º 8
0
         className="four columns",
         children=[
             html.Div(
                 className="markdown-text",
                 children=[
                     dcc.Markdown(
                         children=dedent(
                             """
                             ##### What am I looking at?
 
                             This app detects human faces and proper mask wearing in images and webcam 
                             streams. Under the COVID-19 pandemic, the demand for an effective mask 
                             detection on embedded systems of limited computing capabilities has surged.
                             Trained on MobileNetV2, the app is computationally efficient to deploy to 
                             help control the spread of the disease.
                             
                             ##### More about this Dash app
 
                             The MFN Model is capable of detecting 3 scenarios: 
                             (1) incorrect mask wearing, (2) correct mask wearing and (3) no mask. 
                             The RMFD model is trained to classify 2 scenarios: 
                             (1) mask worn and (2) no mask. To learn more about 
                             the project, please visit the 
                             [project repository](https://github.com/achen353/Face-Mask-Detector).
                             """
                         )
                     )
                 ],
             ),
             html.Div(
                 className="control-element",
                 children=[
Ejemplo n.º 9
0
from textwrap3 import wrap
import textwrap3, nltk

filename = "E:/Eclipse/workspace/py27/temp111.txt"
filename2 = ("E:/Eclipse/workspace/py27/temp2.txt")
#data = file(filename).read() #print by letters
#data.sort()#AttributeError: 'str' object has no attribute 'sort'
data = file(filename).readlines()  #<type 'list'>
#file(filename).close()
for i in range(len(data)):
    print data[i]

text = "".join(data)
x = wrap(text, 60)
for i in range(len(x)):
    print(x[i])
print("--------------------1-------------------------")
for i in range(len(data)):
    dedented_text = textwrap3.dedent(data[i]).strip()
    print dedented_text
print("---------------------2------------------------")
with open(filename2, 'r') as file1:
    lines_in_file = file1.read()
    nltk_tokens = nltk.word_tokenize(lines_in_file)
    print nltk_tokens
    print("\n")
    print("Number of words:", len(nltk_tokens))
Ejemplo n.º 10
0
 def test_roundtrip_mixed(self):
     # A whitespace prefix should roundtrip with dedent
     for text in self.ROUNDTRIP_CASES:
         self.assertEqual(dedent(indent(text, ' \t  \t ')), text)
Ejemplo n.º 11
0
 def assertUnchanged(self, text):
     """assert that dedent() has no effect on 'text'"""
     self.assertEqual(text, dedent(text))
Ejemplo n.º 12
0
def formattingParagraph(text):
    """ formatting paragraph - remove space front of sentence """
    return textwrap3.dedent(text).strip()